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;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
+
@RunWith(PowerMockRunner.class)
-@PowerMockIgnore("org.apache.http.conn.ssl.*")
+@PowerMockIgnore({"org.apache.http.conn.ssl.*", "jdk.internal.reflect.*"})
@PrepareForTest({ DmaapClientUtil.class })
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 {
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");
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());
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");
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());
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");
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");
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");
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());
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");
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());
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);
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());
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);
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",
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());
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);
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());
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",
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());
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);
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());
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);
public void getGTTPErrorResponseCode() {
assertEquals("500", mrBaseClient.getHTTPErrorResponseCode("<title>500</title>"));
}
+
+
+
+ private ClientConfig getClientConfig(){
+ if(config==null){
+ config=DmaapClientUtil.getClientConfig(null);
+ }
+ return config;
+
+ }
}