use of com.microsoft.azure.mobile.analytics.ingestion.models.EventLog 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("mobilecenter.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<>();
{
logs.add(new StartSessionLog());
}
expectedContainer.setLogs(logs);
{
PageLog pageLog = new PageLog();
pageLog.setName("home");
logs.add(pageLog);
}
{
PageLog pageLog = new PageLog();
pageLog.setName("settings");
pageLog.setProperties(new HashMap<String, String>() {
{
put("from", "home_menu");
put("orientation", "portrait");
}
});
logs.add(pageLog);
}
{
EventLog eventLog = new EventLog();
eventLog.setId(UUIDUtils.randomUUID());
eventLog.setName("subscribe");
logs.add(eventLog);
}
{
EventLog eventLog = new EventLog();
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.azure.mobile.analytics.ingestion.models.EventLog in project mobile-center-sdk-android by Microsoft.
the class MainActivity method getAnalyticsListener.
private AnalyticsListener getAnalyticsListener() {
return new AnalyticsListener() {
@Override
public void onBeforeSending(com.microsoft.azure.mobile.ingestion.models.Log log) {
if (log instanceof EventLog) {
Toast.makeText(MainActivity.this, R.string.event_before_sending, Toast.LENGTH_SHORT).show();
} else if (log instanceof PageLog) {
Toast.makeText(MainActivity.this, R.string.page_before_sending, Toast.LENGTH_SHORT).show();
}
analyticsIdlingResource.increment();
}
@Override
public void onSendingFailed(com.microsoft.azure.mobile.ingestion.models.Log log, Exception e) {
String message = null;
if (log instanceof EventLog) {
message = getString(R.string.event_sent_failed);
} else if (log instanceof PageLog) {
message = getString(R.string.page_sent_failed);
}
if (message != null) {
message = String.format("%s\nException: %s", message, e.toString());
Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
}
analyticsIdlingResource.decrement();
}
@Override
public void onSendingSucceeded(com.microsoft.azure.mobile.ingestion.models.Log log) {
String message = null;
if (log instanceof EventLog) {
message = String.format("%s\nName: %s", getString(R.string.event_sent_succeeded), ((EventLog) log).getName());
} else if (log instanceof PageLog) {
message = String.format("%s\nName: %s", 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(MainActivity.this, message, Toast.LENGTH_SHORT).show();
}
analyticsIdlingResource.decrement();
}
};
}
use of com.microsoft.azure.mobile.analytics.ingestion.models.EventLog in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method testAnalyticsListenerNull.
@Test
public void testAnalyticsListenerNull() {
AnalyticsListener analyticsListener = mock(AnalyticsListener.class);
Analytics.setListener(analyticsListener);
Analytics.setListener(null);
final EventLog testEventLog = new EventLog();
testEventLog.setId(UUID.randomUUID());
testEventLog.setName("name");
final Exception testException = new Exception("test exception message");
Channel.GroupListener listener = Analytics.getInstance().getChannelListener();
listener.onBeforeSending(testEventLog);
listener.onSuccess(testEventLog);
listener.onFailure(testEventLog, testException);
verify(analyticsListener, never()).onBeforeSending(any(EventLog.class));
verify(analyticsListener, never()).onSendingSucceeded(any(EventLog.class));
verify(analyticsListener, never()).onSendingFailed(any(EventLog.class), any(Exception.class));
}
use of com.microsoft.azure.mobile.analytics.ingestion.models.EventLog in project mobile-center-sdk-android by Microsoft.
the class SessionTrackerTest method newEvent.
@NonNull
private static EventLog newEvent() {
EventLog eventLog = new EventLog();
eventLog.setId(UUID.randomUUID());
eventLog.setName("test");
return eventLog;
}
Aggregations