use of com.microsoft.appcenter.http.ServiceCall in project mobile-center-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();
}
use of com.microsoft.appcenter.http.ServiceCall in project mobile-center-sdk-android by Microsoft.
the class OneCollectorIngestionTest method ticketsFailToSerialize.
@Test
public void ticketsFailToSerialize() throws Exception {
/* Build some payload. */
final CommonSchemaLog log1 = mock(CommonSchemaLog.class);
final List<String> ticketKeys = new ArrayList<String>() {
{
add("key1");
}
};
TicketCache.putTicket("key1", "value1");
Extensions ext1 = new Extensions() {
{
setProtocol(new ProtocolExtension() {
{
setTicketKeys(ticketKeys);
}
});
}
};
when(log1.getExt()).thenReturn(ext1);
LogContainer container = new LogContainer() {
{
setLogs(new ArrayList<Log>() {
{
add(log1);
}
});
}
};
JSONObject ticketJson = mock(JSONObject.class);
whenNew(JSONObject.class).withNoArguments().thenReturn(ticketJson);
when(ticketJson.put(anyString(), anyString())).thenThrow(new JSONException("mock"));
/* Configure mock HTTP. */
ServiceCall call = mock(ServiceCall.class);
when(mHttpClient.callAsync(anyString(), anyString(), mHeadersCaptor.capture(), any(HttpClient.CallTemplate.class), any(ServiceCallback.class))).thenReturn(call);
/* Verify call to http client. */
LogSerializer serializer = mock(LogSerializer.class);
OneCollectorIngestion ingestion = new OneCollectorIngestion(mHttpClient, serializer);
ingestion.setLogUrl("http://mock");
ServiceCallback serviceCallback = mock(ServiceCallback.class);
assertEquals(call, ingestion.sendAsync(null, null, container, serviceCallback));
/* Verify call to http client was made without headers as JSON failed. */
Map<String, String> headers = mHeadersCaptor.getValue();
assertFalse(headers.containsKey(TICKETS));
}
use of com.microsoft.appcenter.http.ServiceCall in project AppCenter-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();
}
use of com.microsoft.appcenter.http.ServiceCall in project AppCenter-SDK-Android by Microsoft.
the class DistributeBeforeApiSuccessTest method disableWhileCheckingRelease.
@Test
public void disableWhileCheckingRelease() {
/* Mock we already have token. */
when(SharedPreferencesManager.getString(PREFERENCE_KEY_UPDATE_TOKEN)).thenReturn("some token");
ServiceCall firstCall = mock(ServiceCall.class);
when(mHttpClient.callAsync(anyString(), anyString(), anyMapOf(String.class, String.class), any(HttpClient.CallTemplate.class), any(ServiceCallback.class))).thenReturn(firstCall).thenReturn(mock(ServiceCall.class));
/* The call is only triggered when app is resumed. */
start();
verify(mHttpClient, never()).callAsync(anyString(), anyString(), eq(Collections.<String, String>emptyMap()), any(HttpClient.CallTemplate.class), any(ServiceCallback.class));
Distribute.getInstance().onActivityResumed(mActivity);
verify(mHttpClient).callAsync(anyString(), anyString(), eq(Collections.<String, String>emptyMap()), any(HttpClient.CallTemplate.class), any(ServiceCallback.class));
/* Verify cancel on disabling. */
verify(firstCall, never()).cancel();
Distribute.setEnabled(false);
verify(firstCall).cancel();
/* No more call on that one. */
Distribute.setEnabled(true);
Distribute.setEnabled(false);
verify(firstCall).cancel();
}
use of com.microsoft.appcenter.http.ServiceCall in project AppCenter-SDK-Android by Microsoft.
the class DistributeBeforeApiSuccessTest method releaseSuccessDifferentIds.
@Test
public void releaseSuccessDifferentIds() {
when(SharedPreferencesManager.getString(PREFERENCE_KEY_UPDATE_TOKEN)).thenReturn("some token");
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) {
/* Do the call so that id had changed. */
Distribute.getInstance().getLatestReleaseDetails("mockGroup", "token");
((ServiceCallback) invocation.getArguments()[4]).onCallSucceeded(new HttpResponse(200, "mock", Collections.<String, String>emptyMap()));
return mock(ServiceCall.class);
}
}).thenAnswer(new Answer<ServiceCall>() {
/* On second time we don't answer as it's callback from getLatestReleaseDetails above. */
@Override
public ServiceCall answer(InvocationOnMock invocation) {
return mock(ServiceCall.class);
}
});
/* Trigger call. */
start();
Distribute.getInstance().onActivityResumed(mock(Activity.class));
/* Verify on failure we don't complete workflow if ids don't match. */
verifyStatic(never());
SharedPreferencesManager.remove(PREFERENCE_KEY_DOWNLOAD_STATE);
}
Aggregations