Search in sources :

Example 1 with UserExtension

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

the class PropertyConfiguratorTest method inheritCommonSchemaPropertiesFromGrandparent.

@Test
public void inheritCommonSchemaPropertiesFromGrandparent() {
    CommonSchemaLog log = new CommonSchemaEventLog();
    log.setExt(new Extensions());
    log.getExt().setApp(new AppExtension());
    log.getExt().setUser(new UserExtension());
    /* Set properties on parent to override unset properties on child */
    AnalyticsTransmissionTarget grandparent = Analytics.getTransmissionTarget("grandparent");
    grandparent.getPropertyConfigurator().setAppVersion("appVersion");
    grandparent.getPropertyConfigurator().setAppName("appName");
    grandparent.getPropertyConfigurator().setAppLocale("appLocale");
    grandparent.getPropertyConfigurator().setUserId("c:alice");
    /* Set up hierarchy. */
    AnalyticsTransmissionTarget parent = grandparent.getTransmissionTarget("parent");
    AnalyticsTransmissionTarget child = parent.getTransmissionTarget("child");
    /* Simulate channel callbacks. */
    log.addTransmissionTarget("child");
    log.setTag(child);
    grandparent.getPropertyConfigurator().onPreparingLog(log, "groupName");
    parent.getPropertyConfigurator().onPreparingLog(log, "groupName");
    child.getPropertyConfigurator().onPreparingLog(log, "groupName");
    /* Assert properties set on common schema. */
    assertEquals("appVersion", log.getExt().getApp().getVer());
    assertEquals("appName", log.getExt().getApp().getName());
    assertEquals("appLocale", log.getExt().getApp().getLocale());
    assertEquals("c:alice", log.getExt().getUser().getLocalId());
}
Also used : CommonSchemaLog(com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog) AppExtension(com.microsoft.appcenter.ingestion.models.one.AppExtension) UserExtension(com.microsoft.appcenter.ingestion.models.one.UserExtension) 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 2 with UserExtension

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

the class PropertyConfiguratorTest method setCommonSchemaProperties.

@Test
public void setCommonSchemaProperties() {
    CommonSchemaLog log = new CommonSchemaEventLog();
    log.setExt(new Extensions());
    log.getExt().setApp(new AppExtension());
    log.getExt().setUser(new UserExtension());
    /* Get property configurator and set properties. */
    PropertyConfigurator pc = Analytics.getTransmissionTarget("test").getPropertyConfigurator();
    pc.setAppVersion("appVersion");
    pc.setAppName("appName");
    pc.setAppLocale("appLocale");
    pc.setUserId("c:bob");
    /* Simulate what the pipeline does to convert from App Center to Common Schema. */
    log.addTransmissionTarget("test");
    log.setTag(Analytics.getTransmissionTarget("test"));
    pc.onPreparingLog(log, "groupName");
    /* Assert properties set on common schema. */
    assertEquals("appVersion", log.getExt().getApp().getVer());
    assertEquals("appName", log.getExt().getApp().getName());
    assertEquals("appLocale", log.getExt().getApp().getLocale());
    assertEquals("c:bob", log.getExt().getUser().getLocalId());
}
Also used : CommonSchemaLog(com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog) AppExtension(com.microsoft.appcenter.ingestion.models.one.AppExtension) UserExtension(com.microsoft.appcenter.ingestion.models.one.UserExtension) 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 3 with UserExtension

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

the class PropertyConfiguratorTest method setInvalidUserId.

@Test
public void setInvalidUserId() {
    CommonSchemaLog log = new CommonSchemaEventLog();
    log.setExt(new Extensions());
    log.getExt().setApp(new AppExtension());
    log.getExt().setUser(new UserExtension());
    /* Get property configurator and set properties. */
    PropertyConfigurator pc = Analytics.getTransmissionTarget("test").getPropertyConfigurator();
    pc.setUserId("x:bob");
    /* Simulate what the pipeline does to convert from App Center to Common Schema. */
    log.addTransmissionTarget("test");
    log.setTag(Analytics.getTransmissionTarget("test"));
    pc.onPreparingLog(log, "groupName");
    /* Assert property not set on common schema. */
    assertNull(log.getExt().getUser().getLocalId());
    /* Set user id with just the prefix. */
    pc.setUserId("c:");
    /* Assert property not set on common schema. */
    assertNull(log.getExt().getUser().getLocalId());
    /* Set empty user id. */
    pc.setUserId("");
    /* Assert property not set on common schema. */
    assertNull(log.getExt().getUser().getLocalId());
}
Also used : CommonSchemaLog(com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog) AppExtension(com.microsoft.appcenter.ingestion.models.one.AppExtension) UserExtension(com.microsoft.appcenter.ingestion.models.one.UserExtension) 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 4 with UserExtension

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

the class PropertyConfiguratorTest method setNonPrefixUserId.

@Test
public void setNonPrefixUserId() {
    CommonSchemaLog log = new CommonSchemaEventLog();
    log.setExt(new Extensions());
    log.getExt().setUser(new UserExtension());
    /* Get property configurator and set properties. */
    PropertyConfigurator pc = Analytics.getTransmissionTarget("test").getPropertyConfigurator();
    pc.setUserId("bob");
    /* Simulate what the pipeline does to convert from App Center to Common Schema. */
    log.addTransmissionTarget("test");
    log.setTag(Analytics.getTransmissionTarget("test"));
    pc.onPreparingLog(log, "groupName");
    /* Check prefix was added. */
    assertEquals("c:bob", log.getExt().getUser().getLocalId());
}
Also used : CommonSchemaLog(com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog) UserExtension(com.microsoft.appcenter.ingestion.models.one.UserExtension) 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 5 with UserExtension

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

the class PropertyConfiguratorTest method overridingPartAIsNotRetroactive.

@Test
public void overridingPartAIsNotRetroactive() {
    /* Mock deviceId. */
    mockStatic(Secure.class);
    when(Secure.getString(any(ContentResolver.class), anyString())).thenReturn("mockDeviceId");
    /* Start analytics and simulate background thread handler (we hold the thread command and run it in the test). */
    Analytics analytics = Analytics.getInstance();
    AppCenterHandler handler = mock(AppCenterHandler.class);
    final LinkedList<Runnable> backgroundCommands = new LinkedList<>();
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            backgroundCommands.add((Runnable) invocation.getArguments()[0]);
            return null;
        }
    }).when(handler).post(notNull(Runnable.class), any(Runnable.class));
    analytics.onStarting(handler);
    analytics.onStarted(mock(Context.class), mChannel, null, null, true);
    /* Create a target. */
    AnalyticsTransmissionTarget target = Analytics.getTransmissionTarget("test");
    /* Init target background code now. */
    backgroundCommands.removeFirst().run();
    /* Simulate a track event call with no property. */
    CommonSchemaLog logBeforeSetProperty = new CommonSchemaEventLog();
    logBeforeSetProperty.setExt(new Extensions());
    logBeforeSetProperty.getExt().setApp(new AppExtension());
    logBeforeSetProperty.getExt().setUser(new UserExtension());
    logBeforeSetProperty.getExt().setDevice(new DeviceExtension());
    /* Simulate what the pipeline does to convert from App Center to Common Schema. */
    logBeforeSetProperty.addTransmissionTarget("test");
    logBeforeSetProperty.setTag(target);
    /* Set all common properties that should not be set retroactively before first log persisted. */
    target.getPropertyConfigurator().setAppVersion("appVersion");
    target.getPropertyConfigurator().setAppLocale("appLocale");
    target.getPropertyConfigurator().setAppName("appName");
    target.getPropertyConfigurator().setUserId("c:alice");
    target.getPropertyConfigurator().collectDeviceId();
    /* Run background commands in order: first prepare first log, then all the set property calls. */
    target.getPropertyConfigurator().onPreparingLog(logBeforeSetProperty, "groupName");
    for (Runnable command : backgroundCommands) {
        command.run();
    }
    /* Simulate the second track event call. */
    CommonSchemaLog logAfterSetProperty = new CommonSchemaEventLog();
    logAfterSetProperty.setExt(new Extensions());
    logAfterSetProperty.getExt().setApp(new AppExtension());
    logAfterSetProperty.getExt().setUser(new UserExtension());
    logAfterSetProperty.getExt().setDevice(new DeviceExtension());
    /* Simulate what the pipeline does to convert from App Center to Common Schema. */
    logAfterSetProperty.addTransmissionTarget("test");
    logAfterSetProperty.setTag(target);
    target.getPropertyConfigurator().onPreparingLog(logAfterSetProperty, "groupName");
    /* Check first log has no property. */
    assertNull(logBeforeSetProperty.getExt().getApp().getVer());
    assertNull(logBeforeSetProperty.getExt().getApp().getLocale());
    assertNull(logBeforeSetProperty.getExt().getApp().getName());
    assertNull(logBeforeSetProperty.getExt().getUser().getLocalId());
    assertNull(logBeforeSetProperty.getExt().getDevice().getLocalId());
    /* Check second log has all of them. */
    assertEquals("appVersion", logAfterSetProperty.getExt().getApp().getVer());
    assertEquals("appLocale", logAfterSetProperty.getExt().getApp().getLocale());
    assertEquals("appName", logAfterSetProperty.getExt().getApp().getName());
    assertEquals("c:alice", logAfterSetProperty.getExt().getUser().getLocalId());
    assertEquals("a:mockDeviceId", logAfterSetProperty.getExt().getDevice().getLocalId());
}
Also used : Context(android.content.Context) AppExtension(com.microsoft.appcenter.ingestion.models.one.AppExtension) Extensions(com.microsoft.appcenter.ingestion.models.one.Extensions) DeviceExtension(com.microsoft.appcenter.ingestion.models.one.DeviceExtension) LinkedList(java.util.LinkedList) ContentResolver(android.content.ContentResolver) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) AppCenterHandler(com.microsoft.appcenter.AppCenterHandler) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CommonSchemaLog(com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog) UserExtension(com.microsoft.appcenter.ingestion.models.one.UserExtension) CommonSchemaEventLog(com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

UserExtension (com.microsoft.appcenter.ingestion.models.one.UserExtension)11 CommonSchemaEventLog (com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog)10 AppExtension (com.microsoft.appcenter.ingestion.models.one.AppExtension)10 CommonSchemaLog (com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog)10 Extensions (com.microsoft.appcenter.ingestion.models.one.Extensions)10 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 Context (android.content.Context)2 DeviceExtension (com.microsoft.appcenter.ingestion.models.one.DeviceExtension)2 SuppressLint (android.annotation.SuppressLint)1 ContentResolver (android.content.ContentResolver)1 AppCenterHandler (com.microsoft.appcenter.AppCenterHandler)1 LinkedList (java.util.LinkedList)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1