use of com.microsoft.azure.mobile.ingestion.models.Log 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);
}
use of com.microsoft.azure.mobile.ingestion.models.Log 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.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);
Analytics.trackPage(generateString(257, '*'), null);
verify(channel, never()).enqueue(any(Log.class), anyString());
reset(channel);
Analytics.trackPage(generateString(256, '*'), 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(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 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());
}
use of com.microsoft.azure.mobile.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class SessionTrackerTest method ignoreStartService.
@Test
public void ignoreStartService() {
Log startServiceLog = spy(new StartServiceLog());
mSessionTracker.onEnqueuingLog(startServiceLog, TEST_GROUP);
verify(mChannel, never()).enqueue(any(Log.class), anyString());
verify(startServiceLog, never()).setSid(any(UUID.class));
}
use of com.microsoft.azure.mobile.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class SessionTrackerTest method stayOnFirstScreenForLong.
@Test
public void stayOnFirstScreenForLong() {
/* Application is in foreground, send a log, verify decoration with a new session. */
mSessionTracker.onActivityResumed();
UUID expectedSid;
StartSessionLog expectedStartSessionLog = new StartSessionLog();
{
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertNotNull(log.getSid());
expectedSid = log.getSid();
expectedStartSessionLog.setSid(expectedSid);
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* Wait a long time. */
spendTime(30000);
/* Go to another activity. */
mSessionTracker.onActivityPaused();
spendTime(2);
mSessionTracker.onActivityResumed();
/* Send a log again: session must be reused. */
{
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
}
use of com.microsoft.azure.mobile.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class SessionTrackerTest method longSessionStartingFromBackground.
@Test
public void longSessionStartingFromBackground() {
/* Application is in background, send a log, verify decoration. */
UUID firstSid;
long firstSessionTime = mMockTime;
UUID expectedSid;
StartSessionLog expectedStartSessionLog = new StartSessionLog();
{
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertNotNull(log.getSid());
firstSid = expectedSid = log.getSid();
expectedStartSessionLog.setSid(expectedSid);
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* Verify session reused for second log. */
{
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* No usage from background for a long time: new session. */
{
spendTime(30000);
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertNotEquals(expectedSid, log.getSid());
expectedSid = log.getSid();
expectedStartSessionLog.setSid(expectedSid);
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* App comes to foreground and sends a log, still session. */
{
mSessionTracker.onActivityResumed();
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* We are in foreground, even after timeout a log is still in session. */
{
spendTime(30000);
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* Switch to another activity and send a log, still session. */
{
spendTime(2);
mSessionTracker.onActivityPaused();
spendTime(2);
mSessionTracker.onActivityResumed();
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* We are in foreground, even after timeout a log is still in session. */
{
spendTime(30000);
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* Background for a short time and send log: still in session. */
{
spendTime(2);
mSessionTracker.onActivityPaused();
spendTime(2);
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(expectedSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* Background for a long time but correlating a log to first session: should not trigger new session. */
{
Log log = newEvent();
log.setToffset(firstSessionTime + 20);
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertEquals(firstSid, log.getSid());
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* Background for a long time and coming back to foreground: new session. */
{
spendTime(30000);
mSessionTracker.onActivityResumed();
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertNotEquals(expectedSid, log.getSid());
expectedSid = log.getSid();
expectedStartSessionLog.setSid(expectedSid);
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
/* Background for a long time sending a log: new session. */
{
mSessionTracker.onActivityPaused();
spendTime(30000);
Log log = newEvent();
mSessionTracker.onEnqueuingLog(log, TEST_GROUP);
mSessionTracker.onEnqueuingLog(expectedStartSessionLog, TEST_GROUP);
assertNotEquals(expectedSid, log.getSid());
expectedSid = log.getSid();
expectedStartSessionLog.setSid(expectedSid);
verify(mChannel).enqueue(expectedStartSessionLog, TEST_GROUP);
}
}
Aggregations