summaryrefslogtreecommitdiffstats
path: root/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp
diff options
context:
space:
mode:
Diffstat (limited to 'appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp')
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/impl/TestListenerImpl.java43
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/impl/TestProviderOperations.java122
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/impl/TestWorker.java72
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/model/TestEnums.java58
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/model/TestMessages.java151
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL1607/model/TestEnums.java59
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL1607/model/TestMessages.java160
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/LCM/TestConverter.java91
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/LCM1607/model/TestJsonGenericMessages.java99
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/TestAbstractListener.java98
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/TestAppcDmaapListenerActivator.java46
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/TestListenerProperties.java154
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/impl/TestController.java26
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/impl/TestEventHandler.java171
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/impl/TestListener.java112
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/util/TestMapper.java104
16 files changed, 1566 insertions, 0 deletions
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/impl/TestListenerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/impl/TestListenerImpl.java
new file mode 100644
index 000000000..63c98458a
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/impl/TestListenerImpl.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener.CL.impl;
+
+import java.util.Properties;
+
+import org.junit.Before;
+import org.openecomp.appc.configuration.ConfigurationFactory;
+import org.openecomp.appc.listener.ListenerProperties;
+import org.openecomp.appc.listener.CL.impl.ListenerImpl;
+
+public class TestListenerImpl {
+
+ ListenerImpl listener;
+
+ @Before
+ public void setup() {
+ Properties props = ConfigurationFactory.getConfiguration().getProperties();
+ ListenerProperties lProps = new ListenerProperties((String) props.get("test.prefix"), props);
+ lProps.getProperties().setProperty("topic.read.timeout", "5"); // Just for this test
+ listener = new ListenerImpl(lProps);
+ }
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/impl/TestProviderOperations.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/impl/TestProviderOperations.java
new file mode 100644
index 000000000..3d7a7182f
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/impl/TestProviderOperations.java
@@ -0,0 +1,122 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener.CL.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.Properties;
+
+import org.eclipse.osgi.internal.signedcontent.Base64;
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.appc.configuration.ConfigurationFactory;
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.listener.CL.impl.ProviderOperations;
+import org.openecomp.appc.listener.CL.model.IncomingMessage;
+
+public class TestProviderOperations {
+
+ private String ACTIVE_ENDPOINT;
+
+ @Before
+ public void setup() {
+ Properties props = ConfigurationFactory.getConfiguration().getProperties();
+ ACTIVE_ENDPOINT = props.getProperty("appc.ClosedLoop.provider.url");
+ assertNotNull(ACTIVE_ENDPOINT);
+ ProviderOperations.setUrl(ACTIVE_ENDPOINT);
+
+ props.getProperty("test.vm_url");
+ assertNotNull("VM_URL");
+ }
+
+ @Test
+ public void testTopologyOperation() {
+ IncomingMessage msg = new IncomingMessage();
+ // Client and Time are for ID
+ msg.setRequestClient("APPC");
+ msg.setRequestTime("TEST");
+ msg.setRequest("Restart");
+
+ // Null Input
+ try {
+ ProviderOperations.topologyDG(null);
+ fail("Topology Operation with null input should fail");
+ } catch (APPCException e) {
+ assertNotNull(e.getMessage());
+ }
+
+ // Bad URL
+ msg.setUrl("some bad url here");
+ try {
+ ProviderOperations.topologyDG(msg);
+ // Could also be issue in IaaS Adapter
+ fail("Topology Operation with bad url should fail");
+ } catch (APPCException e) {
+ assertNotNull(e.getMessage());
+ }
+
+ // Will be tested in worker
+ // msg.setUrl(VM_URL);
+ // System.out.println("Rebooting real VM. Test can take up to 90s");
+ // try {
+ // assertTrue(ProviderOperations.topologyDG(msg));
+ // } catch (APPCException e) {
+ // fail("Topology Operation with good url should succeed. Check url in gui first");
+ // }
+
+ }
+
+ @Test
+ public void testConfigurationOperation() {
+ try {
+ ProviderOperations.topologyDG(null);
+ fail("Configuration Operation should throw execption. Not yet supported");
+ } catch (APPCException e) {
+ assertNotNull(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testBasicAuthFormating() {
+ String user = "user";
+ String pass = "pass";
+
+ String result = ProviderOperations.setAuthentication(user, pass);
+
+ assertNotNull(result);
+ String decode = new String(Base64.decode(result.getBytes()));
+ assertEquals(user + ":" + pass, decode);
+ }
+
+ @Test
+ public void testGetSet() {
+ // Every test URL will get reset
+ assertEquals(ACTIVE_ENDPOINT, ProviderOperations.getUrl());
+
+ String newUrl = "http://example.com";
+ ProviderOperations.setUrl(newUrl);
+ assertEquals(newUrl, ProviderOperations.getUrl());
+ }
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/impl/TestWorker.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/impl/TestWorker.java
new file mode 100644
index 000000000..1cd9cdc44
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/impl/TestWorker.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener.CL.impl;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Properties;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.appc.configuration.ConfigurationFactory;
+import org.openecomp.appc.listener.EventHandler;
+import org.openecomp.appc.listener.ListenerProperties;
+import org.openecomp.appc.listener.CL.impl.ProviderOperations;
+import org.openecomp.appc.listener.CL.impl.WorkerImpl;
+import org.openecomp.appc.listener.CL.model.IncomingMessage;
+import org.openecomp.appc.listener.impl.EventHandlerImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestWorker {
+
+ private static final Logger LOG = LoggerFactory.getLogger(WorkerImpl.class);
+
+ private IncomingMessage msg;
+ private EventHandler dmaap;
+
+ @Before
+ public void setup() {
+ Properties props = ConfigurationFactory.getConfiguration().getProperties();
+ String activeEndpoint = props.getProperty("appc.ClosedLoop.provider.url");
+ assertNotNull(activeEndpoint);
+ ProviderOperations.setUrl(activeEndpoint);
+
+ String vmUrl = props.getProperty("test.vm_url");
+ assertNotNull(vmUrl);
+ msg = new IncomingMessage();
+ // Client and Time are for ID
+ msg.setRequestClient("APPC");
+ msg.setRequestTime("TEST");
+ msg.setRequest("Restart");
+ msg.setUrl(vmUrl);
+
+ dmaap = new EventHandlerImpl(new ListenerProperties("appc.ClosedLoop", props));
+ }
+
+ @Test
+ public void testWorker() {
+ WorkerImpl w = new WorkerImpl(msg, dmaap);
+ w.run();
+ }
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/model/TestEnums.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/model/TestEnums.java
new file mode 100644
index 000000000..a934cb432
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/model/TestEnums.java
@@ -0,0 +1,58 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener.CL.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+import org.openecomp.appc.listener.CL.model.Action;
+import org.openecomp.appc.listener.CL1607.model.Status;
+
+public class TestEnums {
+
+ @Test
+ public void testAction() {
+ assertEquals(Action.Rebuild, Action.toAction("Rebuild"));
+ assertEquals(Action.Restart, Action.toAction("restart"));
+ assertEquals(Action.Migrate, Action.toAction("MIGRATE"));
+ assertEquals(Action.Evacuate, Action.toAction("Evacuate"));
+ assertNull(Action.toAction("Unknown"));
+ assertNull(Action.toAction(null));
+
+ assertEquals(4, Action.values().length);
+ }
+
+ @Test
+ public void testStatus() {
+
+ assertEquals(Status.ACCEPTED, Status.toStatus("ACCEPTED"));
+ assertEquals(Status.SUCCESS, Status.toStatus("SuCcEsS"));
+ assertEquals(Status.FAILURE, Status.toStatus("Failure"));
+ assertNull(Status.toStatus("Unknown"));
+ assertNull(Status.toStatus(null));
+
+ assertEquals(3, Status.values().length);
+
+ }
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/model/TestMessages.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/model/TestMessages.java
new file mode 100644
index 000000000..e9fa1ace8
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL/model/TestMessages.java
@@ -0,0 +1,151 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener.CL.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.commons.io.IOUtils;
+import org.json.JSONObject;
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.appc.listener.CL.model.IncomingMessage;
+import org.openecomp.appc.listener.CL.model.OutgoingMessage;
+import org.openecomp.appc.listener.CL.model.Status;
+import org.openecomp.appc.listener.util.Mapper;
+
+public class TestMessages {
+ private IncomingMessage in;
+ private OutgoingMessage out;
+
+ private String incomingStr;
+ private String outgoingStr;
+
+ @Before
+ public void setup() {
+ try {
+ incomingStr = IOUtils.toString(getClass().getResourceAsStream("/IncomingMessage.txt"), "UTF-8");
+ outgoingStr = IOUtils.toString(getClass().getResourceAsStream("/OutgoingMessage.txt"), "UTF-8");
+ assertNotNull(incomingStr);
+ assertNotNull(outgoingStr);
+
+ in = Mapper.mapOne(incomingStr, IncomingMessage.class);
+
+ out = Mapper.mapOne(in.toOutgoing(Status.PENDING), OutgoingMessage.class);
+ out.updateResponseTime();
+
+ assertNotNull(in);
+ assertNotNull(out);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ // NOTE Test Mapper will be used to test an event from dmaap.
+ @Test
+ public void testGetterSetter() {
+ assertNotNull(in);
+ assertNotNull(in.getRequestClient());
+ assertNotNull(in.getRequestTime());
+ assertNotNull(in.getMessage());
+ assertNotNull(in.getTenantId());
+ assertNotNull(in.getVmId());
+ assertNotNull(in.getVmName());
+ assertNotNull(in.getAction());
+ assertNotNull(in.getId());
+ assertNotNull(in.getPolicyName());
+ assertNotNull(in.getPolicyVersion());
+ assertNotNull(in.getRequest());
+
+ out = Mapper.mapOne(in.toOutgoing(null), OutgoingMessage.class);
+ assertNotNull(out.getRequestClient());
+ assertEquals(in.getRequestClient(), out.getRequestClient());
+ assertNotNull(out.getRequestTime());
+ assertEquals(in.getRequestTime(), out.getRequestTime());
+ assertNotNull(out.getMessage());
+ assertEquals(in.getMessage(), out.getMessage());
+ assertNotNull(out.getVmName());
+ assertEquals(in.getVmName(), out.getVmName());
+ assertNotNull(out.getPolicyName());
+ assertEquals(in.getPolicyName(), out.getPolicyName());
+ assertNotNull(out.getPolicyVersion());
+ assertEquals(in.getPolicyVersion(), out.getPolicyVersion());
+ assertNotNull(out.getOriginalRequest());
+ assertNotNull(in.getRequest(), out.getOriginalRequest());
+ }
+
+ @Test
+ public void testToString() {
+ in = new IncomingMessage();
+ assertNotNull(in.toString());
+ String id = "test";
+ in.setId(id);
+ assertNotNull(in.toString());
+ assertTrue(in.toString().contains(id));
+ }
+
+ @Test
+ public void testOutgoingUpdateTime() {
+ String old = out.getResponseTime();
+ out.updateResponseTime();
+ assertFalse(old.equals(out.getResponseTime()));
+ }
+
+ // Testing for 1510
+ @Test
+ public void testOutgoingToJson() {
+ // Message Set
+ String message = "MSG";
+ out.setMessage(message);
+ JSONObject json = out.toResponse();
+ assertNotNull(json);
+ String respStr = json.getString("response");
+ assertTrue(respStr.contains(out.getResponse().getValue()));
+
+ String msgStr = json.getString("message");
+ assertNotNull(msgStr);
+ assertFalse(msgStr.contains(out.getOriginalRequest())); // False for 1602
+ assertTrue(msgStr.contains(out.getMessage()));
+
+ // Null Message
+ out.setMessage(null);
+ json = out.toResponse();
+ assertNotNull(json);
+ msgStr = json.getString("message");
+ assertNotNull(msgStr);
+ assertFalse(msgStr.contains(out.getOriginalRequest())); // False for 1602
+ assertTrue(msgStr.contains(out.getResponse().getValue()));
+
+ // Echoing request
+ assertNotNull(out.getOriginalRequest());
+ }
+
+ @Test
+ public void testOutgoingToString() {
+ String s = out.toString();
+ assertTrue(s.contains(out.getId()));
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL1607/model/TestEnums.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL1607/model/TestEnums.java
new file mode 100644
index 000000000..73e38aa4f
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL1607/model/TestEnums.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener.CL1607.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+import org.openecomp.appc.listener.CL.model.Action;
+import org.openecomp.appc.listener.CL.model.Status;
+
+public class TestEnums {
+
+ @Test
+ public void testAction() {
+ assertEquals(Action.Rebuild, Action.toAction("Rebuild"));
+ assertEquals(Action.Restart, Action.toAction("restart"));
+ assertEquals(Action.Migrate, Action.toAction("MIGRATE"));
+ assertEquals(Action.Evacuate, Action.toAction("Evacuate"));
+ assertNull(Action.toAction("Unknown"));
+ assertNull(Action.toAction(null));
+
+ assertEquals(4, Action.values().length);
+ }
+
+ @Test
+ public void testStatus() {
+
+ assertEquals(Status.PENDING, Status.toStatus("Pending"));
+ assertEquals(Status.ACTIVE, Status.toStatus("active"));
+ assertEquals(Status.SUCCESS, Status.toStatus("SuCcEsS"));
+ assertEquals(Status.FAILURE, Status.toStatus("Failure"));
+ assertNull(Status.toStatus("Unknown"));
+ assertNull(Status.toStatus(null));
+
+ assertEquals(4, Status.values().length);
+
+ }
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL1607/model/TestMessages.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL1607/model/TestMessages.java
new file mode 100644
index 000000000..c7bc86300
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL1607/model/TestMessages.java
@@ -0,0 +1,160 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener.CL1607.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.commons.io.IOUtils;
+import org.json.JSONObject;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.openecomp.appc.listener.CL1607.model.IncomingMessage;
+import org.openecomp.appc.listener.CL1607.model.OutgoingMessage;
+import org.openecomp.appc.listener.CL1607.model.Status;
+import org.openecomp.appc.listener.util.Mapper;
+
+public class TestMessages {
+ private IncomingMessage in;
+ private OutgoingMessage out;
+
+ private String incomingStr;
+ private String outgoingStr;
+
+ @Before
+ public void setup() {
+ try {
+ incomingStr = IOUtils.toString(getClass().getResourceAsStream("/IncomingMessage1607.txt"), "UTF-8");
+ outgoingStr = IOUtils.toString(getClass().getResourceAsStream("/OutgoingMessage1607.txt"), "UTF-8");
+ assertNotNull(incomingStr);
+ assertNotNull(outgoingStr);
+
+ in = Mapper.mapOne(incomingStr, IncomingMessage.class);
+
+ out = Mapper.mapOne(outgoingStr, OutgoingMessage.class);
+
+ assertNotNull(in);
+ assertNotNull(out);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ // NOTE Test Mapper will be used to test an event from dmaap.
+ @Test
+ public void testGetterSetter() {
+ assertNotNull(in);
+ assertNotNull(in.getAction());
+ assertNotNull(in.getHeader().getApiVer());
+ assertNotNull(in.getHeader().getOriginatorId());
+ assertNotNull(in.getHeader().getRequestID());
+ assertNotNull(in.getHeader().getSubRequestId());
+ assertNotNull(in.getHeader().getTimeStamp());
+
+ assertNotNull(out);
+ assertNotNull(out.getHeader().getApiVer());
+ assertNotNull(out.getHeader().getOriginatorId());
+ assertNotNull(out.getHeader().getRequestID());
+ assertNotNull(out.getHeader().getSubRequestId());
+ assertNotNull(out.getHeader().getTimeStamp());
+ assertNotNull(out.getStatus().getCode());
+ assertNotNull(out.getStatus().getValue());
+
+ }
+
+ @Test
+ @Ignore
+ public void testIncommingToOutgoing(){
+ OutgoingMessage newOut;
+ newOut = Mapper.mapOne(in.toOutgoing(Status.ACCEPTED), OutgoingMessage.class);
+ assertNotNull(newOut);
+ assertNotNull(newOut.getHeader().getApiVer());
+ assertNotNull(newOut.getHeader().getOriginatorId());
+ assertNotNull(newOut.getHeader().getRequestID());
+ assertNotNull(newOut.getHeader().getSubRequestId());
+ assertNotNull(newOut.getHeader().getTimeStamp());
+ assertNotNull(newOut.getStatus().getCode());
+ assertNotNull(newOut.getStatus().getValue());
+ }
+
+ @Test
+ @Ignore
+ public void testToString() {
+ in = new IncomingMessage();
+ assertNotNull(in.toString());
+ String id = "test";
+ //in.setId(id);
+ assertNotNull(in.toString());
+ assertTrue(in.toString().contains(id));
+ }
+
+
+ @Test
+ @Ignore
+ public void testOutgoingUpdateTime() {
+ //String old = out.getResponseTime();
+ out.updateResponseTime();
+ //assertFalse(old.equals(out.getResponseTime()));
+ }
+
+ // Testing for 1510
+ @Test
+ @Ignore
+ public void testOutgoingToJson() {
+ // Message Set
+ String message = "MSG";
+ //out.setMessage(message);
+ JSONObject json = out.toResponse();
+ assertNotNull(json);
+ String respStr = json.getString("response");
+ //assertTrue(respStr.contains(out.getResponse().getValue()));
+
+ String msgStr = json.getString("message");
+ assertNotNull(msgStr);
+ //assertFalse(msgStr.contains(out.getOriginalRequest())); // False for 1602
+ //assertTrue(msgStr.contains(out.getMessage()));
+
+ // Null Message
+ //out.setMessage(null);
+ json = out.toResponse();
+ assertNotNull(json);
+ msgStr = json.getString("message");
+ assertNotNull(msgStr);
+ //assertFalse(msgStr.contains(out.getOriginalRequest())); // False for 1602
+ //assertTrue(msgStr.contains(out.getResponse().getValue()));
+
+ // Echoing request
+ //assertNotNull(out.getOriginalRequest());
+ }
+
+ @Test
+ @Ignore
+ public void testOutgoingToString() {
+ String s = out.toString();
+ //assertTrue(s.contains(out.getId()));
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/LCM/TestConverter.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/LCM/TestConverter.java
new file mode 100644
index 000000000..2062e80d8
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/LCM/TestConverter.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener.LCM;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.appc.listener.LCM.conv.Converter;
+import org.openecomp.appc.listener.LCM.model.DmaapIncomingMessage;
+import org.openecomp.appc.listener.LCM.model.DmaapOutgoingMessage;
+import org.openecomp.appc.listener.util.Mapper;
+
+public class TestConverter {
+
+ private String jsonInputBodyStr ="{\"input\":{ \"common-header\": { \"timestamp\": \"2016-08-03T08:50:18.97Z\", \"api-ver\": \"1\", \"originator-id\": \"1\", \"request-id\": \"123\", \"sub-request-id\": \"1\", \"flags\": { \"force\":\"TRUE\", \"ttl\":\"9900\" } }, \"action\": \"Stop\", \"action-identifiers\": { \"vnf-id\": \"TEST\" } }}";
+ private String jsonOutputBodyStr ="{\"output\":{\"common-header\":{\"timestamp\":\"2016-08-03T08:50:18.97Z\",\"api-ver\":\"1\",\"flags\":{\"force\":\"TRUE\",\"ttl\":\"9900\"},\"sub-request-id\":\"1\",\"request-id\":\"123\",\"originator-id\":\"1\"},\"status\":{\"value\":\"TestException\",\"code\":200}}}";
+
+ @Test
+ public void buildDmaapOutgoingMessageWithUnexpectedErrorTest() throws JsonProcessingException {
+ DmaapIncomingMessage dmaapIncomingMessage = buildDmaapIncomingMessage();
+ String errMsg = "TestException";
+ DmaapOutgoingMessage dmaapOutgoingMessage = Converter.buildDmaapOutgoingMessageWithUnexpectedError(dmaapIncomingMessage.getBody(), "test", new Exception(errMsg));
+ int code = dmaapOutgoingMessage.getBody().get("output").get("status").get("code").asInt();
+ String value = dmaapOutgoingMessage.getBody().get("output").get("status").get("value").asText();
+ Assert.assertEquals(200,code);
+ Assert.assertEquals(errMsg,value);
+ }
+
+ private static String expectedDmaapOutgoingMessageAsJsonString = "{\"body\":{\"output\":{\"common-header\":{\"timestamp\":\"2016-08-03T08:50:18.97Z\",\"api-ver\":\"1\",\"flags\":{\"force\":\"TRUE\",\"ttl\":\"9900\"},\"sub-request-id\":\"1\",\"request-id\":\"123\",\"originator-id\":\"1\"},\"status\":{\"value\":\"TestException\",\"code\":200}}},\"cambria.partition\":\"MSO\",\"rpc-name\":\"test\"}";
+ @Test
+ public void convDmaapOutgoingMessageToJsonStringTest() throws JsonProcessingException {
+ DmaapOutgoingMessage dmaapOutgoingMessage = buildDmaapOutgoingMessage();
+ String dmaapOutgoingMessageAsJsonString = Converter.convDmaapOutgoingMessageToJsonString(dmaapOutgoingMessage);
+// Assert.assertEquals(dmaapOutgoingMessageAsJsonString,dmaapOutgoingMessageAsJsonString);
+ Assert.assertEquals(expectedDmaapOutgoingMessageAsJsonString,dmaapOutgoingMessageAsJsonString);
+ }
+
+ private DmaapIncomingMessage buildDmaapIncomingMessage() {
+ DmaapIncomingMessage dmaapIncomingMessage = new DmaapIncomingMessage();
+ dmaapIncomingMessage.setRpcName("test");
+ JsonNode jsonNode = Mapper.toJsonNodeFromJsonString(jsonInputBodyStr);
+ dmaapIncomingMessage.setBody(jsonNode);
+ return dmaapIncomingMessage;
+
+ }
+
+ private DmaapOutgoingMessage buildDmaapOutgoingMessage() {
+ DmaapOutgoingMessage dmaapOutgoingMessage = new DmaapOutgoingMessage();
+ dmaapOutgoingMessage.setRpcName("test");
+ JsonNode jsonNode = Mapper.toJsonNodeFromJsonString(jsonOutputBodyStr);
+ dmaapOutgoingMessage.setBody(jsonNode);
+ return dmaapOutgoingMessage;
+
+ }
+
+
+ @Test
+ public void extractRequestIdWithSubIdTest() {
+ DmaapIncomingMessage dmaapIncomingMessage = buildDmaapIncomingMessage();
+ String equestIdWithSubId = Converter.extractRequestIdWithSubId(dmaapIncomingMessage.getBody());
+ Assert.assertEquals("123-1",equestIdWithSubId);
+ }
+
+ @Test
+ public void extractStatusCodeTest() {
+ DmaapOutgoingMessage dmaapOutgoingMessage = buildDmaapOutgoingMessage();
+ Integer statusCode = Converter.extractStatusCode(dmaapOutgoingMessage.getBody());
+ Assert.assertEquals(200L,statusCode.longValue());
+ }
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/LCM1607/model/TestJsonGenericMessages.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/LCM1607/model/TestJsonGenericMessages.java
new file mode 100644
index 000000000..203a13dce
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/LCM1607/model/TestJsonGenericMessages.java
@@ -0,0 +1,99 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener.LCM1607.model;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.appc.listener.util.Mapper;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class TestJsonGenericMessages {/*
+
+ @Test
+ public void serializeIncomingMessage() {
+
+ final String expectedJson = "{\"CommonHeader\":{\"TimeStamp\":\"2016-05-02 19:50:37.09\",\"TransactionID\":\"1\",\"APIver\":\"1.01\",\"RequestTrack\":[\"1\",\"4\",\"12\",\"3\"],\"Flags\":null,\"SubrequestID\":null,\"OriginatorID\":\"2\"},\"Payload\":\"{ \\\"command\\\": \\\"start\\\", \\\"target-id\\\": \\\"111\\\", \\\"flag10\\\": {\\\"object-1\\\": {\\\"key-1\\\": \\\"key\\\", \\\"value-1\\\": \\\"value\\\" }} }\",\"Action\":\"CONFIGURE\",\"ObjectID\":\"200\",\"TargetID\":\"100\"}";
+ InputBody msg = createIncomingMessage();
+
+ String json = Mapper.toJsonObject(msg).toString();
+ //System.out.println(json);
+ Assert.assertEquals(expectedJson, json);
+ }
+
+ @Test
+ public void deserializeIncomingMessage() throws IOException {
+ final String originalJson = "{\"CommonHeader\":{\"TimeStamp\":\"2016-05-02 19:50:37.09\",\"TransactionID\":\"1\",\"Flags\":{\"FORCE\":\"Y\",\"TTL\":\"12\"},\"SubrequestID\":\"2345\",\"OriginatorID\":\"2\",\"APIver\":\"1.01\"}, \"Payload\": \" \\\"Graceful\\\" : \\\"Yes\\\" \",\"Action\":\"CONFIGURE\",\"ObjectID\":\"200\",\"TargetID\":\"100\"}";
+
+ ObjectMapper mapper = new ObjectMapper();
+ InputBody msg = mapper.readValue(originalJson, InputBody.class);
+
+ Assert.assertNotNull(msg);
+ Assert.assertEquals("2016-05-02 19:50:37.09", msg.getCommonHeader().getTimeStamp());
+ Assert.assertEquals("1", msg.getCommonHeader().getRequestID());
+ Assert.assertEquals("1.01", msg.getCommonHeader().getApiVer());
+ Assert.assertEquals("200", msg.getObjectId());
+ Assert.assertEquals("100", msg.getTargetId());
+ Assert.assertEquals(" \"Graceful\" : \"Yes\" ", msg.getPayload());
+ Assert.assertEquals("CONFIGURE", msg.getAction());
+
+ }
+
+ @Test
+ public void serializeResponseMessage() {
+ InputBody imsg = createIncomingMessage();
+ OutputBody omsg = new OutputBody(imsg);
+ omsg.setStatus(new ResponseStatus("200", "OK"));
+
+ String json = Mapper.toJsonObject(omsg).toString();
+ System.out.println(json);
+ //Assert.assertEquals(expectedJson, json);
+ Assert.assertNotEquals("", json);
+
+ }
+
+ private InputBody createIncomingMessage() {
+ InputBody msg = new InputBody();
+ CommonHeader rh = new CommonHeader();
+ rh.setTimeStamp("2016-05-02 19:50:37.09");
+ rh.setApiVer("1.01");
+ rh.setRequestID("1");
+ rh.setOriginatorId("2");
+
+
+ Map<String, String> flags = new HashMap<>();
+ flags.put("FORCE", "Y");
+ flags.put("TTL", "12");
+
+ msg.setCommonHeader(rh);
+ msg.setAction("CONFIGURE");
+ msg.setTargetId("100");
+ msg.setObjectId("200");
+ msg.setPayloadAsString("{ \"command\": \"start\", \"target-id\": \"111\", \"flag10\": {\"object-1\": {\"key-1\": \"key\", \"value-1\": \"value\" }} }");
+ return msg;
+ }
+*/
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/TestAbstractListener.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/TestAbstractListener.java
new file mode 100644
index 000000000..c193f7c2d
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/TestAbstractListener.java
@@ -0,0 +1,98 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Properties;
+import java.util.concurrent.ThreadPoolExecutor;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.appc.listener.AbstractListener;
+import org.openecomp.appc.listener.ListenerProperties;
+
+public class TestAbstractListener {
+
+ private class DummyListener extends AbstractListener {
+ public DummyListener(ListenerProperties props) {
+ super(props);
+ }
+
+ public boolean getRun() {
+ return run.get();
+ }
+
+ public ThreadPoolExecutor getExecutor() {
+ return executor;
+ }
+ }
+
+ private DummyListener listener;
+ private ListenerProperties props;
+
+ @Before
+ public void setup() throws Exception {
+ Properties regularProps = new Properties();
+ regularProps.load(getClass().getResourceAsStream("/org/openecomp/appc/default.properties"));
+ props = new ListenerProperties("", regularProps);
+ listener = new DummyListener(props);
+ }
+
+ @Test
+ public void testRun() {
+ Thread t = new Thread(listener);
+ t.run();
+ assertFalse(t.isAlive()); // Should die immediately
+ }
+
+ @Test
+ public void testStop() {
+ listener.stop();
+ assertFalse(listener.getRun());
+ assertTrue(listener.getExecutor().isShutdown());
+ }
+
+ @Test
+ public void testStopNow() {
+ listener.stopNow();
+ assertFalse(listener.getRun());
+ assertTrue(listener.getExecutor().isShutdown());
+ }
+
+ @Test
+ public void testBenchmark() {
+ String out = listener.getBenchmark();
+ assertNotNull(out);
+ assertTrue(out.contains(listener.getListenerId()));
+ }
+
+ @Test
+ public void testListenerId() {
+ assertEquals(props.getPrefix(), listener.getListenerId());
+ listener.setListenerId("newId");
+ assertEquals("newId", listener.getListenerId());
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/TestAppcDmaapListenerActivator.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/TestAppcDmaapListenerActivator.java
new file mode 100644
index 000000000..a5348d145
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/TestAppcDmaapListenerActivator.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.openecomp.appc.listener.AppcEventListenerActivator;
+
+public class TestAppcDmaapListenerActivator {
+
+ @Test
+ public void testStartStop() {
+ // TODO - How do we tests activators
+ AppcEventListenerActivator appc = new AppcEventListenerActivator();
+ try {
+ appc.start(null);
+ Thread.sleep(2000);
+ appc.stop(null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ assertNotNull(appc.getName());
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/TestListenerProperties.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/TestListenerProperties.java
new file mode 100644
index 000000000..9a70a8427
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/TestListenerProperties.java
@@ -0,0 +1,154 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Properties;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.appc.listener.AbstractListener;
+import org.openecomp.appc.listener.ListenerProperties;
+import org.openecomp.appc.listener.ListenerProperties.KEYS;
+
+public class TestListenerProperties {
+
+ private Properties good, bad, both;
+ private String prefix;
+
+ private ListenerProperties props;
+
+ @Before
+ public void setup() {
+ prefix = "test";
+ good = new Properties();
+ bad = new Properties();
+ both = new Properties();
+
+ good.setProperty(String.format("%s.%s", prefix, "a"), "1");
+ good.setProperty(String.format("%s.%s", prefix, "a.b"), "2");
+ good.setProperty(String.format("%s.%s", prefix, "a.b.c"), "3");
+
+ bad.setProperty(prefix, "NA");
+ bad.setProperty(prefix + ".", "NA");
+ bad.setProperty(String.format("%s.%s", prefix + "x", "bad"), "NA");
+ bad.setProperty(String.format("%s.%s", "x" + prefix, "bad"), "NA");
+
+ for (String key : good.stringPropertyNames()) {
+ both.put(key, good.getProperty(key));
+ }
+ for (String key : bad.stringPropertyNames()) {
+ both.put(key, bad.getProperty(key));
+ }
+
+ props = new ListenerProperties(prefix, both);
+ }
+
+ @Test
+ public void testConstructor() {
+ props = new ListenerProperties(prefix, good);
+ assertEquals(prefix, props.getPrefix());
+ assertEquals(good.size(), props.getProperties().size());
+
+ props = new ListenerProperties(prefix, bad);
+ assertEquals(prefix, props.getPrefix());
+ assertTrue(props.getProperties().isEmpty());
+
+ props = new ListenerProperties(prefix, both);
+ assertEquals(prefix, props.getPrefix());
+ assertEquals(good.size(), props.getProperties().size());
+
+ for (Object val : props.getProperties().values()) {
+ assertFalse("NA".equals(val.toString()));
+ }
+
+ assertTrue(props.toString().contains(prefix));
+ }
+
+ @Test
+ public void testGetClass() {
+ assertNull(props.getListenerClass());
+ props.setListenerClass(AbstractListener.class);
+ assertNotNull(props.getListenerClass());
+ assertEquals(AbstractListener.class, props.getListenerClass());
+ }
+
+ @Test
+ public void testMessageServices() {
+ // Hardcode count so tests must be updated when values are added
+ assertEquals(1, ListenerProperties.MessageService.values().length);
+
+ // Bad Input
+ ListenerProperties.MessageService def = ListenerProperties.MessageService.DMaaP;
+ assertEquals(def, ListenerProperties.MessageService.parse(null));
+ assertEquals(def, ListenerProperties.MessageService.parse(""));
+ assertEquals(def, ListenerProperties.MessageService.parse("NotDmaapOrDMaaP"));
+
+
+ // DMaaP case sensitivity
+ assertEquals(ListenerProperties.MessageService.DMaaP, ListenerProperties.MessageService.parse("dmaap"));
+ assertEquals(ListenerProperties.MessageService.DMaaP, ListenerProperties.MessageService.parse("DMAAP"));
+ assertEquals(ListenerProperties.MessageService.DMaaP, ListenerProperties.MessageService.parse("DMaaP"));
+ }
+
+ @Test
+ public void testKeys() {
+ // Hardcode count so tests must be updated when values are added
+ assertEquals(15, ListenerProperties.KEYS.values().length);
+
+ Properties tmp = new Properties();
+ try {
+ tmp.load(getClass().getResourceAsStream("/org/openecomp/appc/default.properties"));
+ } catch (Exception e) {
+ fail("Could not load properties to test");
+ }
+ String realPrefix = tmp.getProperty("test.prefix");
+ assertNotNull(realPrefix);
+ props = new ListenerProperties(realPrefix, tmp);
+
+ for (KEYS key : ListenerProperties.KEYS.values()) {
+ assertNotNull(key.getFullProp(realPrefix));
+ assertNotNull(props.getProperty(key));
+ assertNotNull(props.getProperty(key.getPropertySuffix()));
+ }
+ }
+
+ @Test
+ public void testDisabled() throws Exception {
+ assertFalse(props.isDisabled());
+ props.getProperties().put(KEYS.DISABLED.getPropertySuffix(), "TRUE");
+ assertTrue(props.isDisabled());
+ props.getProperties().put(KEYS.DISABLED.getPropertySuffix(), "N/A");
+ assertFalse(props.isDisabled());
+ props.getProperties().put(KEYS.DISABLED.getPropertySuffix(), "fAlse");
+ assertFalse(props.isDisabled());
+ props.getProperties().remove(KEYS.DISABLED.getPropertySuffix());
+ assertFalse(props.isDisabled());
+ }
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/impl/TestController.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/impl/TestController.java
new file mode 100644
index 000000000..a67b94647
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/impl/TestController.java
@@ -0,0 +1,26 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener.impl;
+
+public class TestController {
+
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/impl/TestEventHandler.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/impl/TestEventHandler.java
new file mode 100644
index 000000000..788aa961a
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/impl/TestEventHandler.java
@@ -0,0 +1,171 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.lang3.StringUtils;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.openecomp.appc.listener.EventHandler;
+import org.openecomp.appc.listener.ListenerProperties;
+import org.openecomp.appc.listener.impl.EventHandlerImpl;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+/**
+ * Test the ProviderAdapter implementation.
+ *
+ */
+
+public class TestEventHandler {
+
+ private ListenerProperties prop;
+
+ private EventHandler adapter;
+
+ private static final String PROP_FILE = "/org/openecomp/appc/default.properties";
+
+ private static final String MESSAGE_FILE = "/DCAEResponse.txt";
+
+ /**
+ * Setup the test environment.
+ *
+ * @throws NoSuchMethodException
+ * @throws SecurityException
+ * @throws NoSuchFieldException
+ */
+ @Before
+ public void setup() {
+ Properties allProps = new Properties();
+ try {
+ allProps.load(getClass().getResourceAsStream(PROP_FILE));
+ allProps.remove("appc.ClosedLoop.topic.read.filter");
+ prop = new ListenerProperties("appc.ClosedLoop", allProps);
+ } catch (IOException e) {
+ System.out.println("WARNING: Failed to load properties file: " + PROP_FILE);
+ }
+ adapter = new EventHandlerImpl(prop);
+ }
+
+ @Test
+ public void testInitialProperties() {
+ assertEquals(prop.getProperty("topic.read"), adapter.getReadTopic());
+ assertTrue(adapter.getWriteTopics().contains(prop.getProperty("topic.write")));
+ assertEquals(prop.getProperty("client.name"), adapter.getClientName());
+ assertEquals(prop.getProperty("client.name.id"), adapter.getClientId());
+
+ String hostStr = prop.getProperty("poolMembers");
+ int hostCount = hostStr.length()>0 ? hostStr.split(",").length : 0;
+ assertEquals(hostCount, adapter.getPool().size());
+ }
+
+ @Test
+ public void testGettersAndSetters() {
+ String readTopic = "read";
+ Set<String> writeTopic = new HashSet<String>();
+ writeTopic.add("write");
+ String clientName = "APPC-TEST";
+ String clientId = "00";
+ String newHost = "google.com";
+
+ adapter.setReadTopic(readTopic);
+ assertEquals(readTopic, adapter.getReadTopic());
+
+ adapter.setWriteTopics(writeTopic);
+ assertEquals(writeTopic, adapter.getWriteTopics());
+
+ adapter.setClientName(clientName);
+ assertEquals(clientName, adapter.getClientName());
+
+ adapter.setClientId(clientId);
+ assertEquals(clientId, adapter.getClientId());
+
+ adapter.setCredentials("fake", "secret");
+ adapter.clearCredentials();
+
+ int oldSize = adapter.getPool().size();
+ adapter.addToPool(newHost);
+ assertEquals(oldSize + 1, adapter.getPool().size());
+ assertTrue(adapter.getPool().contains(newHost));
+
+ adapter.removeFromPool(newHost);
+ assertEquals(oldSize, adapter.getPool().size());
+ assertFalse(adapter.getPool().contains(newHost));
+
+ }
+
+ @Test
+ @Ignore
+ public void testRun() {
+ // Runoff any old data
+ List<String> result1 = adapter.getIncomingEvents();
+ assertNotNull(result1);
+
+ // Post new data
+ DummyObj data = new DummyObj();
+ data.key = "value";
+ adapter.postStatus(data.toJson());
+
+ // Wait to account for network delay
+ sleep(2000);
+
+ // Get data back
+ List<DummyObj> result2 = adapter.getIncomingEvents(DummyObj.class);
+ assertNotNull(result2);
+ assertEquals(1, result2.size());
+ assertEquals(data.toJson(), result2.get(0).toJson());
+ }
+
+ @JsonSerialize
+ public static class DummyObj implements Serializable {
+ @JsonProperty("request") // Call request for default filter
+ public String key;
+
+ public DummyObj() {
+ }
+
+ public String toJson() {
+ return String.format("{\"request\": \"%s\"}", key);
+ }
+ }
+
+ private void sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ } catch (Exception e) {
+ return;
+ }
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/impl/TestListener.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/impl/TestListener.java
new file mode 100644
index 000000000..a1c7917f9
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/impl/TestListener.java
@@ -0,0 +1,112 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.Properties;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.openecomp.appc.listener.Listener;
+import org.openecomp.appc.listener.ListenerProperties;
+import org.openecomp.appc.listener.CL.impl.ListenerImpl;
+
+@Ignore
+public class TestListener {
+
+ private static final String PROP_FILE = "/org/openecomp/appc/default.properties";
+
+ private Listener listener;
+
+ private Properties props;
+
+ @Before
+ public void setup() {
+ props = new Properties();
+ try {
+ props.load(getClass().getResourceAsStream(PROP_FILE));
+ props.setProperty("topic.read", "DCAE-CLOSED-LOOP-EVENTS-DEV1510SIM");
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Failed to setup test: " + e.getMessage());
+ }
+ listener = new ListenerImpl(new ListenerProperties("appc.ClosedLoop", props));
+ }
+
+ @Test
+ public void testListenerId() {
+ String originalId = listener.getListenerId();
+ String newId = originalId + "-new";
+
+ listener.setListenerId(newId);
+ assertEquals(newId, listener.getListenerId());
+ }
+
+ @Test
+ public void testRun() {
+ try {
+ Thread t = new Thread(listener);
+ t.start();
+
+ Thread.sleep(5000);
+
+ listener.stopNow();
+
+ System.out.println(listener.getBenchmark());
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testUpdateProperties() {
+
+ }
+
+ @Test
+ public void printSampleData() {
+ try {
+ props.setProperty("threads.queuesize.min", "1");
+ props.setProperty("threads.queuesize.max", "1");
+ props.setProperty("threads.poolsize.min", "1");
+ props.setProperty("threads.poolsize.max", "1");
+
+ Thread t = new Thread(listener);
+ t.start();
+
+ Thread.sleep(2000);
+
+ listener.stop();
+
+ System.out.println(listener.getBenchmark());
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/util/TestMapper.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/util/TestMapper.java
new file mode 100644
index 000000000..430b28e61
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/util/TestMapper.java
@@ -0,0 +1,104 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.listener.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.json.JSONObject;
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.appc.listener.util.Mapper;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+public class TestMapper {
+
+ private String dummyJson = "{\"a\":\"%s\"}";
+ private DummyObj dummyObj = new DummyObj();
+
+ @JsonSerialize
+ public static class DummyObj implements Serializable {
+ @JsonProperty("a")
+ public String a;
+
+ public DummyObj() {
+ }
+ }
+
+ @Before
+ public void setup() {
+ }
+
+ @Test
+ public void testGetMapper() {
+ assertNotNull(Mapper.getMapper());
+ }
+
+ @Test
+ public void testToJsonObject() {
+ JSONObject out;
+ out = Mapper.toJsonObject(".");
+ assertNull(out);
+
+ String value = "b";
+ out = Mapper.toJsonObject(String.format(dummyJson, value));
+ assertNotNull(out);
+ assertEquals(value, out.get("a"));
+ }
+
+ @Test
+ public void testConstructor() {
+ // Only here for code coverage
+ Mapper m = new Mapper();
+ assertNotNull(m);
+ }
+
+ @Test
+ public void testMap() {
+ List<String> in = new ArrayList<String>();
+ in.add("");
+ in.add(null);
+
+ List<DummyObj> out = Mapper.mapList(in, DummyObj.class);
+ assertNotNull(out);
+ assertTrue(out.isEmpty());
+
+ in.add(String.format(dummyJson, "1"));
+ in.add("{\"invalid\":\"yes\"}");
+ in.add(String.format(dummyJson, "2"));
+
+ out = Mapper.mapList(in, DummyObj.class);
+ assertNotNull(out);
+ assertEquals(2, out.size());
+ assertEquals("1", out.get(0).a);
+ assertEquals("2", out.get(1).a);
+ }
+
+}