use of com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog in project mobile-center-sdk-android by Microsoft.
the class PropertyConfiguratorTest method defaultTargetIsNotReturnedFromGetTransmissionTarget.
@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());
}
use of com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog in project mobile-center-sdk-android by Microsoft.
the class EventLogFactoryTest method convertEventWithoutProperties.
@Test
@PrepareForTest({ PartAUtils.class, CommonSchemaDataUtils.class })
public void convertEventWithoutProperties() {
/* Mock utilities. */
mockStatic(PartAUtils.class);
mockStatic(CommonSchemaDataUtils.class);
/* Create event log. */
EventLog log = new EventLog();
log.setName("test");
/* Old properties are ignored. */
Map<String, String> oldProperties = new HashMap<>();
oldProperties.put("ignored", "ignored");
log.setProperties(oldProperties);
/* Set typed properties. */
List<TypedProperty> properties = new ArrayList<>();
StringTypedProperty stringTypedProperty = new StringTypedProperty();
stringTypedProperty.setName("a");
stringTypedProperty.setValue("b");
properties.add(stringTypedProperty);
log.setTypedProperties(properties);
/* With 2 targets. */
log.addTransmissionTarget("t1");
log.addTransmissionTarget("t2");
/* And with a tag. */
Object tag = new Object();
log.setTag(tag);
/* When we convert logs. */
Collection<CommonSchemaLog> convertedLogs = new EventLogFactory().toCommonSchemaLogs(log);
/* Check number of logs: 1 per target. */
assertNotNull(convertedLogs);
assertEquals(2, convertedLogs.size());
/* For each target. */
for (CommonSchemaLog commonSchemaLog : convertedLogs) {
/* Check name was added. */
verifyStatic();
PartAUtils.setName(same(commonSchemaLog), eq("test"));
/* Check tag was added. */
assertSame(tag, commonSchemaLog.getTag());
}
/* Check Part A was added with target tokens. */
verifyStatic();
PartAUtils.addPartAFromLog(eq(log), notNull(CommonSchemaLog.class), eq("t1"));
verifyStatic();
PartAUtils.addPartAFromLog(eq(log), notNull(CommonSchemaLog.class), eq("t2"));
/* Check data was added with typed properties (and thus not old ones). */
verifyStatic(times(2));
CommonSchemaDataUtils.addCommonSchemaData(eq(properties), notNull(CommonSchemaLog.class));
}
use of com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog in project mobile-center-sdk-android by Microsoft.
the class EventLogFactoryTest method dontConvertEventWithoutTargetTokens.
@Test
public void dontConvertEventWithoutTargetTokens() {
/* Create event log with just a name and no target. */
EventLog log = new EventLog();
log.setName("test");
Collection<CommonSchemaLog> convertedLogs = new CommonSchemaEventLogFactory().toCommonSchemaLogs(log);
assertNotNull(convertedLogs);
assertEquals(0, convertedLogs.size());
}
use of com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog in project mobile-center-sdk-android by Microsoft.
the class AnalyticsTransmissionTargetTest method registerCallbackWhenDisabledWorks.
@Test
public void registerCallbackWhenDisabledWorks() {
/* Simulate disabling and background thread. */
Analytics analytics = Analytics.getInstance();
AppCenterHandler handler = mock(AppCenterHandler.class);
ArgumentCaptor<Runnable> backgroundRunnable = ArgumentCaptor.forClass(Runnable.class);
ArgumentCaptor<Runnable> disabledRunnable = ArgumentCaptor.forClass(Runnable.class);
doNothing().when(handler).post(backgroundRunnable.capture(), disabledRunnable.capture());
analytics.onStarting(handler);
analytics.onStarted(mock(Context.class), mChannel, null, "test", true);
/* Disable. */
Analytics.setEnabled(false);
backgroundRunnable.getValue().run();
/* Add authentication provider while disabled. */
AuthenticationProvider.TokenProvider tokenProvider = mock(AuthenticationProvider.TokenProvider.class);
AuthenticationProvider authenticationProvider = spy(new AuthenticationProvider(AuthenticationProvider.Type.MSA_COMPACT, "key1", tokenProvider));
AnalyticsTransmissionTarget.addAuthenticationProvider(authenticationProvider);
/* Unlock command. */
disabledRunnable.getValue().run();
/* Verify update while disabled. */
assertEquals(authenticationProvider, AnalyticsTransmissionTarget.sAuthenticationProvider);
verify(authenticationProvider).acquireTokenAsync();
/* Enable. */
Analytics.setEnabled(true);
disabledRunnable.getValue().run();
/* Call prepare log. */
ProtocolExtension protocol = new ProtocolExtension();
Extensions ext = new Extensions();
ext.setProtocol(protocol);
CommonSchemaLog log = new CommonSchemaEventLog();
log.setExt(ext);
AnalyticsTransmissionTarget.getChannelListener().onPreparingLog(log, "test");
/* Verify log. */
assertEquals(Collections.singletonList(authenticationProvider.getTicketKeyHash()), protocol.getTicketKeys());
/* And that we check expiry. */
verify(authenticationProvider).checkTokenExpiry();
}
use of com.microsoft.appcenter.ingestion.models.one.CommonSchemaLog in project mobile-center-sdk-android by Microsoft.
the class DatabasePersistenceAndroidTest method getLogsFilteringOutPausedTargetKeys.
@Test
public void getLogsFilteringOutPausedTargetKeys() throws PersistenceException {
/* Initialize database persistence. */
DatabasePersistence persistence = new DatabasePersistence(sContext);
/* Set a mock log serializer. */
LogSerializer logSerializer = new DefaultLogSerializer();
logSerializer.addLogFactory(MockCommonSchemaLog.TYPE, new MockCommonSchemaLogFactory());
persistence.setLogSerializer(logSerializer);
try {
/* Test constants. */
int numberOfLogsPerKey = 10;
/* Generate and persist some logs with a first iKey. */
String pausedKey1 = "1";
generateCsLogsWithIKey(persistence, pausedKey1, numberOfLogsPerKey);
/* Generate more logs with another iKey to exclude. */
String pausedKey2 = "2";
generateCsLogsWithIKey(persistence, pausedKey2, numberOfLogsPerKey);
/* Generate logs from a third key. */
String resumedKey = "3";
generateCsLogsWithIKey(persistence, resumedKey, numberOfLogsPerKey);
/* Get logs without disabled keys. */
List<Log> outLogs = new ArrayList<>();
int limit = numberOfLogsPerKey * 3;
String batchId = persistence.getLogs("test", Arrays.asList(pausedKey1, pausedKey2), limit, outLogs);
assertNotNull(batchId);
/* Verify we get a subset of logs without the disabled keys. */
assertEquals(numberOfLogsPerKey, outLogs.size());
assertEquals(limit, persistence.countLogs("test"));
for (Log log : outLogs) {
assertTrue(log instanceof CommonSchemaLog);
assertEquals(resumedKey, ((CommonSchemaLog) log).getIKey());
}
/* Calling a second time should return nothing since the batch is in progress. */
outLogs.clear();
batchId = persistence.getLogs("test", Arrays.asList(pausedKey1, pausedKey2), limit, outLogs);
assertNull(batchId);
assertEquals(0, outLogs.size());
/* If we try to get a second batch without filtering, we should get all disabled logs. */
outLogs.clear();
batchId = persistence.getLogs("test", Collections.<String>emptyList(), limit, outLogs);
assertNotNull(batchId);
assertEquals(numberOfLogsPerKey * 2, outLogs.size());
for (Log log : outLogs) {
assertTrue(log instanceof CommonSchemaLog);
assertNotEquals(resumedKey, ((CommonSchemaLog) log).getIKey());
}
} finally {
persistence.close();
}
}
Aggregations