use of com.microsoft.identity.common.internal.net.HttpResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class HttpResponseTest method testHttpResponseWithEmptyBody.
@Test
public void testHttpResponseWithEmptyBody() {
final HttpResponse response = new HttpResponse(HttpURLConnection.HTTP_OK, "", Collections.<String, List<String>>emptyMap());
Assert.assertNotNull(response.getBody());
Assert.assertTrue(response.getBody().isEmpty());
}
use of com.microsoft.identity.common.internal.net.HttpResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class HttpResponseTest method testHttpResponseWithNullBody.
@Test
public void testHttpResponseWithNullBody() {
final HttpResponse response = new HttpResponse(HttpURLConnection.HTTP_OK, null, Collections.<String, List<String>>emptyMap());
Assert.assertNull(response.getBody());
Assert.assertTrue(response.getStatusCode() == HttpURLConnection.HTTP_OK);
Assert.assertTrue(response.getHeaders().isEmpty());
}
use of com.microsoft.identity.common.internal.net.HttpResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class HttpRequestTest method testHttpMethodFailedWithStatusCodeRetryFails.
/**
* Verify the correct response is returned if first network call fails with internal error,
* and retry succeeds.
*/
private void testHttpMethodFailedWithStatusCodeRetryFails(HttpTestMethod method, int code) throws Exception {
// Set up three connections, all with the specified code. all failures.
final HttpURLConnection firstConnection = getMockedConnectionWithFailureResponse(code, getErrorResponse());
mockRequestBody(firstConnection);
final HttpURLConnection secondConnection = getMockedConnectionWithFailureResponse(code, getErrorResponse());
mockRequestBody(secondConnection);
final HttpURLConnection thirdConnection = getMockedConnectionWithFailureResponse(code, getErrorResponse());
mockRequestBody(thirdConnection);
addMockedConnection(firstConnection);
addMockedConnection(secondConnection);
addMockedConnection(thirdConnection);
assertEquals(3, getMockedConnectionCountInQueue());
try {
final HttpResponse response = sendWithMethod(method);
fail();
} finally {
assertEquals(1, getMockedConnectionCountInQueue());
final InOrder inOrder = Mockito.inOrder(firstConnection, secondConnection);
inOrder.verify(firstConnection).getInputStream();
inOrder.verify(firstConnection).getErrorStream();
inOrder.verify(firstConnection).getResponseCode();
inOrder.verify(firstConnection).getDate();
inOrder.verify(firstConnection).getHeaderFields();
inOrder.verify(secondConnection).getInputStream();
inOrder.verify(secondConnection).getErrorStream();
inOrder.verify(secondConnection).getResponseCode();
inOrder.verify(secondConnection).getDate();
inOrder.verify(secondConnection).getHeaderFields();
inOrder.verifyNoMoreInteractions();
}
}
use of com.microsoft.identity.common.internal.net.HttpResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class HttpRequestTest method testHttpMethodFailedNoRetry.
/**
* Verify that http request fails with {@link HttpURLConnection#HTTP_UNAUTHORIZED},
* no retry happens.
*/
private void testHttpMethodFailedNoRetry(HttpTestMethod method, int code) throws Exception {
final HttpURLConnection mockedFailureConnection = getMockedConnectionWithFailureResponse(code, getErrorResponse());
mockRequestBody(mockedFailureConnection);
addMockedConnection(mockedFailureConnection);
// send a post request
try {
assertEquals(1, getMockedConnectionCountInQueue());
final HttpResponse response = sendWithMethod(method);
assertNotNull(response);
assertEquals(response.getStatusCode(), code);
assertEquals(response.getBody(), getErrorResponse());
} catch (final IOException e) {
fail();
}
assertEquals(0, getMockedConnectionCountInQueue());
final InOrder inOrder = Mockito.inOrder(mockedFailureConnection);
inOrder.verify(mockedFailureConnection).getInputStream();
inOrder.verify(mockedFailureConnection).getErrorStream();
inOrder.verify(mockedFailureConnection).getResponseCode();
inOrder.verify(mockedFailureConnection).getDate();
inOrder.verify(mockedFailureConnection).getHeaderFields();
inOrder.verifyNoMoreInteractions();
}
use of com.microsoft.identity.common.internal.net.HttpResponse in project microsoft-authentication-library-common-for-android by AzureAD.
the class HttpRequestTest method testHttpMethodFailedNoRetryNoResponseBody.
/**
* Verify that http get request fails with {@link HttpURLConnection#HTTP_BAD_METHOD}
* and no response body, no retry happens.
*/
public void testHttpMethodFailedNoRetryNoResponseBody(HttpTestMethod method) throws Exception {
final HttpURLConnection mockedFailureConnection = getMockedConnectionWithFailureResponse(HttpURLConnection.HTTP_BAD_METHOD, null);
addMockedConnection(mockedFailureConnection);
try {
assertEquals(1, getMockedConnectionCountInQueue());
final HttpResponse response = sendWithMethod(method);
assertNotNull(response);
assertEquals(response.getStatusCode(), HttpURLConnection.HTTP_BAD_METHOD);
assertTrue(response.getBody().isEmpty());
} catch (final IOException e) {
fail();
}
assertEquals(0, getMockedConnectionCountInQueue());
final InOrder inOrder = Mockito.inOrder(mockedFailureConnection);
inOrder.verify(mockedFailureConnection).getInputStream();
inOrder.verify(mockedFailureConnection).getErrorStream();
inOrder.verify(mockedFailureConnection).getResponseCode();
inOrder.verify(mockedFailureConnection).getHeaderFields();
inOrder.verifyNoMoreInteractions();
}
Aggregations