BindToStringPayload implements Binder { @Override public <R extends HttpRequest> R bindToRequest(R request, Object payload) { request.setPayload(payload.toString()); return request; }  @Override R bindToRequest(R request, Object payload);  }
@Test public void testMap() throws SecurityException, NoSuchMethodException { BindToStringPayload binder = new BindToStringPayload(); HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: request = binder.bindToRequest(request, ImmutableMap.of("imageName", "foo", "serverId", "2")); assertEquals(request.getPayload().getRawContent(), "{imageName=foo, serverId=2}"); assertEquals(request.getPayload().getContentMetadata().getContentType(), "application/unknown"); }
@Test public void testSomethingNotAMap() throws SecurityException, NoSuchMethodException { BindToStringPayload binder = new BindToStringPayload(); HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: request = binder.bindToRequest(request, new File("foo")); assertEquals(request.getPayload().getRawContent(), "foo"); assertEquals(request.getPayload().getContentMetadata().getContentType(), "application/unknown"); }
@Test(expectedExceptions = NullPointerException.class) public void testNullIsBad() { BindToStringPayload binder = new BindToStringPayload(); binder.bindToRequest(HttpRequest.builder().method("GET").endpoint("http: }