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.java80
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRBaseClientTest.java709
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRBatchPublisherTest.java53
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRConstantsTest.java217
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRConsumerImplTest.java273
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRMetaClientTest.java178
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchConsumerTest.java80
-rw-r--r--src/test/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisherTest.java448
8 files changed, 1012 insertions, 1026 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 5d63759..ca4fb3b 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
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2018 IBM Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,20 +19,10 @@
* ============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.mockito.Matchers.any;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import java.util.Properties;
-
-import javax.ws.rs.client.Invocation.Builder;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.Response;
+package org.onap.dmaap.mr.client.impl;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
@@ -40,6 +32,16 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import javax.ws.rs.client.Invocation.Builder;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
public class DMaapClientUtilTest {
@Mock
Response response;
@@ -47,56 +49,56 @@ public class DMaapClientUtilTest {
Builder builder;
@Mock
WebTarget target;
- private ClientConfig config=null;
+ private ClientConfig config = null;
@Before
- public void setup(){
+ public void setup() {
MockitoAnnotations.initMocks(this);
}
-
+
@Test
public void testGetTarget() {
- WebTarget actual = DmaapClientUtil.getTarget(getClientConfig(),"testpath");
-
+ WebTarget actual = DmaapClientUtil.getTarget(getClientConfig(), "testpath");
+
assertEquals("testpath", actual.getUri().getPath());
}
-
+
@Test
public void testGetTargetWithParams() {
- WebTarget actual = DmaapClientUtil.getTarget(getClientConfig(),"testpath", "testuser", "testpassword");
-
+ WebTarget actual = DmaapClientUtil.getTarget(getClientConfig(), "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);
-
+ 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);
verify(target).request();
verify(builder, times(2)).header((String) any(), any());
}
-
+
@Test
public void testSetHttpClientProperties() {
- Properties properties = new Properties();
- properties.setProperty(ClientProperties.PROXY_URI, "http://localhost:1234");
- ClientConfig cConfig = DmaapClientUtil.getClientConfig(properties);
+ Properties properties = new Properties();
+ properties.setProperty(ClientProperties.PROXY_URI, "http://localhost:1234");
+ ClientConfig cConfig = DmaapClientUtil.getClientConfig(properties);
- assertEquals(cConfig.getConnectorProvider().getClass().getSimpleName(), "ApacheConnectorProvider");
+ assertEquals("ApacheConnectorProvider", cConfig.getConnectorProvider().getClass().getSimpleName());
}
- private ClientConfig getClientConfig(){
- if(config==null){
- config=DmaapClientUtil.getClientConfig(null);
- }
- return config;
-
- }
+ 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 dc2c5ff..9d47192 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
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,23 +19,10 @@
* ============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 static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.verify;
-
-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;
+package org.onap.dmaap.mr.client.impl;
import org.apache.http.HttpException;
import org.glassfish.jersey.client.ClientConfig;
@@ -50,447 +39,457 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import java.net.MalformedURLException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.verify;
+
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"org.apache.http.conn.ssl.*", "jdk.internal.reflect.*"})
-@PrepareForTest({ DmaapClientUtil.class })
+@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";
- private ClientConfig config=null;
-
- @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");
-
- Mockito.when(response.getStatus()).thenReturn(200);
- Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- Mockito.when(response.getHeaders()).thenReturn(map);
-
- Mockito.when(
- DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password"))
- .thenReturn(response);
-
- 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);
- Mockito
- .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username",
- "password"))
- .thenReturn(
- responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
- JSONObject result = mrBaseClient.get("/path", "username", "password", "HTTPAUTH");
- assertEquals(403, result.getInt("status"));
- }
-
- @Test
- public void testGet_basicauth() throws JSONException, HttpException {
-
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
+ // @InjectMocks
+ 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 {
+ 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");
+
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
+
+ Mockito.when(
+ DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"), "username", "password"))
+ .thenReturn(response);
+
+ 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);
+ Mockito
+ .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"), "username",
+ "password"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+ JSONObject result = mrBaseClient.get("/path", "username", "password", "HTTPAUTH");
+ assertEquals(403, result.getInt("status"));
+ }
+
+ @Test
+ public void testGet_basicauth() throws JSONException, HttpException {
+
+ Response response = Mockito.mock(Response.class);
+ MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
+ map.add("transactionid", "transactionid");
+
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.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);
+ Mockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"),
+ Base64.encodeAsString("username:password"))).thenReturn(response);
- Mockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"),
- Base64.encodeAsString("username:password"))).thenReturn(response);
+ 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();
+
+ }
- 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();
-
- }
+ @Test(expected = HttpException.class)
+ public void testGet_error() throws JSONException, HttpException {
- @Test(expected = HttpException.class)
- public void testGet_error() throws JSONException, HttpException {
+ ResponseBuilder responseBuilder = Response.ok();
+ Mockito.when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"), "username",
+ "password"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
- ResponseBuilder responseBuilder = Response.ok();
- Mockito.when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username",
- "password"))
- .thenReturn(
- responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+ mrBaseClient.get("/path", null, null, "HTTPAUTH");
+ }
- mrBaseClient.get("/path", null, null, "HTTPAUTH");
- }
+ @Test
+ public void testGet_wrongjson() throws JSONException, HttpException {
- @Test
- public void testGet_wrongjson() throws JSONException, HttpException {
+ Response response = Mockito.mock(Response.class);
+ MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
+ map.add("transactionid", "transactionid");
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("[[");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- Mockito.when(response.getStatus()).thenReturn(200);
- Mockito.when(response.readEntity(String.class)).thenReturn("[[");
- Mockito.when(response.getHeaders()).thenReturn(map);
+ Mockito.when(
+ DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"), "username", "password"))
+ .thenReturn(response);
- Mockito.when(
- DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password"))
- .thenReturn(response);
+ mrBaseClient.get("/path", "username", "password", "HTTPAUTH");
+ verify(response, atLeast(1)).getStatus();
+ verify(response).readEntity(String.class);
+ verify(response).getHeaders();
+ }
- mrBaseClient.get("/path", "username", "password", "HTTPAUTH");
- verify(response, atLeast(1)).getStatus();
- verify(response).readEntity(String.class);
- verify(response).getHeaders();
- }
+ @Test
+ public void testGetResponse() throws JSONException, HttpException {
- @Test
- public void testGetResponse() throws JSONException, HttpException {
+ Response response = Mockito.mock(Response.class);
+ MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
+ map.add("transactionid", "transactionid");
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.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);
-
- Mockito.when(
- DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password"))
- .thenReturn(response);
+ Mockito.when(
+ DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"), "username", "password"))
+ .thenReturn(response);
- mrBaseClient.getResponse("/path", "username", "password", "HTTPAUTH");
- assertTrue(true);
+ 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");
-
- Mockito.when(response.getStatus()).thenReturn(200);
- Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- Mockito.when(response.getHeaders()).thenReturn(map);
-
- Mockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"),
- Base64.encodeAsString("username:password"))).thenReturn(response);
-
- mrBaseClient.getResponse("/path", "username", "password", "HTTPAAF");
- 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");
- @Test(expected = HttpException.class)
- public void testGetResponse_error() throws JSONException, HttpException {
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- ResponseBuilder responseBuilder = Response.ok();
- Mockito
- .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username",
- "password"))
- .thenReturn(
- responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+ Mockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"),
+ Base64.encodeAsString("username:password"))).thenReturn(response);
- mrBaseClient.getResponse("/path", null, null, "HTTPAUTH");
- }
+ mrBaseClient.getResponse("/path", "username", "password", "HTTPAAF");
+ assertTrue(true);
- @Test
- public void testAuthResponse() throws JSONException, HttpException {
+ }
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
+ @Test(expected = HttpException.class)
+ public void testGetResponse_error() throws JSONException, HttpException {
- Mockito.when(response.getStatus()).thenReturn(200);
- Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- Mockito.when(response.getHeaders()).thenReturn(map);
+ ResponseBuilder responseBuilder = Response.ok();
+ Mockito
+ .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"), "username",
+ "password"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
- Mockito.when(
- DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username", "password"))
- .thenReturn(response);
+ mrBaseClient.getResponse("/path", null, null, "HTTPAUTH");
+ }
- mrBaseClient.getAuthResponse("/path", "username", "password", "username", "password", "HTTPAUTH");
- assertTrue(true);
+ @Test
+ public void testAuthResponse() throws JSONException, HttpException {
- }
+ Response response = Mockito.mock(Response.class);
+ MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
+ map.add("transactionid", "transactionid");
- @Test(expected = HttpException.class)
- public void testAuthResponsee_error() throws JSONException, HttpException {
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- ResponseBuilder responseBuilder = Response.ok();
- Mockito
- .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username",
- "password"))
- .thenReturn(
- responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+ Mockito.when(
+ DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"), "username", "password"))
+ .thenReturn(response);
- mrBaseClient.getAuthResponse("/path", null, null, null, null, "HTTPAUTH");
+ mrBaseClient.getAuthResponse("/path", "username", "password", "username", "password", "HTTPAUTH");
+ assertTrue(true);
- }
+ }
- @Test
- public void testPostAuth() throws JSONException, HttpException {
+ @Test(expected = HttpException.class)
+ public void testAuthResponsee_error() throws JSONException, HttpException {
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
+ ResponseBuilder responseBuilder = Response.ok();
+ Mockito
+ .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"), "username",
+ "password"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
- Mockito.when(response.getStatus()).thenReturn(200);
- Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- Mockito.when(response.getHeaders()).thenReturn(map);
+ mrBaseClient.getAuthResponse("/path", null, null, null, null, "HTTPAUTH");
- Mockito
- .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username",
- "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
- .thenReturn(response);
+ }
- mrBaseClient.postAuth(new PostAuthDataObject().setPath("/path")
- .setData( new String("{\"test\":\"test\"}").getBytes())
- .setContentType("application/json")
- .setAuthKey("username")
- .setAuthDate("password")
- .setUsername("username")
- .setPassword("password")
- .setProtocolFlag("HTTPAUTH"));
- assertTrue(true);
+ @Test
+ public void testPostAuth() throws JSONException, HttpException {
- }
+ Response response = Mockito.mock(Response.class);
+ MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
+ map.add("transactionid", "transactionid");
- @Test(expected = HttpException.class)
- public void testPostAuth_error() throws JSONException, HttpException {
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- ResponseBuilder responseBuilder = Response.ok();
- Mockito
- .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());
-
- mrBaseClient.postAuth(new PostAuthDataObject().setPath("/path")
- .setData( new String("{\"test\":\"test\"}").getBytes())
+ Mockito
+ .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"), "username",
+ "password", ("{\"test\":\"test\"}").getBytes(), "application/json"))
+ .thenReturn(response);
+
+ mrBaseClient.postAuth(new PostAuthDataObject().setPath("/path")
+ .setData(("{\"test\":\"test\"}").getBytes())
+ .setContentType("application/json")
+ .setAuthKey("username")
+ .setAuthDate("password")
+ .setUsername("username")
+ .setPassword("password")
+ .setProtocolFlag("HTTPAUTH"));
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testPostAuth_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ Mockito
+ .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"), "username",
+ "password", ("{\"test\":\"test\"}").getBytes(), "application/json"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.postAuth(new PostAuthDataObject().setPath("/path")
+ .setData(("{\"test\":\"test\"}").getBytes())
.setContentType("application/json")
.setAuthKey(null)
.setAuthDate(null)
- .setUsername(null)
+ .setUsername(null)
.setPassword(null)
.setProtocolFlag("HTTPAUTH"));
- }
+ }
+
+ @Test
+ public void testGetNoAuthResponse() throws JSONException, HttpException {
+
+ Response response = Mockito.mock(Response.class);
+ MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
+ map.add("transactionid", "transactionid");
+
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- @Test
- public void testGetNoAuthResponse() throws JSONException, HttpException {
+ Mockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"))).thenReturn(response);
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
+ mrBaseClient.getNoAuthResponse("/path", "username", "password", "HTTPAUTH");
+ assertTrue(true);
- Mockito.when(response.getStatus()).thenReturn(200);
- Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- Mockito.when(response.getHeaders()).thenReturn(map);
+ }
- Mockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"))).thenReturn(response);
+ @Test
+ public void testPost() throws JSONException, HttpException {
- mrBaseClient.getNoAuthResponse("/path", "username", "password", "HTTPAUTH");
- assertTrue(true);
+ Response response = Mockito.mock(Response.class);
+ MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
+ map.add("transactionid", "transactionid");
- }
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- @Test
- public void testPost() throws JSONException, HttpException {
+ Mockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"),
+ Base64.encodeAsString("username:password"), ("{\"test\":\"test\"}").getBytes(), "application/json")).thenReturn(response);
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
+ mrBaseClient.post("/path", ("{\"test\":\"test\"}").getBytes(), "application/json", "username",
+ "password", "HTTPAUTH");
+ verify(response, atLeast(1)).getStatus();
+ verify(response).readEntity(String.class);
+ verify(response).getHeaders();
- Mockito.when(response.getStatus()).thenReturn(200);
- Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- Mockito.when(response.getHeaders()).thenReturn(map);
+ }
- Mockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"),
- Base64.encodeAsString("username:password"), new String("{\"test\":\"test\"}").getBytes(), "application/json")).thenReturn(response);
+ @Test(expected = HttpException.class)
+ public void testPost_error() throws JSONException, HttpException {
- mrBaseClient.post("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", "username",
- "password", "HTTPAUTH");
- verify(response, atLeast(1)).getStatus();
- verify(response).readEntity(String.class);
- verify(response).getHeaders();
+ ResponseBuilder responseBuilder = Response.ok();
+ Mockito
+ .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"),
+ Base64.encodeAsString("username:password")))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
- }
+ mrBaseClient.post("/path", ("{\"test\":\"test\"}").getBytes(), "application/json", null, null,
+ "HTTPAUTH");
- @Test(expected = HttpException.class)
- public void testPost_error() throws JSONException, HttpException {
+ }
- ResponseBuilder responseBuilder = Response.ok();
- Mockito
- .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"),
- Base64.encodeAsString("username:password")))
- .thenReturn(
- responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+ @Test
+ public void testPostAuthwithResponse() throws JSONException, HttpException {
- mrBaseClient.post("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", null, null,
- "HTTPAUTH");
+ Response response = Mockito.mock(Response.class);
+ MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
+ map.add("transactionid", "transactionid");
- }
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- @Test
- public void testPostAuthwithResponse() throws JSONException, HttpException {
+ Mockito
+ .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"), "username",
+ "password", ("{\"test\":\"test\"}").getBytes(), "application/json"))
+ .thenReturn(response);
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
+ mrBaseClient.postAuthwithResponse("/path", ("{\"test\":\"test\"}").getBytes(), "application/json",
+ "username", "password", "username", "password", "HTTPAUTH");
+ assertTrue(true);
- Mockito.when(response.getStatus()).thenReturn(200);
- Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- Mockito.when(response.getHeaders()).thenReturn(map);
+ }
- Mockito
- .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"), "username",
- "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
- .thenReturn(response);
+ @Test(expected = HttpException.class)
+ public void testPostAuthwithResponse_error() throws JSONException, HttpException {
- mrBaseClient.postAuthwithResponse("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json",
- "username", "password", "username", "password", "HTTPAUTH");
- assertTrue(true);
+ ResponseBuilder responseBuilder = Response.ok();
+ Mockito
+ .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"), "username",
+ "password", ("{\"test\":\"test\"}").getBytes(), "application/json"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
- }
+ mrBaseClient.postAuthwithResponse("/path", ("{\"test\":\"test\"}").getBytes(), "application/json",
+ null, null, null, null, "HTTPAUTH");
- @Test(expected = HttpException.class)
- public void testPostAuthwithResponse_error() throws JSONException, HttpException {
+ }
- ResponseBuilder responseBuilder = Response.ok();
- Mockito
- .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());
+ @Test
+ public void testPostWithResponse() throws JSONException, HttpException {
- mrBaseClient.postAuthwithResponse("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json",
- null, null, null, null, "HTTPAUTH");
- assertTrue(true);
+ Response response = Mockito.mock(Response.class);
+ MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
+ map.add("transactionid", "transactionid");
- }
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- @Test
- public void testPostWithResponse() throws JSONException, HttpException {
+ Mockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"),
+ Base64.encodeAsString("username:password"), ("{\"test\":\"test\"}").getBytes(), "application/json")).thenReturn(response);
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
+ mrBaseClient.postWithResponse("/path", ("{\"test\":\"test\"}").getBytes(), "application/json",
+ "username", "password", "HTTPAUTH");
+ assertTrue(true);
- Mockito.when(response.getStatus()).thenReturn(200);
- Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- Mockito.when(response.getHeaders()).thenReturn(map);
+ }
- Mockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"),
- Base64.encodeAsString("username:password"), new String("{\"test\":\"test\"}").getBytes(), "application/json")).thenReturn(response);
+ @Test(expected = HttpException.class)
+ public void testPostWithResponse_error() throws JSONException, HttpException {
- mrBaseClient.postWithResponse("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json",
- "username", "password", "HTTPAUTH");
- assertTrue(true);
+ ResponseBuilder responseBuilder = Response.ok();
+ Mockito
+ .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"),
+ Base64.encodeAsString("username:password")))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
- }
+ mrBaseClient.postWithResponse("/path", ("{\"test\":\"test\"}").getBytes(), "application/json", null,
+ null, "HTTPAUTH");
- @Test(expected = HttpException.class)
- public void testPostWithResponse_error() throws JSONException, HttpException {
+ }
- ResponseBuilder responseBuilder = Response.ok();
- Mockito
- .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"),
- Base64.encodeAsString("username:password")))
- .thenReturn(
- responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+ @Test
+ public void testGetAuth() throws JSONException, HttpException {
- mrBaseClient.postWithResponse("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", null,
- null, "HTTPAUTH");
+ Response response = Mockito.mock(Response.class);
+ MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
+ map.add("transactionid", "transactionid");
- }
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- @Test
- public void testGetAuth() throws JSONException, HttpException {
+ Mockito.when(
+ DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"), "username", "password"))
+ .thenReturn(response);
+ mrBaseClient.getAuth("/path", "username", "password", "username", "password", "HTTPAUTH");
+ assertTrue(true);
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
+ }
- Mockito.when(response.getStatus()).thenReturn(200);
- Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- Mockito.when(response.getHeaders()).thenReturn(map);
+ @Test(expected = HttpException.class)
+ public void testGetAuth_error() throws JSONException, HttpException {
- Mockito.when(
- 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(getClientConfig(), "/path"), "username",
+ "password", ("{\"test\":\"test\"}").getBytes(), "application/json"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
- }
+ mrBaseClient.getAuth("/path", null, null, null, null, "HTTPAUTH");
- @Test(expected = HttpException.class)
- public void testGetAuth_error() throws JSONException, HttpException {
+ }
- ResponseBuilder responseBuilder = Response.ok();
- Mockito
- .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());
+ @Test
+ public void testGetNoAuth() throws JSONException, HttpException {
- mrBaseClient.getAuth("/path", null, null, null, null, "HTTPAUTH");
- assertTrue(true);
+ Response response = Mockito.mock(Response.class);
+ MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
+ map.add("transactionid", "transactionid");
- }
+ Mockito.when(response.getStatus()).thenReturn(200);
+ Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
+ Mockito.when(response.getHeaders()).thenReturn(map);
- @Test
- public void testGetNoAuth() throws JSONException, HttpException {
+ Mockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget(getClientConfig(), "/path"))).thenReturn(response);
+ mrBaseClient.getNoAuth("/path");
+ assertTrue(true);
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
+ }
- Mockito.when(response.getStatus()).thenReturn(200);
- Mockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- Mockito.when(response.getHeaders()).thenReturn(map);
- Mockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget(getClientConfig(),"/path"))).thenReturn(response);
- mrBaseClient.getNoAuth("/path");
- assertTrue(true);
+ @Test
+ public void testGetHTTPErrorResponseMessage() {
+ assertEquals("testtest", mrBaseClient.getHTTPErrorResponseMessage("<body>testtest</body>"));
- }
+ }
+ @Test
+ public void getGTTPErrorResponseCode() {
+ assertEquals("500", mrBaseClient.getHTTPErrorResponseCode("<title>500</title>"));
+ }
- @Test
- public void testGetHTTPErrorResponseMessage() {
- assertEquals("testtest", mrBaseClient.getHTTPErrorResponseMessage("<body>testtest</body>"));
- }
+ private ClientConfig getClientConfig() {
+ if (config == null) {
+ config = DmaapClientUtil.getClientConfig(null);
+ }
+ return config;
- @Test
- public void getGTTPErrorResponseCode() {
- assertEquals("500", mrBaseClient.getHTTPErrorResponseCode("<title>500</title>"));
- }
-
-
-
- private ClientConfig getClientConfig(){
- if(config==null){
- config=DmaapClientUtil.getClientConfig(null);
- }
- return config;
-
- }
+ }
}
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
index 3d1e3d0..4d8811f 100644
--- a/src/test/java/org/onap/dmaap/mr/client/impl/MRBatchPublisherTest.java
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRBatchPublisherTest.java
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,38 +19,39 @@
* ============LICENSE_END=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *
+ *
*******************************************************************************/
+
package org.onap.dmaap.mr.client.impl;
+import org.junit.Before;
+import org.junit.Test;
+
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(expected = Test.None.class /* no exception expected */)
- public void testSend() throws IOException{
- mrBatchPublisher.send("testmessage");
- }
-
- @Test(expected = Test.None.class /* no exception expected */)
- public void testClose() throws IOException{
- mrBatchPublisher.close();
- }
+
+ private Collection<String> hosts = new HashSet<>(Arrays.asList("/test"));
+ private MRBatchPublisher mrBatchPublisher = new MRBatchPublisher(hosts, "topic", 2, 20, true);
+
+
+ @Before
+ public void setup() {
+
+
+ }
+
+ @Test(expected = Test.None.class /* no exception expected */)
+ public void testSend() throws IOException {
+ mrBatchPublisher.send("testmessage");
+ }
+
+ @Test(expected = Test.None.class /* no exception expected */)
+ 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
index d912f9d..09fc2a8 100644
--- a/src/test/java/org/onap/dmaap/mr/client/impl/MRConstantsTest.java
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRConstantsTest.java
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,125 +19,112 @@
* ============LICENSE_END=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *
+ *
*******************************************************************************/
+
package org.onap.dmaap.mr.client.impl;
+import junit.framework.TestCase;
+import org.apache.http.HttpHost;
+import org.junit.Test;
+
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;
-
-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.STD_MR_SERVICE_PORT, first.getPort () );
- assertEquals ( "foo", first.getHostName () );
-
- final HttpHost second = it.next ();
- assertEquals ( MRConstants.STD_MR_SERVICE_PORT, 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.STD_MR_SERVICE_PORT},
- { ":oops", null, "-1" },
- { "host:1.3", null, "-1" },
- { "host:13", "host", "13" },
- { "host:", "host", "" + MRConstants.STD_MR_SERVICE_PORT},
- };
-
- @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 );
- }
- }
- }
+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.STD_MR_SERVICE_PORT, first.getPort());
+ assertEquals("foo", first.getHostName());
+
+ final HttpHost second = it.next();
+ assertEquals(MRConstants.STD_MR_SERVICE_PORT, 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.STD_MR_SERVICE_PORT},
+ {":oops", null, "-1"},
+ {"host:1.3", null, "-1"},
+ {"host:13", "host", "13"},
+ {"host:", "host", "" + MRConstants.STD_MR_SERVICE_PORT},
+ };
+
+ @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
index 52c7111..7b77a95 100644
--- a/src/test/java/org/onap/dmaap/mr/client/impl/MRConsumerImplTest.java
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRConsumerImplTest.java
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,182 +19,181 @@
* ============LICENSE_END=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *
+ *
*******************************************************************************/
package org.onap.dmaap.mr.client.impl;
+import junit.framework.TestCase;
+import org.junit.Test;
+import org.onap.dmaap.mr.client.MRClientFactory;
+import org.onap.dmaap.mr.client.ProtocolType;
+
import java.io.File;
import java.io.FileOutputStream;
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.test.clients.ProtocolTypeConstants;
-
public class MRConsumerImplTest extends TestCase {
- @Test
- public void testNullFilter() throws IOException {
- final LinkedList<String> hosts = new LinkedList<String>();
- hosts.add("localhost:8080");
+ @Test
+ public void testNullFilter() throws IOException {
+ final LinkedList<String> hosts = new LinkedList<String>();
+ hosts.add("localhost:8080");
final MRConsumerImpl c = new MRConsumerImpl.MRConsumerImplBuilder().setHostPart(hosts)
.setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(-1)
.setLimit(-1).setFilter(null).setApiKey_username(null).setApiSecret_password(null)
.createMRConsumerImpl();
- 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 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.MRConsumerImplBuilder().setHostPart(hosts)
.setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(-1)
.setLimit(-1).setFilter("filter").setApiKey_username(null)
.setApiSecret_password(null).createMRConsumerImpl();
- 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 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.MRConsumerImplBuilder().setHostPart(hosts)
.setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(30000)
.setLimit(-1).setFilter(null).setApiKey_username(null).setApiSecret_password(null)
.createMRConsumerImpl();
- 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 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.MRConsumerImplBuilder().setHostPart(hosts)
.setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(-1)
.setLimit(100).setFilter(null).setApiKey_username(null).setApiSecret_password(null)
.createMRConsumerImpl();
- 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 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.MRConsumerImplBuilder().setHostPart(hosts)
.setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(1000)
.setLimit(400).setFilter("f").setApiKey_username(null).setApiSecret_password(null)
.createMRConsumerImpl();
- 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 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.MRConsumerImplBuilder().setHostPart(hosts)
.setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(-1)
.setLimit(-1).setFilter("{ \"foo\"=\"bar\"bar\" }").setApiKey_username(null)
.setApiSecret_password(null).createMRConsumerImpl();
- 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(
- MRSimplerBatchPublisherTest.class.getClassLoader().getResourceAsStream("dme2/consumer.properties"));
-
- String routeFilePath = "dme2/preferredRoute.txt";
-
- File file = new File(MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());
- properties.put("routeFilePath",
- MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());
-
- File outFile = new File(file.getParent() + "/consumer_tmp.properties");
- properties.store(new FileOutputStream(outFile), "");
-
- MRClientFactory.prop=properties;
+ 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(
+ MRSimplerBatchPublisherTest.class.getClassLoader().getResourceAsStream("dme2/consumer.properties"));
+
+ String routeFilePath = "dme2/preferredRoute.txt";
+
+ File file = new File(MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());
+ properties.put("routeFilePath",
+ MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());
+
+ File outFile = new File(file.getParent() + "/consumer_tmp.properties");
+ properties.store(new FileOutputStream(outFile), "");
+
+ MRClientFactory.prop = properties;
final MRConsumerImpl c = new MRConsumerImpl.MRConsumerImplBuilder().setHostPart(hosts)
.setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(-1)
.setLimit(-1).setFilter("{ \"foo\"=\"bar\"bar\" }").setApiKey_username(null)
.setApiSecret_password(null).createMRConsumerImpl();
- c.setProps(properties);
- assertNotNull(c.fetchWithReturnConsumerResponse());
- c.setProtocolFlag(ProtocolTypeConstants.AAF_AUTH.getValue());
- assertNotNull(c.fetchWithReturnConsumerResponse());
- c.setProtocolFlag(ProtocolTypeConstants.HTTPNOAUTH.getValue());
- assertNotNull(c.fetchWithReturnConsumerResponse());
- c.setProtocolFlag(ProtocolTypeConstants.AUTH_KEY.getValue());
- assertNotNull(c.fetchWithReturnConsumerResponse());
- assertTrue(true);
- }
-
- @Test
- public void testFetch() throws Exception {
- final LinkedList<String> hosts = new LinkedList<String>();
- hosts.add("localhost:8080");
-
-
- Properties properties = new Properties();
- properties.load(
- MRSimplerBatchPublisherTest.class.getClassLoader().getResourceAsStream("dme2/consumer.properties"));
-
- String routeFilePath = "dme2/preferredRoute.txt";
-
- File file = new File(MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());
- properties.put("routeFilePath",
- MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());
-
- File outFile = new File(file.getParent() + "/consumer_tmp.properties");
- properties.store(new FileOutputStream(outFile), "");
-
- MRClientFactory.prop=properties;
+ c.setProps(properties);
+ assertNotNull(c.fetchWithReturnConsumerResponse());
+ c.setProtocolFlag(ProtocolType.AAF_AUTH.getValue());
+ assertNotNull(c.fetchWithReturnConsumerResponse());
+ c.setProtocolFlag(ProtocolType.HTTPNOAUTH.getValue());
+ assertNotNull(c.fetchWithReturnConsumerResponse());
+ c.setProtocolFlag(ProtocolType.AUTH_KEY.getValue());
+ assertNotNull(c.fetchWithReturnConsumerResponse());
+ assertTrue(true);
+ }
+
+ @Test
+ public void testFetch() throws Exception {
+ final LinkedList<String> hosts = new LinkedList<String>();
+ hosts.add("localhost:8080");
+
+
+ Properties properties = new Properties();
+ properties.load(
+ MRSimplerBatchPublisherTest.class.getClassLoader().getResourceAsStream("dme2/consumer.properties"));
+
+ String routeFilePath = "dme2/preferredRoute.txt";
+
+ File file = new File(MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());
+ properties.put("routeFilePath",
+ MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());
+
+ File outFile = new File(file.getParent() + "/consumer_tmp.properties");
+ properties.store(new FileOutputStream(outFile), "");
+
+ MRClientFactory.prop = properties;
final MRConsumerImpl c = new MRConsumerImpl.MRConsumerImplBuilder().setHostPart(hosts)
.setTopic("topic").setConsumerGroup("cg").setConsumerId("cid").setTimeoutMs(-1)
.setLimit(-1).setFilter("{ \"foo\"=\"bar\"bar\" }").setApiKey_username(null)
.setApiSecret_password(null).createMRConsumerImpl();
- c.setProps(properties);
- try {
- c.fetch();
- } catch (Exception e) {
- assertTrue(true);
- }
- c.setProtocolFlag(ProtocolTypeConstants.AAF_AUTH.getValue());
- try {
- c.fetch();
- } catch (Exception e) {
- assertTrue(true);
- }
- c.setProtocolFlag(ProtocolTypeConstants.HTTPNOAUTH.getValue());
- try {
- c.fetch();
- } catch (Exception e) {
- assertTrue(true);
- }
- c.setProtocolFlag(ProtocolTypeConstants.AUTH_KEY.getValue());
- try {
- c.fetch();
- } catch (Exception e) {
- assertTrue(true);
- }
- }
+ c.setProps(properties);
+ try {
+ c.fetch();
+ } catch (Exception e) {
+ assertTrue(true);
+ }
+ c.setProtocolFlag(ProtocolType.AAF_AUTH.getValue());
+ try {
+ c.fetch();
+ } catch (Exception e) {
+ assertTrue(true);
+ }
+ c.setProtocolFlag(ProtocolType.HTTPNOAUTH.getValue());
+ try {
+ c.fetch();
+ } catch (Exception e) {
+ assertTrue(true);
+ }
+ c.setProtocolFlag(ProtocolType.AUTH_KEY.getValue());
+ try {
+ c.fetch();
+ } catch (Exception e) {
+ 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
index ea9cab4..00f1278 100644
--- a/src/test/java/org/onap/dmaap/mr/client/impl/MRMetaClientTest.java
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRMetaClientTest.java
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,110 +19,98 @@
* ============LICENSE_END=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *
+ *
*******************************************************************************/
+
package org.onap.dmaap.mr.client.impl;
+import com.att.nsa.apiClient.http.HttpException;
+import com.att.nsa.apiClient.http.HttpObjectNotFoundException;
+import org.junit.Test;
+import org.onap.dmaap.mr.client.MRTopicManager.TopicInfo;
+
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Set;
-import org.junit.Before;
-import org.junit.Test;
import static org.junit.Assert.assertNotNull;
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.MRTopicManager.TopicInfo;
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:" +3904 );
-
- MRMetaClient c;
- try {
- c = new MRMetaClient(hosts);
- Set<String> setString=c.getTopics();
- } catch (IOException e) {
- e.printStackTrace();
- }
- assertNotNull(hosts);
-
-
- // assertEquals ("http://localhost:8080/events/" + "topic/cg/cid", url );
-
- }
-
- @Test
- public void getTopicMetadataTest() {
- final Collection<String> hosts = new LinkedList<String> ();
- hosts.add ( "localhost:" + 3904 );
-
- final String topic ="topic1";
-
- MRMetaClient c;
- try {
- c = new MRMetaClient(hosts);
- TopicInfo topicInfo=c.getTopicMetadata(topic);
- } catch (IOException | HttpObjectNotFoundException e) {
- e.printStackTrace();
- }
- assertNotNull(topic);
-
- }
-
- @Test
- public void testcreateTopic(){
- final Collection<String> hosts = new LinkedList<String> ();
- hosts.add ( "localhost:" + 3904 );
-
- MRMetaClient c;
- try {
- c = new MRMetaClient(hosts);
- c.createTopic("topic1", "testTopic", 1, 1);
- } catch (IOException | HttpException e) {
- e.printStackTrace();
- }
- assertNotNull(hosts);
- }
- @Test
- public void testupdateApiKey(){
- final Collection<String> hosts = new LinkedList<String> ();
- hosts.add ( "localhost:" + 3904 );
-
- 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);
- }
-
- }
-
-
+
+ @Test
+ public void getTopicsTest() {
+ final Collection<String> hosts = new LinkedList<String>();
+ hosts.add("localhost:" + 3904);
+
+ MRMetaClient c;
+ try {
+ c = new MRMetaClient(hosts);
+ Set<String> setString = c.getTopics();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ assertNotNull(hosts);
+
+
+ //assertEquals ("http://localhost:8080/events/" + "topic/cg/cid", url );
+
+ }
+
+ @Test
+ public void getTopicMetadataTest() {
+ final Collection<String> hosts = new LinkedList<String>();
+ hosts.add("localhost:" + 3904);
+
+ final String topic = "topic1";
+
+ MRMetaClient c;
+ try {
+ c = new MRMetaClient(hosts);
+ TopicInfo topicInfo = c.getTopicMetadata(topic);
+ } catch (IOException | HttpObjectNotFoundException e) {
+ e.printStackTrace();
+ }
+ assertNotNull(topic);
+
+ }
+
+ @Test
+ public void testcreateTopic() {
+ final Collection<String> hosts = new LinkedList<String>();
+ hosts.add("localhost:" + 3904);
+
+ MRMetaClient c;
+ try {
+ c = new MRMetaClient(hosts);
+ c.createTopic("topic1", "testTopic", 1, 1);
+ } catch (IOException | HttpException e) {
+ e.printStackTrace();
+ }
+ assertNotNull(hosts);
+ }
+
+ @Test
+ public void testupdateApiKey() {
+ final Collection<String> hosts = new LinkedList<String>();
+ hosts.add("localhost:" + 3904);
+
+ 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
index af5ccd2..26fee9e 100644
--- a/src/test/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchConsumerTest.java
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchConsumerTest.java
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,54 +19,56 @@
* ============LICENSE_END=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *
+ *
*******************************************************************************/
package org.onap.dmaap.mr.client.impl;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.dmaap.mr.client.MRClientFactory;
+import org.onap.dmaap.mr.client.MRConsumer;
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.dmaap.mr.client.MRClientFactory;
-import org.onap.dmaap.mr.client.MRConsumer;
import static org.junit.Assert.assertNotNull;
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 () );
- }
- assertNotNull(cc);
-
- }
-
+
+ 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());
+ }
+ assertNotNull(cc);
+
+ }
+
}
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
index b2f8817..1ac22ef 100644
--- a/src/test/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisherTest.java
+++ b/src/test/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisherTest.java
@@ -4,11 +4,13 @@
* ================================================================================
* Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright © 2021 Orange.
+ * ================================================================================
* 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.
@@ -17,302 +19,298 @@
* ============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 org.json.JSONObject;
+import org.junit.Assert;
+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.ProtocolType;
+import org.onap.dmaap.mr.client.response.MRPublisherResponse;
import java.io.File;
-import java.io.FileNotFoundException;
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.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;
-import org.onap.dmaap.mr.test.clients.ProtocolTypeConstants;
+import static org.junit.Assert.assertEquals;
public class MRSimplerBatchPublisherTest {
- File outFile;
+ File outFile;
+
+ public void setUp(String contentType) 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());
+ if (contentType != null) {
+ properties.put("contenttype", contentType);
+ }
+ outFile = new File(file.getParent() + "/producer_tmp.properties");
+ properties.store(new FileOutputStream(outFile), "");
+ }
+
+ @Test
+ public void testSend() throws Exception {
+
+ setUp(null);
+
+ 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);
+ Assert.assertEquals(1, stuck.size());
+
+ }
+
+ @Test
+ public void testSendBatchWithResponse() throws Exception {
+
+ setUp(null);
+
+ 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());
+
+ }
+
+ @Test
+ public void testSendBatchWithResponseConText() throws Exception {
+
+ setUp("text/plain");
+
+ 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);
+ Assert.assertEquals(1, stuck.size());
+
+ }
+
+ @Test
+ public void testSendBatchWithResponseContCambria() throws Exception {
- public void setUp(String contentType) throws Exception {
- Properties properties = new Properties();
- properties.load(
- MRSimplerBatchPublisherTest.class.getClassLoader().getResourceAsStream("dme2/producer.properties"));
+ setUp("application/cambria-zip");
- String routeFilePath = "dme2/preferredRoute.txt";
+ final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
+ .createBatchingPublisher(outFile.getPath());
- File file = new File(MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());
- properties.put("DME2preferredRouterFilePath",
- MRSimplerBatchPublisherTest.class.getClassLoader().getResource(routeFilePath).getFile());
- if (contentType != null) {
- properties.put("contenttype", contentType);
- }
- outFile = new File(file.getParent() + "/producer_tmp.properties");
- properties.store(new FileOutputStream(outFile), "");
- }
+ // publish some messages
+ final JSONObject msg1 = new JSONObject();
+ pub.send("MyPartitionKey", msg1.toString());
- @Test
- public void testSend() throws Exception {
+ final List<Message> stuck = pub.close(1, TimeUnit.SECONDS);
+ Assert.assertEquals(1, stuck.size());
- setUp(null);
+ }
- final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
- .createBatchingPublisher(outFile.getPath());
+ @Test
+ public void testSendBatchWithResponseProtKey() throws Exception {
- // publish some messages
- final JSONObject msg1 = new JSONObject();
- pub.send("MyPartitionKey", msg1.toString());
+ setUp(null);
- final List<message> stuck = pub.close(1, TimeUnit.SECONDS);
- Assert.assertEquals(1, stuck.size());
+ final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
+ .createBatchingPublisher(outFile.getPath());
+ pub.setProtocolFlag(ProtocolType.AUTH_KEY.getValue());
+ // publish some messages
+ final JSONObject msg1 = new JSONObject();
+ pub.send("MyPartitionKey", msg1.toString());
- }
+ final List<Message> stuck = pub.close(1, TimeUnit.SECONDS);
+ Assert.assertEquals(1, stuck.size());
- @Test
- public void testSendBatchWithResponse() throws Exception {
+ }
- setUp(null);
+ @Test
+ public void testSendBatchWithResponseProtAaf() throws Exception {
- final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
- .createBatchingPublisher(outFile.getPath(), true);
+ setUp(null);
- // publish some messages
- final JSONObject msg1 = new JSONObject();
- pub.send("MyPartitionKey", msg1.toString());
- MRPublisherResponse pubResponse = new MRPublisherResponse();
- pub.setPubResponse(pubResponse);
+ final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
+ .createBatchingPublisher(outFile.getPath());
+ pub.setProtocolFlag(ProtocolType.AAF_AUTH.getValue());
+ // publish some messages
+ final JSONObject msg1 = new JSONObject();
+ pub.send("MyPartitionKey", msg1.toString());
- MRPublisherResponse mrPublisherResponse = pub.sendBatchWithResponse();
- Assert.assertEquals(1, mrPublisherResponse.getPendingMsgs());
+ final List<Message> stuck = pub.close(1, TimeUnit.SECONDS);
+ Assert.assertEquals(1, stuck.size());
- }
+ }
- @Test
- public void testSendBatchWithResponseConText() throws Exception {
+ @Test
+ public void testSendBatchWithResponseProtNoAuth() throws Exception {
- setUp("text/plain");
+ setUp(null);
- final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
- .createBatchingPublisher(outFile.getPath());
+ final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
+ .createBatchingPublisher(outFile.getPath());
+ pub.setProtocolFlag(ProtocolType.HTTPNOAUTH.getValue());
+ // publish some messages
+ final JSONObject msg1 = new JSONObject();
+ pub.send("MyPartitionKey", msg1.toString());
- // publish some messages
- final JSONObject msg1 = new JSONObject();
- pub.send("MyPartitionKey", msg1.toString());
+ final List<Message> stuck = pub.close(1, TimeUnit.SECONDS);
+ Assert.assertEquals(1, stuck.size());
- final List<message> stuck = pub.close(1, TimeUnit.SECONDS);
- Assert.assertEquals(1, stuck.size());
+ }
- }
+ @Test
+ public void testSendBatchWithResponsecontypeText() throws Exception {
- @Test
- public void testSendBatchWithResponseContCambria() throws Exception {
+ setUp("text/plain");
- setUp("application/cambria-zip");
+ final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
+ .createBatchingPublisher(outFile.getPath(), true);
- final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
- .createBatchingPublisher(outFile.getPath());
+ // publish some messages
+ final JSONObject msg1 = new JSONObject();
+ pub.send("MyPartitionKey", "payload");
+ MRPublisherResponse pubResponse = new MRPublisherResponse();
+ pub.setPubResponse(pubResponse);
- // publish some messages
- final JSONObject msg1 = new JSONObject();
- pub.send("MyPartitionKey", msg1.toString());
+ MRPublisherResponse mrPublisherResponse = pub.sendBatchWithResponse();
+ Assert.assertEquals(1, mrPublisherResponse.getPendingMsgs());
- final List<message> stuck = pub.close(1, TimeUnit.SECONDS);
- Assert.assertEquals(1, stuck.size());
+ }
- }
+ @Test
+ public void testSendBatchWithResponsecontypeCambria() throws Exception {
- @Test
- public void testSendBatchWithResponseProtKey() throws Exception {
+ setUp("application/cambria-zip");
- setUp(null);
+ final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
+ .createBatchingPublisher(outFile.getPath(), true);
- final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
- .createBatchingPublisher(outFile.getPath());
- pub.setProtocolFlag(ProtocolTypeConstants.AUTH_KEY.getValue());
- // publish some messages
- final JSONObject msg1 = new JSONObject();
- pub.send("MyPartitionKey", msg1.toString());
+ // publish some messages
+ final JSONObject msg1 = new JSONObject();
+ pub.send("MyPartitionKey", "payload");
+ MRPublisherResponse pubResponse = new MRPublisherResponse();
+ pub.setPubResponse(pubResponse);
- final List<message> stuck = pub.close(1, TimeUnit.SECONDS);
- Assert.assertEquals(1, stuck.size());
+ MRPublisherResponse mrPublisherResponse = pub.sendBatchWithResponse();
+ Assert.assertEquals(1, mrPublisherResponse.getPendingMsgs());
- }
+ }
- @Test
- public void testSendBatchWithResponseProtAaf() throws Exception {
+ @Test
+ public void testSendBatchWithResponsePrAuthKey() throws Exception {
- setUp(null);
+ setUp(null);
- final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
- .createBatchingPublisher(outFile.getPath());
- pub.setProtocolFlag(ProtocolTypeConstants.AAF_AUTH.getValue());
- // publish some messages
- final JSONObject msg1 = new JSONObject();
- pub.send("MyPartitionKey", msg1.toString());
+ final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
+ .createBatchingPublisher(outFile.getPath(), true);
+ pub.setProtocolFlag(ProtocolType.AUTH_KEY.getValue());
- final List<message> stuck = pub.close(1, TimeUnit.SECONDS);
- Assert.assertEquals(1, stuck.size());
+ // 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());
- @Test
- public void testSendBatchWithResponseProtNoAuth() throws Exception {
+ }
- setUp(null);
+ @Test
+ public void testSendBatchWithResponsePrAaf() throws Exception {
- final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
- .createBatchingPublisher(outFile.getPath());
- pub.setProtocolFlag(ProtocolTypeConstants.HTTPNOAUTH.getValue());
- // publish some messages
- final JSONObject msg1 = new JSONObject();
- pub.send("MyPartitionKey", msg1.toString());
+ setUp(null);
- final List<message> stuck = pub.close(1, TimeUnit.SECONDS);
- Assert.assertEquals(1, stuck.size());
+ final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
+ .createBatchingPublisher(outFile.getPath(), true);
+ pub.setProtocolFlag(ProtocolType.AAF_AUTH.getValue());
- }
+ // publish some messages
+ final JSONObject msg1 = new JSONObject();
+ pub.send("MyPartitionKey", msg1.toString());
+ MRPublisherResponse pubResponse = new MRPublisherResponse();
+ pub.setPubResponse(pubResponse);
- @Test
- public void testSendBatchWithResponsecontypeText() throws Exception {
+ MRPublisherResponse mrPublisherResponse = pub.sendBatchWithResponse();
+ Assert.assertEquals(1, mrPublisherResponse.getPendingMsgs());
- setUp("text/plain");
+ }
- final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
- .createBatchingPublisher(outFile.getPath(), true);
+ @Test
+ public void testSendBatchWithResponsePrNoauth() throws Exception {
- // publish some messages
- final JSONObject msg1 = new JSONObject();
- pub.send("MyPartitionKey", "payload");
- MRPublisherResponse pubResponse = new MRPublisherResponse();
- pub.setPubResponse(pubResponse);
+ setUp(null);
- MRPublisherResponse mrPublisherResponse = pub.sendBatchWithResponse();
- Assert.assertEquals(1, mrPublisherResponse.getPendingMsgs());
+ final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
+ .createBatchingPublisher(outFile.getPath(), true);
+ pub.setProtocolFlag(ProtocolType.HTTPNOAUTH.getValue());
- }
+ // publish some messages
+ final JSONObject msg1 = new JSONObject();
+ pub.send("MyPartitionKey", msg1.toString());
+ MRPublisherResponse pubResponse = new MRPublisherResponse();
+ pub.setPubResponse(pubResponse);
- @Test
- public void testSendBatchWithResponsecontypeCambria() throws Exception {
+ MRPublisherResponse mrPublisherResponse = pub.sendBatchWithResponse();
+ Assert.assertEquals(1, mrPublisherResponse.getPendingMsgs());
- setUp("application/cambria-zip");
+ }
- final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
- .createBatchingPublisher(outFile.getPath(), true);
+ @Test
+ public void createPublisherResponse() throws Exception {
+ setUp(null);
+ MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
+ .createBatchingPublisher(outFile.getPath(), true);
- // publish some messages
- final JSONObject msg1 = new JSONObject();
- pub.send("MyPartitionKey", "payload");
- MRPublisherResponse pubResponse = new MRPublisherResponse();
- pub.setPubResponse(pubResponse);
+ MRPublisherResponse response = pub.createMRPublisherResponse("{\"message\": \"published the message\", \"status\": \"200\"}", new MRPublisherResponse());
+ assertEquals("200", response.getResponseCode());
- MRPublisherResponse mrPublisherResponse = pub.sendBatchWithResponse();
- Assert.assertEquals(1, mrPublisherResponse.getPendingMsgs());
+ }
- }
+ @Test
+ public void createPublisherResponseSucc() throws Exception {
+ setUp(null);
+ MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
+ .createBatchingPublisher(outFile.getPath(), true);
- @Test
- public void testSendBatchWithResponsePrAuthKey() throws Exception {
+ MRPublisherResponse response = pub.createMRPublisherResponse("{\"fakemessage\": \"published the message\", \"fakestatus\": \"200\"}", new MRPublisherResponse());
+ assertEquals("200", response.getResponseCode());
- setUp(null);
+ }
- final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
- .createBatchingPublisher(outFile.getPath(), true);
- pub.setProtocolFlag(ProtocolTypeConstants.AUTH_KEY.getValue());
+ @Test
+ public void createPublisherResponseError() throws Exception {
+ setUp(null);
+ 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());
-
- }
-
- @Test
- public void testSendBatchWithResponsePrAaf() throws Exception {
+ MRPublisherResponse response = pub.createMRPublisherResponse("", new MRPublisherResponse());
+ assertEquals("400", response.getResponseCode());
- setUp(null);
-
- final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
- .createBatchingPublisher(outFile.getPath(), true);
- pub.setProtocolFlag(ProtocolTypeConstants.AAF_AUTH.getValue());
-
- // 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());
-
- }
-
- @Test
- public void testSendBatchWithResponsePrNoauth() throws Exception {
-
- setUp(null);
-
- final MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
- .createBatchingPublisher(outFile.getPath(), true);
- pub.setProtocolFlag(ProtocolTypeConstants.HTTPNOAUTH.getValue());
-
- // 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());
-
- }
-
- @Test
- public void createPublisherResponse() throws Exception{
- setUp(null);
- MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
- .createBatchingPublisher(outFile.getPath(), true);
-
- MRPublisherResponse response=pub.createMRPublisherResponse("{\"message\": \"published the message\", \"status\": \"200\"}", new MRPublisherResponse());
- assertEquals("200", response.getResponseCode());
-
- }
-
- @Test
- public void createPublisherResponseSucc() throws Exception{
- setUp(null);
- MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
- .createBatchingPublisher(outFile.getPath(), true);
-
- MRPublisherResponse response=pub.createMRPublisherResponse("{\"fakemessage\": \"published the message\", \"fakestatus\": \"200\"}", new MRPublisherResponse());
- assertEquals("200", response.getResponseCode());
-
- }
-
- @Test
- public void createPublisherResponseError() throws Exception{
- setUp(null);
- MRSimplerBatchPublisher pub = (MRSimplerBatchPublisher) MRClientFactory
- .createBatchingPublisher(outFile.getPath(), true);
-
- MRPublisherResponse response=pub.createMRPublisherResponse("", new MRPublisherResponse());
- assertEquals("400", response.getResponseCode());
-
- }
+ }
}