Search in sources :

Example 16 with CommonSchemaEventLog

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

the class PropertyConfiguratorTest method defaultTargetIsNotReturnedFromGetTransmissionTarget.

@Test
public void defaultTargetIsNotReturnedFromGetTransmissionTarget() {
    /* Start the application with a token. */
    Analytics analytics = Analytics.getInstance();
    analytics.onStarting(mAppCenterHandler);
    String defaultToken = "test";
    analytics.onStarted(mock(Context.class), mChannel, null, defaultToken, true);
    /* Create the test target with the same default token. */
    AnalyticsTransmissionTarget target = Analytics.getTransmissionTarget(defaultToken);
    /* Verify it's not the same instance. */
    assertNotSame(target, analytics.mDefaultTransmissionTarget);
    /* Set a Part A property on the target. */
    target.getPropertyConfigurator().setAppName("someName");
    /* Simulate what the pipeline does to convert from App Center to Common Schema. */
    CommonSchemaLog log = new CommonSchemaEventLog();
    log.setExt(new Extensions());
    log.getExt().setApp(new AppExtension());
    log.getExt().setUser(new UserExtension());
    log.addTransmissionTarget("test");
    log.setTag(target);
    /* When the callback is called on the default target. */
    analytics.mDefaultTransmissionTarget.getPropertyConfigurator().onPreparingLog(log, "groupName");
    /* Then the log is not modified. */
    assertNull(log.getExt().getApp().getName());
    /* When the callback is called on the returned target. */
    target.getPropertyConfigurator().onPreparingLog(log, "groupName");
    /* Check the property is added to the log. */
    assertEquals("someName", log.getExt().getApp().getName());
}
Also used : Context(android.content.Context) CommonSchemaLog(com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog) AppExtension(com.microsoft.appcenter.ingestion.models.one.AppExtension) UserExtension(com.microsoft.appcenter.ingestion.models.one.UserExtension) Matchers.anyString(org.mockito.Matchers.anyString) CommonSchemaEventLog(com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog) Extensions(com.microsoft.appcenter.ingestion.models.one.Extensions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with CommonSchemaEventLog

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

the class AnalyticsTransmissionTargetTest method registerCallbackWhenDisabledWorks.

@Test
public void registerCallbackWhenDisabledWorks() {
    /* Simulate disabling and background thread. */
    Analytics analytics = Analytics.getInstance();
    AppCenterHandler handler = mock(AppCenterHandler.class);
    ArgumentCaptor<Runnable> backgroundRunnable = ArgumentCaptor.forClass(Runnable.class);
    ArgumentCaptor<Runnable> disabledRunnable = ArgumentCaptor.forClass(Runnable.class);
    doNothing().when(handler).post(backgroundRunnable.capture(), disabledRunnable.capture());
    analytics.onStarting(handler);
    analytics.onStarted(mock(Context.class), mChannel, null, "test", true);
    /* Disable. */
    Analytics.setEnabled(false);
    backgroundRunnable.getValue().run();
    /* Add authentication provider while disabled. */
    AuthenticationProvider.TokenProvider tokenProvider = mock(AuthenticationProvider.TokenProvider.class);
    AuthenticationProvider authenticationProvider = spy(new AuthenticationProvider(AuthenticationProvider.Type.MSA_COMPACT, "key1", tokenProvider));
    AnalyticsTransmissionTarget.addAuthenticationProvider(authenticationProvider);
    /* Unlock command. */
    disabledRunnable.getValue().run();
    /* Verify update while disabled. */
    assertEquals(authenticationProvider, AnalyticsTransmissionTarget.sAuthenticationProvider);
    verify(authenticationProvider).acquireTokenAsync();
    /* Enable. */
    Analytics.setEnabled(true);
    disabledRunnable.getValue().run();
    /* Call prepare log. */
    ProtocolExtension protocol = new ProtocolExtension();
    Extensions ext = new Extensions();
    ext.setProtocol(protocol);
    CommonSchemaLog log = new CommonSchemaEventLog();
    log.setExt(ext);
    AnalyticsTransmissionTarget.getChannelListener().onPreparingLog(log, "test");
    /* Verify log. */
    assertEquals(Collections.singletonList(authenticationProvider.getTicketKeyHash()), protocol.getTicketKeys());
    /* And that we check expiry. */
    verify(authenticationProvider).checkTokenExpiry();
}
Also used : Context(android.content.Context) AppCenterHandler(com.microsoft.appcenter.AppCenterHandler) ProtocolExtension(com.microsoft.appcenter.ingestion.models.one.ProtocolExtension) CommonSchemaLog(com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog) CommonSchemaEventLog(com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog) Extensions(com.microsoft.appcenter.ingestion.models.one.Extensions) Test(org.junit.Test)

Aggregations

CommonSchemaEventLog (com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog)17 CommonSchemaLog (com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog)16 Test (org.junit.Test)16 Extensions (com.microsoft.appcenter.ingestion.models.one.Extensions)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 UserExtension (com.microsoft.appcenter.ingestion.models.one.UserExtension)10 AppExtension (com.microsoft.appcenter.ingestion.models.one.AppExtension)9 Context (android.content.Context)5 AppCenterHandler (com.microsoft.appcenter.AppCenterHandler)4 ContentResolver (android.content.ContentResolver)3 EventLog (com.microsoft.appcenter.analytics.ingestion.models.EventLog)3 DeviceExtension (com.microsoft.appcenter.ingestion.models.one.DeviceExtension)3 ProtocolExtension (com.microsoft.appcenter.ingestion.models.one.ProtocolExtension)3 Log (com.microsoft.appcenter.ingestion.models.Log)2 AppCenterLog (com.microsoft.appcenter.utils.AppCenterLog)2 LinkedList (java.util.LinkedList)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 ArrayList (java.util.ArrayList)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1