final T response = handleResponse(request, responseHandler, httpResponse, executionContext);
@Test(expected = CRC32MismatchException.class) public void testHandleResponseThrowsCRC32MisMatch() throws IOException { Request<?> request = new DefaultRequest<String>("ServiceName"); final HttpResponse httpResponse = new HttpResponse.Builder().statusText("TestResponse") .statusCode(200).build(); HttpResponseHandler<AmazonWebServiceResponse<String>> responseHandler = new HttpResponseHandler<AmazonWebServiceResponse<String>>() { @Override public AmazonWebServiceResponse<String> handle(HttpResponse response) throws Exception { assertSame(response, httpResponse); throw new CRC32MismatchException("test"); } @Override public boolean needsConnectionLeftOpen() { return false; } }; client.handleResponse(request, responseHandler, httpResponse, new ExecutionContext()); }
@Test(expected = IOException.class) public void testHandleResponseThrowsIOException() throws IOException { Request<?> request = new DefaultRequest<String>("ServiceName"); final HttpResponse httpResponse = new HttpResponse.Builder().statusText("TestResponse") .statusCode(200).build(); HttpResponseHandler<AmazonWebServiceResponse<String>> responseHandler = new HttpResponseHandler<AmazonWebServiceResponse<String>>() { @Override public AmazonWebServiceResponse<String> handle(HttpResponse response) throws Exception { assertSame(response, httpResponse); throw new IOException("test"); } @Override public boolean needsConnectionLeftOpen() { return false; } }; client.handleResponse(request, responseHandler, httpResponse, new ExecutionContext()); }
@Test(expected = RuntimeException.class) public void testHandleResponseWithNullResult() throws IOException { Request<?> request = new DefaultRequest<String>("ServiceName"); final HttpResponse httpResponse = new HttpResponse.Builder().statusText("TestResponse") .statusCode(200).build(); HttpResponseHandler<AmazonWebServiceResponse<String>> responseHandler = new HttpResponseHandler<AmazonWebServiceResponse<String>>() { @Override public AmazonWebServiceResponse<String> handle(HttpResponse response) throws Exception { assertSame(response, httpResponse); return null; } @Override public boolean needsConnectionLeftOpen() { return false; } }; client.handleResponse(request, responseHandler, httpResponse, new ExecutionContext()); }
@Test(expected = Exception.class) public void testHandleResponseThrowsGenericException() throws IOException { Request<?> request = new DefaultRequest<String>("ServiceName"); final HttpResponse httpResponse = new HttpResponse.Builder().statusText("TestResponse") .statusCode(200).build(); HttpResponseHandler<AmazonWebServiceResponse<String>> responseHandler = new HttpResponseHandler<AmazonWebServiceResponse<String>>() { @Override public AmazonWebServiceResponse<String> handle(HttpResponse response) throws Exception { assertSame(response, httpResponse); throw new Exception("test"); } @Override public boolean needsConnectionLeftOpen() { return false; } }; client.handleResponse(request, responseHandler, httpResponse, new ExecutionContext()); }
@Test public void testHandleResponse() throws IOException { Request<?> request = new DefaultRequest<String>("ServiceName"); final HttpResponse httpResponse = new HttpResponse.Builder().statusText("TestResponse") .statusCode(200).build(); HttpResponseHandler<AmazonWebServiceResponse<String>> responseHandler = new HttpResponseHandler<AmazonWebServiceResponse<String>>() { @Override public AmazonWebServiceResponse<String> handle(HttpResponse response) throws Exception { assertSame(response, httpResponse); AmazonWebServiceResponse<String> awsResponse = new AmazonWebServiceResponse<String>(); awsResponse.setResult("Result"); return awsResponse; } @Override public boolean needsConnectionLeftOpen() { return false; } }; assertEquals("Result", client.handleResponse(request, responseHandler, httpResponse, new ExecutionContext())); }
final T response = handleResponse(request, responseHandler, httpResponse, executionContext);
final T response = handleResponse(request, responseHandler, httpResponse, executionContext);