summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/dcae/common
diff options
context:
space:
mode:
authors00370346 <swarup.nayak1@huawei.com>2019-07-12 11:35:54 +0530
committers00370346 <swarup.nayak1@huawei.com>2019-07-12 14:50:21 +0530
commitc818065d90aad39e61992ee44fa13568b80ee7b3 (patch)
tree02126cd73fbdd7c825b7a120a54699fb340ba3ac /src/test/java/org/onap/dcae/common
parent20d8093fd688f0385b7bb9b8e4b09ff60ef23f26 (diff)
Issue-ID: DCAEGEN2-1661 Fix Some Compilation warnings, sonar issue
Signed-off-by: s00370346 <swarup.nayak1@huawei.com> Change-Id: Id01028b87c101ff2544d93c68a59f9cc46020d8d
Diffstat (limited to 'src/test/java/org/onap/dcae/common')
-rw-r--r--src/test/java/org/onap/dcae/common/AdditionalHeaderWebTargetTest.java60
-rw-r--r--src/test/java/org/onap/dcae/common/AuthTypeTest.java6
-rw-r--r--src/test/java/org/onap/dcae/common/DataChangeEventListnerTest.java18
-rw-r--r--src/test/java/org/onap/dcae/common/EventConnectionStateTest.java7
-rw-r--r--src/test/java/org/onap/dcae/common/EventProcessorTest.java157
-rw-r--r--src/test/java/org/onap/dcae/common/FormatTest.java5
-rw-r--r--src/test/java/org/onap/dcae/common/RestApiCallNodeTest.java197
-rw-r--r--src/test/java/org/onap/dcae/common/RestConfContextTest.java10
-rw-r--r--src/test/java/org/onap/dcae/common/XmlJsonUtilTest.java59
-rw-r--r--src/test/java/org/onap/dcae/common/XmlParserTest.java15
-rw-r--r--src/test/java/org/onap/dcae/common/publishing/DMaaPEventPublisherTest.java14
-rw-r--r--src/test/java/org/onap/dcae/common/publishing/DMaaPPublishersCacheTest.java61
-rw-r--r--src/test/java/org/onap/dcae/common/publishing/JsonParserTest.java28
13 files changed, 454 insertions, 183 deletions
diff --git a/src/test/java/org/onap/dcae/common/AdditionalHeaderWebTargetTest.java b/src/test/java/org/onap/dcae/common/AdditionalHeaderWebTargetTest.java
index 8f47899..3a927e1 100644
--- a/src/test/java/org/onap/dcae/common/AdditionalHeaderWebTargetTest.java
+++ b/src/test/java/org/onap/dcae/common/AdditionalHeaderWebTargetTest.java
@@ -20,31 +20,61 @@
package org.onap.dcae.common;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
-import javax.ws.rs.client.WebTarget;
-import static org.mockito.Mockito.*;
+
@RunWith(MockitoJUnitRunner.Silent.class)
public class AdditionalHeaderWebTargetTest {
-
@Test
- public void AdditionalHaderWebTargettestBase() {
+ public void additionalHaderWebTargettestBase() {
+ final Invocation.Builder mockBuilder = Mockito.mock(Invocation.Builder.class);
+
WebTarget target = mock(WebTarget.class);
- AdditionalHeaderWebTarget t = new AdditionalHeaderWebTarget(target, "aaa112", "someheader");
- t.getConfiguration();
- t.getUri();
- t.getUriBuilder();
- t.path("");
- t.register(AdditionalHeaderWebTarget.class);
- t.register(AdditionalHeaderWebTarget.class,0);
- t.register(AdditionalHeaderWebTarget.class, AdditionalHeaderWebTarget.class);
+ when(target.request()).thenReturn(mockBuilder);
+ when(target.request("application/json")).thenReturn(mockBuilder);
+ when(target.request(MediaType.APPLICATION_JSON)).thenReturn(mockBuilder);
+ JSONObject jsonObject = new JSONObject("{\"key\": 1}");
+ Map<String, Object> someMap = new HashMap<>();
+ someMap.put("id", jsonObject);
+ AdditionalHeaderWebTarget webTarget = new AdditionalHeaderWebTarget(target, "aaa112",
+ "someheader");
+ webTarget.getConfiguration();
+ webTarget.getUri();
+ webTarget.getUriBuilder();
+ webTarget.path("");
+ webTarget.register(AdditionalHeaderWebTarget.class);
+ webTarget.register(AdditionalHeaderWebTarget.class,0);
+ webTarget.register(AdditionalHeaderWebTarget.class, AdditionalHeaderWebTarget.class);
Object obj = new Object();
- t.register(obj);
- t.register(obj, 0);
- t.register(obj, AdditionalHeaderWebTarget.class);
+ webTarget.register(obj);
+ webTarget.register(obj, 0);
+ webTarget.register(obj, AdditionalHeaderWebTarget.class);
+ webTarget.request();
+ webTarget.request("application/json");
+ webTarget.request(MediaType.APPLICATION_JSON_TYPE);
+ webTarget.resolveTemplate("key", jsonObject);
+ webTarget.resolveTemplate("key", jsonObject, false);
+ webTarget.resolveTemplateFromEncoded("key", jsonObject);
+ webTarget.resolveTemplates(someMap);
+ webTarget.resolveTemplates(someMap, false);
+ webTarget.resolveTemplatesFromEncoded(someMap);
+
+ webTarget.matrixParam("key", jsonObject);
+ webTarget.queryParam("key", jsonObject);
+ webTarget.property("key", jsonObject);
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/common/AuthTypeTest.java b/src/test/java/org/onap/dcae/common/AuthTypeTest.java
index a8a8729..604730f 100644
--- a/src/test/java/org/onap/dcae/common/AuthTypeTest.java
+++ b/src/test/java/org/onap/dcae/common/AuthTypeTest.java
@@ -17,12 +17,12 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common;
-import org.junit.Test;
-import org.onap.dcae.common.AuthType;
+import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.*;
+import org.junit.Test;
public class AuthTypeTest {
diff --git a/src/test/java/org/onap/dcae/common/DataChangeEventListnerTest.java b/src/test/java/org/onap/dcae/common/DataChangeEventListnerTest.java
index 95c8012..3d48bf2 100644
--- a/src/test/java/org/onap/dcae/common/DataChangeEventListnerTest.java
+++ b/src/test/java/org/onap/dcae/common/DataChangeEventListnerTest.java
@@ -17,28 +17,21 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common;
+import static org.mockito.Mockito.when;
-import org.glassfish.jersey.media.sse.EventInput;
+import java.util.concurrent.LinkedBlockingQueue;
import org.glassfish.jersey.media.sse.InboundEvent;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import static org.mockito.Mockito.*;
-
import org.onap.dcae.RestConfCollector;
-import org.onap.dcae.common.publishing.DMaaPConfigurationParser;
-import org.onap.dcae.common.publishing.EventPublisher;
-import org.slf4j.LoggerFactory;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.concurrent.LinkedBlockingQueue;
@RunWith(MockitoJUnitRunner.class)
public class DataChangeEventListnerTest {
@@ -59,9 +52,12 @@ public class DataChangeEventListnerTest {
DataChangeEventListener listner = new DataChangeEventListener(null);
listner.onEvent(event);
}
+
@Test
public void testDataChangeEventListenerJsonArray() {
- when(event.readData()).thenReturn("[{ \"name\":\"Ford\", \"models\":[ \"Fiesta\",\"Focus\", \"Mustang\" ] },{\"name\":\"BMW\", \"models\":[ \"320\", \"X3\",\"X5\" ] },{\"name\":\"Fiat\",\"models\":[ \"500\", \"Panda\" ]}]");
+ when(event.readData()).thenReturn("[{ \"name\":\"Ford\", \"models\":[ \"Fiesta\",\"Focus\", \"Mustang\" ] },"
+ + "{\"name\":\"BMW\", \"models\":[ \"320\", \"X3\",\"X5\" ] },{\"name\":\"Fiat\",\"models\":"
+ + "[ \"500\", \"Panda\" ]}]");
RestConfCollector.fProcessingInputQueue = new LinkedBlockingQueue<>(4);
DataChangeEventListener listner = new DataChangeEventListener(null);
listner.onEvent(event);
diff --git a/src/test/java/org/onap/dcae/common/EventConnectionStateTest.java b/src/test/java/org/onap/dcae/common/EventConnectionStateTest.java
index c6327bc..8970e73 100644
--- a/src/test/java/org/onap/dcae/common/EventConnectionStateTest.java
+++ b/src/test/java/org/onap/dcae/common/EventConnectionStateTest.java
@@ -17,11 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common;
+import static org.junit.Assert.assertEquals;
+
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
+
public class EventConnectionStateTest {
@@ -30,7 +33,7 @@ public class EventConnectionStateTest {
assertEquals(EventConnectionState.INIT, EventConnectionState.fromString("init"));
assertEquals(EventConnectionState.SUBSCRIBED, EventConnectionState.fromString("subscribed"));
assertEquals(EventConnectionState.UNSUBSCRIBED, EventConnectionState.fromString("unsubscribed"));
- assertEquals(EventConnectionState.Unspecified, EventConnectionState.fromString("unspecified"));
+ assertEquals(EventConnectionState.UNSPECIFIED, EventConnectionState.fromString("unspecified"));
}
@Test(expected = IllegalArgumentException.class)
diff --git a/src/test/java/org/onap/dcae/common/EventProcessorTest.java b/src/test/java/org/onap/dcae/common/EventProcessorTest.java
index 04a2952..e86af85 100644
--- a/src/test/java/org/onap/dcae/common/EventProcessorTest.java
+++ b/src/test/java/org/onap/dcae/common/EventProcessorTest.java
@@ -17,14 +17,18 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.LinkedBlockingQueue;
import org.json.JSONObject;
import org.junit.Before;
-
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -38,25 +42,9 @@ import org.onap.dcae.controller.AccessController;
import org.onap.dcae.controller.PersistentEventConnection;
import org.slf4j.LoggerFactory;
-
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.concurrent.LinkedBlockingQueue;
-
-
-
-import static io.vavr.API.Map;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.when;
-import static org.onap.dcae.common.publishing.DMaaPConfigurationParser.parseToDomainMapping;
-
@RunWith(MockitoJUnitRunner.Silent.class)
public class EventProcessorTest {
-
-
@Mock
private ApplicationSettings properties;
@@ -72,10 +60,13 @@ public class EventProcessorTest {
protected static final Path RCC_KEYSTORE_PASSWORD_FILE = Paths.get(RESOURCES.toString(), "rcc_passwordfile");
protected static final Path RCC_KEYSTORE = Paths.get(RESOURCES.toString(), "sdnc.p12");
+ /**
+ * set up before testcase.
+ */
@Before
public void setUp() {
- eventPublisher = EventPublisher.createPublisher(LoggerFactory.getLogger("some_log"), DMaaPConfigurationParser.
- parseToDomainMapping(path).get());
+ eventPublisher = EventPublisher.createPublisher(LoggerFactory.getLogger("some_log"),
+ DMaaPConfigurationParser.parseToDomainMapping(path).get());
streamMap = RestConfCollector.parseStreamIdToStreamHashMapping("notification=device-registration");
}
@@ -83,59 +74,77 @@ public class EventProcessorTest {
@Test
public void testEventProcessorRunException() {
try {
- when(properties.truststoreFileLocation()).thenReturn(TRUSTSTORE.toString());
-
- when(properties.truststorePasswordFileLocation()).thenReturn(TRUSTSTORE_PASSWORD_FILE.toString());
- when(properties.keystoreFileLocation()).thenReturn(KEYSTORE.toString());
- when(properties.keystorePasswordFileLocation()).thenReturn(KEYSTORE_PASSWORD_FILE.toString());
- when(properties.rccKeystoreFileLocation()).thenReturn(RCC_KEYSTORE.toString());
- when(properties.rccKeystorePasswordFileLocation()).thenReturn(RCC_KEYSTORE_PASSWORD_FILE.toString());
- when(properties.controllerConfigFileLocation()).thenReturn(Paths.get("etc/ont_config.json").toAbsolutePath().toString());
-
- RestapiCallNode restApiCallNode = Mockito.mock(RestapiCallNode.class);
- Mockito.doNothing().when(restApiCallNode).sendRequest(any(), any(), any());
-
-
- JSONObject controller = new JSONObject(
- "{\"controller_name\":\"AccessM&C\",\"controller_restapiUrl\":\"10.118.191.43:26335\",\"controller_restapiUser\":\"access\",\"controller_restapiPassword\":\"Huawei@123\",\"controller_accessTokenUrl\":\"/rest/plat/smapp/v1/oauth/token\",\"controller_accessTokenFile\":\"./etc/access-token.json\",\"controller_accessTokenMethod\":\"put\",\"controller_subsMethod\":\"post\",\"controller_subscriptionUrl\":\"/restconf/v1/operations/huawei-nce-notification-action:establish-subscription\",\"controller_disableSsl\":\"true\",\"event_details\":[{\"event_name\":\"ONT_registration\",\"event_description\":\"ONTregistartionevent\",\"event_sseventUrlEmbed\":\"true\",\"event_sseventsField\":\"output.url\",\"event_sseventsUrl\":\"null\",\"event_subscriptionTemplate\":\"./etc/ont_registartion_subscription_template.json\",\"event_unSubscriptionTemplate\":\"./etc/ont_registartion_unsubscription_template.json\",\"event_ruleId\":\"777777777\"}]}");
- AccessController acClr = new AccessController(controller, properties);
-
- PersistentEventConnection p = new PersistentEventConnection.PersistentEventConnectionBuilder().setEventName("")
- .setEventDescription("").setEventSseventUrlEmbed(true).setEventSseventsField("").setEventSseventsUrl("")
- .setEventSubscriptionTemplate("").setEventUnSubscriptionTemplate("").setEventRuleId("1234646346")
- .setParentCtrllr(acClr).setModifyEvent(true).setModifyMethod("modifyOntEvent")
- .setUserData("remote_id=AC9.0234.0337;svlan=1001;macAddress=00:11:22:33:44:55;")
- .createPersistentEventConnection();
- p.getEventParamMapValue("restapiUrl");
- p.modifyEventParamMap("restapiUrl", "10.118.191.43:26335");
- RestConfCollector.fProcessingInputQueue = new LinkedBlockingQueue<>(4);
- p.getParentCtrllr().setRestApiCallNode(restApiCallNode);
- RestConfCollector.fProcessingInputQueue.offer(new EventData(p, new JSONObject("{\n" +
- " \"notification\" : {\n" +
- " \"notification-id\" : \"01010101011\",\n" +
- " \"event-time\" : \"2019-3-9T3:30:30.547z\",\n" +
- " \"message\" : {\n" +
- " \"object-type\" : \"onu\",\n" +
- " \"topic\" : \"resources\",\n" +
- " \"version\" : \"v1\",\n" +
- " \"operation\" : \"create\",\n" +
- " \"content\" : {\n" +
- " \"onu\" : {\n" +
- " \"alias\" : \"\",\n" +
- " \"refParentLTP\" : \"gpon.0.5.1\",\n" +
- " \"sn\" : \"HWTCC01B7503\",\n" +
- " \"refParentLTPNativeId\" : \"NE=167772165,FR=0,S=5,CP=-1,PP=||1|\",\n" +
- " \"onuId\": \"\",\n" +
- " \"refParentNE\" : \"aaaaaaaaa-aaaaa-aaaa-aaaa-aaa167772165\",\n" +
- " \"refParentNeNativeId\": \"NE=167772165\"\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- " }\n" +
- "}")));
- RestConfCollector.fProcessingInputQueue.offer(new EventData(null, null));
- EventProcessor ev = new EventProcessor(eventPublisher, streamMap);
- ev.run();
- } catch (Exception e){}
+ when(properties.truststoreFileLocation()).thenReturn(TRUSTSTORE.toString());
+ when(properties.truststorePasswordFileLocation()).thenReturn(TRUSTSTORE_PASSWORD_FILE.toString());
+ when(properties.keystoreFileLocation()).thenReturn(KEYSTORE.toString());
+ when(properties.keystorePasswordFileLocation()).thenReturn(KEYSTORE_PASSWORD_FILE.toString());
+ when(properties.rccKeystoreFileLocation()).thenReturn(RCC_KEYSTORE.toString());
+ when(properties.rccKeystorePasswordFileLocation()).thenReturn(RCC_KEYSTORE_PASSWORD_FILE.toString());
+ when(properties.controllerConfigFileLocation())
+ .thenReturn(Paths.get("etc/ont_config.json").toAbsolutePath().toString());
+
+ RestapiCallNode restApiCallNode = Mockito.mock(RestapiCallNode.class);
+ Mockito.doNothing().when(restApiCallNode).sendRequest(any(), any(), any());
+
+
+ JSONObject controller = new JSONObject(
+ "{\"controller_name\":\"AccessM&C\",\"controller_restapiUrl\":\"10.118.191.43:26335\","
+ + "\"controller_restapiUser\":\"access\",\"controller_restapiPassword\":\"Huawei@123\","
+ + "\"controller_accessTokenUrl\":\"/rest/plat/smapp/v1/oauth/token\","
+ + "\"controller_accessTokenFile\":\"./etc/access-token.json\","
+ + "\"controller_accessTokenMethod\":\"put\",\"controller_subsMethod\":\"post\","
+ + "\"controller_subscriptionUrl\":"
+ + "\"/restconf/v1/operations/huawei-nce-notification-action:establish-subscription\","
+ + "\"controller_disableSsl\":\"true\",\"event_details\":[{\"event_name\":"
+ + "\"ONT_registration\",\"event_description\":\"ONTregistartionevent\","
+ + "\"event_sseventUrlEmbed\":\"true\",\"event_sseventsField\":\"output.url\","
+ + "\"event_sseventsUrl\":\"null\","
+ + "\"event_subscriptionTemplate\":\"./etc/ont_registartion_subscription_template.json\","
+ + "\"event_unSubscriptionTemplate\":"
+ + "\"./etc/ont_registartion_unsubscription_template.json\","
+ + "\"event_ruleId\":\"777777777\"}]}");
+ AccessController acClr = new AccessController(controller, properties);
+
+ PersistentEventConnection eventConnection = new PersistentEventConnection.PersistentEventConnectionBuilder()
+ .setEventName("")
+ .setEventDescription("").setEventSseventUrlEmbed(true).setEventSseventsField("")
+ .setEventSseventsUrl("")
+ .setEventSubscriptionTemplate("").setEventUnSubscriptionTemplate("").setEventRuleId("1234646346")
+ .setParentCtrllr(acClr).setModifyEvent(true).setModifyMethod("modifyOntEvent")
+ .setUserData("remote_id=AC9.0234.0337;svlan=1001;macAddress=00:11:22:33:44:55;")
+ .createPersistentEventConnection();
+ eventConnection.getEventParamMapValue("restapiUrl");
+ eventConnection.modifyEventParamMap("restapiUrl", "10.118.191.43:26335");
+ RestConfCollector.fProcessingInputQueue = new LinkedBlockingQueue<>(4);
+ eventConnection.getParentCtrllr().setRestApiCallNode(restApiCallNode);
+ RestConfCollector.fProcessingInputQueue.offer(new EventData(eventConnection, new JSONObject("{\n"
+ + " \"notification\" : {\n"
+ + " \"notification-id\" : \"01010101011\",\n"
+ + " \"event-time\" : \"2019-3-9T3:30:30.547z\",\n"
+ + " \"message\" : {\n"
+ + " \"object-type\" : \"onu\",\n"
+ + " \"topic\" : \"resources\",\n"
+ + " \"version\" : \"v1\",\n"
+ + " \"operation\" : \"create\",\n"
+ + " \"content\" : {\n"
+ + " \"onu\" : {\n"
+ + " \"alias\" : \"\",\n"
+ + " \"refParentLTP\" : \"gpon.0.5.1\",\n"
+ + " \"sn\" : \"HWTCC01B7503\",\n"
+ + " \"refParentLTPNativeId\" : \"NE=167772165,FR=0,S=5,CP=-1,PP=||1|\",\n"
+ + " \"onuId\": \"\",\n"
+ + " \"refParentNE\" : \"aaaaaaaaa-aaaaa-aaaa-aaaa-aaa167772165\",\n"
+ + " \"refParentNeNativeId\": \"NE=167772165\"\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + "}")));
+ RestConfCollector.fProcessingInputQueue.offer(new EventData(null, null));
+ EventProcessor ev = new EventProcessor(eventPublisher, streamMap);
+ ev.run();
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/common/FormatTest.java b/src/test/java/org/onap/dcae/common/FormatTest.java
index e54dd9b..61e9e85 100644
--- a/src/test/java/org/onap/dcae/common/FormatTest.java
+++ b/src/test/java/org/onap/dcae/common/FormatTest.java
@@ -17,13 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common;
-import org.junit.Test;
-import org.onap.dcae.common.Format;
import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
public class FormatTest {
@Test
diff --git a/src/test/java/org/onap/dcae/common/RestApiCallNodeTest.java b/src/test/java/org/onap/dcae/common/RestApiCallNodeTest.java
index 3534a6c..3b533e9 100644
--- a/src/test/java/org/onap/dcae/common/RestApiCallNodeTest.java
+++ b/src/test/java/org/onap/dcae/common/RestApiCallNodeTest.java
@@ -20,20 +20,26 @@
package org.onap.dcae.common;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
import com.sun.jersey.api.client.WebResource;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+import javax.ws.rs.core.MultivaluedHashMap;
import org.glassfish.jersey.client.ClientResponse;
import org.junit.Test;
import org.mockito.Mockito;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.*;
public class RestApiCallNodeTest {
@Test
- public void RestApiCallNodeTestSendEmptyMessageNoTemplate() {
+ public void restApiCallNodeTestSendEmptyMessageNoTemplate() {
RestapiCallNode rest = new RestapiCallNode();
RestConfContext ctx = new RestConfContext();
Map<String, String> paraMap = new HashMap<>();
@@ -65,8 +71,8 @@ public class RestApiCallNodeTest {
String trustPassword = "admin";
paraMap.put(Constants.KSETTING_TRUST_STORE_PASSWORD, trustPassword);
paraMap.put(Constants.KSETTING_KEY_STORE_FILENAME, null);
- String KeyPassword = "admin";
- paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, KeyPassword);
+ String keyPassword = "admin";
+ paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, keyPassword);
WebResource webResource = mock(WebResource.class);
@@ -77,11 +83,13 @@ public class RestApiCallNodeTest {
when(webResource.accept(anyString())).thenReturn(webResourceBuilder);
rest.sendRequest(paraMap, ctx, 1);
- }catch (Exception e){}
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
@Test
- public void RestApiCallNodeTestSendEmptyMessageWithTemplate() {
+ public void restApiCallNodeTestSendEmptyMessageWithTemplate() {
RestapiCallNode rest = new RestapiCallNode();
RestConfContext ctx = new RestConfContext();
Map<String, String> paraMap = new HashMap<>();
@@ -97,7 +105,7 @@ public class RestApiCallNodeTest {
paraMap.put(Constants.KSETTING_REST_PASSWD, null);
paraMap.put(Constants.KDEFAULT_REQUESTBODY, null);
- paraMap.put(Constants.KSETTING_AUTH_TYPE, "unspecified");
+ paraMap.put(Constants.KSETTING_AUTH_TYPE, "digest");
paraMap.put(Constants.KSETTING_CONTENT_TYPE, "application/json");
paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_KEY, null);
paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_SECRET, null);
@@ -113,9 +121,60 @@ public class RestApiCallNodeTest {
String trustPassword = "admin";
paraMap.put(Constants.KSETTING_TRUST_STORE_PASSWORD, trustPassword);
paraMap.put(Constants.KSETTING_KEY_STORE_FILENAME, null);
- String KeyPassword = "admin";
- paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, KeyPassword);
+ String keyPassword = "admin";
+ paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, keyPassword);
+
+
+ WebResource webResource = mock(WebResource.class);
+ WebResource.Builder webResourceBuilder = mock(WebResource.Builder.class);
+ ClientResponse clientResponse = mock(ClientResponse.class);
+ try {
+ Mockito.doNothing().when(webResourceBuilder).method("post");
+ when(webResource.accept(anyString())).thenReturn(webResourceBuilder);
+
+ rest.sendRequest(paraMap, ctx, 1);
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
+ }
+
+ @Test
+ public void restApiCallNodeTestSkipSending() {
+ RestapiCallNode rest = new RestapiCallNode();
+ RestConfContext ctx = new RestConfContext();
+ Map<String, String> paraMap = new HashMap<>();
+ paraMap.put(Constants.KDEFAULT_TEMP_FILENAME, null);
+ paraMap.put(Constants.KSETTING_REST_API_URL, "https://127.0.0.1:8080/rest/sample");
+ paraMap.put(Constants.KSETTING_HTTP_METHOD, "post");
+ paraMap.put(Constants.KSETTING_RESP_PREFIX, "responsePrefix");
+ paraMap.put(Constants.KSETTING_SKIP_SENDING, "false");
+ paraMap.put(Constants.KSETTING_SSE_CONNECT_URL, null);
+ paraMap.put(Constants.KSETTING_FORMAT, "json");
+
+ paraMap.put(Constants.KSETTING_REST_UNAME, null);
+ paraMap.put(Constants.KSETTING_REST_PASSWD, null);
+ paraMap.put(Constants.KDEFAULT_REQUESTBODY, null);
+ paraMap.put(Constants.KSETTING_AUTH_TYPE, "unspecified");
+ paraMap.put(Constants.KSETTING_CONTENT_TYPE, "application/json");
+ paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_KEY, null);
+ paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_SECRET, null);
+ paraMap.put(Constants.KSETTING_OAUTH_SIGNATURE_METHOD, null);
+ paraMap.put(Constants.KSETTING_OAUTH_VERSION, null);
+
+ paraMap.put(Constants.KSETTING_CUSTOMHTTP_HEADER, null);
+ paraMap.put(Constants.KSETTING_TOKENID, null);
+ paraMap.put(Constants.KSETTING_DUMP_HEADER, "false");
+ paraMap.put(Constants.KSETTING_RETURN_REQUEST_PAYLOAD, "false");
+
+ paraMap.put(Constants.KSETTING_TRUST_STORE_FILENAME, null);
+ String trustPassword = "admin";
+ paraMap.put(Constants.KSETTING_TRUST_STORE_PASSWORD, trustPassword);
+ paraMap.put(Constants.KSETTING_KEY_STORE_FILENAME, null);
+ String keyPassword = "admin";
+ paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, keyPassword);
+ paraMap.put(Constants.KDEFAULT_DISABLE_SSL, "false");
+ paraMap.put(Constants.KSETTING_SKIP_SENDING, "true");
WebResource webResource = mock(WebResource.class);
WebResource.Builder webResourceBuilder = mock(WebResource.Builder.class);
@@ -123,9 +182,119 @@ public class RestApiCallNodeTest {
try {
Mockito.doNothing().when(webResourceBuilder).method("post");
when(webResource.accept(anyString())).thenReturn(webResourceBuilder);
+ rest.sendRequest(paraMap, ctx, 1);
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
+ }
+
+ @Test
+ public void restApiCallNodeTestHttpResponse() {
+ RestapiCallNode rest = spy(RestapiCallNode.class);
+ RestConfContext ctx = new RestConfContext();
+ Map<String, String> paraMap = new HashMap<>();
+ paraMap.put(Constants.KDEFAULT_TEMP_FILENAME, null);
+ paraMap.put(Constants.KSETTING_REST_API_URL, "https://127.0.0.1:8080/rest/sample");
+ paraMap.put(Constants.KSETTING_HTTP_METHOD, "post");
+ paraMap.put(Constants.KSETTING_RESP_PREFIX, "responsePrefix");
+ paraMap.put(Constants.KSETTING_SKIP_SENDING, "false");
+ paraMap.put(Constants.KSETTING_SSE_CONNECT_URL, null);
+ paraMap.put(Constants.KSETTING_FORMAT, "json");
+
+ paraMap.put(Constants.KSETTING_REST_UNAME, null);
+ paraMap.put(Constants.KSETTING_REST_PASSWD, null);
+ paraMap.put(Constants.KDEFAULT_REQUESTBODY, null);
+ paraMap.put(Constants.KSETTING_AUTH_TYPE, "unspecified");
+ paraMap.put(Constants.KSETTING_CONTENT_TYPE, "application/json");
+ paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_KEY, null);
+ paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_SECRET, null);
+ paraMap.put(Constants.KSETTING_OAUTH_SIGNATURE_METHOD, null);
+ paraMap.put(Constants.KSETTING_OAUTH_VERSION, null);
+
+ paraMap.put(Constants.KSETTING_CUSTOMHTTP_HEADER, null);
+ paraMap.put(Constants.KSETTING_TOKENID, null);
+ paraMap.put(Constants.KSETTING_DUMP_HEADER, "false");
+ paraMap.put(Constants.KSETTING_RETURN_REQUEST_PAYLOAD, "false");
+
+ paraMap.put(Constants.KSETTING_TRUST_STORE_FILENAME, null);
+ String trustPassword = "admin";
+ paraMap.put(Constants.KSETTING_TRUST_STORE_PASSWORD, trustPassword);
+ paraMap.put(Constants.KSETTING_KEY_STORE_FILENAME, null);
+ String keyPassword = "admin";
+ paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, keyPassword);
+ paraMap.put(Constants.KDEFAULT_DISABLE_SSL, "false");
+ paraMap.put(Constants.KSETTING_SKIP_SENDING, "true");
+
+ WebResource webResource = mock(WebResource.class);
+ WebResource.Builder webResourceBuilder = mock(WebResource.Builder.class);
+ ClientResponse clientResponse = mock(ClientResponse.class);
+ HttpResponse response = new HttpResponse();
+ response.code = 200;
+ response.body = "{\"prop2\"=\"value\", \"prop1\"=\"value\"}";;
+ response.message = "Some message";
+ response.headers = new MultivaluedHashMap<>();
+ response.headers.add("connection", "close");
+ response.headers.add("content-encoding", "gzip");
+ try {
+ Mockito.doNothing().when(webResourceBuilder).method("post");
+ when(webResource.accept(anyString())).thenReturn(webResourceBuilder);
+ doReturn(response).when(rest).sendHttpRequest(any(), any());
rest.sendRequest(paraMap, ctx, 1);
- }catch (Exception e){}
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
+ @Test
+ public void restApiCallNodeTestWithSsl() {
+ RestapiCallNode rest = new RestapiCallNode();
+ RestConfContext ctx = new RestConfContext();
+ Map<String, String> paraMap = new HashMap<>();
+ paraMap.put(Constants.KDEFAULT_TEMP_FILENAME, null);
+ paraMap.put(Constants.KSETTING_REST_API_URL, "https://127.0.0.1:8080/rest/sample");
+ paraMap.put(Constants.KSETTING_HTTP_METHOD, "post");
+ paraMap.put(Constants.KSETTING_RESP_PREFIX, "responsePrefix");
+ paraMap.put(Constants.KSETTING_SKIP_SENDING, "false");
+ paraMap.put(Constants.KSETTING_SSE_CONNECT_URL, null);
+ paraMap.put(Constants.KSETTING_FORMAT, "json");
+
+ paraMap.put(Constants.KSETTING_REST_UNAME, null);
+ paraMap.put(Constants.KSETTING_REST_PASSWD, null);
+ paraMap.put(Constants.KDEFAULT_REQUESTBODY, null);
+
+ paraMap.put(Constants.KSETTING_AUTH_TYPE, "unspecified");
+ paraMap.put(Constants.KSETTING_CONTENT_TYPE, "application/json");
+ paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_KEY, null);
+ paraMap.put(Constants.KSETTING_OAUTH_CONSUMER_SECRET, null);
+ paraMap.put(Constants.KSETTING_OAUTH_SIGNATURE_METHOD, null);
+ paraMap.put(Constants.KSETTING_OAUTH_VERSION, null);
+
+ paraMap.put(Constants.KSETTING_CUSTOMHTTP_HEADER, null);
+ paraMap.put(Constants.KSETTING_TOKENID, null);
+ paraMap.put(Constants.KSETTING_DUMP_HEADER, "false");
+ paraMap.put(Constants.KSETTING_RETURN_REQUEST_PAYLOAD, "false");
+ paraMap.put(Constants.KSETTING_SKIP_SENDING, "true");
+
+ paraMap.put(Constants.KSETTING_TRUST_STORE_FILENAME, "src/test/resources/truststore");
+ String trustPassword = "vestest";
+ paraMap.put(Constants.KSETTING_TRUST_STORE_PASSWORD, trustPassword);
+ paraMap.put(Constants.KSETTING_KEY_STORE_FILENAME, "src/test/resources/keystore");
+ String keyPassword = "vestest";
+ paraMap.put(Constants.KSETTING_KEY_STORE_PASSWD, keyPassword);
+ paraMap.put(Constants.KDEFAULT_DISABLE_SSL, "false");
+
+ WebResource webResource = mock(WebResource.class);
+ WebResource.Builder webResourceBuilder = mock(WebResource.Builder.class);
+ ClientResponse clientResponse = mock(ClientResponse.class);
+
+ try {
+ Mockito.doNothing().when(webResourceBuilder).method("post");
+ when(webResource.accept(anyString())).thenReturn(webResourceBuilder);
+
+ rest.sendRequest(paraMap, ctx, 1);
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
+ }
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/common/RestConfContextTest.java b/src/test/java/org/onap/dcae/common/RestConfContextTest.java
index 00b07f8..c8bfe48 100644
--- a/src/test/java/org/onap/dcae/common/RestConfContextTest.java
+++ b/src/test/java/org/onap/dcae/common/RestConfContextTest.java
@@ -20,10 +20,13 @@
package org.onap.dcae.common;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import org.junit.Test;
-import org.onap.dcae.common.RestConfContext;
-import static org.junit.Assert.*;
+
public class RestConfContextTest {
@@ -47,6 +50,7 @@ public class RestConfContextTest {
RestConfContext restConfContext = new RestConfContext();
restConfContext.setAttribute(key,value);
restConfContext.setAttribute(key1,value1);
- assertTrue(restConfContext.getAttributeKeySet().contains(key) && restConfContext.getAttributeKeySet().contains(key1));
+ assertTrue(restConfContext.getAttributeKeySet().contains(key)
+ && restConfContext.getAttributeKeySet().contains(key1));
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/common/XmlJsonUtilTest.java b/src/test/java/org/onap/dcae/common/XmlJsonUtilTest.java
index f05541f..d34e508 100644
--- a/src/test/java/org/onap/dcae/common/XmlJsonUtilTest.java
+++ b/src/test/java/org/onap/dcae/common/XmlJsonUtilTest.java
@@ -20,15 +20,13 @@
package org.onap.dcae.common;
-import org.json.XML;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
+import org.junit.Test;
+
-import static org.junit.Assert.assertEquals;
public class XmlJsonUtilTest {
@@ -43,29 +41,33 @@ public class XmlJsonUtilTest {
mm.put("result.output", "xml2json");
mm.put("result.[", "start");
mm.put("result.]", "end");
- mm.put("result.list", "<LIST>\n" +
- " <LITERAL VALUE=\"\"/>\n" +
- " </LIST>");
+ mm.put("result.list", "<LIST>\n"
+ + " <LITERAL VALUE=\"\"/>\n"
+ + " </LIST>");
try {
String str = XmlJsonUtil.getXml(mm, var);
assertEquals(str.startsWith("<"), true);
String str2 = XmlJsonUtil.getJson(mm, var);
assertEquals(str2.startsWith("{"), true);
- }catch (Exception e) {}
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
@Test
public void removeEmptystructFromXml() {
- String var = "<time>2018 12:04</time>\n" +
- "<output>t2</output>\n" +
- "<start>bad\n" +
- "<status>200</status>";
+ String var = "<time>2018 12:04</time>\n"
+ + "<output>t2</output>\n"
+ + "<start>bad\n"
+ + "<status>200</status>";
Map<String, String> mm = new HashMap<>();
try {
String str = XmlJsonUtil.removeEmptyStructXml(var);
- }catch (Exception e) {}
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
@Test
@@ -75,14 +77,37 @@ public class XmlJsonUtilTest {
try {
String str = XmlJsonUtil.removeEmptyStructJson(var);
- }catch (Exception e) {}
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
@Test
public void removeLastCommaJson() {
- String var2 ="{\"name\":\"john\",\"age\":22,\"class\":\"mca\", \"data\":{}, \"arr\" : [\"some\" : {},],}";
+ String var2 = "{\"name\":\"john\",\"age\":22,\"class\":\"mca\", \"data\":{}, \"arr\" : [\"some\" : {},],}";
try {
String str = XmlJsonUtil.removeLastCommaJson(var2);
- }catch (Exception e) {}
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
+
+ @Test
+ public void getJsonOrXmlTest2() {
+ String var = "result";
+ Map<String, String> mm = new HashMap<>();
+
+ mm.put("result[0]", "{\"metaname\": \"remote-id\",\"metaval\": "
+ + "\"AC9.0234.0337\",\"resource-version\": \"1553802421110\"}");
+ mm.put("result[1]", "{\"metaname\": \"remote-id\",\"metaval\": "
+ + "\"AC9.0234.0337\",\"resource-version\": \"1553802421110\"}");
+
+ try {
+ String str2 = XmlJsonUtil.getJson(mm, var);
+ assertEquals(str2.startsWith("["), true);
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
+ }
+
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/common/XmlParserTest.java b/src/test/java/org/onap/dcae/common/XmlParserTest.java
index b005c89..5ca80c0 100644
--- a/src/test/java/org/onap/dcae/common/XmlParserTest.java
+++ b/src/test/java/org/onap/dcae/common/XmlParserTest.java
@@ -20,27 +20,26 @@
package org.onap.dcae.common;
-import org.junit.Test;
-
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-
-import static org.junit.Assert.*;
+import org.junit.Test;
public class XmlParserTest {
@Test
public void setAttribute() {
- String convert = "<time>2018 12:04</time>\n" +
- "<output>t2</output>\n" +
- "<status>200</status>";
+ String convert = "<time>2018 12:04</time>\n"
+ + "<output>t2</output>\n"
+ + "<status>200</status>";
Set<String> listNameList = new HashSet<>();
listNameList.add("result");
Map<String, String> propMap;
try {
propMap = XmlParser.convertToProperties(convert, listNameList);
System.out.println(propMap);
- }catch (Exception e) {}
+ } catch (Exception e) {
+ System.out.println("Exception " + e);
+ }
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/common/publishing/DMaaPEventPublisherTest.java b/src/test/java/org/onap/dcae/common/publishing/DMaaPEventPublisherTest.java
index 2865b75..79ac03b 100644
--- a/src/test/java/org/onap/dcae/common/publishing/DMaaPEventPublisherTest.java
+++ b/src/test/java/org/onap/dcae/common/publishing/DMaaPEventPublisherTest.java
@@ -18,6 +18,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common.publishing;
import static io.vavr.API.Option;
@@ -40,14 +41,17 @@ public class DMaaPEventPublisherTest {
private DMaaPEventPublisher eventPublisher;
private CambriaBatchingPublisher cambriaPublisher;
- private DMaaPPublishersCache DMaaPPublishersCache;
+ private DMaaPPublishersCache dmaapPublishersCache;
+ /**
+ * Setup before test.
+ */
@Before
public void setUp() {
cambriaPublisher = mock(CambriaBatchingPublisher.class);
- DMaaPPublishersCache = mock(DMaaPPublishersCache.class);
- when(DMaaPPublishersCache.getPublisher(anyString())).thenReturn(Option(cambriaPublisher));
- eventPublisher = new DMaaPEventPublisher(DMaaPPublishersCache, mock(Logger.class));
+ dmaapPublishersCache = mock(DMaaPPublishersCache.class);
+ when(dmaapPublishersCache.getPublisher(anyString())).thenReturn(Option(cambriaPublisher));
+ eventPublisher = new DMaaPEventPublisher(dmaapPublishersCache, mock(Logger.class));
}
@Test
@@ -74,6 +78,6 @@ public class DMaaPEventPublisherTest {
eventPublisher.sendEvent(event, STREAM_ID);
// then
- verify(DMaaPPublishersCache).closePublisherFor(STREAM_ID);
+ verify(dmaapPublishersCache).closePublisherFor(STREAM_ID);
}
} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/common/publishing/DMaaPPublishersCacheTest.java b/src/test/java/org/onap/dcae/common/publishing/DMaaPPublishersCacheTest.java
index 2884e44..6f3696d 100644
--- a/src/test/java/org/onap/dcae/common/publishing/DMaaPPublishersCacheTest.java
+++ b/src/test/java/org/onap/dcae/common/publishing/DMaaPPublishersCacheTest.java
@@ -18,6 +18,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common.publishing;
import static io.vavr.API.List;
@@ -43,22 +44,41 @@ import org.onap.dcae.common.publishing.DMaaPPublishersCache.OnPublisherRemovalLi
public class DMaaPPublishersCacheTest {
private String streamId1;
- private Map<String, PublisherConfig> dMaaPConfigs;
-
+ private Map<String, PublisherConfig> dmaapconfigs;
+ private Map<String, PublisherConfig> dmaapconfigs2;
+ /**
+ * Setup before test.
+ */
@Before
public void setUp() {
streamId1 = "sampleStream1";
- dMaaPConfigs = Map("sampleStream1", new PublisherConfig(List("destination1"), "topic1"));
+ dmaapconfigs = Map("sampleStream1", new PublisherConfig(List("destination1"), "topic1"));
+ dmaapconfigs2 = Map("sampleStream1", new PublisherConfig(List("destination1"),
+ "topic1", "user", "pass"));
+
}
@Test
public void shouldReturnTheSameCachedInstanceOnConsecutiveRetrievals() {
// given
- DMaaPPublishersCache dMaaPPublishersCache = new DMaaPPublishersCache(dMaaPConfigs);
+ DMaaPPublishersCache dmaapPublishersCache = new DMaaPPublishersCache(dmaapconfigs);
+
+ // when
+ Option<CambriaBatchingPublisher> firstPublisher = dmaapPublishersCache.getPublisher(streamId1);
+ Option<CambriaBatchingPublisher> secondPublisher = dmaapPublishersCache.getPublisher(streamId1);
+
+ // then
+ assertSame("should return same instance", firstPublisher.get(), secondPublisher.get());
+ }
+
+ @Test
+ public void shouldReturnTheSameCachedInstanceOnConsecutiveRetrievals2() {
+ // given
+ DMaaPPublishersCache dmaapPublishersCache = new DMaaPPublishersCache(dmaapconfigs2);
// when
- Option<CambriaBatchingPublisher> firstPublisher = dMaaPPublishersCache.getPublisher(streamId1);
- Option<CambriaBatchingPublisher> secondPublisher = dMaaPPublishersCache.getPublisher(streamId1);
+ Option<CambriaBatchingPublisher> firstPublisher = dmaapPublishersCache.getPublisher(streamId1);
+ Option<CambriaBatchingPublisher> secondPublisher = dmaapPublishersCache.getPublisher(streamId1);
// then
assertSame("should return same instance", firstPublisher.get(), secondPublisher.get());
@@ -69,14 +89,14 @@ public class DMaaPPublishersCacheTest {
// given
CambriaBatchingPublisher cambriaPublisherMock1 = mock(CambriaBatchingPublisher.class);
CambriaPublishersCacheLoader cacheLoaderMock = mock(CambriaPublishersCacheLoader.class);
- DMaaPPublishersCache dMaaPPublishersCache = new DMaaPPublishersCache(cacheLoaderMock,
+ DMaaPPublishersCache dmaapPublishersCache = new DMaaPPublishersCache(cacheLoaderMock,
new OnPublisherRemovalListener(),
- dMaaPConfigs);
+ dmaapconfigs);
when(cacheLoaderMock.load(streamId1)).thenReturn(cambriaPublisherMock1);
// when
- dMaaPPublishersCache.getPublisher(streamId1);
- dMaaPPublishersCache.closePublisherFor(streamId1);
+ dmaapPublishersCache.getPublisher(streamId1);
+ dmaapPublishersCache.closePublisherFor(streamId1);
// then
verify(cambriaPublisherMock1).close(20, TimeUnit.SECONDS);
@@ -84,12 +104,12 @@ public class DMaaPPublishersCacheTest {
}
@Test
- public void shouldReturnNoneIfThereIsNoDMaaPConfigurationForGivenStreamID() {
+ public void shouldReturnNoneIfThereIsNoDmaaPConfigurationForGivenStreamId() {
// given
- DMaaPPublishersCache dMaaPPublishersCache = new DMaaPPublishersCache(dMaaPConfigs);
+ DMaaPPublishersCache dmaapPublishersCache = new DMaaPPublishersCache(dmaapconfigs);
// then
- assertTrue("should not exist", dMaaPPublishersCache.getPublisher("non-existing").isEmpty());
+ assertTrue("should not exist", dmaapPublishersCache.getPublisher("non-existing").isEmpty());
}
@@ -106,19 +126,22 @@ public class DMaaPPublishersCacheTest {
secondDomain,
new PublisherConfig(List("destination2"), "topic2",
"user", "pass"));
- Map<String, PublisherConfig> newConfig = Map(firstDomain, new PublisherConfig(List("destination1"), "topic1"),
- secondDomain, new PublisherConfig(List("destination2"), "topic2"));
- DMaaPPublishersCache dMaaPPublishersCache = new DMaaPPublishersCache(cacheLoaderMock,
+
+ DMaaPPublishersCache dmaapPublishersCache = new DMaaPPublishersCache(cacheLoaderMock,
new OnPublisherRemovalListener(),
oldConfig);
+ final Map<String, PublisherConfig> newConfig = Map(firstDomain,
+ new PublisherConfig(List("destination1"), "topic1"),
+ secondDomain, new PublisherConfig(List("destination2"), "topic2"));
+
when(cacheLoaderMock.load(firstDomain)).thenReturn(cambriaPublisherMock1);
when(cacheLoaderMock.load(secondDomain)).thenReturn(cambriaPublisherMock2);
- dMaaPPublishersCache.getPublisher(firstDomain);
- dMaaPPublishersCache.getPublisher(secondDomain);
+ dmaapPublishersCache.getPublisher(firstDomain);
+ dmaapPublishersCache.getPublisher(secondDomain);
// when
- dMaaPPublishersCache.reconfigure(newConfig);
+ dmaapPublishersCache.reconfigure(newConfig);
// then
verify(cambriaPublisherMock2).close(20, TimeUnit.SECONDS);
diff --git a/src/test/java/org/onap/dcae/common/publishing/JsonParserTest.java b/src/test/java/org/onap/dcae/common/publishing/JsonParserTest.java
index f00df2c..54d0cfc 100644
--- a/src/test/java/org/onap/dcae/common/publishing/JsonParserTest.java
+++ b/src/test/java/org/onap/dcae/common/publishing/JsonParserTest.java
@@ -17,22 +17,30 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common.publishing;
-import java.util.Map;
+import static org.junit.Assert.assertEquals;
+import java.util.Map;
import org.junit.Test;
import org.onap.dcae.common.JsonParser;
-import junit.framework.Assert;
-
-
public class JsonParserTest {
- @Test
- public void convertToPropertiesTest() throws Exception {
- String testJson="{\"prop2\"=\"value\", \"prop1\"=\"value\"}";
- Map<String, String> response= JsonParser.convertToProperties(testJson);
- Assert.assertEquals("value", response.get("prop2"));
- }
+ @Test
+ public void convertToPropertiesTest() throws Exception {
+ String testJson = "{\"prop2\"=\"value\", \"prop1\"=\"value\"}";
+ Map<String, String> response = JsonParser.convertToProperties(testJson);
+ assertEquals("value", response.get("prop2"));
+ }
+
+ @Test
+ public void convertToPropertiesTestwithArray() throws Exception {
+ String testJson = "{\"metadatum\": [{\"metaname\": \"remote-id\",\"metaval\": \"AC9.0234.0337\","
+ + "\"resource-version\": \"1553802421110\"},{\"metaname\": \"svlan\",\"metaval\": \"100\","
+ + "\"resource-version\": \"1553802421082\"}]}";
+ Map<String, String> response = JsonParser.convertToProperties(testJson);
+ assertEquals("100", response.get("metadatum[1].metaval"));
+ }
}