Function<JsonObject,String> uri) { return HttpStreams.<JsonObject,JsonObject>requests(stream, clientCreator, t -> HttpDelete.METHOD_NAME, uri, HttpResponders.json());
Function<JsonObject,String> uri) { return HttpStreams.<JsonObject,JsonObject>requests(stream, clientCreator, t -> HttpGet.METHOD_NAME, uri, HttpResponders.json());
@Test public void testStatusCode() throws Exception { DirectProvider ep = new DirectProvider(); Topology topology = ep.newTopology(); String url = "http://httpbin.org/status/"; TStream<Integer> rc = HttpStreams.<Integer,Integer>requests( topology.collection(Arrays.asList(200, 404, 202)), HttpClients::noAuthentication, t-> HttpGet.METHOD_NAME, t-> url + Integer.toString(t), (t,resp) -> resp.getStatusLine().getStatusCode()); Tester tester = topology.getTester(); Condition<List<Integer>> endCondition = tester.streamContents(rc, 200, 404, 202); tester.complete(ep, new JsonObject(), endCondition, 10, TimeUnit.SECONDS); assertTrue(endCondition.valid()); }
/** * Test basic authentication, first with valid user/password * and then with invalid (results in 401). * @throws Exception on failure */ @Test public void testBasicAuthentication() throws Exception { DirectProvider ep = new DirectProvider(); Topology topology = ep.newTopology(); String url = "http://httpbin.org/basic-auth/"; TStream<Integer> rc = HttpStreams.<String,Integer>requests( topology.strings("A", "B"), () -> HttpClients.basic("usA", "pwdA4"), t-> HttpGet.METHOD_NAME, t-> url + "us" + t + "/pwd" + t + "4", (t,resp) -> resp.getStatusLine().getStatusCode()); Tester tester = topology.getTester(); Condition<List<Integer>> endCondition = tester.streamContents(rc, 200, 401); tester.complete(ep, new JsonObject(), endCondition, 10, TimeUnit.SECONDS); assertTrue(endCondition.getResult().toString(), endCondition.valid()); }
@Test public void testDelete() throws Exception { DirectProvider ep = new DirectProvider(); Topology topology = ep.newTopology(); String url = "http://httpbin.org/delete"; TStream<String> stream = topology.strings(url); TStream<String> rc = HttpStreams.<String, String>requests( stream, HttpClients::noAuthentication, t -> HttpDelete.METHOD_NAME, t-> t, 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 testGet() throws Exception { DirectProvider ep = new DirectProvider(); Topology topology = ep.newTopology(); String url = "http://httpbin.org/get"; TStream<String> rc = HttpStreams.<String,String>requests( topology.strings(url), HttpClients::noAuthentication, t-> HttpGet.METHOD_NAME, t->t, 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()); }