use of com.microsoft.appcenter.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class OneCollectorChannelListenerTest method shouldFilterAppCenterLog.
@Test
public void shouldFilterAppCenterLog() {
Channel channel = mock(Channel.class);
OneCollectorChannelListener listener = new OneCollectorChannelListener(channel, mock(LogSerializer.class), createHttpClient(mock(Context.class)), UUID.randomUUID());
/* App center log with no transmission target must not be filtered. */
Log log = mock(Log.class);
assertFalse(listener.shouldFilter(log));
/* App center log with transmission target must be filtered. */
when(log.getTransmissionTargetTokens()).thenReturn(new HashSet<>(Collections.singletonList("token")));
assertTrue(listener.shouldFilter(log));
/* Common schema logs never filtered out by this listener if no validation. */
assertFalse(listener.shouldFilter(mock(CommonSchemaLog.class)));
}
use of com.microsoft.appcenter.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelAlternateIngestionTest method startWithoutAppSecret.
@Test
public void startWithoutAppSecret() throws Persistence.PersistenceException {
/* Set up channel without app secret. */
String appCenterGroup = "test_group1";
String oneCollectorGroup = "test_group2";
Persistence mockPersistence = mock(Persistence.class);
Ingestion defaultIngestion = mock(Ingestion.class);
when(defaultIngestion.isEnabled()).thenReturn(true);
Ingestion alternateIngestion = mock(Ingestion.class);
when(alternateIngestion.isEnabled()).thenReturn(true);
/* Simulate we have 1 pending log in storage. */
when(mockPersistence.countLogs(anyString())).thenReturn(1);
when(mockPersistence.getLogs(any(String.class), anyListOf(String.class), anyInt(), anyListOf(Log.class))).then(getGetLogsAnswer(1));
/* Create channel and groups. */
DefaultChannel channel = new DefaultChannel(mock(Context.class), null, mockPersistence, defaultIngestion, mAppCenterHandler);
channel.addGroup(appCenterGroup, 2, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null, null);
channel.addGroup(oneCollectorGroup, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, alternateIngestion, null);
/* App center previous log not sent yet. */
verify(defaultIngestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* One collector previous log sent. */
verify(alternateIngestion).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Enqueuing 1 new event for app center. */
channel.enqueue(mock(Log.class), appCenterGroup, Flags.DEFAULTS);
/* Not sent. */
verify(defaultIngestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Verify we didn't persist the log since AppCenter not started with app secret. */
verify(mockPersistence, never()).putLog(any(Log.class), eq(appCenterGroup), eq(Flags.NORMAL));
/* Enqueuing 1 event from one collector group. */
channel.enqueue(mock(Log.class), oneCollectorGroup, Flags.DEFAULTS);
/* Verify that we have called sendAsync on the alternate ingestion a second time. */
verify(alternateIngestion, times(2)).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
verify(defaultIngestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Verify that we can now send logs to app center after we have set app secret. */
channel.setAppSecret("testAppSecret");
channel.enqueue(mock(Log.class), appCenterGroup, Flags.DEFAULTS);
verify(defaultIngestion).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
}
use of com.microsoft.appcenter.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelAlternateIngestionTest method pendingLogsDisableSetAppSecretThenEnable.
@Test
public void pendingLogsDisableSetAppSecretThenEnable() {
/* Set up channel without app secret. */
String appCenterGroup = "test_group1";
String oneCollectorGroup = "test_group2";
Persistence mockPersistence = mock(Persistence.class);
Ingestion defaultIngestion = mock(Ingestion.class);
when(defaultIngestion.isEnabled()).thenReturn(true);
Ingestion alternateIngestion = mock(Ingestion.class);
when(alternateIngestion.isEnabled()).thenReturn(true);
when(mockPersistence.getLogs(any(String.class), anyListOf(String.class), anyInt(), anyListOf(Log.class))).then(getGetLogsAnswer(1));
/* Simulate we have 1 pending log in storage for App Center. */
when(mockPersistence.countLogs(appCenterGroup)).thenReturn(1);
/* Create channel with the two groups. */
DefaultChannel channel = new DefaultChannel(mock(Context.class), null, mockPersistence, defaultIngestion, mAppCenterHandler);
channel.addGroup(appCenterGroup, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null, null);
channel.addGroup(oneCollectorGroup, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, alternateIngestion, null);
/* Disable channel. */
channel.setEnabled(false);
/* Verify that no log is sent even if we set app secret while channel is disabled. */
channel.setAppSecret("testAppSecret");
verify(defaultIngestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
verify(alternateIngestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
/* Enable channel. */
channel.setEnabled(true);
/* Verify that now logs are sent when channel is enabled. */
verify(defaultIngestion).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
verify(alternateIngestion, never()).sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class));
}
use of com.microsoft.appcenter.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class AppCenterIngestionTest method sendLogsWhenIngestionDisable.
@Test
public void sendLogsWhenIngestionDisable() throws JSONException, IOException {
mockStatic(SharedPreferencesManager.class);
when(SharedPreferencesManager.getBoolean(ALLOWED_NETWORK_REQUEST, true)).thenReturn(false);
/* Build some payload. */
LogContainer container = new LogContainer();
Log log = mock(Log.class);
List<Log> logs = new ArrayList<>();
logs.add(log);
container.setLogs(logs);
LogSerializer serializer = mock(LogSerializer.class);
when(serializer.serializeContainer(any(LogContainer.class))).thenReturn("mockPayload");
/* Configure mock HTTP. */
final ServiceCall call = mock(ServiceCall.class);
/* Test calling code. */
AppCenterIngestion ingestion = new AppCenterIngestion(mHttpClient, serializer);
ingestion.setLogUrl("http://mock");
String appSecret = UUID.randomUUID().toString();
UUID installId = UUID.randomUUID();
ServiceCallback serviceCallback = mock(ServiceCallback.class);
assertNull(ingestion.sendAsync(appSecret, installId, container, serviceCallback));
/* Verify call to http client. */
HashMap<String, String> expectedHeaders = new HashMap<>();
expectedHeaders.put(Constants.APP_SECRET, appSecret);
expectedHeaders.put(AppCenterIngestion.INSTALL_ID, installId.toString());
verify(mHttpClient, never()).callAsync(eq("http://mock" + AppCenterIngestion.API_PATH), eq(METHOD_POST), eq(expectedHeaders), notNull(HttpClient.CallTemplate.class), eq(serviceCallback));
}
use of com.microsoft.appcenter.ingestion.models.Log in project mobile-center-sdk-android by Microsoft.
the class LogContainerTest method compareLogContainer.
@Test
public void compareLogContainer() {
LogContainer container1 = new LogContainer();
LogContainer container2 = new LogContainer();
TestUtils.compareSelfNullClass(container1);
TestUtils.checkEquals(container1, container2);
Log log1 = new AbstractLog() {
@Override
public String getType() {
return "null";
}
};
log1.setSid(UUID.randomUUID());
container1.setLogs(Collections.singletonList(log1));
TestUtils.compareSelfNullClass(container1);
TestUtils.checkNotEquals(container1, container2);
container2.setLogs(Collections.singletonList(log1));
TestUtils.compareSelfNullClass(container1);
TestUtils.checkEquals(container1, container2);
Log log2 = new AbstractLog() {
@Override
public String getType() {
return null;
}
};
log2.setSid(UUID.randomUUID());
container2.setLogs(Collections.singletonList(log2));
TestUtils.compareSelfNullClass(container1);
TestUtils.checkNotEquals(container1, container2);
}
Aggregations