Search in sources :

Example 1 with CredentialsRequestHandler

use of com.amazonaws.handlers.CredentialsRequestHandler in project aws-sdk-android by aws-amplify.

the class AmazonHttpClientTest method testRequestHander2s.

@Test
public void testRequestHander2s() {
    final Request<?> testRequest = new DefaultRequest<String>("test");
    final List<Object> calls = new ArrayList<Object>();
    List<RequestHandler2> handlers = new ArrayList<RequestHandler2>();
    RequestHandler2 defaultHandler = new RequestHandler2() {

        @Override
        public void beforeRequest(Request<?> request) {
            assertSame(testRequest, request);
            calls.add(this);
        }

        @Override
        public void afterResponse(Request<?> request, Response<?> response) {
        }

        @Override
        public void afterError(Request<?> request, Response<?> response, Exception e) {
        }
    };
    RequestHandler2 credentialHandler = new CredentialsRequestHandler() {

        @Override
        public void beforeRequest(Request<?> request) {
            assertSame(testRequest, request);
            calls.add(this);
        }

        @Override
        public void afterResponse(Request<?> request, Response<?> response) {
        }

        @Override
        public void afterError(Request<?> request, Response<?> response, Exception e) {
        }
    };
    handlers.add(defaultHandler);
    handlers.add(credentialHandler);
    ExecutionContext ec = new ExecutionContext(handlers, false, null);
    client.requestHandler2s(testRequest, ec);
    assertEquals(calls.size(), 2);
    assertTrue(calls.contains(defaultHandler));
    assertTrue(calls.contains(credentialHandler));
}
Also used : AmazonWebServiceResponse(com.amazonaws.AmazonWebServiceResponse) Response(com.amazonaws.Response) DefaultRequest(com.amazonaws.DefaultRequest) RequestHandler2(com.amazonaws.handlers.RequestHandler2) ArrayList(java.util.ArrayList) Request(com.amazonaws.Request) DefaultRequest(com.amazonaws.DefaultRequest) AmazonWebServiceRequest(com.amazonaws.AmazonWebServiceRequest) URISyntaxException(java.net.URISyntaxException) CRC32MismatchException(com.amazonaws.internal.CRC32MismatchException) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) AmazonClientException(com.amazonaws.AmazonClientException) CredentialsRequestHandler(com.amazonaws.handlers.CredentialsRequestHandler) Test(org.junit.Test)

Aggregations

AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1 AmazonWebServiceRequest (com.amazonaws.AmazonWebServiceRequest)1 AmazonWebServiceResponse (com.amazonaws.AmazonWebServiceResponse)1 DefaultRequest (com.amazonaws.DefaultRequest)1 Request (com.amazonaws.Request)1 Response (com.amazonaws.Response)1 CredentialsRequestHandler (com.amazonaws.handlers.CredentialsRequestHandler)1 RequestHandler2 (com.amazonaws.handlers.RequestHandler2)1 CRC32MismatchException (com.amazonaws.internal.CRC32MismatchException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1