use of com.amazonaws.Request 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.Request 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.Request 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.Request in project aws-sdk-android by aws-amplify.
the class PutObjectRequestTest method doTestClone.
/**
* Returns the cloned object.
*/
private <T extends PutObjectRequest> T doTestClone(T from, String bucket, String key, File file) {
assertNull(from.getAccessControlList());
assertEquals("bucket", from.getBucketName());
assertNull(from.getCannedAcl());
assertEquals(file, from.getFile());
assertNull(from.getInputStream());
assertNull(from.getRedirectLocation());
assertNull(from.getStorageClass());
// Fill it up - the base
final ProgressListener listener = new ProgressListener() {
@Override
public void progressChanged(ProgressEvent progressEvent) {
}
};
final AWSCredentials credentials = new BasicAWSCredentials("accesskey", "accessid");
final RequestMetricCollector collector = new RequestMetricCollector() {
@Override
public void collectMetrics(Request<?> request, Response<?> response) {
}
};
from.setGeneralProgressListener(listener);
from.setRequestCredentials(credentials);
from.setRequestMetricCollector(collector);
final AccessControlList accessControlList = new AccessControlList();
final ObjectMetadata metadata = new ObjectMetadata();
metadata.addUserMetadata("um_k1", "um_v1");
metadata.addUserMetadata("um_k2", "um_v2");
final SSECustomerKey sseKey = new SSECustomerKey(new byte[32]);
// Fill it up - the rest
from.setAccessControlList(accessControlList);
from.setCannedAcl(CannedAccessControlList.Private);
from.setInputStream(System.in);
from.setMetadata(metadata);
from.setSSECustomerKey(sseKey);
from.setRedirectLocation("redirectLocation");
from.setStorageClass(StorageClass.Standard);
assertSame(metadata, from.getMetadata());
// Clone it
final T to = (T) from.clone();
// Verify
assertSame(accessControlList, to.getAccessControlList());
assertSame(CannedAccessControlList.Private, to.getCannedAcl());
assertSame(System.in, to.getInputStream());
assertNotSame(from.getMetadata(), to.getMetadata());
final ObjectMetadata toOMD = to.getMetadata();
assertEquals("um_v1", toOMD.getUserMetaDataOf("um_k1"));
assertEquals("um_v2", toOMD.getUserMetaDataOf("um_k2"));
assertSame(sseKey, to.getSSECustomerKey());
assertEquals("redirectLocation", to.getRedirectLocation());
assertEquals(StorageClass.Standard.toString(), to.getStorageClass());
return to;
}
use of com.amazonaws.Request in project aws-sdk-android by aws-amplify.
the class DefaultSigningMethodTest method createFakeGetObjectRequest.
private static Request<?> createFakeGetObjectRequest(AmazonS3Client s3) {
try {
final GetObjectRequest fakeRequest = new GetObjectRequest(FAKE_BUCKET, FAKE_KEY);
final Request<?> fakeGetObjectRequest = (Request<?>) CREATE_REQUEST.invoke(s3, FAKE_BUCKET, FAKE_KEY, fakeRequest, HttpMethodName.GET);
return fakeGetObjectRequest;
} catch (final Exception e) {
fail("Exception when calling the private \"createRequest\" method. " + e.getMessage());
return null;
}
}
Aggregations