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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations