From 1c064b284757ed0c794cbf8f3a6d65e34564af3a Mon Sep 17 00:00:00 2001 From: Duncan Grant Date: Fri, 24 Mar 2017 09:15:47 +0000 Subject: [PATCH] HttpCommandEffector allows string payload Also fixed integration tests that failing due to https://httpbin --- .../effector/http/HttpCommandEffector.java | 2 +- .../HttpCommandEffectorIntegrationTest.java | 14 ++++++------- .../http/HttpCommandEffectorTest.java | 20 +++++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/apache/brooklyn/core/effector/http/HttpCommandEffector.java b/core/src/main/java/org/apache/brooklyn/core/effector/http/HttpCommandEffector.java index 1388a926d6..a32e0fe9c3 100644 --- a/core/src/main/java/org/apache/brooklyn/core/effector/http/HttpCommandEffector.java +++ b/core/src/main/java/org/apache/brooklyn/core/effector/http/HttpCommandEffector.java @@ -181,7 +181,7 @@ private HttpRequest buildHttpRequest(String httpVerb, URI uri, Mapof( "description", "Created via API", @@ -92,7 +92,7 @@ public void testHttpEffectorWithPayload() throws Exception { public void testHttpEffectorWithJsonPath() throws Exception { new HttpCommandEffector(ConfigBag.newInstance() .configure(HttpCommandEffector.EFFECTOR_NAME, "Httpbin") - .configure(HttpCommandEffector.EFFECTOR_URI, "https://httpbin.org/get?id=myId") + .configure(HttpCommandEffector.EFFECTOR_URI, "http://httpbin.org/get?id=myId") .configure(HttpCommandEffector.EFFECTOR_HTTP_VERB, "GET") .configure(HttpCommandEffector.JSON_PATH, "$.args.id") .configure(HttpCommandEffector.PUBLISH_SENSOR, "result") @@ -107,19 +107,19 @@ public void testHttpEffectorWithJsonPath() throws Exception { public void testHttpEffectorWithParameters() throws Exception { new HttpCommandEffector(ConfigBag.newInstance() .configure(HttpCommandEffector.EFFECTOR_NAME, "Httpbin") - .configure(HttpCommandEffector.EFFECTOR_URI, "https://httpbin.org/get") + .configure(HttpCommandEffector.EFFECTOR_URI, "http://httpbin.org/get") .configure(HttpCommandEffector.EFFECTOR_HTTP_VERB, "GET") .configure(HttpCommandEffector.EFFECTOR_PARAMETER_DEFS, - MutableMap.of("uri", MutableMap.of("defaultValue", "https://httpbin.org/get")))) + MutableMap.of("uri", MutableMap.of("defaultValue", "http://httpbin.org/get")))) .apply(entity); String val; // explicit value - val = entity.invoke(EFFECTOR_HTTPBIN, MutableMap.of("uri", "https://httpbin.org/ip")).get(); + val = entity.invoke(EFFECTOR_HTTPBIN, MutableMap.of("uri", "http://httpbin.org/ip")).get(); Assert.assertNotNull(JsonPath.parse(val).read("$.origin", String.class)); // default value val = entity.invoke(EFFECTOR_HTTPBIN, MutableMap.of()).get(); - Assert.assertEquals(JsonPath.parse(val).read("$.url", String.class), "https://httpbin.org/get"); + Assert.assertEquals(JsonPath.parse(val).read("$.url", String.class), "http://httpbin.org/get"); } } diff --git a/core/src/test/java/org/apache/brooklyn/core/effector/http/HttpCommandEffectorTest.java b/core/src/test/java/org/apache/brooklyn/core/effector/http/HttpCommandEffectorTest.java index 8d620a4881..d3d5b7fe66 100644 --- a/core/src/test/java/org/apache/brooklyn/core/effector/http/HttpCommandEffectorTest.java +++ b/core/src/test/java/org/apache/brooklyn/core/effector/http/HttpCommandEffectorTest.java @@ -166,6 +166,26 @@ public void testPayloadWithContentTypeHeaderJson() throws InterruptedException { assertSent(server, "POST", "/post"); } + @Test + public void testPayloadWithContentTypeHeaderYaml() throws InterruptedException { + server.enqueue((jsonResponse("map-response.json"))); + + httpCommandEffector = new HttpCommandEffector(ConfigBag.newInstance() + .configure(HttpCommandEffector.EFFECTOR_NAME, EFFECTOR_HTTP_COMMAND.getName()) + .configure(HttpCommandEffector.EFFECTOR_URI, url("/post")) + .configure(HttpCommandEffector.EFFECTOR_HTTP_VERB, "POST") + .configure(HttpCommandEffector.EFFECTOR_HTTP_PAYLOAD, "my yaml") + .configure(HttpCommandEffector.EFFECTOR_HTTP_HEADERS, ImmutableMap.of(HttpHeaders.CONTENT_TYPE, "application/yaml")) + .configure(HttpCommandEffector.JSON_PATH, "$.data") + ); + assertNotNull(httpCommandEffector); + TestEntity testEntity = app.createAndManageChild(buildEntitySpec(httpCommandEffector)); + testEntity.invoke(EFFECTOR_HTTP_COMMAND, ImmutableMap.of()).getUnchecked(Duration.minutes(1)); + + assertEquals(server.getRequestCount(), 1); + assertEquals(new String(server.takeRequest().getBody()), "my yaml"); + } + @Test public void testPayloadWithoutContentTypeHeader() throws InterruptedException { server.enqueue(jsonResponse("map-response.json"));