diff options
author | su622b <su622b@att.com> | 2020-06-11 17:20:09 -0400 |
---|---|---|
committer | su622b <su622b@att.com> | 2020-06-11 17:28:53 -0400 |
commit | 2fa245d0944a24f317bae4ce74111e2bd9620eb8 (patch) | |
tree | 6624f3c672a1f737bb1c2ceed1a30c4ebcde06bc /src/test/java/org/onap | |
parent | ebbbdfe1543809bc044781f3ce30e65d106e21d8 (diff) |
read and set the jersey client properties
Issue-ID: DMAAP-1443
Change-Id: I0f92536fa88c2d21a1467f6c92e162cbe46db85f
Signed-off-by: su622b <su622b@att.com>
Diffstat (limited to 'src/test/java/org/onap')
-rw-r--r-- | src/test/java/org/onap/dmaap/mr/client/impl/DMaapClientUtilTest.java | 16 | ||||
-rw-r--r-- | src/test/java/org/onap/dmaap/mr/client/impl/MRBaseClientTest.java | 57 |
2 files changed, 47 insertions, 26 deletions
diff --git a/src/test/java/org/onap/dmaap/mr/client/impl/DMaapClientUtilTest.java b/src/test/java/org/onap/dmaap/mr/client/impl/DMaapClientUtilTest.java index a845572..4378942 100644 --- a/src/test/java/org/onap/dmaap/mr/client/impl/DMaapClientUtilTest.java +++ b/src/test/java/org/onap/dmaap/mr/client/impl/DMaapClientUtilTest.java @@ -23,13 +23,14 @@ package org.onap.dmaap.mr.client.impl; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; -import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import javax.ws.rs.client.Invocation.Builder; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; + +import org.glassfish.jersey.client.ClientConfig; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -43,6 +44,7 @@ public class DMaapClientUtilTest { Builder builder; @Mock WebTarget target; + private ClientConfig config=null; @Before public void setup(){ @@ -51,14 +53,14 @@ public class DMaapClientUtilTest { @Test public void testGetTarget() { - WebTarget actual = DmaapClientUtil.getTarget("testpath"); + WebTarget actual = DmaapClientUtil.getTarget(getClientConfig(),"testpath"); assertEquals("testpath", actual.getUri().getPath()); } @Test public void testGetTargetWithParams() { - WebTarget actual = DmaapClientUtil.getTarget("testpath", "testuser", "testpassword"); + WebTarget actual = DmaapClientUtil.getTarget(getClientConfig(),"testpath", "testuser", "testpassword"); assertEquals("testpath", actual.getUri().getPath()); } @@ -77,6 +79,12 @@ public class DMaapClientUtilTest { verify(builder, times(2)).header((String) any(), any()); } - + private ClientConfig getClientConfig(){ + if(config==null){ + config=DmaapClientUtil.getClientConfig(null); + } + return config; + + } } diff --git a/src/test/java/org/onap/dmaap/mr/client/impl/MRBaseClientTest.java b/src/test/java/org/onap/dmaap/mr/client/impl/MRBaseClientTest.java index a02691c..235a83b 100644 --- a/src/test/java/org/onap/dmaap/mr/client/impl/MRBaseClientTest.java +++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRBaseClientTest.java @@ -36,6 +36,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; import org.apache.http.HttpException; +import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.internal.util.Base64; import org.glassfish.jersey.internal.util.collection.StringKeyIgnoreCaseMultivaluedMap; import org.json.JSONException; @@ -49,6 +50,7 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; + @RunWith(PowerMockRunner.class) @PowerMockIgnore("org.apache.http.conn.ssl.*") @PrepareForTest({ DmaapClientUtil.class }) @@ -58,6 +60,7 @@ public class MRBaseClientTest { private MRBaseClient mrBaseClient; private Collection<String> hosts = new HashSet<>(Arrays.asList("localhost:8080")); private String clientSignature = "topic" + "::" + "cg" + "::" + "cid"; + private ClientConfig config=null; @Before public void setup() throws MalformedURLException { @@ -77,7 +80,7 @@ public class MRBaseClientTest { Mockito.when(response.getHeaders()).thenReturn(map); Mockito.when( - DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password")) + DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password")) .thenReturn(response); JSONObject result = mrBaseClient.get("/path", "username", "password", "HTTPAUTH"); @@ -92,7 +95,7 @@ public class MRBaseClientTest { public void testGet_403() throws JSONException, HttpException { ResponseBuilder responseBuilder = Response.status(403); Mockito - .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", + .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password")) .thenReturn( responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build()); @@ -111,7 +114,7 @@ public class MRBaseClientTest { Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}"); Mockito.when(response.getHeaders()).thenReturn(map); - Mockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"), + Mockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), Base64.encodeAsString("username:password"))).thenReturn(response); JSONObject result = mrBaseClient.get("/path", "username", "password", "HTTPAAF"); @@ -126,7 +129,7 @@ public class MRBaseClientTest { public void testGet_error() throws JSONException, HttpException { ResponseBuilder responseBuilder = Response.ok(); - Mockito.when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", + Mockito.when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password")) .thenReturn( responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build()); @@ -146,7 +149,7 @@ public class MRBaseClientTest { Mockito.when(response.getHeaders()).thenReturn(map); Mockito.when( - DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password")) + DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password")) .thenReturn(response); mrBaseClient.get("/path", "username", "password", "HTTPAUTH"); @@ -167,7 +170,7 @@ public class MRBaseClientTest { Mockito.when(response.getHeaders()).thenReturn(map); Mockito.when( - DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password")) + DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password")) .thenReturn(response); mrBaseClient.getResponse("/path", "username", "password", "HTTPAUTH"); @@ -186,7 +189,7 @@ public class MRBaseClientTest { Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}"); Mockito.when(response.getHeaders()).thenReturn(map); - Mockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"), + Mockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), Base64.encodeAsString("username:password"))).thenReturn(response); mrBaseClient.getResponse("/path", "username", "password", "HTTPAAF"); @@ -199,7 +202,7 @@ public class MRBaseClientTest { ResponseBuilder responseBuilder = Response.ok(); Mockito - .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", + .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password")) .thenReturn( responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build()); @@ -219,7 +222,7 @@ public class MRBaseClientTest { Mockito.when(response.getHeaders()).thenReturn(map); Mockito.when( - DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password")) + DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password")) .thenReturn(response); mrBaseClient.getAuthResponse("/path", "username", "password", "username", "password", "HTTPAUTH"); @@ -232,7 +235,7 @@ public class MRBaseClientTest { ResponseBuilder responseBuilder = Response.ok(); Mockito - .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", + .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password")) .thenReturn( responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build()); @@ -253,7 +256,7 @@ public class MRBaseClientTest { Mockito.when(response.getHeaders()).thenReturn(map); Mockito - .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", + .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password", new String("{\"test\":\"test\"}").getBytes(), "application/json")) .thenReturn(response); @@ -274,7 +277,7 @@ public class MRBaseClientTest { ResponseBuilder responseBuilder = Response.ok(); Mockito - .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", + .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password", new String("{\"test\":\"test\"}").getBytes(), "application/json")) .thenReturn( responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build()); @@ -300,7 +303,7 @@ public class MRBaseClientTest { Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}"); Mockito.when(response.getHeaders()).thenReturn(map); - Mockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget("/path"))).thenReturn(response); + Mockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"))).thenReturn(response); mrBaseClient.getNoAuthResponse("/path", "username", "password", "HTTPAUTH"); assertTrue(true); @@ -318,7 +321,7 @@ public class MRBaseClientTest { Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}"); Mockito.when(response.getHeaders()).thenReturn(map); - Mockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"), + Mockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), Base64.encodeAsString("username:password"), new String("{\"test\":\"test\"}").getBytes(), "application/json")).thenReturn(response); mrBaseClient.post("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", "username", @@ -334,7 +337,7 @@ public class MRBaseClientTest { ResponseBuilder responseBuilder = Response.ok(); Mockito - .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"), + .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), Base64.encodeAsString("username:password"))) .thenReturn( responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build()); @@ -356,7 +359,7 @@ public class MRBaseClientTest { Mockito.when(response.getHeaders()).thenReturn(map); Mockito - .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", + .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password", new String("{\"test\":\"test\"}").getBytes(), "application/json")) .thenReturn(response); @@ -371,7 +374,7 @@ public class MRBaseClientTest { ResponseBuilder responseBuilder = Response.ok(); Mockito - .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", + .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password", new String("{\"test\":\"test\"}").getBytes(), "application/json")) .thenReturn( responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build()); @@ -393,7 +396,7 @@ public class MRBaseClientTest { Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}"); Mockito.when(response.getHeaders()).thenReturn(map); - Mockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"), + Mockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), Base64.encodeAsString("username:password"), new String("{\"test\":\"test\"}").getBytes(), "application/json")).thenReturn(response); mrBaseClient.postWithResponse("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", @@ -407,7 +410,7 @@ public class MRBaseClientTest { ResponseBuilder responseBuilder = Response.ok(); Mockito - .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"), + .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), Base64.encodeAsString("username:password"))) .thenReturn( responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build()); @@ -429,7 +432,7 @@ public class MRBaseClientTest { Mockito.when(response.getHeaders()).thenReturn(map); Mockito.when( - DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password")) + DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password")) .thenReturn(response); mrBaseClient.getAuth("/path", "username", "password", "username", "password", "HTTPAUTH"); assertTrue(true); @@ -441,7 +444,7 @@ public class MRBaseClientTest { ResponseBuilder responseBuilder = Response.ok(); Mockito - .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", + .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password", new String("{\"test\":\"test\"}").getBytes(), "application/json")) .thenReturn( responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build()); @@ -462,7 +465,7 @@ public class MRBaseClientTest { Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}"); Mockito.when(response.getHeaders()).thenReturn(map); - Mockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget("/path"))).thenReturn(response); + Mockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"))).thenReturn(response); mrBaseClient.getNoAuth("/path"); assertTrue(true); @@ -479,5 +482,15 @@ public class MRBaseClientTest { public void getGTTPErrorResponseCode() { assertEquals("500", mrBaseClient.getHTTPErrorResponseCode("<title>500</title>")); } + + + + private ClientConfig getClientConfig(){ + if(config==null){ + config=DmaapClientUtil.getClientConfig(null); + } + return config; + + } } |