Search in sources :

Example 36 with HttpResponse

use of com.microsoft.appcenter.http.HttpResponse in project mobile-center-sdk-android by Microsoft.

the class DefaultChannelTest method invokeCallbacksAfterSuspendFatalNoListener.

@Test
public void invokeCallbacksAfterSuspendFatalNoListener() {
    Persistence mockPersistence = mock(Persistence.class);
    AppCenterIngestion mockIngestion = mock(AppCenterIngestion.class);
    when(mockIngestion.isEnabled()).thenReturn(true);
    Channel.GroupListener mockListener = mock(Channel.GroupListener.class);
    /* Simulate a lot of logs already in database. */
    when(mockPersistence.getLogs(eq(TEST_GROUP), anyListOf(String.class), anyInt(), anyListOf(Log.class))).then(getGetLogsAnswer(1)).then(getGetLogsAnswer(1)).then(getGetLogsAnswer(DefaultChannel.CLEAR_BATCH_SIZE));
    /* Make first call hang, and the second call return a fatal error. */
    when(mockIngestion.sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class))).thenReturn(null).then(getSendAsyncAnswer(new HttpException(new HttpResponse(403))));
    DefaultChannel channel = new DefaultChannel(mock(Context.class), UUID.randomUUID().toString(), mockPersistence, mockIngestion, mAppCenterHandler);
    channel.addGroup(TEST_GROUP, 1, 1, MAX_PARALLEL_BATCHES, null, null);
    channel.addGroup(TEST_GROUP + "2", 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null, mockListener);
    /* Enqueuing 2 events. */
    channel.enqueue(mock(Log.class), TEST_GROUP, Flags.DEFAULTS);
    channel.enqueue(mock(Log.class), TEST_GROUP, Flags.DEFAULTS);
    /* Verify callbacks not invoked. */
    verify(mockListener, never()).onBeforeSending(any(Log.class));
    verify(mockListener, never()).onFailure(any(Log.class), any(Exception.class));
    /* Verify logs were deleted. */
    verify(mockPersistence).deleteLogs(TEST_GROUP);
}
Also used : Persistence(com.microsoft.appcenter.persistence.Persistence) Context(android.content.Context) AppCenterIngestion(com.microsoft.appcenter.ingestion.AppCenterIngestion) Log(com.microsoft.appcenter.ingestion.models.Log) HttpResponse(com.microsoft.appcenter.http.HttpResponse) HttpException(com.microsoft.appcenter.http.HttpException) Matchers.anyString(org.mockito.Matchers.anyString) HttpException(com.microsoft.appcenter.http.HttpException) SocketException(java.net.SocketException) IOException(java.io.IOException) CancellationException(com.microsoft.appcenter.CancellationException) Test(org.junit.Test)

Aggregations

HttpResponse (com.microsoft.appcenter.http.HttpResponse)36 ServiceCallback (com.microsoft.appcenter.http.ServiceCallback)33 Matchers.anyString (org.mockito.Matchers.anyString)31 Test (org.junit.Test)30 InvocationOnMock (org.mockito.invocation.InvocationOnMock)25 ServiceCall (com.microsoft.appcenter.http.ServiceCall)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 Activity (android.app.Activity)18 Context (android.content.Context)12 HttpException (com.microsoft.appcenter.http.HttpException)12 AppCenterIngestion (com.microsoft.appcenter.ingestion.AppCenterIngestion)10 Log (com.microsoft.appcenter.ingestion.models.Log)10 LogContainer (com.microsoft.appcenter.ingestion.models.LogContainer)10 Persistence (com.microsoft.appcenter.persistence.Persistence)10 HashMap (java.util.HashMap)9 UUID (java.util.UUID)9 DistributionStartSessionLog (com.microsoft.appcenter.distribute.ingestion.models.DistributionStartSessionLog)7 Answer (org.mockito.stubbing.Answer)7 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)6 DialogInterface (android.content.DialogInterface)5