use of com.microsoft.appcenter.http.HttpResponse in project mobile-center-sdk-android by Microsoft.
the class DistributeTest method tryResetWorkflowWhenApplicationEnterForegroundWhenChannelNotNull.
@Test
public void tryResetWorkflowWhenApplicationEnterForegroundWhenChannelNotNull() {
/* Prepare data. */
mockStatic(DistributeUtils.class);
when(DistributeUtils.getStoredDownloadState()).thenReturn(DOWNLOAD_STATE_COMPLETED);
final ServiceCall call = mock(ServiceCall.class);
doAnswer(new Answer<ServiceCall>() {
@Override
public ServiceCall answer(InvocationOnMock invocationOnMock) {
((ServiceCallback) invocationOnMock.getArguments()[4]).onCallSucceeded(new HttpResponse(200, ""));
return call;
}
}).when(mHttpClient).callAsync(anyString(), anyString(), eq(Collections.<String, String>emptyMap()), any(HttpClient.CallTemplate.class), any(ServiceCallback.class));
/* Start distribute. */
start();
/* Start activity. */
Distribute.getInstance().onApplicationEnterForeground();
Distribute.getInstance().onActivityResumed(mActivity);
/* Verify download is checked after we reset workflow. */
verify(mHttpClient).callAsync(anyString(), anyString(), eq(Collections.<String, String>emptyMap()), any(HttpClient.CallTemplate.class), any(ServiceCallback.class));
/* Stop activity. */
Distribute.getInstance().onActivityPaused(mActivity);
Distribute.getInstance().onApplicationEnterBackground();
/* Verify that all calls were completed. */
verify(mHttpClient).callAsync(anyString(), anyString(), eq(Collections.<String, String>emptyMap()), any(HttpClient.CallTemplate.class), any(ServiceCallback.class));
/* Enter foreground again. */
Distribute.getInstance().onApplicationEnterForeground();
Distribute.getInstance().onActivityResumed(mActivity);
/* Verify download is checked after we reset workflow again. */
verify(mHttpClient, times(2)).callAsync(anyString(), anyString(), eq(Collections.<String, String>emptyMap()), any(HttpClient.CallTemplate.class), any(ServiceCallback.class));
}
use of com.microsoft.appcenter.http.HttpResponse in project mobile-center-sdk-android by Microsoft.
the class DistributeTest method tryResetWorkflowWhenApplicationEnterForegroundWhenChannelNull.
@Test
public void tryResetWorkflowWhenApplicationEnterForegroundWhenChannelNull() {
/* Mock download state. */
mockStatic(DistributeUtils.class);
when(DistributeUtils.getStoredDownloadState()).thenReturn(DOWNLOAD_STATE_COMPLETED);
final ServiceCall call = mock(ServiceCall.class);
doAnswer(new Answer<ServiceCall>() {
@Override
public ServiceCall answer(InvocationOnMock invocationOnMock) {
((ServiceCallback) invocationOnMock.getArguments()[4]).onCallSucceeded(new HttpResponse(200, ""));
return call;
}
}).when(mHttpClient).callAsync(anyString(), anyString(), eq(Collections.<String, String>emptyMap()), any(HttpClient.CallTemplate.class), any(ServiceCallback.class));
/* Starting distribute. */
Distribute.getInstance().onStarting(mAppCenterHandler);
/* Start activity. */
Distribute.getInstance().onApplicationEnterForeground();
Distribute.getInstance().onActivityResumed(mActivity);
/* Verify download is not checked after we reset workflow. */
verify(mHttpClient, never()).callAsync(anyString(), anyString(), eq(Collections.<String, String>emptyMap()), any(HttpClient.CallTemplate.class), any(ServiceCallback.class));
}
use of com.microsoft.appcenter.http.HttpResponse in project mobile-center-sdk-android by Microsoft.
the class DistributeCustomizationTest method mockHtpCallFailed.
private void mockHtpCallFailed(String payload) {
final HttpException httpException = new HttpException(new HttpResponse(404, payload));
/* Mock http call. */
when(mHttpClient.callAsync(anyString(), anyString(), anyMapOf(String.class, String.class), any(HttpClient.CallTemplate.class), any(ServiceCallback.class))).thenAnswer(new Answer<ServiceCall>() {
@Override
public ServiceCall answer(InvocationOnMock invocation) {
((ServiceCallback) invocation.getArguments()[4]).onCallFailed(httpException);
return mock(ServiceCall.class);
}
});
}
use of com.microsoft.appcenter.http.HttpResponse in project mobile-center-sdk-android by Microsoft.
the class DefaultChannel method sendLogs.
/**
* Send logs.
*
* @param groupState The group state.
* @param currentState The current state.
* @param batch The log batch.
* @param batchId The batch ID.
*/
@MainThread
private void sendLogs(final GroupState groupState, final int currentState, List<Log> batch, final String batchId) {
/* Send logs. */
LogContainer logContainer = new LogContainer();
logContainer.setLogs(batch);
groupState.mIngestion.sendAsync(mAppSecret, mInstallId, logContainer, new ServiceCallback() {
@Override
public void onCallSucceeded(HttpResponse httpResponse) {
mAppCenterHandler.post(new Runnable() {
@Override
public void run() {
handleSendingSuccess(groupState, batchId);
}
});
}
@Override
public void onCallFailed(final Exception e) {
mAppCenterHandler.post(new Runnable() {
@Override
public void run() {
handleSendingFailure(groupState, batchId, e);
}
});
}
});
/* Check for more pending logs. */
mAppCenterHandler.post(new Runnable() {
@Override
public void run() {
checkPendingLogsAfterPost(groupState, currentState);
}
});
}
use of com.microsoft.appcenter.http.HttpResponse in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method suspendWithFailureCallback.
@Test
public void suspendWithFailureCallback() {
Ingestion mockIngestion = mock(Ingestion.class);
Persistence mockPersistence = mock(Persistence.class);
Channel.GroupListener mockListener = mock(Channel.GroupListener.class);
when(mockPersistence.countLogs(anyString())).thenReturn(30);
when(mockPersistence.getLogs(anyString(), anyListOf(String.class), anyInt(), anyListOf(Log.class))).thenAnswer(getGetLogsAnswer(10));
when(mockIngestion.sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class))).then(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
return null;
}
}).then(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
return null;
}
}).then(getSendAsyncAnswer(new HttpException(new HttpResponse(404))));
when(mockIngestion.isEnabled()).thenReturn(true);
DefaultChannel channel = new DefaultChannel(mock(Context.class), UUID.randomUUID().toString(), mockPersistence, mockIngestion, mAppCenterHandler);
channel.addGroup(TEST_GROUP, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null, mockListener);
/* 30 from countLogs and 10 new logs from getLogs. */
verify(mockListener, times(40)).onBeforeSending(any(Log.class));
verify(mockListener, times(40)).onFailure(any(Log.class), any(SocketException.class));
assertFalse(channel.isEnabled());
}
Aggregations