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