BindS3ObjectMetadataToRequest implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof S3Object, "this binder is only valid for S3Object!, not %s", input); checkNotNull(request, "request"); S3Object s3Object = S3Object.class.cast(input); checkArgument(s3Object.getMetadata().getKey() != null, "s3Object.getMetadata().getKey() must be set!"); checkArgument(s3Object.getPayload().getContentMetadata().getContentLength() != null, "contentLength must be set, streaming not supported"); checkArgument(s3Object.getPayload().getContentMetadata().getContentLength() <= 5l * 1024 * 1024 * 1024, "maximum size for put object is 5GB"); request = metadataPrefixer.bindToRequest(request, s3Object.getMetadata().getUserMetadata()); if (s3Object.getMetadata().getCacheControl() != null) { request = (R) request.toBuilder() .replaceHeader(HttpHeaders.CACHE_CONTROL, s3Object.getMetadata().getCacheControl()).build(); } return request; } @Inject  BindS3ObjectMetadataToRequest(BindMapToHeadersWithPrefix metadataPrefixer); @SuppressWarnings("unchecked") @Override R bindToRequest(R request, Object input);  }
@Test public void testPassWithMinimumDetailsAndPayload5GB() { S3Object object = injector.getInstance(S3Object.Factory.class).create(null); Payload payload = Payloads.newStringPayload(""); payload.getContentMetadata().setContentLength(5368709120l); object.setPayload(payload); object.getMetadata().setKey("foo"); HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http: BindS3ObjectMetadataToRequest binder = injector.getInstance(BindS3ObjectMetadataToRequest.class); assertEquals(binder.bindToRequest(request, object), HttpRequest.builder().method("PUT").endpoint( URI.create("http: }
@Test public void testExtendedPropertiesBind() { S3Object object = injector.getInstance(S3Object.Factory.class).create(null); Payload payload = Payloads.newStringPayload(""); payload.getContentMetadata().setContentLength(5368709120l); object.setPayload(payload); object.getMetadata().setKey("foo"); object.getMetadata().setCacheControl("no-cache"); object.getMetadata().setUserMetadata(ImmutableMap.of("foo", "bar")); HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http: BindS3ObjectMetadataToRequest binder = injector.getInstance(BindS3ObjectMetadataToRequest.class); assertEquals(binder.bindToRequest(request, object), HttpRequest.builder().method("PUT").endpoint( URI.create("http: ImmutableMultimap.of("Cache-Control", "no-cache", "x-amz-meta-foo", "bar")).build()); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNoContentLengthIsBad() { S3Object object = injector.getInstance(S3Object.Factory.class).create(null); Payload payload = Payloads.newStringPayload(""); payload.getContentMetadata().setContentLength(null); object.setPayload(payload); object.getMetadata().setKey("foo"); HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http: BindS3ObjectMetadataToRequest binder = injector.getInstance(BindS3ObjectMetadataToRequest.class); binder.bindToRequest(request, object); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNoKeyIsBad() { S3Object object = injector.getInstance(S3Object.Factory.class).create(null); Payload payload = Payloads.newStringPayload(""); payload.getContentMetadata().setContentLength(5368709120000l); object.setPayload(payload); HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http: BindS3ObjectMetadataToRequest binder = injector.getInstance(BindS3ObjectMetadataToRequest.class); binder.bindToRequest(request, object); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testOver5GBIsBad() { S3Object object = injector.getInstance(S3Object.Factory.class).create(null); Payload payload = Payloads.newStringPayload(""); payload.getContentMetadata().setContentLength(5368709120000l); object.setPayload(payload); object.getMetadata().setKey("foo"); HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http: BindS3ObjectMetadataToRequest binder = injector.getInstance(BindS3ObjectMetadataToRequest.class); binder.bindToRequest(request, object); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testMustBeS3Object() { HttpRequest request = HttpRequest.builder().method("POST").endpoint("http: injector.getInstance(BindS3ObjectMetadataToRequest.class).bindToRequest(request, new File("foo")); }
@Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class }) public void testNullIsBad() { BindMapToHeadersWithPrefix binder = new BindMapToHeadersWithPrefix("prefix:"); HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: binder.bindToRequest(request, null); }