aboutsummaryrefslogtreecommitdiffstats
path: root/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap
diff options
context:
space:
mode:
authorPatrick Brady <pb071s@att.com>2017-12-13 11:19:06 -0800
committerPatrick Brady <pb071s@att.com>2017-12-13 11:19:17 -0800
commit781b1a6df324419c846c84ea983c18fc8362bfd3 (patch)
tree580008010dd50ca32db2ef6dc2e36628cf8c2b5b /appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap
parent161df8a94bb3b0c34ed16fd4fdba078bd1eeef9a (diff)
Third part of onap rename
This part of the commit changes the folder structure on all other folders of appc. Change-Id: I8acfa11cdfcdcd36be0e137245d1dd7324f1abd3 Signed-off-by: Patrick Brady <pb071s@att.com> Issue-ID: APPC-13
Diffstat (limited to 'appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap')
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java119
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java69
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/JsonDgUtilImplTest.java172
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVNFConfiguratorImpl.java108
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVnfExecutionFlowImpl.java420
5 files changed, 888 insertions, 0 deletions
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java
new file mode 100644
index 000000000..7c36360f8
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java
@@ -0,0 +1,119 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.dg.common.impl;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.*;
+import org.onap.appc.adapter.message.EventSender;
+import org.onap.appc.adapter.message.MessageDestination;
+import org.onap.appc.adapter.message.event.EventMessage;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import java.util.HashMap;
+import java.util.Map;
+
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({DCAEReporterPluginImpl.class, FrameworkUtil.class})
+public class DCAEReporterPluginImplTest {
+ private SvcLogicContext ctx;
+ private Map<String, String> params;
+
+ private final BundleContext bundleContext = Mockito.mock(BundleContext.class);
+ private final Bundle bundleService = Mockito.mock(Bundle.class);
+ private final ServiceReference sref = Mockito.mock(ServiceReference.class);
+
+ @InjectMocks
+ private DCAEReporterPluginImpl dcaeReporterPlugin;
+ @Spy
+ private EventSenderMock eventSender = new EventSenderMock();
+
+ private String apiVer = "2.0.0";
+ private String requestId = "123";
+ private String error = "test-error";
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp() throws NoSuchFieldException, IllegalAccessException {
+ PowerMockito.mockStatic(FrameworkUtil.class);
+ PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
+ PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
+ PowerMockito.when(bundleContext.getServiceReference(Matchers.any(Class.class))).thenReturn(sref);
+ PowerMockito.when(bundleContext.<EventSender>getService(sref)).thenReturn(eventSender);
+ }
+
+ @Test
+ public void testReportErrorDescriptionNullBwcModeFalse() throws Exception {
+ ctx = new SvcLogicContext();
+ params = new HashMap<>();
+ params.put("output.status.message", null);
+ ctx.setAttribute("input.common-header.api-ver", apiVer);
+ ctx.setAttribute("input.common-header.request-id", requestId);
+
+ errorReasonNullAssert();
+ }
+
+ @Test
+ public void testReportBwcFalse() throws Exception {
+ ctx = new SvcLogicContext();
+ params = new HashMap<>();
+ ctx.setAttribute("isBwcMode", "false");
+ params.put("output.status.message", error);
+ ctx.setAttribute("input.common-header.api-ver", apiVer);
+ ctx.setAttribute("input.common-header.request-id", requestId);
+
+ positiveAssert();
+ }
+
+ private void errorReasonNullAssert() throws APPCException {
+ dcaeReporterPlugin.report(params, ctx);
+ MessageDestination destination = eventSender.getDestination();
+ EventMessage msg = eventSender.getMsg();
+ Assert.assertEquals("wrong API version", apiVer, msg.getEventHeader().getApiVer());
+ Assert.assertEquals("wrong requestId", requestId, msg.getEventHeader().getEventId());
+ Assert.assertEquals("wrong error message", "Unknown", msg.getEventStatus().getReason());
+ Assert.assertEquals("wrong destination", destination.name(), "DCAE");
+ }
+
+ private void positiveAssert() throws APPCException {
+ dcaeReporterPlugin.report(params, ctx);
+ MessageDestination destination = eventSender.getDestination();
+ EventMessage msg = eventSender.getMsg();
+ Assert.assertEquals("wrong API version", apiVer, msg.getEventHeader().getApiVer());
+ Assert.assertEquals("wrong requestId", requestId, msg.getEventHeader().getEventId());
+ Assert.assertEquals("wrong error message", error, msg.getEventStatus().getReason());
+ Assert.assertEquals("wrong destination", destination.name(), "DCAE");
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java
new file mode 100644
index 000000000..cc30d3aea
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/EventSenderMock.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.dg.common.impl;
+
+import java.util.Map;
+
+import org.onap.appc.adapter.message.EventSender;
+import org.onap.appc.adapter.message.MessageDestination;
+import org.onap.appc.adapter.message.event.EventMessage;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+
+
+public class EventSenderMock implements EventSender {
+ EventMessage msg;
+ MessageDestination destination;
+
+ @Override
+ public boolean sendEvent(MessageDestination destination, EventMessage msg) {
+ if (destination != null && msg != null){
+ this.msg = msg;
+ this.destination = destination;
+ return true;
+ }
+ else{
+ return false;
+ }
+ }
+
+ @Override
+ public boolean sendEvent(MessageDestination destination, EventMessage msg, String eventTopicName) {
+ return false;
+ }
+
+ @Override
+ public boolean sendEvent(MessageDestination destination, Map<String, String> params, SvcLogicContext ctx) throws APPCException {
+ return false;
+ }
+
+ public EventMessage getMsg() {
+ return msg;
+ }
+
+ public MessageDestination getDestination() {
+ return destination;
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/JsonDgUtilImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/JsonDgUtilImplTest.java
new file mode 100644
index 000000000..6f5a0f13d
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/JsonDgUtilImplTest.java
@@ -0,0 +1,172 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.dg.common.impl;
+
+import ch.qos.logback.core.Appender;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.appc.dg.common.impl.JsonDgUtilImpl;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.mockito.Mockito.mock;
+
+public class JsonDgUtilImplTest {
+
+ private final Appender appender = mock(Appender.class);
+
+
+ @Test
+ public void testFlatAndAddToContext() throws Exception {
+ JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl();
+ String key = "payload";
+ String testValueKey = "test-key";
+ String testValueValue = "test-value";
+ String testValueKey2 = "test-key2";
+ String testValueValue2 = "test-value2";
+ String payload = "{\"" + testValueKey + "\": \"" + testValueValue + "\",\""+testValueKey2+"\": \""+testValueValue2+"\"}";
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> params = new HashMap<>();
+ params.put(key, payload);
+ jsonDgUtil.flatAndAddToContext(params, ctx);
+
+
+ Assert.assertEquals(ctx.getAttribute(testValueKey), testValueValue);
+ Assert.assertEquals(ctx.getAttribute(testValueKey2), testValueValue2);
+
+
+
+ }
+
+
+ @Test
+ public void testFlatAndAddToContextNegativeWrongPayload() throws Exception {
+ JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl();
+ String key = "payload";
+ String testValueKey = "test-key";
+ String testValueValue = "test-value";
+ String testValueKey2 = "test-key2";
+ String testValueValue2 = "test-value2";
+ String payload = "{{\"" + testValueKey + "\": \"" + testValueValue + "\",\""+testValueKey2+"\": \""+testValueValue2+"\"}";
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> params = new HashMap<>();
+ params.put(key, payload);
+ try {
+ jsonDgUtil.flatAndAddToContext(params, ctx);
+
+ } catch (APPCException e) {
+ Assert.assertNull(ctx.getAttribute(testValueKey));
+ Assert.assertNull(ctx.getAttribute(testValueKey2));
+ Assert.assertNotNull(ctx.getAttribute("error-message"));
+ }
+
+
+ }
+
+
+ @Test
+ public void testFlatAndAddToContextPayloadFromContext() throws Exception {
+ JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl();
+ String key = "payload";
+ String testValueKey = "test-key";
+ String testValueValue = "test-value";
+ String testValueKey2 = "test-key2";
+ String testValueValue2 = "test-value2";
+ String payload = "{\"" + testValueKey + "\": \"" + testValueValue + "\",\""+testValueKey2+"\": \""+testValueValue2+"\"}";
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> params = new HashMap<>();
+ params.put(key, "");
+ ctx.setAttribute("input.payload", payload);
+ jsonDgUtil.flatAndAddToContext(params, ctx);
+
+
+ Assert.assertEquals(ctx.getAttribute(testValueKey), testValueValue);
+ Assert.assertEquals(ctx.getAttribute(testValueKey2), testValueValue2);
+ }
+
+ @Test
+ public void testFlatAndAddToContextNegativeNullPayload() throws Exception {
+ JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl();
+ String testValueKey = "test-key";
+ String testValueKey2 = "test-key2";
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> params = new HashMap<>();
+ jsonDgUtil.flatAndAddToContext(params, ctx);
+
+
+ Assert.assertNull(ctx.getAttribute(testValueKey));
+ Assert.assertNull(ctx.getAttribute(testValueKey2));
+ }
+
+
+ @Test
+ public void testFlatAndAddToContextNegativeEmptyPayload() throws Exception {
+
+ JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl();
+ String key = "payload";
+ String testValueKey = "test-key";
+ String testValueKey2 = "test-key2";
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> params = new HashMap<>();
+ params.put(key, "");
+ jsonDgUtil.flatAndAddToContext(params, ctx);
+
+ Assert.assertNull(ctx.getAttribute(testValueKey));
+ Assert.assertNull(ctx.getAttribute(testValueKey2));
+ }
+
+
+ @Test
+ public void testGenerateOutputPayloadFromContext() throws Exception {
+
+ JsonDgUtilImpl jsonDgUtil = new JsonDgUtilImpl();
+ String key = "output.payload";
+ String key1 = "output.payload.test-key[0]";
+ String key2 = "output.payload.test-key[1]";
+ String testValueKey1 = "value1";
+ String testValueKey2 = "value2";
+
+ String key3 = "output.payload.test-key3";
+ String testValueKey3 = "value3";
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> params = new HashMap<>();
+ ctx.setAttribute(key1, testValueKey1);
+ ctx.setAttribute(key2, testValueKey2);
+ ctx.setAttribute(key3, testValueKey3);
+ jsonDgUtil.generateOutputPayloadFromContext(params, ctx);
+
+ Assert.assertNotNull(ctx.getAttribute(key));
+
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVNFConfiguratorImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVNFConfiguratorImpl.java
new file mode 100644
index 000000000..ca3e7f5e2
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVNFConfiguratorImpl.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.dg.common.impl;
+
+import org.onap.appc.dg.common.VNFConfigurator;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.mdsal.MDSALStore;
+import org.onap.appc.mdsal.impl.MDSALStoreFactory;
+import org.onap.appc.mdsal.impl.MDSALStoreImpl;
+import org.onap.appc.mdsal.objects.BundleInfo;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({MDSALStoreImpl.class,MDSALStoreFactory.class})
+public class TestVNFConfiguratorImpl {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestVNFConfiguratorImpl.class);
+
+ @Before
+ public void setUp() {
+ logger.setLevel(EELFLogger.Level.DEBUG);
+ }
+
+ @Test(expected = APPCException.class)
+ public void testValidations() throws APPCException {
+ VNFConfigurator configurator = new VNFConfiguratorImpl();
+ Map<String,String> params = new HashMap<String, String>();
+ params.put("uniqueId","uniqueId");
+ params.put("yang","yang");
+ params.put("configJSON","configJSON");
+ configurator.storeConfig(params,new SvcLogicContext());
+ }
+
+ @Test
+ public void testYangPresentScenario() throws APPCException {
+
+ VNFConfigurator configurator = new VNFConfiguratorImpl();
+ PowerMockito.mockStatic(MDSALStoreFactory.class);
+ MDSALStore mdsalStore = PowerMockito.mock(MDSALStoreImpl.class);
+ PowerMockito.when(MDSALStoreFactory.createMDSALStore()).thenReturn(mdsalStore);
+ PowerMockito.when(mdsalStore.isModulePresent(Matchers.anyString(),(Date) Matchers.anyObject())).thenReturn(true);
+
+ Map<String,String> params = new HashMap<String, String>();
+ params.put("uniqueId","uniqueId");
+ params.put("yang","yang");
+ params.put("configJSON","configJSON");
+ params.put("requestId","requestId");
+ configurator.storeConfig(params,new SvcLogicContext());
+ }
+
+ @Test
+ public void testYangAbsentScenario() throws Exception {
+
+ VNFConfigurator configurator = new VNFConfiguratorImpl();
+ PowerMockito.mockStatic(MDSALStoreFactory.class);
+
+ MDSALStore mdsalStore = PowerMockito.mock(MDSALStoreImpl.class);
+
+ PowerMockito.when(MDSALStoreFactory.createMDSALStore()).thenReturn(mdsalStore);
+
+ PowerMockito.when(mdsalStore.isModulePresent(Matchers.anyString(),(Date) Matchers.anyObject())).thenReturn(false);
+
+ PowerMockito.doNothing().when(mdsalStore).storeYangModule(Matchers.anyString(),(BundleInfo)Matchers.anyObject());
+
+ Map<String,String> params = new HashMap<>();
+ params.put("uniqueId","uniqueId");
+ params.put("yang","yang");
+ params.put("configJSON","configJSON");
+ params.put("requestId","requestId");
+ configurator.storeConfig(params,new SvcLogicContext());
+
+ }
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVnfExecutionFlowImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVnfExecutionFlowImpl.java
new file mode 100644
index 000000000..bad862030
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVnfExecutionFlowImpl.java
@@ -0,0 +1,420 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.dg.common.impl;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.onap.appc.dg.common.VnfExecutionFlow;
+import org.onap.appc.dg.common.impl.Constants;
+import org.onap.appc.dg.common.impl.VnfExecutionFlowImpl;
+import org.onap.appc.dg.dependencymanager.DependencyManager;
+import org.onap.appc.dg.dependencymanager.exception.DependencyModelNotFound;
+import org.onap.appc.dg.dependencymanager.impl.DependencyModelFactory;
+import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModel;
+import org.onap.appc.dg.objects.DependencyTypes;
+import org.onap.appc.dg.objects.Node;
+import org.onap.appc.dg.objects.VnfcDependencyModel;
+import org.onap.appc.domainmodel.Vnfc;
+import org.onap.appc.metadata.objects.DependencyModelIdentifier;
+import org.osgi.framework.FrameworkUtil;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TestVnfExecutionFlowImpl.class, FrameworkUtil.class,DependencyManager.class,DependencyModelFactory.class})
+public class TestVnfExecutionFlowImpl {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestVnfExecutionFlowImpl.class);
+
+ @Before
+ public void setUp() {
+ logger.setLevel(EELFLogger.Level.DEBUG);
+ }
+
+ @Test
+ public void testPositiveFlow() throws DependencyModelNotFound {
+ Map<String, String> params = prepareParams();
+ SvcLogicContext context = prepareContext();
+ VnfcDependencyModel dependencyModel = readDependencyModel();
+
+ PowerMockito.mockStatic(DependencyModelFactory.class);
+ DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
+
+ PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
+ PowerMockito.when(dependencyManager.getVnfcDependencyModel((
+ DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
+ .thenReturn(dependencyModel);
+
+ VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ vnfExecutionFlow.getVnfExecutionFlowData(params,context);
+ }
+
+ @Test
+ public void testComplexFlow() throws DependencyModelNotFound {
+ Map<String, String> params = prepareParams();
+ SvcLogicContext context = prepareContextForComplexDependency();
+ VnfcDependencyModel dependencyModel = readComplexDependencyModel();
+
+ PowerMockito.mockStatic(DependencyModelFactory.class);
+ DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
+
+ PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
+ PowerMockito.when(dependencyManager.getVnfcDependencyModel((
+ DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
+ .thenReturn(dependencyModel);
+
+ VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ vnfExecutionFlow.getVnfExecutionFlowData(params,context);
+ }
+
+ @Test(expected = InvalidDependencyModel.class)
+ public void testCycleFlow() throws DependencyModelNotFound {
+ Map<String, String> params = prepareParams();
+ SvcLogicContext context = prepareContextForComplexDependency();
+ VnfcDependencyModel dependencyModel = readCyclicDependencyModel();
+ PowerMockito.mockStatic(DependencyModelFactory.class);
+ DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
+
+ PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
+ PowerMockito.when(dependencyManager.getVnfcDependencyModel((
+ DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
+ .thenReturn(dependencyModel);
+
+ VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ vnfExecutionFlow.getVnfExecutionFlowData(params,context);
+ }
+
+ private VnfcDependencyModel readCyclicDependencyModel() {
+
+ Vnfc a = new Vnfc("A","Active-Passive",null);
+ Vnfc b = new Vnfc("B","Active-Active",null);
+ Vnfc c = new Vnfc("C","Active-Active",null);
+ Vnfc d = new Vnfc("D","Active-Active",null);
+ Vnfc e = new Vnfc("E","Active-Active",null);
+ Vnfc f = new Vnfc("F","Active-Active",null);
+ Vnfc g = new Vnfc("G","Active-Active",null);
+
+ Node aNode = new Node(a);
+ Node bNode = new Node(b);
+ Node cNode = new Node(c);
+ Node dNode = new Node(d);
+ Node eNode = new Node(e);
+ Node fNode = new Node(f);
+ Node gNode = new Node(g);
+
+ bNode.addParent(a);
+ cNode.addParent(a);
+ cNode.addParent(b);
+
+ bNode.addParent(d);
+ dNode.addParent(c);
+
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ dependencies.add(aNode);
+ dependencies.add(bNode);
+ dependencies.add(cNode);
+ dependencies.add(dNode);
+ dependencies.add(eNode);
+ dependencies.add(fNode);
+ dependencies.add(gNode);
+
+ return new VnfcDependencyModel(dependencies);
+
+ }
+
+ private SvcLogicContext prepareContextForComplexDependency() {
+ SvcLogicContext context = new SvcLogicContext();
+ context.setAttribute("input.action-identifiers.vnf-id","1");
+ context.setAttribute("vnf.type","vSCP");
+ context.setAttribute("vnf.vnfcCount","7");
+
+ context.setAttribute("vnf.vnfc[0].name","A");
+ context.setAttribute("vnf.vnfc[0].type","A");
+ context.setAttribute("vnf.vnfc[0].vm_count","2");
+ context.setAttribute("vnf.vnfc[0].vm[0].url","A1");
+ context.setAttribute("vnf.vnfc[0].vm[1].url","A2");
+
+ context.setAttribute("vnf.vnfc[1].name","B");
+ context.setAttribute("vnf.vnfc[1].type","B");
+ context.setAttribute("vnf.vnfc[1].vm_count","5");
+ context.setAttribute("vnf.vnfc[1].vm[0].url","B1");
+ context.setAttribute("vnf.vnfc[1].vm[1].url","B2");
+ context.setAttribute("vnf.vnfc[1].vm[2].url","B3");
+ context.setAttribute("vnf.vnfc[1].vm[3].url","B4");
+ context.setAttribute("vnf.vnfc[1].vm[4].url","B5");
+
+ context.setAttribute("vnf.vnfc[2].name","C");
+ context.setAttribute("vnf.vnfc[2].type","C");
+ context.setAttribute("vnf.vnfc[2].vm_count","4");
+ context.setAttribute("vnf.vnfc[2].vm[0].url","C1");
+ context.setAttribute("vnf.vnfc[2].vm[1].url","C2");
+ context.setAttribute("vnf.vnfc[2].vm[2].url","C3");
+ context.setAttribute("vnf.vnfc[2].vm[3].url","C4");
+
+ context.setAttribute("vnf.vnfc[3].name","D");
+ context.setAttribute("vnf.vnfc[3].type","D");
+ context.setAttribute("vnf.vnfc[3].vm_count","3");
+ context.setAttribute("vnf.vnfc[3].vm[0].url","D1");
+ context.setAttribute("vnf.vnfc[3].vm[1].url","D2");
+ context.setAttribute("vnf.vnfc[3].vm[2].url","D3");
+
+ context.setAttribute("vnf.vnfc[4].name","E");
+ context.setAttribute("vnf.vnfc[4].type","E");
+ context.setAttribute("vnf.vnfc[4].vm_count","2");
+ context.setAttribute("vnf.vnfc[4].vm[0].url","E1");
+ context.setAttribute("vnf.vnfc[4].vm[1].url","E2");
+
+ context.setAttribute("vnf.vnfc[5].name","F");
+ context.setAttribute("vnf.vnfc[5].type","F");
+ context.setAttribute("vnf.vnfc[5].vm_count","1");
+ context.setAttribute("vnf.vnfc[5].vm[0].url","F1");
+
+ context.setAttribute("vnf.vnfc[6].name","G");
+ context.setAttribute("vnf.vnfc[6].type","G");
+ context.setAttribute("vnf.vnfc[6].vm_count","1");
+ context.setAttribute("vnf.vnfc[6].vm[0].url","G1");
+
+
+ return context;
+ }
+
+ private VnfcDependencyModel readComplexDependencyModel() {
+ Vnfc a = new Vnfc("A","Active-Passive",null);
+ Vnfc b = new Vnfc("B","Active-Active",null);
+ Vnfc c = new Vnfc("C","Active-Active",null);
+ Vnfc d = new Vnfc("D","Active-Active",null);
+ Vnfc e = new Vnfc("E","Active-Active",null);
+ Vnfc f = new Vnfc("F","Active-Active",null);
+ Vnfc g = new Vnfc("G","Active-Active",null);
+
+
+ Node aNode = new Node(a);
+ Node bNode = new Node(b);
+ Node cNode = new Node(c);
+ Node dNode = new Node(d);
+ Node eNode = new Node(e);
+ Node fNode = new Node(f);
+ Node gNode = new Node(g);
+
+ bNode.addParent(a);
+ cNode.addParent(a);
+
+ dNode.addParent(b);
+ eNode.addParent(b);
+ gNode.addParent(b);
+
+ fNode.addParent(c);
+
+ gNode.addParent(f);
+
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ dependencies.add(aNode);
+ dependencies.add(bNode);
+ dependencies.add(cNode);
+ dependencies.add(dNode);
+ dependencies.add(eNode);
+ dependencies.add(fNode);
+ dependencies.add(gNode);
+
+ return new VnfcDependencyModel(dependencies);
+ }
+
+ private VnfcDependencyModel readDependencyModel() {
+
+ Vnfc smp = new Vnfc("SMP","Active-Passive",null);
+ Vnfc be = new Vnfc("BE","Active-Active",null);
+ Vnfc fe = new Vnfc("FE","Active-Active",null);
+
+
+ Node smpNode = new Node(smp);
+ Node beNode = new Node(be);
+ Node feNode = new Node(fe);
+
+ beNode.addParent(smp);
+ feNode.addParent(be);
+// smpNode.addParent(fe);
+
+ Set<Node<Vnfc>> dependencies = new HashSet<>();
+ dependencies.add(smpNode);
+ dependencies.add(feNode);
+ dependencies.add(beNode);
+
+ return new VnfcDependencyModel(dependencies);
+ }
+
+ private Map<String, String> prepareParams() {
+ Map<String,String> params = new HashMap<>();
+ params.put(Constants.DEPENDENCY_TYPE,"RESOURCE");
+ params.put(Constants.FLOW_STRATEGY,"FORWARD");
+
+ params.put(Constants.VNF_TYPE,"vSCP");
+ params.put(Constants.VNF_VERION,"1.00");
+ return params;
+ }
+
+ private SvcLogicContext prepareContext() {
+ SvcLogicContext context = new SvcLogicContext();
+ context.setAttribute("input.action-identifiers.vnf-id","1");
+ context.setAttribute("vnf.type","vSCP");
+ context.setAttribute("vnf.vnfcCount","3");
+
+ context.setAttribute("vnf.vnfc[0].name","SMPname");
+ context.setAttribute("vnf.vnfc[0].type","SMP");
+ context.setAttribute("vnf.vnfc[0].vm_count","2");
+ context.setAttribute("vnf.vnfc[0].vm[0].url","SMP_URL1");
+ context.setAttribute("vnf.vnfc[0].vm[1].url","SMP_URL2");
+
+ context.setAttribute("vnf.vnfc[1].name","BEname");
+ context.setAttribute("vnf.vnfc[1].type","BE");
+ context.setAttribute("vnf.vnfc[1].vm_count","5");
+ context.setAttribute("vnf.vnfc[1].vm[0].url","BE_URL1");
+ context.setAttribute("vnf.vnfc[1].vm[1].url","BE_URL2");
+ context.setAttribute("vnf.vnfc[1].vm[2].url","BE_URL3");
+ context.setAttribute("vnf.vnfc[1].vm[3].url","BE_URL4");
+ context.setAttribute("vnf.vnfc[1].vm[4].url","BE_URL5");
+
+ context.setAttribute("vnf.vnfc[2].name","FEname");
+ context.setAttribute("vnf.vnfc[2].type","FE");
+ context.setAttribute("vnf.vnfc[2].vm_count","2");
+ context.setAttribute("vnf.vnfc[2].vm[0].url","FE_URL1");
+ context.setAttribute("vnf.vnfc[2].vm[1].url","FE_URL2");
+
+ return context;
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testMissingVnfcTypeInDependencyModel() throws DependencyModelNotFound {
+ Map<String, String> params = prepareParams();
+ SvcLogicContext context = prepareContext();
+ context.setAttribute("vnf.vnfc[3].name","XEname");
+ context.setAttribute("vnf.vnfc[3].type","XE");
+ context.setAttribute("vnf.vnfc[3].vm_count","2");
+ context.setAttribute("vnf.vnfc[3].vm[0].url","XE_URL1");
+ context.setAttribute("vnf.vnfc[3].vm[1].url","XE_URL2");
+ context.setAttribute("vnf.vnfcCount","4");
+
+ VnfcDependencyModel dependencyModel = readDependencyModel();
+
+ PowerMockito.mockStatic(DependencyModelFactory.class);
+ DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
+
+ PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
+ PowerMockito.when(dependencyManager.getVnfcDependencyModel((
+ DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
+ .thenReturn(dependencyModel);
+
+ VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ vnfExecutionFlow.getVnfExecutionFlowData(params,context);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testMissingMandatoryVnfcTypeInInventoryModel() throws DependencyModelNotFound {
+ Map<String, String> params = prepareParams();
+ SvcLogicContext context = prepareContext();
+ VnfcDependencyModel dependencyModel = readDependencyModel();
+
+ Vnfc xe = new Vnfc("XE","Active-Active",null, true);
+ Node xeNode = new Node(xe);
+ dependencyModel.getDependencies().add(xeNode);
+
+ PowerMockito.mockStatic(DependencyModelFactory.class);
+ DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
+
+ PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
+ PowerMockito.when(dependencyManager.getVnfcDependencyModel((
+ DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
+ .thenReturn(dependencyModel);
+
+ VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ vnfExecutionFlow.getVnfExecutionFlowData(params,context);
+ }
+
+ @Test
+ public void testMissingOptionalVnfcTypeInInventoryModel() throws DependencyModelNotFound {
+ Map<String, String> params = prepareParams();
+ SvcLogicContext context = prepareContext();
+ VnfcDependencyModel dependencyModel = readDependencyModel();
+
+ Vnfc xe = new Vnfc("XE","Active-Active",null, false);
+ Node xeNode = new Node(xe);
+ dependencyModel.getDependencies().add(xeNode);
+
+ PowerMockito.mockStatic(DependencyModelFactory.class);
+ DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
+
+ PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
+ PowerMockito.when(dependencyManager.getVnfcDependencyModel((
+ DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
+ .thenReturn(dependencyModel);
+
+ VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ vnfExecutionFlow.getVnfExecutionFlowData(params,context);
+ }
+
+ @Test
+ public void testMissingOptionalVnfcTypeInInventoryModelWithDependentChild() throws DependencyModelNotFound {
+ Map<String, String> params = prepareParams();
+ SvcLogicContext context = prepareContext();
+ context.setAttribute("vnf.vnfc[3].name","YEname");
+ context.setAttribute("vnf.vnfc[3].type","YE");
+ context.setAttribute("vnf.vnfc[3].vm_count","2");
+ context.setAttribute("vnf.vnfc[3].vm[0].url","YE_URL1");
+ context.setAttribute("vnf.vnfc[3].vm[1].url","YE_URL2");
+ context.setAttribute("vnf.vnfcCount","4");
+
+ VnfcDependencyModel dependencyModel = readDependencyModel();
+
+ Vnfc xe = new Vnfc("XE","Active-Active",null, false);
+ Vnfc ye = new Vnfc("YE","Active-Active",null, true);
+ Node xeNode = new Node(xe);
+ Node yeNode = new Node(ye);
+ yeNode.addParent(xe);
+
+ dependencyModel.getDependencies().add(yeNode);
+ dependencyModel.getDependencies().add(xeNode);
+
+ PowerMockito.mockStatic(DependencyModelFactory.class);
+ DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
+
+ PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
+ PowerMockito.when(dependencyManager.getVnfcDependencyModel((
+ DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
+ .thenReturn(dependencyModel);
+
+ VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
+ vnfExecutionFlow.getVnfExecutionFlowData(params,context);
+ }
+}