UnaryOperator<JsonObject> body) { return HttpStreams.<JsonObject, JsonObject> requestsWithBody(stream, clientCreator, t -> HttpPost.METHOD_NAME, uri, t -> new ByteArrayEntity(body.apply(t).toString().getBytes(StandardCharsets.UTF_8)),
Function<JsonObject, String> uri, UnaryOperator<JsonObject> body) { return HttpStreams.<JsonObject, JsonObject> requestsWithBody(stream, clientCreator, t -> HttpPut.METHOD_NAME, uri, t -> new ByteArrayEntity(body.apply(t).toString().getBytes(StandardCharsets.UTF_8)),
@Test public void testPost() throws Exception { DirectProvider ep = new DirectProvider(); Topology topology = ep.newTopology(); String url = "http://httpbin.org/post"; TStream<String> stream = topology.strings(url); TStream<String> rc = HttpStreams.<String, String>requestsWithBody( stream, HttpClients::noAuthentication, t -> HttpPost.METHOD_NAME, t-> t, t-> new ByteArrayEntity(t.getBytes()), HttpResponders.inputOn200()); Tester tester = topology.getTester(); Condition<List<String>> endCondition = tester.streamContents(rc, url); tester.complete(ep, new JsonObject(), endCondition, 10, TimeUnit.SECONDS); assertTrue(endCondition.valid()); }
@Test public void testPut() throws Exception { DirectProvider ep = new DirectProvider(); Topology topology = ep.newTopology(); String url = "http://httpbin.org/put"; TStream<String> stream = topology.strings(url); TStream<String> rc = HttpStreams.<String, String>requestsWithBody( stream, HttpClients::noAuthentication, t -> HttpPut.METHOD_NAME, t-> t, t-> new ByteArrayEntity(t.getBytes()), HttpResponders.inputOn200()); Tester tester = topology.getTester(); Condition<List<String>> endCondition = tester.streamContents(rc, url); tester.complete(ep, new JsonObject(), endCondition, 10, TimeUnit.SECONDS); assertTrue(endCondition.valid()); }