From: Shashikanth VH Date: Fri, 6 May 2022 06:01:15 +0000 (+0000) Subject: Merge "Add UT to increase code coverage" X-Git-Tag: 1.11.0~29 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=e89df29768b65e4be077a8bcfe16fd1a915be3ee;hp=ba91d86be9f174077556d387f4031151096bcb13;p=so.git Merge "Add UT to increase code coverage" --- diff --git a/common/src/test/java/org/onap/so/client/HttpClientTest.java b/common/src/test/java/org/onap/so/client/HttpClientTest.java index e9e8fe7853..3966d183f7 100644 --- a/common/src/test/java/org/onap/so/client/HttpClientTest.java +++ b/common/src/test/java/org/onap/so/client/HttpClientTest.java @@ -97,4 +97,113 @@ public class HttpClientTest { postRequestedFor(urlEqualTo("/services/sdnc/post")).withHeader("Accept", equalTo("application/json"))); } + @Test + public void testPostUsingXmlClient_success() throws MalformedURLException { + + wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post")) + .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(""))); + + URL url = new URL("http://localhost:" + wireMockRule.port() + "/services/sdnc/post"); + HttpClient client = httpClientFactory.newXmlClient(url, ONAPComponents.BPMN); + + client.addBasicAuthHeader( + "97FF88AB352DA16E00DDD81E3876431DEF8744465DACA489EB3B3BE1F10F63EDA1715E626D0A4827A3E19CD88421BF", + "123"); + client.addAdditionalHeader("Accept", "application/xml"); + + client.post("{}"); + + verify(exactly(1), postRequestedFor(urlEqualTo("/services/sdnc/post"))); + } + + @Test + public void testPostUsingXmlClient_nullHeader() throws MalformedURLException { + + wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post")) + .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(""))); + + URL url = new URL("http://localhost:" + wireMockRule.port() + "/services/sdnc/post"); + HttpClient client = httpClientFactory.newXmlClient(url, ONAPComponents.BPMN); + + client.accept = "application/xml"; + client.addAdditionalHeader("id", null); + + client.post("{}"); + + verify(exactly(1), + postRequestedFor(urlEqualTo("/services/sdnc/post")).withHeader("Accept", equalTo("application/xml"))); + } + + @Test + public void testPostUsingXmlClient_nullBasicAuth() throws MalformedURLException { + + wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post")) + .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/xml").withBody(""))); + + URL url = new URL("http://localhost:" + wireMockRule.port() + "/services/sdnc/post"); + HttpClient client = httpClientFactory.newXmlClient(url, ONAPComponents.BPMN); + + client.accept = "application/xml"; + client.addBasicAuthHeader("", "12345"); + + client.post("{}"); + + verify(exactly(1), + postRequestedFor(urlEqualTo("/services/sdnc/post")).withHeader("Accept", equalTo("application/xml"))); + } + + @Test + public void testPostUsingTextXmlClient_success() throws MalformedURLException { + + wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post")) + .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/xml").withBody(""))); + + URL url = new URL("http://localhost:" + wireMockRule.port() + "/services/sdnc/post"); + HttpClient client = httpClientFactory.newTextXmlClient(url, ONAPComponents.BPMN); + + client.addBasicAuthHeader( + "97FF88AB352DA16E00DDD81E3876431DEF8744465DACA489EB3B3BE1F10F63EDA1715E626D0A4827A3E19CD88421BF", + "123"); + client.addAdditionalHeader("Accept", "text/xml"); + + client.post("{}"); + + verify(exactly(1), postRequestedFor(urlEqualTo("/services/sdnc/post"))); + } + + @Test + public void testPostUsingTextXmlClient_nullHeader() throws MalformedURLException { + + wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post")) + .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/xml").withBody(""))); + + URL url = new URL("http://localhost:" + wireMockRule.port() + "/services/sdnc/post"); + HttpClient client = httpClientFactory.newTextXmlClient(url, ONAPComponents.BPMN); + + client.addAdditionalHeader("Accept", "text/xml"); + client.addAdditionalHeader("id", null); + + client.post("{}"); + + verify(exactly(1), + postRequestedFor(urlEqualTo("/services/sdnc/post")).withHeader("Accept", equalTo("text/xml"))); + } + + @Test + public void testPostUsingTextXmlClient_nullBasicAuth() throws MalformedURLException { + + wireMockRule.stubFor(post(urlEqualTo("/services/sdnc/post")) + .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/xml").withBody(""))); + + URL url = new URL("http://localhost:" + wireMockRule.port() + "/services/sdnc/post"); + HttpClient client = httpClientFactory.newTextXmlClient(url, ONAPComponents.BPMN); + + client.addBasicAuthHeader("", "12345"); + client.addAdditionalHeader("Accept", "text/xml"); + + client.post("{}"); + + verify(exactly(1), + postRequestedFor(urlEqualTo("/services/sdnc/post")).withHeader("Accept", equalTo("text/xml"))); + } }