use of com.microsoft.appcenter.ingestion.models.one.AppExtension 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.AppExtension 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.AppExtension 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());
}
use of com.microsoft.appcenter.ingestion.models.one.AppExtension 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());
}
use of com.microsoft.appcenter.ingestion.models.one.AppExtension 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());
}
Aggregations