Search in sources :

Example 11 with Extensions

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

the class PropertyConfiguratorTest method grandparentsHaveNoPropertiesSet.

@Test
public void grandparentsHaveNoPropertiesSet() {
    CommonSchemaLog log = new CommonSchemaEventLog();
    log.setExt(new Extensions());
    log.getExt().setApp(new AppExtension());
    log.getExt().setUser(new UserExtension());
    /* Set up empty chain of parents. */
    AnalyticsTransmissionTarget grandparent = Analytics.getTransmissionTarget("grandparent");
    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 not set on common schema for child. */
    assertNull(log.getExt().getApp().getVer());
    assertNull(log.getExt().getApp().getName());
    assertNull(log.getExt().getApp().getLocale());
    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 12 with Extensions

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

the class PropertyConfiguratorTest method unsetUserId.

@Test
public void unsetUserId() {
    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("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("c:bob", log.getExt().getUser().getLocalId());
    /* Create second log. */
    CommonSchemaLog log2 = new CommonSchemaEventLog();
    log2.setExt(new Extensions());
    log2.getExt().setApp(new AppExtension());
    log2.getExt().setUser(new UserExtension());
    /* Un-set user ID. */
    pc.setUserId(null);
    /* Simulate what the pipeline does to convert from App Center to Common Schema. */
    log2.addTransmissionTarget("test");
    log2.setTag(Analytics.getTransmissionTarget("test"));
    pc.onPreparingLog(log2, "groupName");
    /* Assert properties set on common schema. */
    assertNull(log2.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 13 with Extensions

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

the class PropertyConfiguratorTest method checkGrandParentNotOverriddenByDescendants.

@Test
public void checkGrandParentNotOverriddenByDescendants() {
    CommonSchemaLog log = new CommonSchemaEventLog();
    log.setExt(new Extensions());
    log.getExt().setApp(new AppExtension());
    log.getExt().setUser(new UserExtension());
    /* Set up hierarchy. */
    AnalyticsTransmissionTarget grandparent = Analytics.getTransmissionTarget("grandparent");
    AnalyticsTransmissionTarget parent = grandparent.getTransmissionTarget("parent");
    AnalyticsTransmissionTarget child = parent.getTransmissionTarget("child");
    /* Set properties on parent to override unset properties on child (but not grandparent). */
    parent.getPropertyConfigurator().setAppVersion("appVersion");
    parent.getPropertyConfigurator().setAppName("appName");
    parent.getPropertyConfigurator().setAppLocale("appLocale");
    parent.getPropertyConfigurator().setUserId("c:bob");
    /* Also set 1 on child. */
    child.getPropertyConfigurator().setAppName("childName");
    /* Simulate channel callbacks. */
    log.addTransmissionTarget("grandParent");
    log.setTag(grandparent);
    grandparent.getPropertyConfigurator().onPreparingLog(log, "groupName");
    parent.getPropertyConfigurator().onPreparingLog(log, "groupName");
    child.getPropertyConfigurator().onPreparingLog(log, "groupName");
    /* Assert properties not set on common schema for grandparent. */
    assertNull(log.getExt().getApp().getVer());
    assertNull(log.getExt().getApp().getName());
    assertNull(log.getExt().getApp().getLocale());
    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 14 with Extensions

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

the class PropertyConfiguratorTest method commonSchemaPropertiesNotSetWhenDisabled.

@Test
public void commonSchemaPropertiesNotSetWhenDisabled() {
    CommonSchemaLog log = new CommonSchemaEventLog();
    log.setExt(new Extensions());
    log.getExt().setApp(new AppExtension());
    log.getExt().setUser(new UserExtension());
    /* Get target, disable it, and set properties. */
    AnalyticsTransmissionTarget target = Analytics.getTransmissionTarget("test");
    target.setEnabledAsync(false).get();
    target.getPropertyConfigurator().setAppVersion("appVersion");
    target.getPropertyConfigurator().setAppName("appName");
    target.getPropertyConfigurator().setAppLocale("appLocale");
    target.getPropertyConfigurator().setUserId("c:alice");
    /* Simulate what the pipeline does to convert from App Center to Common Schema. */
    log.addTransmissionTarget("test");
    log.setTag(target);
    target.getPropertyConfigurator().onPreparingLog(log, "groupName");
    /* Assert properties are null. */
    assertNull(log.getExt().getApp().getVer());
    assertNull(log.getExt().getApp().getName());
    assertNull(log.getExt().getApp().getLocale());
    assertNull(log.getExt().getUser().getLocalId());
    /* The properties are not applied but are saved, if we enable now we can see the values. */
    target.setEnabledAsync(true).get();
    target.getPropertyConfigurator().onPreparingLog(log, "groupName");
    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 15 with Extensions

use of com.microsoft.appcenter.ingestion.models.one.Extensions 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)

Aggregations

CommonSchemaLog (com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog)20 Extensions (com.microsoft.appcenter.ingestion.models.one.Extensions)20 Test (org.junit.Test)19 CommonSchemaEventLog (com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 UserExtension (com.microsoft.appcenter.ingestion.models.one.UserExtension)10 AppExtension (com.microsoft.appcenter.ingestion.models.one.AppExtension)9 Log (com.microsoft.appcenter.ingestion.models.Log)7 ProtocolExtension (com.microsoft.appcenter.ingestion.models.one.ProtocolExtension)7 AppCenterLog (com.microsoft.appcenter.utils.AppCenterLog)6 Context (android.content.Context)5 LogSerializer (com.microsoft.appcenter.ingestion.models.json.LogSerializer)5 Matchers.anyString (org.mockito.Matchers.anyString)5 AppCenterHandler (com.microsoft.appcenter.AppCenterHandler)4 ServiceCall (com.microsoft.appcenter.http.ServiceCall)4 ServiceCallback (com.microsoft.appcenter.http.ServiceCallback)4 LogContainer (com.microsoft.appcenter.ingestion.models.LogContainer)4 ContentResolver (android.content.ContentResolver)3 DeviceExtension (com.microsoft.appcenter.ingestion.models.one.DeviceExtension)3 ArrayList (java.util.ArrayList)3