aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorrv871f <richard.vondadelszen@amdocs.com>2018-03-20 10:21:42 -0400
committerrv871f <richard.vondadelszen@amdocs.com>2018-03-20 11:03:34 -0400
commitbf99eb77b31a4cfbc590762cc6ba669820c21439 (patch)
tree6251d665e64a09eb98e79540967dff832f4226b4 /src/test/java
parent1aae9de4d596a1108818c2d035225a3ba2737501 (diff)
Process VNF event from spike
Issue-ID: AAI-899 Change-Id: I2d056734e6af0fe0b4efe92681971e2b74153a0e Signed-off-by: rv871f <richard.vondadelszen@amdocs.com>
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/aai/datarouter/policy/SpikeAggregateGenericVnfProcessorStubbed.java34
-rw-r--r--src/test/java/org/onap/aai/datarouter/policy/SpikeAggregateGenericVnfProcessorTest.java111
-rw-r--r--src/test/java/org/onap/aai/datarouter/policy/SpikeAutosuggestProcessorStubbed.java34
-rw-r--r--src/test/java/org/onap/aai/datarouter/policy/SpikeAutosuggestProcessorTest.java89
-rw-r--r--src/test/java/org/onap/aai/datarouter/policy/SpikeEntitySearchProcessorStubbed.java54
-rw-r--r--src/test/java/org/onap/aai/datarouter/policy/SpikeEntitySearchProcessorTest.java117
-rw-r--r--src/test/java/org/onap/aai/datarouter/policy/SpikeEventPolicyConfigTest.java59
7 files changed, 498 insertions, 0 deletions
diff --git a/src/test/java/org/onap/aai/datarouter/policy/SpikeAggregateGenericVnfProcessorStubbed.java b/src/test/java/org/onap/aai/datarouter/policy/SpikeAggregateGenericVnfProcessorStubbed.java
new file mode 100644
index 0000000..5bd35f6
--- /dev/null
+++ b/src/test/java/org/onap/aai/datarouter/policy/SpikeAggregateGenericVnfProcessorStubbed.java
@@ -0,0 +1,34 @@
+package org.onap.aai.datarouter.policy;
+
+import java.io.FileNotFoundException;
+
+import org.onap.aai.datarouter.entity.DocumentStoreDataEntity;
+
+public class SpikeAggregateGenericVnfProcessorStubbed extends SpikeAggregateGenericVnfProcessor {
+
+
+ public SpikeAggregateGenericVnfProcessorStubbed(SpikeEventPolicyConfig config) throws FileNotFoundException {
+ super(config);
+
+ }
+
+ protected void handleSearchServiceOperation(DocumentStoreDataEntity eventEntity, String action, String index) {
+ //Stub out the actual call to Search Data service and instead store/update documents in memory
+ try {
+ switch (action.toLowerCase()) {
+ case "create":
+ InMemorySearchDatastore.put(eventEntity.getId(), eventEntity.getAsJson()); // they are executed if variable == c1
+ break;
+ case "update":
+ InMemorySearchDatastore.put(eventEntity.getId(), eventEntity.getAsJson()); // they are executed if variable == c1
+ break;
+ case "delete":
+ InMemorySearchDatastore.remove(eventEntity.getId()); // they are executed if variable == c1
+ break;
+ default:
+ break;
+ }
+ } catch (Exception ex) {
+ }
+ }
+}
diff --git a/src/test/java/org/onap/aai/datarouter/policy/SpikeAggregateGenericVnfProcessorTest.java b/src/test/java/org/onap/aai/datarouter/policy/SpikeAggregateGenericVnfProcessorTest.java
new file mode 100644
index 0000000..d1c01af
--- /dev/null
+++ b/src/test/java/org/onap/aai/datarouter/policy/SpikeAggregateGenericVnfProcessorTest.java
@@ -0,0 +1,111 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * 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.onap.aai.datarouter.policy;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.commons.io.IOUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.datarouter.util.NodeUtils;
+import org.onap.aai.datarouter.util.SearchServiceAgent;
+import org.powermock.api.mockito.PowerMockito;
+
+
+
+public class SpikeAggregateGenericVnfProcessorTest {
+ SpikeAggregateGenericVnfProcessor policy;
+ String eventJson;
+
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void init() throws Exception {
+ SpikeEventPolicyConfig config = PowerMockito.mock(SpikeEventPolicyConfig.class);
+ PowerMockito.when(config.getSearchKeystorePwd()).thenReturn("password");
+ PowerMockito.when(config.getSourceDomain()).thenReturn("JUNIT");
+
+
+ SearchServiceAgent searchServiceAgent = PowerMockito.mock(SearchServiceAgent.class);
+ PowerMockito.whenNew(SearchServiceAgent.class).withAnyArguments()
+ .thenReturn(searchServiceAgent);
+
+
+ policy = new SpikeAggregateGenericVnfProcessorStubbed(config);
+ FileInputStream event = new FileInputStream(new File("src/test/resources/spike_event.json"));
+ eventJson = IOUtils.toString(event, "UTF-8");
+
+ }
+
+ @Test
+ public void testProcess_success() throws Exception {
+ policy.process(getExchangeEvent("12345", "create", "generic-vnf"));
+ policy.process(getExchangeEvent("23456", "create", "generic-vnf"));
+
+ assertNotNull(
+ InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("generic-vnf/12345")));
+ assertNotNull(
+ InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("generic-vnf/23456")));
+
+
+ policy.process(getExchangeEvent("23456", "delete", "generic-vnf"));
+ assertNull(InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("23456")));
+ }
+ @Test
+ public void testProcess_fail() throws Exception {
+ policy.process(getExchangeEvent("666666", "create", "NotValid"));
+ assertNull(
+ InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("NotValid/666666")));
+
+ policy.process(getExchangeEvent("", "create", "generic-vnf"));
+ assertNull(
+ InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("generic-vnf/")));
+
+ }
+
+
+ private Exchange getExchangeEvent(String key, String action, String type) {
+ Object obj = eventJson.replace("$KEY", key).replace("$ACTION", action).replace("$TYPE", type);
+ Exchange exchange = PowerMockito.mock(Exchange.class);
+ Message inMessage = PowerMockito.mock(Message.class);
+ Message outMessage = PowerMockito.mock(Message.class);
+ PowerMockito.when(exchange.getIn()).thenReturn(inMessage);
+ PowerMockito.when(inMessage.getBody()).thenReturn(obj);
+
+ PowerMockito.when(exchange.getOut()).thenReturn(outMessage);
+ PowerMockito.doNothing().when(outMessage).setBody(anyObject());
+ PowerMockito.doNothing().when(outMessage).setHeader(anyString(), anyObject());
+
+ return exchange;
+
+ }
+
+
+
+}
diff --git a/src/test/java/org/onap/aai/datarouter/policy/SpikeAutosuggestProcessorStubbed.java b/src/test/java/org/onap/aai/datarouter/policy/SpikeAutosuggestProcessorStubbed.java
new file mode 100644
index 0000000..cf3b255
--- /dev/null
+++ b/src/test/java/org/onap/aai/datarouter/policy/SpikeAutosuggestProcessorStubbed.java
@@ -0,0 +1,34 @@
+package org.onap.aai.datarouter.policy;
+
+import java.io.FileNotFoundException;
+
+import org.onap.aai.datarouter.entity.DocumentStoreDataEntity;
+
+public class SpikeAutosuggestProcessorStubbed extends SpikeAutosuggestIndexProcessor {
+
+
+ public SpikeAutosuggestProcessorStubbed(SpikeEventPolicyConfig config) throws FileNotFoundException {
+ super(config);
+
+ }
+
+ protected void handleSearchServiceOperation(DocumentStoreDataEntity eventEntity, String action, String index) {
+ //Stub out the actual call to Search Data service and instead store/update documents in memory
+ try {
+ switch (action.toLowerCase()) {
+ case "create":
+ InMemorySearchDatastore.put(eventEntity.getId(), eventEntity.getAsJson()); // they are executed if variable == c1
+ break;
+ case "update":
+ InMemorySearchDatastore.put(eventEntity.getId(), eventEntity.getAsJson()); // they are executed if variable == c1
+ break;
+ case "delete":
+ InMemorySearchDatastore.remove(eventEntity.getId()); // they are executed if variable == c1
+ break;
+ default:
+ break;
+ }
+ } catch (Exception ex) {
+ }
+ }
+}
diff --git a/src/test/java/org/onap/aai/datarouter/policy/SpikeAutosuggestProcessorTest.java b/src/test/java/org/onap/aai/datarouter/policy/SpikeAutosuggestProcessorTest.java
new file mode 100644
index 0000000..f3c72f1
--- /dev/null
+++ b/src/test/java/org/onap/aai/datarouter/policy/SpikeAutosuggestProcessorTest.java
@@ -0,0 +1,89 @@
+package org.onap.aai.datarouter.policy;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.commons.io.IOUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.datarouter.util.NodeUtils;
+import org.onap.aai.datarouter.util.SearchServiceAgent;
+import org.powermock.api.mockito.PowerMockito;
+
+
+
+public class SpikeAutosuggestProcessorTest {
+ SpikeAutosuggestIndexProcessor policy;
+ String eventJson;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void init() throws Exception {
+ SpikeEventPolicyConfig config = PowerMockito.mock(SpikeEventPolicyConfig.class);
+ PowerMockito.when(config.getSearchKeystorePwd()).thenReturn("password");
+ PowerMockito.when(config.getSourceDomain()).thenReturn("JUNIT");
+
+
+ SearchServiceAgent searchServiceAgent = PowerMockito.mock(SearchServiceAgent.class);
+ PowerMockito.whenNew(SearchServiceAgent.class).withAnyArguments()
+ .thenReturn(searchServiceAgent);
+
+
+ policy = new SpikeAutosuggestProcessorStubbed(config);
+ FileInputStream event = new FileInputStream(new File("src/test/resources/spike_event.json"));
+ eventJson = IOUtils.toString(event, "UTF-8");
+
+ }
+
+ @Test
+ public void testProcess_success() throws Exception {
+ policy.process(getExchangeEvent("77777", "create", "generic-vnf"));
+
+ assertNotNull(
+ InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("junk and Running VNFs")));
+ assertNotNull(
+ InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("junk VNFs")));
+ assertNotNull(
+ InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("Running VNFs")));
+
+
+ }
+ @Test
+ public void testProcess_fail() throws Exception {
+ policy.process(getExchangeEvent("666666", "create", "NotValid"));
+ assertNull(
+ InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("NotValid/666666")));
+
+ policy.process(getExchangeEvent("", "create", "generic-vnf"));
+ assertNull(
+ InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("generic-vnf/")));
+
+ }
+
+
+ private Exchange getExchangeEvent(String key, String action, String type) {
+ Object obj = eventJson.replace("$KEY", key).replace("$ACTION", action).replace("$TYPE", type);
+ Exchange exchange = PowerMockito.mock(Exchange.class);
+ Message inMessage = PowerMockito.mock(Message.class);
+ Message outMessage = PowerMockito.mock(Message.class);
+ PowerMockito.when(exchange.getIn()).thenReturn(inMessage);
+ PowerMockito.when(inMessage.getBody()).thenReturn(obj);
+
+ PowerMockito.when(exchange.getOut()).thenReturn(outMessage);
+ PowerMockito.doNothing().when(outMessage).setBody(anyObject());
+ PowerMockito.doNothing().when(outMessage).setHeader(anyString(), anyObject());
+
+ return exchange;
+
+ }
+
+
+
+}
diff --git a/src/test/java/org/onap/aai/datarouter/policy/SpikeEntitySearchProcessorStubbed.java b/src/test/java/org/onap/aai/datarouter/policy/SpikeEntitySearchProcessorStubbed.java
new file mode 100644
index 0000000..100ff0a
--- /dev/null
+++ b/src/test/java/org/onap/aai/datarouter/policy/SpikeEntitySearchProcessorStubbed.java
@@ -0,0 +1,54 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * 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.onap.aai.datarouter.policy;
+
+import java.io.FileNotFoundException;
+
+import org.onap.aai.datarouter.entity.DocumentStoreDataEntity;
+
+public class SpikeEntitySearchProcessorStubbed extends SpikeEntitySearchProcessor {
+
+
+ public SpikeEntitySearchProcessorStubbed(SpikeEventPolicyConfig config) throws FileNotFoundException {
+ super(config);
+
+ }
+
+ protected void handleSearchServiceOperation(DocumentStoreDataEntity eventEntity, String action, String index) {
+ //Stub out the actual call to Search Data service and instead store/update documents in memory
+ try {
+ switch (action.toLowerCase()) {
+ case "create":
+ InMemorySearchDatastore.put(eventEntity.getId(), eventEntity.getAsJson()); // they are executed if variable == c1
+ break;
+ case "update":
+ InMemorySearchDatastore.put(eventEntity.getId(), eventEntity.getAsJson()); // they are executed if variable == c1
+ break;
+ case "delete":
+ InMemorySearchDatastore.remove(eventEntity.getId()); // they are executed if variable == c1
+ break;
+ default:
+ break;
+ }
+ } catch (Exception ex) {
+ }
+ }
+}
diff --git a/src/test/java/org/onap/aai/datarouter/policy/SpikeEntitySearchProcessorTest.java b/src/test/java/org/onap/aai/datarouter/policy/SpikeEntitySearchProcessorTest.java
new file mode 100644
index 0000000..08518b1
--- /dev/null
+++ b/src/test/java/org/onap/aai/datarouter/policy/SpikeEntitySearchProcessorTest.java
@@ -0,0 +1,117 @@
+package org.onap.aai.datarouter.policy;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.commons.io.IOUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aai.datarouter.util.NodeUtils;
+import org.onap.aai.datarouter.util.SearchServiceAgent;
+import org.powermock.api.mockito.PowerMockito;
+
+
+
+public class SpikeEntitySearchProcessorTest {
+ SpikeEntitySearchProcessor policy;
+ String eventJson;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void init() throws Exception {
+ SpikeEventPolicyConfig config = PowerMockito.mock(SpikeEventPolicyConfig.class);
+ PowerMockito.when(config.getSearchKeystorePwd()).thenReturn("password");
+ PowerMockito.when(config.getSourceDomain()).thenReturn("JUNIT");
+
+
+ SearchServiceAgent searchServiceAgent = PowerMockito.mock(SearchServiceAgent.class);
+ PowerMockito.whenNew(SearchServiceAgent.class).withAnyArguments()
+ .thenReturn(searchServiceAgent);
+
+
+ policy = new SpikeEntitySearchProcessorStubbed(config);
+ FileInputStream event = new FileInputStream(new File("src/test/resources/spike_event.json"));
+ eventJson = IOUtils.toString(event, "UTF-8");
+
+ }
+
+ @Test
+ public void testProcess_success() throws Exception {
+ policy.process(getExchangeEvent("12345", "create", "generic-vnf"));
+ policy.process(getExchangeEvent("23456", "create", "generic-vnf"));
+
+ assertNotNull(
+ InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("generic-vnf/12345")));
+ assertNotNull(
+ InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("generic-vnf/23456")));
+
+
+ policy.process(getExchangeEvent("23456", "delete", "generic-vnf"));
+ assertNull(InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("generic-vnf/23456")));
+
+ policy.process(getExchangeEvent("333333", "", "generic-vnf"));
+ assertNull(InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("generic-vnf/333333")));
+ }
+ @Test
+ public void testProcess_fail() throws Exception {
+ policy.process(getExchangeEvent("xxxxx", "create", "NotValid"));
+ assertNull(
+ InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("NotValid/xxxxx")));
+
+ policy.process(getExchangeEvent("", "create", "generic-vnf"));
+ assertNull(
+ InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("generic-vnf/")));
+
+ policy.process(getExchangeEvent("yyyy", "create", ""));
+ assertNull(
+ InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("/yyyy")));
+ policy.process(getExchangeEvent("", "create", ""));
+ assertNull(
+ InMemorySearchDatastore.get(NodeUtils.generateUniqueShaDigest("/")));
+ }
+ @Test
+ public void testProcess_null() throws Exception {
+ policy.process(getExchangeEvent());
+ }
+
+ private Exchange getExchangeEvent(String key, String action, String type) {
+ Object obj = eventJson.replace("$KEY", key).replace("$ACTION", action).replace("$TYPE", type);
+ Exchange exchange = PowerMockito.mock(Exchange.class);
+ Message inMessage = PowerMockito.mock(Message.class);
+ Message outMessage = PowerMockito.mock(Message.class);
+ PowerMockito.when(exchange.getIn()).thenReturn(inMessage);
+ PowerMockito.when(inMessage.getBody()).thenReturn(obj);
+
+ PowerMockito.when(exchange.getOut()).thenReturn(outMessage);
+ PowerMockito.doNothing().when(outMessage).setBody(anyObject());
+ PowerMockito.doNothing().when(outMessage).setHeader(anyString(), anyObject());
+
+ return exchange;
+
+ }
+
+ private Exchange getExchangeEvent() {
+ Object obj = "";
+ Exchange exchange = PowerMockito.mock(Exchange.class);
+ Message inMessage = PowerMockito.mock(Message.class);
+ Message outMessage = PowerMockito.mock(Message.class);
+ PowerMockito.when(exchange.getIn()).thenReturn(inMessage);
+ PowerMockito.when(inMessage.getBody()).thenReturn(obj);
+
+ PowerMockito.when(exchange.getOut()).thenReturn(outMessage);
+ PowerMockito.doNothing().when(outMessage).setBody(anyObject());
+ PowerMockito.doNothing().when(outMessage).setHeader(anyString(), anyObject());
+
+ return exchange;
+
+ }
+
+
+}
diff --git a/src/test/java/org/onap/aai/datarouter/policy/SpikeEventPolicyConfigTest.java b/src/test/java/org/onap/aai/datarouter/policy/SpikeEventPolicyConfigTest.java
new file mode 100644
index 0000000..831695e
--- /dev/null
+++ b/src/test/java/org/onap/aai/datarouter/policy/SpikeEventPolicyConfigTest.java
@@ -0,0 +1,59 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.datarouter.policy;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class SpikeEventPolicyConfigTest {
+
+ @Test
+ public void testAllMethods() {
+ SpikeEventPolicyConfig eConfig = new SpikeEventPolicyConfig();
+ eConfig.setSourceDomain("source-domain");
+ Assert.assertEquals(eConfig.getSourceDomain(),"source-domain");
+
+ eConfig.setSearchBaseUrl("http://base-url");
+ Assert.assertEquals(eConfig.getSearchBaseUrl(),"http://base-url");
+
+ eConfig.setSearchEndpoint("end-point");
+ Assert.assertEquals(eConfig.getSearchEndpoint(),"end-point");
+
+ eConfig.setSearchEndpointDocuments("end-document");
+ Assert.assertEquals(eConfig.getSearchEndpointDocuments(),"end-document");
+
+
+ eConfig.setSearchCertName("cert-name");
+ Assert.assertEquals(eConfig.getSearchCertName(),"cert-name");
+
+ eConfig.setSearchKeystore("key-store");
+ Assert.assertEquals(eConfig.getSearchKeystore(),"key-store");
+
+ eConfig.setSearchKeystorePwd("key-store-pass");
+ Assert.assertEquals(eConfig.getSearchKeystorePwd(),"key-store-pass");
+
+ }
+
+} \ No newline at end of file