use of com.microsoft.appcenter.http.HttpResponse in project mobile-center-sdk-android by Microsoft.
the class DistributeCustomizationTest method distributeNotRecentCoverage.
private void distributeNotRecentCoverage(DistributeListener actualListener, DistributeListener verificationListener, boolean onPause) throws Exception {
/* Set the package version higher than the portal's one. */
mockStatic(DeviceInfoHelper.class);
when(DeviceInfoHelper.getVersionCode(any(PackageInfo.class))).thenReturn(11);
/* Mock http call. */
ArgumentCaptor<ServiceCallback> httpCallback = ArgumentCaptor.forClass(ServiceCallback.class);
when(mHttpClient.callAsync(anyString(), anyString(), anyMapOf(String.class, String.class), any(HttpClient.CallTemplate.class), httpCallback.capture())).thenReturn(mock(ServiceCall.class));
/* Mock data model. */
mockStatic(ReleaseDetails.class);
ReleaseDetails details = mock(ReleaseDetails.class);
when(details.getId()).thenReturn(1);
when(details.getVersion()).thenReturn(10);
when(details.getShortVersion()).thenReturn("2.3.4");
when(details.isMandatoryUpdate()).thenReturn(false);
when(details.getReleaseHash()).thenReturn("some_hash");
when(ReleaseDetails.parse(anyString())).thenReturn(details);
/* Mock update token. */
when(SharedPreferencesManager.getString(PREFERENCE_KEY_UPDATE_TOKEN)).thenReturn("some token");
/* Start Distribute service. */
restartProcessAndSdk();
/* Set Distribute listener and customize it. */
Distribute.setListener(actualListener);
/* Resume activity. */
Distribute.getInstance().onActivityResumed(mActivity);
if (onPause) {
Distribute.getInstance().onActivityPaused(mActivity);
}
/* Simulate network latency. */
httpCallback.getValue().onCallSucceeded(new HttpResponse(200, "mock"));
/* Verify the right listener gets called. */
verify(verificationListener, never()).onNoReleaseAvailable(any(Activity.class));
verify(verificationListener, never()).onReleaseAvailable(any(Activity.class), any(ReleaseDetails.class));
}
use of com.microsoft.appcenter.http.HttpResponse in project mobile-center-sdk-android by Microsoft.
the class DistributeCustomizationTest method distributeNoReleaseAvailableCoverage.
private void distributeNoReleaseAvailableCoverage(DistributeListener actualListener, DistributeListener verificationListener, boolean onPause) throws Exception {
/* Mock error parsing. */
ErrorDetails errorDetails = mock(ErrorDetails.class);
when(errorDetails.getCode()).thenReturn(ErrorDetails.NO_RELEASES_FOUND);
mockStatic(ErrorDetails.class);
when(ErrorDetails.parse(anyString())).thenReturn(errorDetails);
/* Mock http call. */
final HttpException httpException = new HttpException(new HttpResponse(404, "{code:'not_found'}"));
/* Mock http call. */
ArgumentCaptor<ServiceCallback> httpCallback = ArgumentCaptor.forClass(ServiceCallback.class);
when(mHttpClient.callAsync(anyString(), anyString(), anyMapOf(String.class, String.class), any(HttpClient.CallTemplate.class), httpCallback.capture())).thenReturn(mock(ServiceCall.class));
/* Start Distribute service. */
restartProcessAndSdk();
/* Set Distribute listener and customize it. */
Distribute.setListener(actualListener);
/* Resume activity. */
Distribute.getInstance().onActivityResumed(mActivity);
if (onPause) {
Distribute.getInstance().onActivityPaused(mActivity);
}
/* Simulate network latency. */
httpCallback.getValue().onCallFailed(httpException);
/* Verify the right listener gets called. */
verify(verificationListener, never()).onNoReleaseAvailable(any(Activity.class));
verify(verificationListener, never()).onReleaseAvailable(any(Activity.class), any(ReleaseDetails.class));
}
use of com.microsoft.appcenter.http.HttpResponse in project mobile-center-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);
}
use of com.microsoft.appcenter.http.HttpResponse in project mobile-center-sdk-android by Microsoft.
the class DistributeBeforeApiSuccessTest method checkReleaseFailsParsing.
@Test
public void checkReleaseFailsParsing() throws Exception {
/* Mock we already have token. */
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) {
((ServiceCallback) invocation.getArguments()[4]).onCallSucceeded(new HttpResponse(200, "mock", Collections.<String, String>emptyMap()));
return mock(ServiceCall.class);
}
});
Map<String, String> headers = new HashMap<>();
when(ReleaseDetails.parse(anyString())).thenThrow(new JSONException("mock"));
/* Trigger call. */
start();
Distribute.getInstance().onActivityResumed(mock(Activity.class));
verify(mHttpClient).callAsync(anyString(), anyString(), eq(headers), any(HttpClient.CallTemplate.class), any(ServiceCallback.class));
/* Verify on failure we complete workflow. */
verifyStatic();
SharedPreferencesManager.remove(PREFERENCE_KEY_DOWNLOAD_STATE);
/* After that if we resume app nothing happens. */
Distribute.getInstance().onActivityPaused(mock(Activity.class));
Distribute.getInstance().onActivityResumed(mock(Activity.class));
verify(mHttpClient).callAsync(anyString(), anyString(), eq(headers), any(HttpClient.CallTemplate.class), any(ServiceCallback.class));
}
use of com.microsoft.appcenter.http.HttpResponse in project mobile-center-sdk-android by Microsoft.
the class DefaultChannelTest method disableBeforeCheckingPendingLogs.
@Test
public void disableBeforeCheckingPendingLogs() {
Ingestion ingestion = mock(Ingestion.class);
when(ingestion.isEnabled()).thenReturn(true);
Persistence persistence = mock(Persistence.class);
final DefaultChannel channel = new DefaultChannel(mock(Context.class), UUID.randomUUID().toString(), persistence, ingestion, mAppCenterHandler);
when(persistence.getLogs(anyString(), anyListOf(String.class), anyInt(), anyListOf(Log.class))).thenAnswer(getGetLogsAnswer(1));
when(ingestion.sendAsync(anyString(), any(UUID.class), any(LogContainer.class), any(ServiceCallback.class))).thenAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
/* Simulate a service disabled in the middle of network transaction. */
ServiceCallback callback = (ServiceCallback) invocation.getArguments()[3];
channel.removeGroup(TEST_GROUP);
callback.onCallSucceeded(new HttpResponse(200, ""));
return null;
}
});
channel.addGroup(TEST_GROUP, 1, BATCH_TIME_INTERVAL, MAX_PARALLEL_BATCHES, null, null);
channel.enqueue(mock(Log.class), TEST_GROUP, Flags.DEFAULTS);
verify(mAppCenterHandler, never()).postDelayed(any(Runnable.class), eq(BATCH_TIME_INTERVAL));
}
Aggregations