BindMetadataToHeaders implements Binder { @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof AtmosObject, "this binder is only valid for AtmosObject!"); checkNotNull(request, "request"); AtmosObject object = AtmosObject.class.cast(input); checkNotNull(object.getPayload(), "object payload"); checkArgument(object.getPayload().getContentMetadata().getContentLength() != null, "contentLength must be set, streaming not supported"); return metaBinder.bindToRequest(request, object.getUserMetadata()); } @Inject protected  BindMetadataToHeaders(BindUserMetadataToHeaders metaBinder); @Override R bindToRequest(R request, Object input);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testMustBeAtmosObject() { HttpRequest request = HttpRequest.builder().method("POST").endpoint("http: binder.bindToRequest(request, new File("foo")); }
@Test(expectedExceptions = NullPointerException.class) public void testNullIsBad() { HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: binder.bindToRequest(request, null); }
@Test(expectedExceptions = NullPointerException.class) public void testNullPayloadIsBad() { AtmosObject object = injector.getInstance(AtmosObject.Factory.class).create(null); HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: binder.bindToRequest(request, object); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullContentLengthIllegal() { AtmosObject object = injector.getInstance(AtmosObject.Factory.class).create(null); Payload payload = Payloads.newStringPayload(""); payload.getContentMetadata().setContentLength(null); object.setPayload(payload); HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: binder.bindToRequest(request, object); }