use of com.microsoft.azure.mobile.analytics.ingestion.models.EventLog in project mobile-center-sdk-android by Microsoft.
the class AnalyticsAndroidTest method testAnalyticsListener.
@Test
public void testAnalyticsListener() {
AnalyticsListener analyticsListener = mock(AnalyticsListener.class);
Analytics.setListener(analyticsListener);
Channel channel = mock(Channel.class);
Analytics.getInstance().onStarted(sContext, "", channel);
Analytics.trackEvent("event");
/* First process: enqueue log but network is down... */
final EventLog log = new EventLog();
log.setId(randomUUID());
log.setName("name");
Analytics.unsetInstance();
Analytics.setListener(analyticsListener);
verify(channel).enqueue(any(Log.class), anyString());
verifyNoMoreInteractions(analyticsListener);
/* Second process: sending succeeds. */
final AtomicReference<Channel.GroupListener> groupListener = new AtomicReference<>();
channel = mock(Channel.class);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
Channel.GroupListener listener = (Channel.GroupListener) invocationOnMock.getArguments()[4];
groupListener.set(listener);
listener.onBeforeSending(log);
return null;
}
}).when(channel).addGroup(anyString(), anyInt(), anyInt(), anyInt(), any(Channel.GroupListener.class));
Analytics.unsetInstance();
Analytics.setListener(analyticsListener);
Analytics.getInstance().onStarted(sContext, "", channel);
assertNotNull(groupListener.get());
groupListener.get().onSuccess(log);
verify(channel, never()).enqueue(any(Log.class), anyString());
verify(analyticsListener).onBeforeSending(any(EventLog.class));
verify(analyticsListener).onSendingSucceeded(any(EventLog.class));
verifyNoMoreInteractions(analyticsListener);
}
use of com.microsoft.azure.mobile.analytics.ingestion.models.EventLog in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method testTrackEvent.
@Test
public void testTrackEvent() {
Analytics analytics = Analytics.getInstance();
Channel channel = mock(Channel.class);
analytics.onStarted(mock(Context.class), "", channel);
Analytics.trackEvent(null, null);
verify(channel, never()).enqueue(any(Log.class), anyString());
reset(channel);
Analytics.trackEvent("", null);
verify(channel, never()).enqueue(any(Log.class), anyString());
reset(channel);
Analytics.trackEvent(" ", null);
verify(channel, times(1)).enqueue(any(Log.class), anyString());
reset(channel);
Analytics.trackEvent(generateString(257, '*'), null);
verify(channel, never()).enqueue(any(Log.class), anyString());
reset(channel);
Analytics.trackEvent(generateString(256, '*'), null);
verify(channel, times(1)).enqueue(any(Log.class), anyString());
reset(channel);
Analytics.trackEvent("eventName", new HashMap<String, String>() {
{
put(null, null);
put("", null);
put(generateString(65, '*'), null);
put("1", null);
put("2", generateString(65, '*'));
}
});
verify(channel, times(1)).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof EventLog) {
EventLog eventLog = (EventLog) item;
return eventLog.getProperties().size() == 0;
}
return false;
}
}), anyString());
reset(channel);
final String validMapItem = "valid";
Analytics.trackEvent("eventName", 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 EventLog) {
EventLog eventLog = (EventLog) item;
return eventLog.getProperties().size() == 5;
}
return false;
}
}), anyString());
}
use of com.microsoft.azure.mobile.analytics.ingestion.models.EventLog in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method trackEvent.
@Test
public void trackEvent() {
Analytics analytics = Analytics.getInstance();
Channel channel = mock(Channel.class);
analytics.onStarted(mock(Context.class), "", channel);
final String name = "testEvent";
final HashMap<String, String> properties = new HashMap<>();
properties.put("a", "b");
Analytics.trackEvent(name, properties);
verify(channel).enqueue(argThat(new ArgumentMatcher<Log>() {
@Override
public boolean matches(Object item) {
if (item instanceof EventLog) {
EventLog eventLog = (EventLog) item;
return name.equals(eventLog.getName()) && properties.equals(eventLog.getProperties()) && eventLog.getId() != null;
}
return false;
}
}), eq(analytics.getGroupName()));
}
use of com.microsoft.azure.mobile.analytics.ingestion.models.EventLog in project mobile-center-sdk-android by Microsoft.
the class Analytics method queueEvent.
/**
* Send an event.
*
* @param name event name.
* @param properties optional properties.
*/
private synchronized void queueEvent(String name, Map<String, String> properties) {
if (isInactive())
return;
EventLog eventLog = new EventLog();
eventLog.setId(UUIDUtils.randomUUID());
eventLog.setName(name);
eventLog.setProperties(properties);
mChannel.enqueue(eventLog, ANALYTICS_GROUP);
}
use of com.microsoft.azure.mobile.analytics.ingestion.models.EventLog in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTest method testGetChannelListener.
@Test
public void testGetChannelListener() throws IOException, ClassNotFoundException {
final EventLog testEventLog = new EventLog();
testEventLog.setId(UUID.randomUUID());
testEventLog.setName("name");
final Exception testException = new Exception("test exception message");
Analytics.setListener(new AnalyticsListener() {
@Override
public void onBeforeSending(Log log) {
assertEquals(log, testEventLog);
}
@Override
public void onSendingSucceeded(Log log) {
assertEquals(log, testEventLog);
}
@Override
public void onSendingFailed(Log log, Exception e) {
assertEquals(log, testEventLog);
assertEquals(e, testException);
}
});
Channel.GroupListener listener = Analytics.getInstance().getChannelListener();
listener.onBeforeSending(testEventLog);
listener.onSuccess(testEventLog);
listener.onFailure(testEventLog, testException);
}
Aggregations