use of com.microsoft.appcenter.http.ServiceCall 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.ServiceCall 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.ServiceCall 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.ServiceCall 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.http.ServiceCall in project mobile-center-sdk-android by Microsoft.
the class AppCenterIngestionTest method getCallTemplate.
private HttpClient.CallTemplate getCallTemplate(String appSecret) {
/* Configure mock HTTP to get an instance of IngestionCallTemplate. */
final ServiceCall call = mock(ServiceCall.class);
final AtomicReference<HttpClient.CallTemplate> callTemplate = new AtomicReference<>();
when(mHttpClient.callAsync(anyString(), anyString(), anyMapOf(String.class, String.class), any(HttpClient.CallTemplate.class), any(ServiceCallback.class))).then(new Answer<ServiceCall>() {
@Override
public ServiceCall answer(InvocationOnMock invocation) {
callTemplate.set((HttpClient.CallTemplate) invocation.getArguments()[3]);
return call;
}
});
AppCenterIngestion ingestion = new AppCenterIngestion(mHttpClient, mock(LogSerializer.class));
ingestion.setLogUrl("http://mock");
assertEquals(call, ingestion.sendAsync(appSecret, UUID.randomUUID(), mock(LogContainer.class), mock(ServiceCallback.class)));
return callTemplate.get();
}
Aggregations