use of com.microsoft.appcenter.analytics.ingestion.models.PageLog in project mobile-center-sdk-android by Microsoft.
the class AnalyticsSerializerTest method someBatch.
@Test
public void someBatch() throws JSONException {
LogContainer expectedContainer = new LogContainer();
Device device = new Device();
device.setSdkName("appcenter.android");
device.setSdkVersion("1.2.3");
device.setModel("S5");
device.setOemName("HTC");
device.setOsName("Android");
device.setOsVersion("4.0.3");
device.setOsBuild("LMY47X");
device.setOsApiLevel(15);
device.setLocale("en_US");
device.setTimeZoneOffset(120);
device.setScreenSize("800x600");
device.setAppVersion("3.2.1");
device.setAppBuild("42");
List<Log> logs = new ArrayList<>();
{
StartSessionLog startSessionLog = new StartSessionLog();
startSessionLog.setTimestamp(new Date());
logs.add(startSessionLog);
}
expectedContainer.setLogs(logs);
{
PageLog pageLog = new PageLog();
pageLog.setTimestamp(new Date());
pageLog.setName("home");
logs.add(pageLog);
}
{
PageLog pageLog = new PageLog();
pageLog.setTimestamp(new Date());
pageLog.setName("settings");
pageLog.setProperties(new HashMap<String, String>() {
{
put("from", "home_menu");
put("orientation", "portrait");
}
});
logs.add(pageLog);
}
{
EventLog eventLog = new EventLog();
eventLog.setTimestamp(new Date());
eventLog.setId(UUIDUtils.randomUUID());
eventLog.setName("subscribe");
logs.add(eventLog);
}
{
EventLog eventLog = new EventLog();
eventLog.setTimestamp(new Date());
eventLog.setId(UUIDUtils.randomUUID());
eventLog.setName("click");
eventLog.setProperties(new HashMap<String, String>() {
{
put("x", "1");
put("y", "2");
}
});
logs.add(eventLog);
}
UUID sid = UUIDUtils.randomUUID();
for (Log log : logs) {
log.setSid(sid);
log.setDevice(device);
}
LogSerializer serializer = new DefaultLogSerializer();
serializer.addLogFactory(StartSessionLog.TYPE, new StartSessionLogFactory());
serializer.addLogFactory(PageLog.TYPE, new PageLogFactory());
serializer.addLogFactory(EventLog.TYPE, new EventLogFactory());
String payload = serializer.serializeContainer(expectedContainer);
android.util.Log.v(TAG, payload);
LogContainer actualContainer = serializer.deserializeContainer(payload);
Assert.assertEquals(expectedContainer, actualContainer);
}
use of com.microsoft.appcenter.analytics.ingestion.models.PageLog in project mobile-center-sdk-android by Microsoft.
the class Analytics method queuePage.
/**
* Enqueue page log now.
*/
@WorkerThread
private void queuePage(String name, Map<String, String> properties) {
PageLog pageLog = new PageLog();
pageLog.setName(name);
pageLog.setProperties(properties);
mChannel.enqueue(pageLog, ANALYTICS_GROUP);
}
use of com.microsoft.appcenter.analytics.ingestion.models.PageLog in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method testTrackPage.
@Test
public void testTrackPage() {
Analytics analytics = Analytics.getInstance();
Channel channel = mock(Channel.class);
analytics.onStarting(mAppCenterHandler);
analytics.onStarted(mock(Context.class), "", channel);
Analytics.trackPage(null, null);
verify(channel, never()).enqueue(any(Log.class), anyString());
reset(channel);
Analytics.trackPage("", null);
verify(channel, never()).enqueue(any(Log.class), anyString());
reset(channel);
Analytics.trackPage(" ", null);
verify(channel, times(1)).enqueue(any(Log.class), anyString());
reset(channel);
final String maxName = generateString(Analytics.MAX_NAME_LENGTH, '*');
Analytics.trackPage(maxName + "*", null);
verify(channel, times(1)).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof PageLog) {
PageLog pageLog = (PageLog) item;
return pageLog.getName().equals(maxName) && pageLog.getProperties() == null;
}
return false;
}
}), anyString());
reset(channel);
Analytics.trackPage(maxName, null);
verify(channel, times(1)).enqueue(any(Log.class), anyString());
reset(channel);
Analytics.trackPage("pageName", new HashMap<String, String>() {
{
put(null, null);
put("", null);
put(generateString(Analytics.MAX_PROPERTY_ITEM_LENGTH + 1, '*'), null);
put("1", null);
}
});
verify(channel, times(1)).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof PageLog) {
PageLog pageLog = (PageLog) item;
return pageLog.getProperties().size() == 0;
}
return false;
}
}), anyString());
reset(channel);
final String validMapItem = "valid";
Analytics.trackPage("pageName", new HashMap<String, String>() {
{
for (int i = 0; i < 10; i++) {
put(validMapItem + i, validMapItem);
}
}
});
verify(channel, times(1)).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof PageLog) {
PageLog pageLog = (PageLog) item;
return pageLog.getProperties().size() == 5;
}
return false;
}
}), anyString());
reset(channel);
final String longerMapItem = generateString(Analytics.MAX_PROPERTY_ITEM_LENGTH + 1, '*');
Analytics.trackPage("pageName", new HashMap<String, String>() {
{
put(longerMapItem, longerMapItem);
}
});
verify(channel, times(1)).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof PageLog) {
PageLog pageLog = (PageLog) item;
if (pageLog.getProperties().size() == 1) {
Map.Entry<String, String> entry = pageLog.getProperties().entrySet().iterator().next();
String truncatedMapItem = generateString(Analytics.MAX_PROPERTY_ITEM_LENGTH, '*');
return entry.getKey().length() == Analytics.MAX_PROPERTY_ITEM_LENGTH && entry.getValue().length() == Analytics.MAX_PROPERTY_ITEM_LENGTH;
}
}
return false;
}
}), anyString());
}
use of com.microsoft.appcenter.analytics.ingestion.models.PageLog in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method activityResumed.
private void activityResumed(final String expectedName, android.app.Activity activity) {
/*
* Before start, calling onActivityResume is ignored.
* In reality it never happens, it means someone is messing with internals directly.
*/
Analytics analytics = Analytics.getInstance();
analytics.onActivityResumed(new Activity());
assertNull(analytics.getCurrentActivity());
verifyStatic();
AppCenterLog.error(anyString(), anyString());
analytics.onActivityPaused(new Activity());
verifyStatic(times(2));
AppCenterLog.error(anyString(), anyString());
/* Start. */
Channel channel = mock(Channel.class);
analytics.onStarting(mAppCenterHandler);
analytics.onStarted(mock(Context.class), "", channel);
/* Test resume/pause. */
analytics.onActivityResumed(activity);
analytics.onActivityPaused(activity);
verify(channel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof PageLog) {
PageLog pageLog = (PageLog) item;
return expectedName.equals(pageLog.getName());
}
return false;
}
}), eq(analytics.getGroupName()));
}
use of com.microsoft.appcenter.analytics.ingestion.models.PageLog in project mobile-center-sdk-android by Microsoft.
the class SasquatchAnalyticsListener method onSendingSucceeded.
@Override
public void onSendingSucceeded(com.microsoft.appcenter.ingestion.models.Log log) {
String message = null;
if (log instanceof EventLog) {
message = String.format("%s\nName: %s", mContext.getString(R.string.event_sent_succeeded), ((EventLog) log).getName());
} else if (log instanceof PageLog) {
message = String.format("%s\nName: %s", mContext.getString(R.string.page_sent_succeeded), ((PageLog) log).getName());
}
if (message != null) {
if (((LogWithProperties) log).getProperties() != null) {
message += String.format("\nProperties: %s", new JSONObject(((LogWithProperties) log).getProperties()).toString());
}
Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
}
analyticsIdlingResource.decrement();
}
Aggregations