use of com.microsoft.appcenter.analytics.ingestion.models.one.CommonSchemaEventLog 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.analytics.ingestion.models.one.CommonSchemaEventLog 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();
}
Aggregations