aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/dmaap/mr/client/impl
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap/dmaap/mr/client/impl')
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/DMaapClientUtilTest.java85
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRBaseClientTest.java471
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRBatchPublisherTest.java54
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRConstantsTest.java143
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRConsumerImplTest.java112
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRMetaClientTest.java129
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchConsumerTest.java76
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisherTest.java96
8 files changed, 1166 insertions, 0 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
new file mode 100644
index 0000000..6fb31a6
--- /dev/null
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/DMaapClientUtilTest.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * Copyright © 2018 IBM Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
+ *******************************************************************************/
+package org.onap.dmaap.mr.client.impl;
+
+import static org.junit.Assert.assertEquals;
+
+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.Mockito;
+
+import com.att.aft.dme2.internal.jersey.core.spi.factory.ResponseImpl;
+
+public class DMaapClientUtilTest {
+
+ Builder builder;
+
+ Response response;
+
+ 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);
+
+ }
+
+ @Test
+ public void testGetTarget() throws IOException{
+ WebTarget actual = DmaapClientUtil.getTarget("testpath");
+
+ assertEquals("testpath", actual.getUri().getPath());
+ }
+
+ @Test
+ public void testGetTargetWithParams() throws IOException{
+ WebTarget actual = DmaapClientUtil.getTarget("testpath", "testuser", "testpassword");
+
+ assertEquals("testpath", actual.getUri().getPath());
+ }
+
+ @Test
+ public void testGetResponsewtCambriaAuth() {
+ Mockito.when(target.request()).thenReturn(builder);
+ Mockito.when(builder.header("X-CambriaAuth", "testuser")).thenReturn(builder);
+ Mockito.when(builder.header("X-CambriaDate", "testpassword")).thenReturn(builder);
+ Mockito.when(builder.get()).thenReturn(response);
+
+ Response actual = DmaapClientUtil.getResponsewtCambriaAuth(target, "testuser", "testpassword");
+
+ assertEquals(response, actual);
+ }
+
+
+
+}
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
new file mode 100644
index 0000000..6fe0e70
--- /dev/null
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRBaseClientTest.java
@@ -0,0 +1,471 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
+ *******************************************************************************/
+package org.onap.dmaap.mr.client.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.net.MalformedURLException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+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.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.powermock.api.mockito.PowerMockito;
+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 })
+public class MRBaseClientTest {
+
+ // @InjectMocks
+ private MRBaseClient mrBaseClient;
+ private Collection<String> hosts = new HashSet<>(Arrays.asList("localhost:8080"));
+ private String clientSignature = "topic" + "::" + "cg" + "::" + "cid";
+
+ @Before
+ public void setup() throws MalformedURLException {
+ mrBaseClient = new MRBaseClient(hosts, clientSignature);
+ PowerMockito.mockStatic(DmaapClientUtil.class);
+ }
+
+ @Test
+ public void testGet() throws JSONException, HttpException {
+
+ Response response = Mockito.mock(Response.class);
+ 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);
+
+ PowerMockito.when(
+ DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password"))
+ .thenReturn(response);
+
+ mrBaseClient.get("/path", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testGet_403() throws JSONException, HttpException {
+ ResponseBuilder responseBuilder = Response.status(403);
+ PowerMockito
+ .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);
+
+ }
+
+ @Test
+ public void testGet_basicauth() throws JSONException, HttpException {
+
+ Response response = Mockito.mock(Response.class);
+ 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);
+
+ PowerMockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
+ Base64.encodeAsString("username:password"))).thenReturn(response);
+
+ mrBaseClient.get("/path", "username", "password", "HTTPAAF");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testGet_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .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
+ public void testGet_wrongjson() throws JSONException, HttpException {
+
+ Response response = Mockito.mock(Response.class);
+ 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);
+
+ PowerMockito.when(
+ DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password"))
+ .thenReturn(response);
+
+ mrBaseClient.get("/path", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+ }
+
+ @Test
+ public void testGetResponse() throws JSONException, HttpException {
+
+ Response response = Mockito.mock(Response.class);
+ 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);
+
+ PowerMockito.when(
+ DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password"))
+ .thenReturn(response);
+
+ mrBaseClient.getResponse("/path", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testGetResponse_aaf() throws JSONException, HttpException {
+
+ Response response = Mockito.mock(Response.class);
+ 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);
+
+ PowerMockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
+ Base64.encodeAsString("username:password"))).thenReturn(response);
+
+ mrBaseClient.getResponse("/path", "username", "password", "HTTPAAF");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testGetResponse_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.getResponse("/path", null, null, "HTTPAUTH");
+
+ }
+
+ @Test
+ public void testAuthResponse() throws JSONException, HttpException {
+
+ Response response = Mockito.mock(Response.class);
+ 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);
+
+ PowerMockito.when(
+ DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password"))
+ .thenReturn(response);
+
+ mrBaseClient.getAuthResponse("/path", "username", "password", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testAuthResponsee_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.getAuthResponse("/path", null, null, null, null, "HTTPAUTH");
+
+ }
+
+ @Test
+ public void testPostAuth() throws JSONException, HttpException {
+
+ Response response = Mockito.mock(Response.class);
+ 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);
+
+ PowerMockito
+ .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
+ .thenReturn(response);
+
+ mrBaseClient.postAuth("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", "username",
+ "password", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testPostAuth_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.postAuth("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", null, null,
+ null, null, "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testGetNoAuthResponse() throws JSONException, HttpException {
+
+ Response response = Mockito.mock(Response.class);
+ 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);
+
+ PowerMockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget("/path"))).thenReturn(response);
+
+ mrBaseClient.getNoAuthResponse("/path", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testPost() throws JSONException, HttpException {
+
+ Response response = Mockito.mock(Response.class);
+ 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);
+
+ PowerMockito.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);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testPost_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
+ Base64.encodeAsString("username:password")))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.post("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", null, null,
+ "HTTPAUTH");
+
+ }
+
+ @Test
+ public void testPostAuthwithResponse() throws JSONException, HttpException {
+
+ Response response = Mockito.mock(Response.class);
+ 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);
+
+ PowerMockito
+ .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
+ .thenReturn(response);
+
+ mrBaseClient.postAuthwithResponse("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json",
+ "username", "password", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testPostAuthwithResponse_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.postAuthwithResponse("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json",
+ null, null, null, null, "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testPostWithResponse() throws JSONException, HttpException {
+
+ Response response = Mockito.mock(Response.class);
+ 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);
+
+ PowerMockito.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",
+ "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testPostWithResponse_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
+ Base64.encodeAsString("username:password")))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.postWithResponse("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", null,
+ null, "HTTPAUTH");
+
+ }
+
+ @Test
+ public void testGetAuth() throws JSONException, HttpException {
+
+ Response response = Mockito.mock(Response.class);
+ 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);
+
+ PowerMockito.when(
+ DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password"))
+ .thenReturn(response);
+ mrBaseClient.getAuth("/path", "username", "password", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testGetAuth_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.getAuth("/path", null, null, null, null, "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testGetNoAuth() throws JSONException, HttpException {
+
+ Response response = Mockito.mock(Response.class);
+ 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);
+
+ PowerMockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget("/path"))).thenReturn(response);
+ mrBaseClient.getNoAuth("/path");
+ assertTrue(true);
+
+ }
+
+
+ @Test
+ public void testGetHTTPErrorResponseMessage() {
+
+ assertEquals(mrBaseClient.getHTTPErrorResponseMessage("<body>testtest</body>"), "testtest");
+
+ }
+
+ @Test
+ public void getGTTPErrorResponseCode() {
+
+ assertEquals(mrBaseClient.getHTTPErrorResponseMessage("<body>testtest</body>"), "testtest");
+
+ }
+
+}
diff --git a/src/test/java/org/onap/dmaap/mr/client/impl/MRBatchPublisherTest.java b/src/test/java/org/onap/dmaap/mr/client/impl/MRBatchPublisherTest.java
new file mode 100644
index 0000000..f13e7fa
--- /dev/null
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRBatchPublisherTest.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
+ *******************************************************************************/
+package org.onap.dmaap.mr.client.impl;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class MRBatchPublisherTest {
+
+ private Collection<String> hosts=new HashSet<>(Arrays.asList("/test"));
+ private MRBatchPublisher mrBatchPublisher=new MRBatchPublisher(hosts, "topic", 2, 20, true);
+
+
+ @Before
+ public void setup(){
+
+
+ }
+
+ @Test
+ public void testSend() throws IOException{
+ mrBatchPublisher.send("testmessage");
+ }
+
+ @Test
+ public void testClose() throws IOException{
+ mrBatchPublisher.close();
+ }
+
+}
diff --git a/src/test/java/org/onap/dmaap/mr/client/impl/MRConstantsTest.java b/src/test/java/org/onap/dmaap/mr/client/impl/MRConstantsTest.java
new file mode 100644
index 0000000..3a427e0
--- /dev/null
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRConstantsTest.java
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
+ *******************************************************************************/
+package org.onap.dmaap.mr.client.impl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+import org.apache.http.HttpHost;
+import org.junit.Test;
+
+import org.onap.dmaap.mr.client.impl.MRConstants;
+
+public class MRConstantsTest extends TestCase
+{
+ @Test
+ public void testPlainHost () throws IOException
+ {
+ final String rawTopic = "bar";
+ final String result = MRConstants.makeUrl ( rawTopic );
+ assertEquals ( "/events/" + "bar", result );
+ }
+
+ @Test
+ public void testHostWithProtocol () throws IOException
+ {
+ final String rawTopic = "bar";
+ final String result = MRConstants.makeUrl ( rawTopic );
+ assertEquals ( "/events/" + "bar", result );
+ }
+
+ @Test
+ public void testHostWithProtocolAndPort () throws IOException
+ {
+ final String rawTopic = "bar";
+ final String result = MRConstants.makeUrl ( rawTopic );
+ assertEquals ( "/events/" + "bar", result );
+ }
+
+ @Test
+ public void testHostWithPort () throws IOException
+ {
+ final String rawTopic = "bar";
+ final String result = MRConstants.makeUrl ( rawTopic );
+ assertEquals ( "/events/" + "bar", result );
+ }
+
+ @Test
+ public void testHostWithPortAndEscapedTopic () throws IOException
+ {
+ final String rawTopic = "bar?bell";
+ final String result = MRConstants.makeUrl ( rawTopic );
+ assertEquals ( "/events/" + "bar%3Fbell", result );
+ }
+
+ @Test
+ public void testConsumerPlainHost () throws IOException
+ {
+ final String rawTopic = "bar";
+ final String rawGroup = "group";
+ final String rawId = "id";
+ final String result = MRConstants.makeConsumerUrl ( rawTopic, rawGroup, rawId );
+ assertEquals ( "/events/" + "bar/group/id", result );
+ }
+
+ @Test
+ public void testCreateHostList ()
+ {
+ final ArrayList<String> in = new ArrayList<String> ();
+ in.add ( "foo" );
+ in.add ( "bar" );
+ in.add ( "baz:80" );
+
+ final Collection<HttpHost> hosts = MRConstants.createHostsList ( in );
+ assertEquals ( 3, hosts.size () );
+
+ final Iterator<HttpHost> it = hosts.iterator ();
+ final HttpHost first = it.next ();
+ assertEquals ( MRConstants.kStdMRServicePort, first.getPort () );
+ assertEquals ( "foo", first.getHostName () );
+
+ final HttpHost second = it.next ();
+ assertEquals ( MRConstants.kStdMRServicePort, second.getPort () );
+ assertEquals ( "bar", second.getHostName () );
+
+ final HttpHost third = it.next ();
+ assertEquals ( 80, third.getPort () );
+ assertEquals ( "baz", third.getHostName () );
+ }
+
+ private static final String[][] hostTests =
+ {
+ { "host", "host", "" + MRConstants.kStdMRServicePort },
+ { ":oops", null, "-1" },
+ { "host:1.3", null, "-1" },
+ { "host:13", "host", "13" },
+ { "host:", "host", "" + MRConstants.kStdMRServicePort },
+ };
+
+ @Test
+ public void testHostParse ()
+ {
+ for ( String[] test : hostTests )
+ {
+ final String hostIn = test[0];
+ final String hostOut = test[1];
+ final int portOut = Integer.parseInt ( test[2] );
+
+ try
+ {
+ final HttpHost hh = MRConstants.hostForString ( hostIn );
+ assertEquals ( hostOut, hh.getHostName () );
+ assertEquals ( portOut, hh.getPort () );
+ }
+ catch ( IllegalArgumentException x )
+ {
+ assertEquals ( -1, portOut );
+ }
+ }
+ }
+}
diff --git a/src/test/java/org/onap/dmaap/mr/client/impl/MRConsumerImplTest.java b/src/test/java/org/onap/dmaap/mr/client/impl/MRConsumerImplTest.java
new file mode 100644
index 0000000..5d8dccd
--- /dev/null
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRConsumerImplTest.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
+ *******************************************************************************/
+package org.onap.dmaap.mr.client.impl;
+
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.junit.Test;
+
+import org.onap.dmaap.mr.client.MRClientFactory;
+import org.onap.dmaap.mr.client.impl.MRConstants;
+import org.onap.dmaap.mr.client.impl.MRConsumerImpl;
+
+public class MRConsumerImplTest extends TestCase
+{
+ @Test
+ public void testNullFilter () throws IOException
+ {
+ final LinkedList<String> hosts = new LinkedList<String> ();
+ hosts.add ( "localhost:8080" );
+ final MRConsumerImpl c = new MRConsumerImpl ( hosts, "topic", "cg", "cid", -1, -1, null, null, null );
+ final String url = c.createUrlPath (MRConstants.makeConsumerUrl ( "localhost:8080", "topic", "cg", "cid","http" ), -1, -1 );
+ assertEquals ("http://localhost:8080/events/" + "topic/cg/cid", url );
+ }
+
+ @Test
+ public void testFilterWithNoTimeoutOrLimit () throws IOException
+ {
+ final LinkedList<String> hosts = new LinkedList<String> ();
+ hosts.add ( "localhost:8080" );
+ final MRConsumerImpl c = new MRConsumerImpl ( hosts, "topic", "cg", "cid", -1, -1, "filter", null, null );
+ final String url = c.createUrlPath ( MRConstants.makeConsumerUrl ( "localhost:8080", "topic", "cg", "cid" ,"http"),-1, -1 );
+ assertEquals ("http://localhost:8080/events/" + "topic/cg/cid?filter=filter", url );
+ }
+
+ @Test
+ public void testTimeoutNoLimitNoFilter () throws IOException
+ {
+ final LinkedList<String> hosts = new LinkedList<String> ();
+ hosts.add ( "localhost:8080" );
+ final MRConsumerImpl c = new MRConsumerImpl ( hosts, "topic", "cg", "cid", 30000, -1, null, null, null );
+ final String url = c.createUrlPath (MRConstants.makeConsumerUrl ( "localhost:8080", "topic", "cg", "cid","http" ), 30000, -1 );
+ assertEquals ( "http://localhost:8080/events/" + "topic/cg/cid?timeout=30000", url );
+ }
+
+ @Test
+ public void testNoTimeoutWithLimitNoFilter () throws IOException
+ {
+ final LinkedList<String> hosts = new LinkedList<String> ();
+ hosts.add ( "localhost:8080" );
+ final MRConsumerImpl c = new MRConsumerImpl ( hosts, "topic", "cg", "cid", -1, 100, null, null, null );
+ final String url = c.createUrlPath (MRConstants.makeConsumerUrl ( "localhost:8080", "topic", "cg", "cid","http" ), -1, 100 );
+ assertEquals ( "http://localhost:8080/events/" + "topic/cg/cid?limit=100", url );
+ }
+
+ @Test
+ public void testWithTimeoutWithLimitWithFilter () throws IOException
+ {
+ final LinkedList<String> hosts = new LinkedList<String> ();
+ hosts.add ( "localhost:8080" );
+ final MRConsumerImpl c = new MRConsumerImpl ( hosts, "topic", "cg", "cid", 1000, 400, "f", null, null );
+ final String url = c.createUrlPath (MRConstants.makeConsumerUrl ( "localhost:8080", "topic", "cg", "cid" ,"http"), 1000, 400 );
+ assertEquals ("http://localhost:8080/events/" + "topic/cg/cid?timeout=1000&limit=400&filter=f", url );
+ }
+
+ @Test
+ public void testFilterEncoding () throws IOException
+ {
+ final LinkedList<String> hosts = new LinkedList<String> ();
+ hosts.add ( "localhost:8080" );
+ final MRConsumerImpl c = new MRConsumerImpl ( hosts, "topic", "cg", "cid", -1, -1, "{ \"foo\"=\"bar\"bar\" }", null, null );
+ final String url = c.createUrlPath (MRConstants.makeConsumerUrl ( "localhost:8080", "topic", "cg", "cid","http" ), -1, -1 );
+ assertEquals ( "http://localhost:8080/events/" + "topic/cg/cid?filter=%7B+%22foo%22%3D%22bar%22bar%22+%7D", url );
+ }
+
+ @Test
+ public void testFetchWithReturnConsumerResponse () throws IOException
+ {
+ final LinkedList<String> hosts = new LinkedList<String> ();
+ hosts.add ( "localhost:8080" );
+ Properties properties = new Properties();
+ properties.load(MRSimplerBatchConsumerTest.class.getClassLoader().getResourceAsStream("dme2/consumer.properties"));
+
+ final MRConsumerImpl c = new MRConsumerImpl ( hosts, "topic", "cg", "cid", -1, -1, "{ \"foo\"=\"bar\"bar\" }", null, null );
+ c.fetchWithReturnConsumerResponse();
+ c.setProtocolFlag("HTTPAAF");
+ c.fetchWithReturnConsumerResponse();
+ assertTrue(true);
+ }
+}
diff --git a/src/test/java/org/onap/dmaap/mr/client/impl/MRMetaClientTest.java b/src/test/java/org/onap/dmaap/mr/client/impl/MRMetaClientTest.java
new file mode 100644
index 0000000..6c2b219
--- /dev/null
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRMetaClientTest.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
+ *******************************************************************************/
+package org.onap.dmaap.mr.client.impl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
+import static org.junit.Assert.assertTrue;
+
+import com.att.nsa.apiClient.http.HttpException;
+import com.att.nsa.apiClient.http.HttpObjectNotFoundException;
+import org.onap.dmaap.mr.client.MRClient.MRApiException;
+import org.onap.dmaap.mr.client.MRTopicManager.TopicInfo;
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+
+
+public class MRMetaClientTest {
+
+ @Rule public WireMockRule wireMock = new WireMockRule();
+
+ @Before
+ public void setUp(){
+ wireMock.stubFor(get(urlEqualTo("/topics"))
+ .willReturn(aResponse().withBody("{\"topics\":[\"topic1\",\"topic2\"]}").withHeader("Content-Type", "application/json")));
+ wireMock.stubFor(get(urlEqualTo("/topics/topic1"))
+ .willReturn(aResponse().withBody("{\"topics\":[\"topic1\",\"topic2\"]}").withHeader("Content-Type", "application/json")));
+ wireMock.stubFor(post(urlEqualTo("/topics/create"))
+ .willReturn(aResponse().withStatus(200)));
+ }
+
+ @Test
+ public void getTopicsTest()
+ {
+ final Collection<String> hosts = new LinkedList<String> ();
+ hosts.add ( "localhost:" + wireMock.port() );
+
+ MRMetaClient c;
+ try {
+ c = new MRMetaClient(hosts);
+ Set<String> setString=c.getTopics();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+
+ // assertEquals ("http://localhost:8080/events/" + "topic/cg/cid", url );
+
+ }
+
+ @Test
+ public void getTopicMetadataTest() {
+ final Collection<String> hosts = new LinkedList<String> ();
+ hosts.add ( "localhost:" + wireMock.port() );
+
+ final String topic ="topic1";
+
+ MRMetaClient c;
+ try {
+ c = new MRMetaClient(hosts);
+ TopicInfo topicInfo=c.getTopicMetadata(topic);
+ } catch (IOException | HttpObjectNotFoundException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ @Test
+ public void testcreateTopic(){
+ final Collection<String> hosts = new LinkedList<String> ();
+ hosts.add ( "localhost:" + wireMock.port() );
+
+ MRMetaClient c;
+ try {
+ c = new MRMetaClient(hosts);
+ c.createTopic("topic1", "testTopic", 1, 1);
+ } catch (IOException | HttpException e) {
+ e.printStackTrace();
+ }
+ }
+ @Test
+ public void testupdateApiKey(){
+ final Collection<String> hosts = new LinkedList<String> ();
+ hosts.add ( "localhost:" + wireMock.port() );
+
+ MRMetaClient c;
+ try {
+ c = new MRMetaClient(hosts);
+ c.updateCurrentApiKey("test@onap.com", "test email");
+ }catch (HttpException e) {
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (NullPointerException e) {
+ assertTrue(true);
+ }
+
+ }
+
+
+}
diff --git a/src/test/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchConsumerTest.java b/src/test/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchConsumerTest.java
new file mode 100644
index 0000000..af02c2f
--- /dev/null
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchConsumerTest.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
+ *******************************************************************************/
+
+package org.onap.dmaap.mr.client.impl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import org.json.JSONObject;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.onap.dmaap.mr.client.MRClientFactory;
+import org.onap.dmaap.mr.client.MRConsumer;
+import org.onap.dmaap.mr.client.MRPublisher.message;
+import org.onap.dmaap.mr.client.response.MRPublisherResponse;
+
+public class MRSimplerBatchConsumerTest {
+
+ File outFile;
+ @Before
+ public void setUp() throws Exception {
+ Properties properties = new Properties();
+ properties.load(MRSimplerBatchConsumerTest.class.getClassLoader().getResourceAsStream("dme2/consumer.properties"));
+
+ String routeFilePath="dme2/preferredRoute.txt";
+
+ File file = new File(MRSimplerBatchConsumerTest.class.getClassLoader().getResource(routeFilePath).getFile());
+ properties.put("DME2preferredRouterFilePath", MRSimplerBatchConsumerTest.class.getClassLoader().getResource(routeFilePath).getFile());
+
+ outFile = new File(file.getParent() + "/consumer_tmp.properties");
+ properties.store(new FileOutputStream(outFile), "");
+ }
+
+ @Test
+ public void testSend() throws IOException, InterruptedException {
+
+ final MRConsumer cc = MRClientFactory.createConsumer(outFile.getPath());
+
+ try {
+ for(String msg : cc.fetch()){
+ System.out.println(msg);
+ }
+ } catch (Exception e) {
+ System.err.println ( e.getClass().getName () + ": " + e.getMessage () );
+ }
+
+ }
+
+
+}
diff --git a/src/test/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisherTest.java b/src/test/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisherTest.java
new file mode 100644
index 0000000..2f9b519
--- /dev/null
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisherTest.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
+ *******************************************************************************/
+
+package org.onap.dmaap.mr.client.impl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import org.json.JSONObject;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.onap.dmaap.mr.client.MRClientFactory;
+import org.onap.dmaap.mr.client.MRPublisher.message;
+import org.onap.dmaap.mr.client.response.MRPublisherResponse;
+
+public class MRSimplerBatchPublisherTest {
+
+ File outFile;
+ @Before
+ public void setUp() throws Exception {
+ Properties properties = new Properties();
+ properties.load(MRSimplerBatchPublisherTest.class.getClassLoader().getResourceAsStream("dme2/producer.properties"));
+
+ String routeFilePath="dme2/preferredRoute.txt";
+
+ File file = new File(MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());
+ properties.put("DME2preferredRouterFilePath", MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());
+
+ outFile = new File(file.getParent() + "/producer_tmp.properties");
+ properties.store(new FileOutputStream(outFile), "");
+ }
+
+ @Test
+ public void testSend() throws IOException, InterruptedException {
+
+ final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher)MRClientFactory.createBatchingPublisher(outFile.getPath());
+
+ //publish some messages
+ final JSONObject msg1 = new JSONObject ();
+ pub.send ( "MyPartitionKey", msg1.toString () );
+
+ final List<message> stuck = pub.close ( 1, TimeUnit.SECONDS );
+ if ( stuck.size () > 0 ) {
+ System.out.println( stuck.size() + " messages unsent" );
+ }
+ else
+ {
+ System.out.println ( "Clean exit; all messages sent." );
+ }
+
+
+ }
+
+ @Test
+ public void testSendBatchWithResponse() throws IOException, InterruptedException {
+
+ final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher)MRClientFactory.createBatchingPublisher(outFile.getPath(), true);
+
+ //publish some messages
+ final JSONObject msg1 = new JSONObject ();
+ pub.send ( "MyPartitionKey", msg1.toString () );
+ MRPublisherResponse pubResponse = new MRPublisherResponse();
+ pub.setPubResponse(pubResponse);
+
+ MRPublisherResponse mrPublisherResponse = pub.sendBatchWithResponse();
+ Assert.assertEquals(1, mrPublisherResponse.getPendingMsgs());
+
+ }
+
+}