Search in sources :

Example 6 with PageLog

use of com.microsoft.appcenter.analytics.ingestion.models.PageLog in project mobile-center-sdk-android by Microsoft.

the class AnalyticsTest method disableAutomaticPageTracking.

@Test
public void disableAutomaticPageTracking() {
    Analytics analytics = Analytics.getInstance();
    assertTrue(Analytics.isAutoPageTrackingEnabled());
    Analytics.setAutoPageTrackingEnabled(false);
    assertFalse(Analytics.isAutoPageTrackingEnabled());
    Channel channel = mock(Channel.class);
    analytics.onStarting(mAppCenterHandler);
    analytics.onStarted(mock(Context.class), "", channel);
    analytics.onActivityResumed(new MyActivity());
    verify(channel).enqueue(argThat(new ArgumentMatcher<Log>() {

        @Override
        public boolean matches(Object argument) {
            return argument instanceof StartSessionLog;
        }
    }), anyString());
    verify(channel, never()).enqueue(argThat(new ArgumentMatcher<Log>() {

        @Override
        public boolean matches(Object argument) {
            return argument instanceof PageLog;
        }
    }), anyString());
    Analytics.setAutoPageTrackingEnabled(true);
    assertTrue(Analytics.isAutoPageTrackingEnabled());
    analytics.onActivityResumed(new SomeScreen());
    verify(channel).enqueue(argThat(new ArgumentMatcher<Log>() {

        @Override
        public boolean matches(Object item) {
            if (item instanceof PageLog) {
                PageLog pageLog = (PageLog) item;
                return "SomeScreen".equals(pageLog.getName());
            }
            return false;
        }
    }), eq(analytics.getGroupName()));
}
Also used : Context(android.content.Context) StartSessionLog(com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog) PageLog(com.microsoft.appcenter.analytics.ingestion.models.PageLog) Channel(com.microsoft.appcenter.channel.Channel) ArgumentMatcher(org.mockito.ArgumentMatcher) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with PageLog

use of com.microsoft.appcenter.analytics.ingestion.models.PageLog in project mobile-center-sdk-android by Microsoft.

the class AnalyticsTest method startSessionAfterUserApproval.

@Test
public void startSessionAfterUserApproval() {
    /*
         * Disable analytics while in background to set up the initial condition
         * simulating the opt-in use case.
         */
    Analytics analytics = Analytics.getInstance();
    Channel channel = mock(Channel.class);
    analytics.onStarting(mAppCenterHandler);
    analytics.onStarted(mock(Context.class), "", channel);
    Analytics.setEnabled(false);
    /* App in foreground: no log yet, we are disabled. */
    analytics.onActivityResumed(new Activity());
    verify(channel, never()).enqueue(any(Log.class), eq(analytics.getGroupName()));
    /* Enable: start session sent retroactively. */
    Analytics.setEnabled(true);
    verify(channel).enqueue(argThat(new ArgumentMatcher<Log>() {

        @Override
        public boolean matches(Object argument) {
            return argument instanceof StartSessionLog;
        }
    }), eq(analytics.getGroupName()));
    verify(channel).enqueue(argThat(new ArgumentMatcher<Log>() {

        @Override
        public boolean matches(Object argument) {
            return argument instanceof PageLog;
        }
    }), eq(analytics.getGroupName()));
    /* Go background. */
    analytics.onActivityPaused(new Activity());
    /* Disable/enable: nothing happens on background. */
    Analytics.setEnabled(false);
    Analytics.setEnabled(true);
    /* No additional log. */
    verify(channel, times(2)).enqueue(any(Log.class), eq(analytics.getGroupName()));
}
Also used : Context(android.content.Context) StartSessionLog(com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog) PageLog(com.microsoft.appcenter.analytics.ingestion.models.PageLog) EventLog(com.microsoft.appcenter.analytics.ingestion.models.EventLog) Log(com.microsoft.appcenter.ingestion.models.Log) AppCenterLog(com.microsoft.appcenter.utils.AppCenterLog) StartSessionLog(com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog) PageLog(com.microsoft.appcenter.analytics.ingestion.models.PageLog) Channel(com.microsoft.appcenter.channel.Channel) ArgumentMatcher(org.mockito.ArgumentMatcher) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

PageLog (com.microsoft.appcenter.analytics.ingestion.models.PageLog)7 Context (android.content.Context)4 EventLog (com.microsoft.appcenter.analytics.ingestion.models.EventLog)4 StartSessionLog (com.microsoft.appcenter.analytics.ingestion.models.StartSessionLog)4 Channel (com.microsoft.appcenter.channel.Channel)4 Test (org.junit.Test)4 ArgumentMatcher (org.mockito.ArgumentMatcher)4 Log (com.microsoft.appcenter.ingestion.models.Log)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 AppCenterLog (com.microsoft.appcenter.utils.AppCenterLog)2 HashMap (java.util.HashMap)2 WorkerThread (android.support.annotation.WorkerThread)1 EventLogFactory (com.microsoft.appcenter.analytics.ingestion.models.json.EventLogFactory)1 PageLogFactory (com.microsoft.appcenter.analytics.ingestion.models.json.PageLogFactory)1 StartSessionLogFactory (com.microsoft.appcenter.analytics.ingestion.models.json.StartSessionLogFactory)1 Device (com.microsoft.appcenter.ingestion.models.Device)1 LogContainer (com.microsoft.appcenter.ingestion.models.LogContainer)1 LogWithProperties (com.microsoft.appcenter.ingestion.models.LogWithProperties)1 DefaultLogSerializer (com.microsoft.appcenter.ingestion.models.json.DefaultLogSerializer)1 LogSerializer (com.microsoft.appcenter.ingestion.models.json.LogSerializer)1