use of com.microsoft.appcenter.http.ServiceCall in project AppCenter-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 AppCenter-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 AppCenter-SDK-Android by Microsoft.
the class AppCenterIngestionTest method failedSerialization.
@Test
public void failedSerialization() throws Exception {
/* 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);
JSONException exception = new JSONException("mock");
when(serializer.serializeContainer(any(LogContainer.class))).thenThrow(exception);
/* Configure mock HTTP. */
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;
}
});
/* 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);
assertEquals(call, 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).callAsync(eq("http://mock/logs?api-version=1.0.0"), eq(METHOD_POST), eq(expectedHeaders), notNull(HttpClient.CallTemplate.class), eq(serviceCallback));
assertNotNull(callTemplate.get());
try {
callTemplate.get().buildRequestBody();
Assert.fail("Expected json exception");
} catch (JSONException ignored) {
}
/* Verify close. */
ingestion.close();
verify(mHttpClient).close();
}
use of com.microsoft.appcenter.http.ServiceCall in project AppCenter-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 AppCenter-SDK-Android by Microsoft.
the class OneCollectorIngestionTest method getCallTemplate.
private HttpClient.CallTemplate getCallTemplate() {
/* Configure mock HTTP to get an instance of IngestionCallTemplate. */
ServiceCall call = mock(ServiceCall.class);
ArgumentCaptor<HttpClient.CallTemplate> callTemplate = ArgumentCaptor.forClass(HttpClient.CallTemplate.class);
when(mHttpClient.callAsync(anyString(), anyString(), anyMapOf(String.class, String.class), callTemplate.capture(), any(ServiceCallback.class))).thenReturn(call);
OneCollectorIngestion ingestion = new OneCollectorIngestion(mHttpClient, mock(LogSerializer.class));
ingestion.setLogUrl("http://mock");
assertEquals(call, ingestion.sendAsync(null, null, mock(LogContainer.class), mock(ServiceCallback.class)));
return callTemplate.getValue();
}
Aggregations