use of com.amazonaws.Response 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));
}
use of com.amazonaws.Response in project aws-sdk-android by aws-amplify.
the class AmazonHttpClientTest method testAfterError.
@Test
public void testAfterError() {
final Request<?> testRequest = new DefaultRequest<String>("test");
final Response<?> testResponse = new Response<String>("test", new HttpResponse.Builder().build());
final List<Object> calls = new ArrayList<Object>();
List<RequestHandler2> handlers = new ArrayList<RequestHandler2>();
final AmazonClientException ace = new AmazonClientException("Test exception");
RequestHandler2 handler = new RequestHandler2() {
@Override
public void beforeRequest(Request<?> request) {
}
@Override
public void afterResponse(Request<?> request, Response<?> response) {
}
@Override
public void afterError(Request<?> request, Response<?> response, Exception e) {
assertSame(testRequest, request);
assertSame(testResponse, response);
assertSame(e, ace);
calls.add(this);
}
};
handlers.add(handler);
client.afterError(testRequest, testResponse, handlers, ace);
assertEquals(calls.size(), 1);
assertTrue(calls.contains(handler));
}
use of com.amazonaws.Response in project aws-sdk-android by aws-amplify.
the class AmazonHttpClientTest method testAfterResponse.
@Test
public void testAfterResponse() {
final Request<?> testRequest = new DefaultRequest<String>("test");
final Response<?> testResponse = new Response<String>("test", new HttpResponse.Builder().build());
final List<Object> calls = new ArrayList<Object>();
List<RequestHandler2> handlers = new ArrayList<RequestHandler2>();
RequestHandler2 handler = new RequestHandler2() {
@Override
public void beforeRequest(Request<?> request) {
}
@Override
public void afterResponse(Request<?> request, Response<?> response) {
assertSame(testRequest, request);
assertSame(testResponse, response);
calls.add(this);
}
@Override
public void afterError(Request<?> request, Response<?> response, Exception e) {
}
};
handlers.add(handler);
client.afterResponse(testRequest, handlers, testResponse, null);
assertEquals(calls.size(), 1);
assertTrue(calls.contains(handler));
}
use of com.amazonaws.Response in project fernet-java8 by l0s.
the class MemoryOverwritingRequestHandlerTest method verifyAfterErrorClearsSecret.
@Test
public void verifyAfterErrorClearsSecret() {
// given
final ByteBuffer secretBinary = ByteBuffer.wrap(new byte[] { 1, 1, 2, 3, 5, 8 });
assertTrue(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8 }));
final PutSecretValueRequest originalRequest = new PutSecretValueRequest();
originalRequest.setSecretBinary(secretBinary);
final Request<PutSecretValueRequest> request = new DefaultRequest<PutSecretValueRequest>(originalRequest, "AWSSecretsManager");
final PutSecretValueResult result = mock(PutSecretValueResult.class);
final HttpResponse httpResponse = mock(HttpResponse.class);
final Response<PutSecretValueResult> response = new Response<PutSecretValueResult>(result, httpResponse);
// when
handler.afterError(request, response, new Exception());
// then
assertFalse(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8 }));
}
use of com.amazonaws.Response in project fernet-java8 by l0s.
the class MemoryOverwritingRequestHandlerTest method verifyAfterResponseClearsSecret.
@Test
public void verifyAfterResponseClearsSecret() {
// given
final ByteBuffer secretBinary = ByteBuffer.wrap(new byte[] { 1, 1, 2, 3, 5, 8 });
assertTrue(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8 }));
final PutSecretValueRequest originalRequest = new PutSecretValueRequest();
originalRequest.setSecretBinary(secretBinary);
final Request<PutSecretValueRequest> request = new DefaultRequest<PutSecretValueRequest>(originalRequest, "AWSSecretsManager");
final PutSecretValueResult result = mock(PutSecretValueResult.class);
final HttpResponse httpResponse = mock(HttpResponse.class);
final Response<PutSecretValueResult> response = new Response<PutSecretValueResult>(result, httpResponse);
// when
handler.afterResponse(request, response);
// then
assertFalse(Arrays.equals(secretBinary.array(), new byte[] { 1, 1, 2, 3, 5, 8 }));
}
Aggregations