From 7642a5d5855b3bbcb69d9027b827ec995b5226ef Mon Sep 17 00:00:00 2001 From: pwielebs Date: Thu, 21 Apr 2022 08:11:57 +0200 Subject: Add UT to increase code coverage Issue-ID: SO-3928 Signed-off-by: Piotr Wielebski Change-Id: I0a4e708c60a8fedc711df09ac1b8516fd366ed3f --- .../java/org/onap/so/client/HttpClientTest.java | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) (limited to 'common/src') 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"))); + } } -- cgit 1.2.3-korg