BindToJsonPayload implements MapBinder { @Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { return bindToRequest(request, (Object) postParams); } @Inject  BindToJsonPayload(Json jsonBinder); @Override R bindToRequest(R request, Map<String, Object> postParams); @Override R bindToRequest(R request, Object payload);  }
@Test public void testMap() throws SecurityException, NoSuchMethodException { BindToJsonPayload binder = new BindToJsonPayload(json); 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/json"); }
@Test public void testSomethingNotAMap() throws SecurityException, NoSuchMethodException { BindToJsonPayload binder = new BindToJsonPayload(json); HttpRequest request = HttpRequest.builder().method("GET").endpoint("http: request = binder.bindToRequest(request, new File("foo")); assertEquals(request.getPayload().getRawContent(), "{\"path\":\"foo\"}"); assertEquals(request.getPayload().getContentMetadata().getContentType(), "application/json"); }
@Test(expectedExceptions = NullPointerException.class) public void testNullIsBad() { BindToJsonPayload binder = new BindToJsonPayload(json); binder.bindToRequest(HttpRequest.builder().method("GET").endpoint("http: }