Search in sources :

Example 1 with CommonSchemaLog

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

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

the class PropertyConfiguratorTest method collectDeviceId.

@Test
public void collectDeviceId() {
    CommonSchemaLog log = new CommonSchemaEventLog();
    log.setExt(new Extensions());
    log.getExt().setDevice(new DeviceExtension());
    /* Mock context. */
    mockStatic(Secure.class);
    when(Secure.getString(any(ContentResolver.class), anyString())).thenReturn("mockDeviceId");
    /* Get property configurator and collect device ID. */
    PropertyConfigurator pc = Analytics.getTransmissionTarget("test").getPropertyConfigurator();
    pc.collectDeviceId();
    /* 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 device ID is collected. */
    assertEquals("a:mockDeviceId", log.getExt().getDevice().getLocalId());
}
Also used : 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) DeviceExtension(com.microsoft.appcenter.ingestion.models.one.DeviceExtension) ContentResolver(android.content.ContentResolver) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with CommonSchemaLog

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

the class PropertyConfiguratorTest method collectDeviceIdSavedWhenDisabled.

@Test
public void collectDeviceIdSavedWhenDisabled() {
    CommonSchemaLog log = new CommonSchemaEventLog();
    log.setExt(new Extensions());
    log.getExt().setDevice(new DeviceExtension());
    /* Mock context. */
    mockStatic(Secure.class);
    when(Secure.getString(any(ContentResolver.class), anyString())).thenReturn("mockDeviceId");
    /* Disable Analytics. */
    Analytics.setEnabled(false).get();
    /* Get property configurator and collect device ID. */
    PropertyConfigurator pc = Analytics.getTransmissionTarget("test").getPropertyConfigurator();
    pc.collectDeviceId();
    /* Simulate what the pipeline does to convert from App Center to Common Schema. */
    log.addTransmissionTarget("test");
    log.setTag(Analytics.getTransmissionTarget("test"));
    /* Enable and simulate log preparing. */
    Analytics.setEnabled(true).get();
    pc.onPreparingLog(log, "groupName");
    /* Assert device ID is collected. */
    assertEquals("a:mockDeviceId", log.getExt().getDevice().getLocalId());
}
Also used : 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) DeviceExtension(com.microsoft.appcenter.ingestion.models.one.DeviceExtension) ContentResolver(android.content.ContentResolver) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with CommonSchemaLog

use of com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog 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 5 with CommonSchemaLog

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

Aggregations

CommonSchemaLog (com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog)32 Test (org.junit.Test)24 Extensions (com.microsoft.appcenter.ingestion.models.one.Extensions)20 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 CommonSchemaEventLog (com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog)16 Log (com.microsoft.appcenter.ingestion.models.Log)10 UserExtension (com.microsoft.appcenter.ingestion.models.one.UserExtension)10 AppExtension (com.microsoft.appcenter.ingestion.models.one.AppExtension)9 LogSerializer (com.microsoft.appcenter.ingestion.models.json.LogSerializer)8 ProtocolExtension (com.microsoft.appcenter.ingestion.models.one.ProtocolExtension)7 AppCenterLog (com.microsoft.appcenter.utils.AppCenterLog)7 EventLog (com.microsoft.appcenter.analytics.ingestion.models.EventLog)6 ArrayList (java.util.ArrayList)6 Context (android.content.Context)5 MockCommonSchemaLog (com.microsoft.appcenter.ingestion.models.one.MockCommonSchemaLog)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