Search in sources :

Example 6 with UserExtension

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

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

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

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

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

the class PropertyConfigurator method onPreparingLog.

/**
 * Override or inherit common schema properties while preparing log.
 *
 * @param log       A log.
 * @param groupName The group name.
 */
@Override
public void onPreparingLog(@NonNull Log log, @NonNull String groupName) {
    if (shouldOverridePartAProperties(log)) {
        AppExtension app = ((CommonSchemaLog) log).getExt().getApp();
        UserExtension user = ((CommonSchemaLog) log).getExt().getUser();
        DeviceExtension device = ((CommonSchemaLog) log).getExt().getDevice();
        /* Override app name if not null, else use the name of the nearest parent. */
        if (mAppName != null) {
            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;
                }
            }
        }
        /* Override app version if not null, else use the version of the nearest parent. */
        if (mAppVersion != null) {
            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;
                }
            }
        }
        /* Override app locale if not null, else use the locale of the nearest parent. */
        if (mAppLocale != null) {
            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;
                }
            }
        }
        /* Override userId if not null, else use the userId of the nearest parent. */
        if (mUserId != null) {
            user.setLocalId(mUserId);
        } else {
            for (AnalyticsTransmissionTarget target = mTransmissionTarget.mParentTarget; target != null; target = target.mParentTarget) {
                String parentUserId = target.getPropertyConfigurator().getUserId();
                if (parentUserId != null) {
                    user.setLocalId(parentUserId);
                    break;
                }
            }
        }
        /* Fill out the device id if it has been collected. */
        if (mDeviceIdEnabled) {
            /* Get device identifier, Secure class already has an in memory cache. */
            @SuppressLint("HardwareIds") String androidId = Secure.getString(mTransmissionTarget.mContext.getContentResolver(), Secure.ANDROID_ID);
            device.setLocalId(ANDROID_DEVICE_ID_PREFIX + androidId);
        }
    }
}
Also used : AppExtension(com.microsoft.appcenter.ingestion.models.one.AppExtension) UserExtension(com.microsoft.appcenter.ingestion.models.one.UserExtension) SuppressLint(android.annotation.SuppressLint) DeviceExtension(com.microsoft.appcenter.ingestion.models.one.DeviceExtension)

Aggregations

UserExtension (com.microsoft.appcenter.ingestion.models.one.UserExtension)11 CommonSchemaEventLog (com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog)10 AppExtension (com.microsoft.appcenter.ingestion.models.one.AppExtension)10 CommonSchemaLog (com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog)10 Extensions (com.microsoft.appcenter.ingestion.models.one.Extensions)10 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 Context (android.content.Context)2 DeviceExtension (com.microsoft.appcenter.ingestion.models.one.DeviceExtension)2 SuppressLint (android.annotation.SuppressLint)1 ContentResolver (android.content.ContentResolver)1 AppCenterHandler (com.microsoft.appcenter.AppCenterHandler)1 LinkedList (java.util.LinkedList)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1