AppExtension a = new AppExtension(); AppExtension b = new AppExtension(); checkEquals(a, b); a.setId("a1"); checkNotEquals(a, b); b.setId("b1"); checkNotEquals(a, b); b.setId("a1"); checkEquals(a, b); a.setVer("a2"); checkNotEquals(a, b); b.setVer("b2"); checkNotEquals(a, b); b.setVer("a2"); checkEquals(a, b); a.setName("a2"); checkNotEquals(a, b); b.setName("b2"); checkNotEquals(a, b); b.setName("a2"); checkEquals(a, b); a.setLocale("a3"); checkNotEquals(a, b); b.setLocale("b3"); checkNotEquals(a, b);
app.setName(mAppName); } else { for (AnalyticsTransmissionTarget target = mTransmissionTarget.mParentTarget; target != null; target = target.mParentTarget) { String parentAppName = target.getPropertyConfigurator().getAppName(); if (parentAppName != null) { app.setName(parentAppName); break; app.setVer(mAppVersion); } else { for (AnalyticsTransmissionTarget target = mTransmissionTarget.mParentTarget; target != null; target = target.mParentTarget) { String parentAppVersion = target.getPropertyConfigurator().getAppVersion(); if (parentAppVersion != null) { app.setVer(parentAppVersion); break; app.setLocale(mAppLocale); } else { for (AnalyticsTransmissionTarget target = mTransmissionTarget.mParentTarget; target != null; target = target.mParentTarget) { String parentAppLocale = target.getPropertyConfigurator().getAppLocale(); if (parentAppLocale != null) { app.setLocale(parentAppLocale); break;
@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()); }
dest.getExt().setApp(new AppExtension()); dest.getExt().getApp().setVer(device.getAppVersion()); dest.getExt().getApp().setId("a" + COMMON_SCHEMA_PREFIX_SEPARATOR + device.getAppNamespace());
AppExtension app = new AppExtension(); app.setVer("1.2.3"); a.setApp(app); checkNotEquals(a, b); b.setApp(new AppExtension()); checkNotEquals(a, b); b.setApp(a.getApp());
@Test public void compareDifferentType() { TestUtils.compareSelfNullClass(new AppExtension()); }
@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()); }
assertEquals("8.1.0-ABC.123-23", commonSchemaLog.getExt().getOs().getVer()); assertNotNull(commonSchemaLog.getExt().getApp()); assertEquals("1.0.0", commonSchemaLog.getExt().getApp().getVer()); assertEquals("a:com.appcenter.test", commonSchemaLog.getExt().getApp().getId()); assertNotNull(commonSchemaLog.getExt().getNet()); assertEquals("carrierName", commonSchemaLog.getExt().getNet().getProvider());
AppExtension app = new AppExtension(); app.read(object.getJSONObject(APP)); setApp(app);
@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()); }
@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()); }
@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()); }
@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()); }
log.getExt().setApp(new AppExtension()); checkSerialization(serializer, log); log.getExt().getApp().setId("com.contoso.app"); checkSerialization(serializer, log); log.getExt().getApp().setVer("1.2.3"); checkSerialization(serializer, log); log.getExt().getApp().setLocale("fr-FR"); checkSerialization(serializer, log); log.getExt().getApp().setUserId("c:charlie"); checkSerialization(serializer, log);
logBeforeSetProperty.getExt().setApp(new AppExtension()); logBeforeSetProperty.getExt().setUser(new UserExtension()); logBeforeSetProperty.getExt().setDevice(new DeviceExtension()); logAfterSetProperty.getExt().setApp(new AppExtension()); logAfterSetProperty.getExt().setUser(new UserExtension()); logAfterSetProperty.getExt().setDevice(new DeviceExtension()); 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()); 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());
@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()); }
@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()); }