[
https://issues.apache.org/jira/browse/QUARKS-96?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15289690#comment-15289690
]
ASF GitHub Bot commented on QUARKS-96:
--------------------------------------
Github user dlaboss commented on a diff in the pull request:
https://github.com/apache/incubator-quarks/pull/106#discussion_r63770856
--- Diff:
connectors/http/src/test/java/quarks/test/connectors/http/HttpTest.java ---
@@ -170,4 +288,80 @@ public void testJsonGet() throws Exception {
assertTrue(endCondition.getResult().toString(),
endCondition.valid());
}
+
+ @Test
+ public void testJsonPost() throws Exception {
+
+ DirectProvider ep = new DirectProvider();
+
+ Topology topology = ep.newTopology();
+
+ final String url = "http://httpbin.org/post";
+
+ JsonObject body = new JsonObject();
+ body.addProperty("foo", "abc");
+ body.addProperty("bar", 42);
+
+ TStream<JsonObject> stream =
topology.collection(Arrays.asList(body));
+ TStream<JsonObject> rc = HttpStreams.postJson(
+ stream, HttpClients::noAuthentication, t -> url,
+ t -> body);
+
+ TStream<Boolean> resStream = rc.map(j -> {
+ assertTrue(j.has("request"));
+ assertTrue(j.has("response"));
+ JsonObject req = j.getAsJsonObject("request");
+ JsonObject res = j.getAsJsonObject("response");
+
+ assertTrue(res.has("status"));
+ assertTrue(res.has("entity"));
+
+ assertEquals(req,
res.getAsJsonObject("entity").getAsJsonObject("json"));
+ return true;
+ });
+
+ rc.print();
+ Tester tester = topology.getTester();
+ Condition<List<Boolean>> endCondition =
tester.streamContents(resStream, true);
+ tester.complete(ep, new JsonObject(), endCondition, 10,
TimeUnit.SECONDS);
+ assertTrue(endCondition.getResult().toString(),
endCondition.valid());
+ }
+
+ @Test
+ public void testJsonPut() throws Exception {
+
+ DirectProvider ep = new DirectProvider();
+
+ Topology topology = ep.newTopology();
+
+ final String url = "http://httpbin.org/put";
+
+ JsonObject body = new JsonObject();
+ body.addProperty("foo", "abc");
+ body.addProperty("bar", 42);
+
+ TStream<JsonObject> stream =
topology.collection(Arrays.asList(body));
+ TStream<JsonObject> rc = HttpStreams.putJson(
+ stream, HttpClients::noAuthentication, t -> url,
+ t -> body);
--- End diff --
should be `t -> t`
> Add an HTTP POST utility method.
> --------------------------------
>
> Key: QUARKS-96
> URL: https://issues.apache.org/jira/browse/QUARKS-96
> Project: Quarks
> Issue Type: Improvement
> Components: Connectors
> Reporter: Daniel John Debrunner
> Assignee: Dale LaBossiere
> Labels: newbie
>
> HTTPStreams.requests can support any type of request but it would be useful
> to have a utility method for POST requests, similar to getJson - i.e., a
> postJson()
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)