summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShashikanth VH <shashikanth.vh@huawei.com>2022-05-06 06:01:15 +0000
committerGerrit Code Review <gerrit@onap.org>2022-05-06 06:01:15 +0000
commite89df29768b65e4be077a8bcfe16fd1a915be3ee (patch)
tree0ecea60b16d79410cbbef98a76695e044bc9739a
parentba91d86be9f174077556d387f4031151096bcb13 (diff)
parent7642a5d5855b3bbcb69d9027b827ec995b5226ef (diff)
Merge "Add UT to increase code coverage"
-rw-r--r--common/src/test/java/org/onap/so/client/HttpClientTest.java109
1 files changed, 109 insertions, 0 deletions
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")));
+ }
}