aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/onap/dmaap/mr/client/impl/MRConstants.java3
-rw-r--r--src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java45
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/DMaapClientUtilTest.java39
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRBaseClientTest.java168
-rw-r--r--src/test/java/org/onap/dmaap/mr/tools/ValidatorUtilTest.java2
5 files changed, 126 insertions, 131 deletions
diff --git a/src/main/java/org/onap/dmaap/mr/client/impl/MRConstants.java b/src/main/java/org/onap/dmaap/mr/client/impl/MRConstants.java
index 5ed44c6..ec17610 100644
--- a/src/main/java/org/onap/dmaap/mr/client/impl/MRConstants.java
+++ b/src/main/java/org/onap/dmaap/mr/client/impl/MRConstants.java
@@ -62,10 +62,9 @@ class MRConstants
public static String makeUrl ( final String host, final String rawTopic )
{
final String cleanTopic = escape ( rawTopic );
-
final StringBuffer url = new StringBuffer();
- if (!host.startsWith("http") || !host.startsWith("https") ) {
+ if (!host.startsWith("http") && !host.startsWith("https") ) {
url.append( PROTOCOL + "://" );
}
url.append(host);
diff --git a/src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java b/src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java
index fb57b94..d9076a4 100644
--- a/src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java
+++ b/src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java
@@ -178,8 +178,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP
try {
final List<message> remains = close(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
if (remains.isEmpty()) {
- getLog().warn("Closing publisher with " + remains.size() + " messages unsent. "
- + "Consider using MRBatchingPublisher.close( long timeout, TimeUnit timeoutUnits ) to recapture unsent messages on close.");
+ getLog().warn("Closing publisher with {} messages unsent. Consider using MRBatchingPublisher.close( long timeout, TimeUnit timeoutUnits ) to recapture unsent messages on close.",
+ remains.size());
}
} catch (InterruptedException e) {
getLog().warn("Possible message loss. " + e.getMessage(), e);
@@ -339,8 +339,9 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP
DME2Configue();
Thread.sleep(5);
- getLog().info("sending " + fPending.size() + " msgs to " + url + subContextPath + ". Oldest: "
- + (nowMs - fPending.peek().timestamp) + " ms");
+ getLog().info(String
+ .format("sending %d msgs to %s%s. Oldest: %d ms", fPending.size(), url, subContextPath,
+ nowMs - fPending.peek().timestamp));
sender.setPayload(os.toString());
String dmeResponse = sender.sendAndWait(5000L);
@@ -351,8 +352,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP
}
if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(protocolFlag)) {
- getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
- + (nowMs - fPending.peek().timestamp) + " ms");
+ getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl,
+ nowMs - fPending.peek().timestamp);
final JSONObject result =
postAuth(new PostAuthDataObject().setPath(httpurl).setData(baseStream.toByteArray())
.setContentType(contentType).setAuthKey(authKey).setAuthDate(authDate)
@@ -370,8 +371,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP
}
if (ProtocolTypeConstants.AAF_AUTH.getValue().equalsIgnoreCase(protocolFlag)) {
- getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
- + (nowMs - fPending.peek().timestamp) + " ms");
+ getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl,
+ nowMs - fPending.peek().timestamp);
final JSONObject result = post(httpurl, baseStream.toByteArray(), contentType, username, password,
protocolFlag);
@@ -388,8 +389,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP
}
if (ProtocolTypeConstants.HTTPNOAUTH.getValue().equalsIgnoreCase(protocolFlag)) {
- getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
- + (nowMs - fPending.peek().timestamp) + " ms");
+ getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl,
+ nowMs - fPending.peek().timestamp);
final JSONObject result = postNoAuth(httpurl, baseStream.toByteArray(), contentType);
// Here we are checking for error response. If HTTP status
@@ -468,8 +469,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP
DME2Configue();
Thread.sleep(5);
- getLog().info("sending " + fPending.size() + " msgs to " + url + subContextPath + ". Oldest: "
- + (nowMs - fPending.peek().timestamp) + " ms");
+ getLog().info("sending {} msgs to {}{}. Oldest: {} ms", fPending.size(), url, subContextPath,
+ nowMs - fPending.peek().timestamp);
sender.setPayload(os.toString());
String dmeResponse = sender.sendAndWait(5000L);
@@ -506,8 +507,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP
}
if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(protocolFlag)) {
- getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
- + (nowMs - fPending.peek().timestamp) + " ms");
+ getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl,
+ nowMs - fPending.peek().timestamp);
final String result = postAuthwithResponse(httpurl, baseStream.toByteArray(), contentType, authKey,
authDate, username, password, protocolFlag);
// Here we are checking for error response. If HTTP status
@@ -529,8 +530,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP
}
if (ProtocolTypeConstants.AAF_AUTH.getValue().equalsIgnoreCase(protocolFlag)) {
- getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
- + (nowMs - fPending.peek().timestamp) + " ms");
+ getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl,
+ nowMs - fPending.peek().timestamp);
final String result = postWithResponse(httpurl, baseStream.toByteArray(), contentType, username,
password, protocolFlag);
@@ -552,8 +553,8 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP
}
if (ProtocolTypeConstants.HTTPNOAUTH.getValue().equalsIgnoreCase(protocolFlag)) {
- getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
- + (nowMs - fPending.peek().timestamp) + " ms");
+ getLog().info("sending {} msgs to {}. Oldest: {} ms", fPending.size(), httpurl,
+ nowMs - fPending.peek().timestamp);
final String result = postNoAuthWithResponse(httpurl, baseStream.toByteArray(), contentType);
// Here we are checking for error response. If HTTP status
@@ -572,7 +573,7 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP
fPending.clear();
return pubResponse;
}
- } catch (IllegalArgumentException x) {
+ } catch (IllegalArgumentException | HttpException x) {
getLog().warn(x.getMessage(), x);
pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_BAD_REQUEST));
pubResponse.setResponseMessage(x.getMessage());
@@ -581,12 +582,6 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP
getLog().warn(x.getMessage(), x);
pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_INTERNAL_SERVER_ERROR));
pubResponse.setResponseMessage(x.getMessage());
-
- } catch (HttpException x) {
- getLog().warn(x.getMessage(), x);
- pubResponse.setResponseCode(String.valueOf(HttpStatus.SC_BAD_REQUEST));
- pubResponse.setResponseMessage(x.getMessage());
-
} catch (Exception x) {
getLog().warn(x.getMessage(), x);
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 21c3b6c..a845572 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
@@ -22,45 +22,42 @@
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 java.io.IOException;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
-
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
public class DMaapClientUtilTest {
-
- Builder builder;
-
- Response response;
-
- WebTarget target;
-
+ @Mock
+ Response response;
+ @Mock
+ Builder builder;
+ @Mock
+ WebTarget target;
+
@Before
public void setup(){
- Mockito.mock(HttpServletRequest.class);
- builder = Mockito.mock(Invocation.Builder.class);
- response = Mockito.mock(Response.class);
- target = Mockito.mock(WebTarget.class);
-
+ MockitoAnnotations.initMocks(this);
}
@Test
- public void testGetTarget() throws IOException{
+ public void testGetTarget() {
WebTarget actual = DmaapClientUtil.getTarget("testpath");
assertEquals("testpath", actual.getUri().getPath());
}
@Test
- public void testGetTargetWithParams() throws IOException{
+ public void testGetTargetWithParams() {
WebTarget actual = DmaapClientUtil.getTarget("testpath", "testuser", "testpassword");
assertEquals("testpath", actual.getUri().getPath());
@@ -74,8 +71,10 @@ public class DMaapClientUtilTest {
Mockito.when(builder.get()).thenReturn(response);
Response actual = DmaapClientUtil.getResponsewtCambriaAuth(target, "testuser", "testpassword");
-
+
assertEquals(response, actual);
+ verify(target).request();
+ verify(builder, times(2)).header((String) any(), any());
}
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 38c7f8a..a02691c 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
@@ -23,6 +23,8 @@ package org.onap.dmaap.mr.client.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.verify;
import java.net.MalformedURLException;
import java.util.Arrays;
@@ -37,6 +39,7 @@ import org.apache.http.HttpException;
import org.glassfish.jersey.internal.util.Base64;
import org.glassfish.jersey.internal.util.collection.StringKeyIgnoreCaseMultivaluedMap;
import org.json.JSONException;
+import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -69,30 +72,32 @@ public class MRBaseClientTest {
MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
map.add("transactionid", "transactionid");
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- PowerMockito.when(
+ Mockito.when(
DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password"))
.thenReturn(response);
- mrBaseClient.get("/path", "username", "password", "HTTPAUTH");
- assertTrue(true);
-
+ JSONObject result = mrBaseClient.get("/path", "username", "password", "HTTPAUTH");
+ assertEquals(200, result.getInt("status"));
+ assertEquals("test", result.getString("test"));
+ verify(response, atLeast(1)).getStatus();
+ verify(response).readEntity(String.class);
+ verify(response).getHeaders();
}
@Test
public void testGet_403() throws JSONException, HttpException {
ResponseBuilder responseBuilder = Response.status(403);
- PowerMockito
+ Mockito
.when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
"password"))
.thenReturn(
responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
- mrBaseClient.get("/path", "username", "password", "HTTPAUTH");
- assertTrue(true);
-
+ JSONObject result = mrBaseClient.get("/path", "username", "password", "HTTPAUTH");
+ assertEquals(403, result.getInt("status"));
}
@Test
@@ -102,15 +107,18 @@ public class MRBaseClientTest {
MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
map.add("transactionid", "transactionid");
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- PowerMockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
+ Mockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
Base64.encodeAsString("username:password"))).thenReturn(response);
- mrBaseClient.get("/path", "username", "password", "HTTPAAF");
- assertTrue(true);
+ JSONObject result = mrBaseClient.get("/path", "username", "password", "HTTPAAF");
+ assertEquals(200, result.getInt("status"));
+ verify(response, atLeast(1)).getStatus();
+ verify(response).readEntity(String.class);
+ verify(response).getHeaders();
}
@@ -118,15 +126,12 @@ public class MRBaseClientTest {
public void testGet_error() throws JSONException, HttpException {
ResponseBuilder responseBuilder = Response.ok();
- PowerMockito
- .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ Mockito.when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
"password"))
.thenReturn(
responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
mrBaseClient.get("/path", null, null, "HTTPAUTH");
- assertTrue(true);
-
}
@Test
@@ -136,16 +141,18 @@ public class MRBaseClientTest {
MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
map.add("transactionid", "transactionid");
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("[[");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("[[");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- PowerMockito.when(
+ Mockito.when(
DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password"))
.thenReturn(response);
mrBaseClient.get("/path", "username", "password", "HTTPAUTH");
- assertTrue(true);
+ verify(response, atLeast(1)).getStatus();
+ verify(response).readEntity(String.class);
+ verify(response).getHeaders();
}
@Test
@@ -155,11 +162,11 @@ public class MRBaseClientTest {
MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
map.add("transactionid", "transactionid");
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- PowerMockito.when(
+ Mockito.when(
DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password"))
.thenReturn(response);
@@ -175,11 +182,11 @@ public class MRBaseClientTest {
MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
map.add("transactionid", "transactionid");
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- PowerMockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
+ Mockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
Base64.encodeAsString("username:password"))).thenReturn(response);
mrBaseClient.getResponse("/path", "username", "password", "HTTPAAF");
@@ -191,14 +198,13 @@ public class MRBaseClientTest {
public void testGetResponse_error() throws JSONException, HttpException {
ResponseBuilder responseBuilder = Response.ok();
- PowerMockito
+ Mockito
.when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
"password"))
.thenReturn(
responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
mrBaseClient.getResponse("/path", null, null, "HTTPAUTH");
-
}
@Test
@@ -208,11 +214,11 @@ public class MRBaseClientTest {
MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
map.add("transactionid", "transactionid");
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- PowerMockito.when(
+ Mockito.when(
DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password"))
.thenReturn(response);
@@ -225,7 +231,7 @@ public class MRBaseClientTest {
public void testAuthResponsee_error() throws JSONException, HttpException {
ResponseBuilder responseBuilder = Response.ok();
- PowerMockito
+ Mockito
.when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
"password"))
.thenReturn(
@@ -242,11 +248,11 @@ public class MRBaseClientTest {
MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
map.add("transactionid", "transactionid");
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- PowerMockito
+ Mockito
.when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
"password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
.thenReturn(response);
@@ -267,7 +273,7 @@ public class MRBaseClientTest {
public void testPostAuth_error() throws JSONException, HttpException {
ResponseBuilder responseBuilder = Response.ok();
- PowerMockito
+ Mockito
.when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
"password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
.thenReturn(
@@ -281,9 +287,6 @@ public class MRBaseClientTest {
.setUsername(null)
.setPassword(null)
.setProtocolFlag("HTTPAUTH"));
-
- assertTrue(true);
-
}
@Test
@@ -293,11 +296,11 @@ public class MRBaseClientTest {
MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
map.add("transactionid", "transactionid");
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- PowerMockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget("/path"))).thenReturn(response);
+ Mockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget("/path"))).thenReturn(response);
mrBaseClient.getNoAuthResponse("/path", "username", "password", "HTTPAUTH");
assertTrue(true);
@@ -311,16 +314,18 @@ public class MRBaseClientTest {
MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
map.add("transactionid", "transactionid");
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- PowerMockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
+ Mockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget("/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",
"password", "HTTPAUTH");
- assertTrue(true);
+ verify(response, atLeast(1)).getStatus();
+ verify(response).readEntity(String.class);
+ verify(response).getHeaders();
}
@@ -328,7 +333,7 @@ public class MRBaseClientTest {
public void testPost_error() throws JSONException, HttpException {
ResponseBuilder responseBuilder = Response.ok();
- PowerMockito
+ Mockito
.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
Base64.encodeAsString("username:password")))
.thenReturn(
@@ -346,11 +351,11 @@ public class MRBaseClientTest {
MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
map.add("transactionid", "transactionid");
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- PowerMockito
+ Mockito
.when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
"password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
.thenReturn(response);
@@ -365,7 +370,7 @@ public class MRBaseClientTest {
public void testPostAuthwithResponse_error() throws JSONException, HttpException {
ResponseBuilder responseBuilder = Response.ok();
- PowerMockito
+ Mockito
.when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
"password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
.thenReturn(
@@ -384,11 +389,11 @@ public class MRBaseClientTest {
MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
map.add("transactionid", "transactionid");
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- PowerMockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
+ Mockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
Base64.encodeAsString("username:password"), new String("{\"test\":\"test\"}").getBytes(), "application/json")).thenReturn(response);
mrBaseClient.postWithResponse("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json",
@@ -401,7 +406,7 @@ public class MRBaseClientTest {
public void testPostWithResponse_error() throws JSONException, HttpException {
ResponseBuilder responseBuilder = Response.ok();
- PowerMockito
+ Mockito
.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
Base64.encodeAsString("username:password")))
.thenReturn(
@@ -419,11 +424,11 @@ public class MRBaseClientTest {
MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
map.add("transactionid", "transactionid");
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- PowerMockito.when(
+ Mockito.when(
DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password"))
.thenReturn(response);
mrBaseClient.getAuth("/path", "username", "password", "username", "password", "HTTPAUTH");
@@ -435,7 +440,7 @@ public class MRBaseClientTest {
public void testGetAuth_error() throws JSONException, HttpException {
ResponseBuilder responseBuilder = Response.ok();
- PowerMockito
+ Mockito
.when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
"password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
.thenReturn(
@@ -453,11 +458,11 @@ public class MRBaseClientTest {
MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
map.add("transactionid", "transactionid");
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- PowerMockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget("/path"))).thenReturn(response);
+ Mockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget("/path"))).thenReturn(response);
mrBaseClient.getNoAuth("/path");
assertTrue(true);
@@ -466,16 +471,13 @@ public class MRBaseClientTest {
@Test
public void testGetHTTPErrorResponseMessage() {
-
- assertEquals(mrBaseClient.getHTTPErrorResponseMessage("<body>testtest</body>"), "testtest");
+ assertEquals("testtest", mrBaseClient.getHTTPErrorResponseMessage("<body>testtest</body>"));
}
@Test
public void getGTTPErrorResponseCode() {
-
- assertEquals(mrBaseClient.getHTTPErrorResponseMessage("<body>testtest</body>"), "testtest");
-
+ assertEquals("500", mrBaseClient.getHTTPErrorResponseCode("<title>500</title>"));
}
}
diff --git a/src/test/java/org/onap/dmaap/mr/tools/ValidatorUtilTest.java b/src/test/java/org/onap/dmaap/mr/tools/ValidatorUtilTest.java
index 1306a30..baa5440 100644
--- a/src/test/java/org/onap/dmaap/mr/tools/ValidatorUtilTest.java
+++ b/src/test/java/org/onap/dmaap/mr/tools/ValidatorUtilTest.java
@@ -41,7 +41,7 @@ public class ValidatorUtilTest {
} catch(IllegalArgumentException e) {
assertEquals(e.getMessage(), "Servicename is needed");
}
-
+
}
@Test