summaryrefslogtreecommitdiffstats
path: root/common/src/test/java
diff options
context:
space:
mode:
authorMichal Kabaj <michal.kabaj@nokia.com>2018-12-17 17:10:24 +0100
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>2019-01-04 12:02:36 +0000
commit61b78a7d5f1eb8f1c5955d6d1439ce9225a39b46 (patch)
tree4f6ab37c32786ad489f6d8f2130d1b03105f8c32 /common/src/test/java
parent85a47c701c3b34c58d2b121ba466d41ffb4fb7b0 (diff)
HttpClientFactory to create HttpClient instances
-Replace constructor calls with existing factory -Add create methods to factory for each required Media Type Change-Id: Ibd03c10230c87a0413c0ec529e0ea9ac800444f9 Issue-ID: SO-1344 Signed-off-by: Michal Kabaj <michal.kabaj@nokia.com>
Diffstat (limited to 'common/src/test/java')
-rw-r--r--common/src/test/java/org/onap/so/client/HttpClientTest.java17
-rw-r--r--common/src/test/java/org/onap/so/client/RestClientTest.java10
2 files changed, 14 insertions, 13 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 221005cb7c..75ce5f322f 100644
--- a/common/src/test/java/org/onap/so/client/HttpClientTest.java
+++ b/common/src/test/java/org/onap/so/client/HttpClientTest.java
@@ -30,22 +30,21 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
import java.net.MalformedURLException;
import java.net.URL;
-
import org.junit.Rule;
import org.junit.Test;
import org.onap.so.utils.TargetEntity;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
-
public class HttpClientTest{
+ private final HttpClientFactory httpClientFactory = new HttpClientFactory();
@Rule
public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicHttpsPort());
- @Test(expected = Test.None.class)
+ @Test
public void testPost_success() throws MalformedURLException{
stubFor(post(urlEqualTo("/services/sdnc/post"))
@@ -54,7 +53,7 @@ public class HttpClientTest{
.withBody("")));
URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post");
- HttpClient client = new HttpClient(url, "application/json", TargetEntity.BPMN);
+ HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN);
client.addBasicAuthHeader("97FF88AB352DA16E00DDD81E3876431DEF8744465DACA489EB3B3BE1F10F63EDA1715E626D0A4827A3E19CD88421BF", "123");
client.addAdditionalHeader("Accept", "application/json");
@@ -64,7 +63,7 @@ public class HttpClientTest{
verify(exactly(1), postRequestedFor(urlEqualTo("/services/sdnc/post")));
}
- @Test(expected = Test.None.class)
+ @Test
public void testPost_nullHeader() throws MalformedURLException{
stubFor(post(urlEqualTo("/services/sdnc/post"))
@@ -73,7 +72,7 @@ public class HttpClientTest{
.withBody("")));
URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post");
- HttpClient client = new HttpClient(url, "application/json", TargetEntity.BPMN);
+ HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN);
client.addAdditionalHeader("Accept", "application/json");
client.addAdditionalHeader("id", null);
@@ -84,7 +83,7 @@ public class HttpClientTest{
.withHeader("Accept", equalTo("application/json")));
}
- @Test(expected = Test.None.class)
+ @Test
public void testPost_nullBasicAuth() throws MalformedURLException{
stubFor(post(urlEqualTo("/services/sdnc/post"))
@@ -93,7 +92,7 @@ public class HttpClientTest{
.withBody("")));
URL url = new URL("http://localhost:" + wireMockConfig().portNumber() + "/services/sdnc/post");
- HttpClient client = new HttpClient(url, "application/json", TargetEntity.BPMN);
+ HttpClient client = httpClientFactory.newJsonClient(url, TargetEntity.BPMN);
client.addBasicAuthHeader("", "12345");
client.addAdditionalHeader("Accept", "application/json");
diff --git a/common/src/test/java/org/onap/so/client/RestClientTest.java b/common/src/test/java/org/onap/so/client/RestClientTest.java
index 6fca4a1820..06196fd73e 100644
--- a/common/src/test/java/org/onap/so/client/RestClientTest.java
+++ b/common/src/test/java/org/onap/so/client/RestClientTest.java
@@ -47,11 +47,12 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class RestClientTest {
-
+
+ private final HttpClientFactory httpClientFactory = new HttpClientFactory();
@Mock
private RestProperties props;
-
-
+
+
@Test
public void retries() throws Exception {
RestClient spy = buildSpy();
@@ -82,7 +83,8 @@ public class RestClientTest {
}
private RestClient buildSpy() throws MalformedURLException, IllegalArgumentException, UriBuilderException {
- RestClient client = new HttpClient(UriBuilder.fromUri("http://localhost/test").build().toURL(), "application/json", TargetEntity.BPMN);
+ RestClient client = httpClientFactory
+ .newJsonClient(UriBuilder.fromUri("http://localhost/test").build().toURL(), TargetEntity.BPMN);
return spy(client);
}