From 71c7a87ad665e900b89d231d7b4ec590e9187d9d Mon Sep 17 00:00:00 2001 From: Ganesh Chandrasekaran Date: Thu, 30 Aug 2018 18:00:27 +0900 Subject: increase coverage for restAdaptor HTTP_POST Issue-ID: APPC-1181 Change-Id: If92c903fa520e1a609d4e4558241709a2b3f6439 Signed-off-by: Ganesh Chandrasekaran --- .../adapter/rest/impl/TestRestAdapterImpl.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/test/java/org/onap/appc/adapter/rest/impl/TestRestAdapterImpl.java b/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/test/java/org/onap/appc/adapter/rest/impl/TestRestAdapterImpl.java index 6ddfe8817..b4c96d5d5 100644 --- a/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/test/java/org/onap/appc/adapter/rest/impl/TestRestAdapterImpl.java +++ b/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/test/java/org/onap/appc/adapter/rest/impl/TestRestAdapterImpl.java @@ -129,6 +129,39 @@ public class TestRestAdapterImpl { assertEquals("http://example.com:8081/posttest", httpPost.getURI().toURL().toString()); assertEquals("{\"name\":\"MyNode\", \"width\":200, \"height\":100}", EntityUtils.toString(httpPost.getEntity())); } + + @Test + public void testCreateRequestNoParamPost() throws IOException, IllegalStateException, IllegalArgumentException, + ZoneException, APPCException { + + SvcLogicContext ctx = new SvcLogicContext(); + Map params = new HashMap<>(); + + adapter.commonPost(params, ctx); + + assertEquals("failure", ctx.getStatus()); + assertEquals("500", ctx.getAttribute("org.openecomp.rest.result.code")); + assertEquals("java.lang.IllegalArgumentException: HTTP request may not be null", + ctx.getAttribute("org.openecomp.rest.result.message")); + } + + @Test + public void testCreateRequestInvalidParamPost() throws IOException, IllegalStateException, IllegalArgumentException, + ZoneException, APPCException { + + SvcLogicContext ctx = new SvcLogicContext(); + Map params = new HashMap<>(); + params.put("org.onap.appc.instance.URI", "boo"); + params.put("org.onap.appc.instance.haveHeader","false"); + params.put("org.onap.appc.instance.requestBody", "{\"name\":\"MyNode2\", \"width\":300, \"height\":300}"); + + adapter.commonPost(params, ctx); + + assertEquals("failure", ctx.getStatus()); + assertEquals("500", ctx.getAttribute("org.openecomp.rest.result.code")); + assertEquals("org.apache.http.client.ClientProtocolException", + ctx.getAttribute("org.openecomp.rest.result.message")); + } @Test public void testCreateHttpRequestPut() throws IOException, IllegalStateException, IllegalArgumentException, -- cgit 1.2.3-korg