Search in sources :

Example 6 with Extensions

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

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

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

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

Example 10 with Extensions

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

the class OneCollectorIngestionTest method ticketsFailToSerialize.

@Test
public void ticketsFailToSerialize() throws Exception {
    /* Build some payload. */
    final CommonSchemaLog log1 = mock(CommonSchemaLog.class);
    final List<String> ticketKeys = new ArrayList<String>() {

        {
            add("key1");
        }
    };
    TicketCache.putTicket("key1", "value1");
    Extensions ext1 = new Extensions() {

        {
            setProtocol(new ProtocolExtension() {

                {
                    setTicketKeys(ticketKeys);
                }
            });
        }
    };
    when(log1.getExt()).thenReturn(ext1);
    LogContainer container = new LogContainer() {

        {
            setLogs(new ArrayList<Log>() {

                {
                    add(log1);
                }
            });
        }
    };
    JSONObject ticketJson = mock(JSONObject.class);
    whenNew(JSONObject.class).withNoArguments().thenReturn(ticketJson);
    when(ticketJson.put(anyString(), anyString())).thenThrow(new JSONException("mock"));
    /* Configure mock HTTP. */
    ServiceCall call = mock(ServiceCall.class);
    when(mHttpClient.callAsync(anyString(), anyString(), mHeadersCaptor.capture(), any(HttpClient.CallTemplate.class), any(ServiceCallback.class))).thenReturn(call);
    /* Verify call to http client. */
    LogSerializer serializer = mock(LogSerializer.class);
    OneCollectorIngestion ingestion = new OneCollectorIngestion(mHttpClient, serializer);
    ingestion.setLogUrl("http://mock");
    ServiceCallback serviceCallback = mock(ServiceCallback.class);
    assertEquals(call, ingestion.sendAsync(null, null, container, serviceCallback));
    /* Verify call to http client was made without headers as JSON failed. */
    Map<String, String> headers = mHeadersCaptor.getValue();
    assertFalse(headers.containsKey(TICKETS));
}
Also used : ServiceCall(com.microsoft.appcenter.http.ServiceCall) ProtocolExtension(com.microsoft.appcenter.ingestion.models.one.ProtocolExtension) CommonSchemaLog(com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog) Log(com.microsoft.appcenter.ingestion.models.Log) AppCenterLog(com.microsoft.appcenter.utils.AppCenterLog) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) Matchers.anyString(org.mockito.Matchers.anyString) LogSerializer(com.microsoft.appcenter.ingestion.models.json.LogSerializer) Extensions(com.microsoft.appcenter.ingestion.models.one.Extensions) ServiceCallback(com.microsoft.appcenter.http.ServiceCallback) JSONObject(org.json.JSONObject) CommonSchemaLog(com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog) LogContainer(com.microsoft.appcenter.ingestion.models.LogContainer) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

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