summaryrefslogtreecommitdiffstats
path: root/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-01-03 16:14:54 +0000
committerJ Armstrong <joss.armstrong@ericsson.com>2019-01-03 16:19:01 +0000
commit3f7df6a33f5d08a8488a8a395de96d16787b1c1c (patch)
tree6f5ca351bb7df02abb31f146210eb201525845de /appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test
parent34aecca733edd7842139a33f57ea050dffb2f2ab (diff)
Increase code coverage in appc-dg-dependency-model
Increased coverage of sub-project from 50% to 80% Issue-ID: APPC-1301 Change-Id: Ib69b010cd34302a8a9c3b9a291bcbc351babd731 Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test')
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/helper/DependencyModelParserTest.java107
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImplTest.java63
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/flowbuilder/TestFlowBuilder.java10
3 files changed, 179 insertions, 1 deletions
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/helper/DependencyModelParserTest.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/helper/DependencyModelParserTest.java
new file mode 100644
index 000000000..e7951c61d
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/helper/DependencyModelParserTest.java
@@ -0,0 +1,107 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * =============================================================================
+ * 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.appc.dg.dependencymanager.helper;
+
+import java.io.IOException;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
+import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModelException;
+import org.onap.appc.dg.objects.VnfcDependencyModel;
+import org.onap.appc.dg.objects.Node;
+import org.onap.appc.domainmodel.Vnfc;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+public class DependencyModelParserTest {
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ DependencyModelParser parser = Mockito.spy(new DependencyModelParser());
+ ObjectMapper mockMapper;
+
+ @Before
+ public void setup() throws JsonProcessingException, IOException {
+ mockMapper = Mockito.mock(ObjectMapper.class);
+ ObjectNode mockNode = Mockito.mock(ObjectNode.class);
+ Mockito.doReturn(mockMapper).when(parser).getMapper();
+ Mockito.doReturn(mockNode).when(mockMapper).readTree("VNF_MODEL");
+ }
+
+ @Test
+ public void testGenerateDependencyModel() throws InvalidDependencyModelException, JsonProcessingException, IOException {
+ ObjectNode topologyTemplate = new ObjectNode(JsonNodeFactory.instance);
+ topologyTemplate = (ObjectNode) new ObjectMapper().readTree(jsonString);
+ Mockito.doReturn(topologyTemplate).when(mockMapper).readTree("VNF_MODEL");
+ VnfcDependencyModel model = parser.generateDependencyModel("VNF_MODEL", "VNF_TYPE");
+ Assert.assertEquals(2, model.getDependencies().size());
+ }
+
+ @Test
+ public void testGenerateDependencyModelWithNode() throws InvalidDependencyModelException, JsonProcessingException, IOException {
+ ObjectNode topologyTemplate = new ObjectNode(JsonNodeFactory.instance);
+ topologyTemplate = (ObjectNode) new ObjectMapper().readTree(jsonString);
+ Node<Vnfc> vnfc = new Node(new Vnfc());
+ Mockito.doReturn(vnfc).when(parser).getNode(Mockito.anySet(), Mockito.anyString());
+ Mockito.doReturn(topologyTemplate).when(mockMapper).readTree("VNF_MODEL");
+ VnfcDependencyModel model = parser.generateDependencyModel("VNF_MODEL", "VNF_TYPE");
+ Assert.assertEquals(0, model.getDependencies().size());
+ }
+
+ @Test
+ public void testGenerateDependencyModelExceptionFlow() throws InvalidDependencyModelException {
+ expectedEx.expect(InvalidDependencyModelException.class);
+ expectedEx.expectMessage("Dependency model is missing 'topology_template' or 'node_templates' elements");
+ VnfcDependencyModel model = parser.generateDependencyModel("VNF_MODEL", "VNF_TYPE");
+ }
+
+ private String jsonString = "{\"topology_template\": {" +
+ " \"node_templates\": {" +
+ " \"Property Definition_Template\": {" +
+ " \"type\": \"org.onap.resource.vfc.vnf_type.abstract.nodes.property definition\"," +
+ " \"properties\": {" +
+ " \"mandatory\": \"true\"," +
+ " \"high_availablity\": \"Active-Passive\"" +
+ " },\"requirements\": [" +
+ " {" +
+ " \"dependency\": {" +
+ " \"capability\": \"tosca.capabilities.Node\"," +
+ " \"node\": \"tosca.nodes.Root\"," +
+ " \"relationship\": \"tosca.relationships.DependsOn\"," +
+ " \"occurrences\": [" +
+ " 0," +
+ " \"UNBOUNDED\"" +
+ " ]" +
+ " }" +
+ " }" +
+ " ]" +
+ " },\"tosca.nodes.Root\": {\"type\": \"VNFC_NAME\"}" +
+ " }" +
+ " }" +
+ "}";
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImplTest.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImplTest.java
new file mode 100644
index 000000000..e0214b1d5
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/dependencymanager/impl/DependencyManagerImplTest.java
@@ -0,0 +1,63 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * =============================================================================
+ * 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.appc.dg.dependencymanager.impl;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.onap.appc.cache.MetadataCache;
+import org.onap.appc.cache.impl.MetadataCacheFactory;
+import org.onap.appc.cache.impl.MetadataCacheImpl;
+import org.onap.appc.dg.dependencymanager.DependencyManager;
+import org.onap.appc.dg.objects.DependencyTypes;
+import org.onap.appc.dg.objects.VnfcDependencyModel;
+import org.onap.appc.metadata.objects.DependencyModelIdentifier;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(MetadataCacheFactory.class)
+public class DependencyManagerImplTest {
+
+ private MetadataCacheFactory metadataCacheFactory = Mockito.mock(MetadataCacheFactory.class);
+ private MetadataCache<DependencyModelIdentifier,VnfcDependencyModel> cache;
+
+ @Before
+ public void setup() {
+ PowerMockito.mockStatic(MetadataCacheFactory.class);
+ PowerMockito.when(MetadataCacheFactory.getInstance()).thenReturn(metadataCacheFactory);
+ cache = (MetadataCacheImpl<DependencyModelIdentifier,VnfcDependencyModel>) Mockito.mock(MetadataCacheImpl.class);
+ PowerMockito.when(metadataCacheFactory.getMetadataCache()).thenReturn(cache);
+ }
+
+ @Test
+ public void testDependencyManager() throws Exception {
+ DependencyManager dmImpl = DependencyModelFactory.createDependencyManager();
+ DependencyModelIdentifier modelIdentifier = new DependencyModelIdentifier("VNF_TYPE", "CATALOG_VERSION");
+ DependencyTypes dependencyType = DependencyTypes.findByString("resource");
+ Mockito.when(cache.getObject(Mockito.any(DependencyModelIdentifier.class))).thenReturn(new VnfcDependencyModel(null));
+ dmImpl.getVnfcDependencyModel(modelIdentifier, dependencyType);
+ }
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/flowbuilder/TestFlowBuilder.java b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/flowbuilder/TestFlowBuilder.java
index 7b5800698..383417a1f 100644
--- a/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/flowbuilder/TestFlowBuilder.java
+++ b/appc-dg/appc-dg-shared/appc-dg-dependency-model/src/test/java/org/onap/appc/dg/flowbuilder/TestFlowBuilder.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +25,7 @@
package org.onap.appc.dg.flowbuilder;
+import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Test;
import org.onap.appc.dg.flowbuilder.FlowBuilder;
@@ -82,6 +85,8 @@ public class TestFlowBuilder {
list = itr.next();
Assert.assertTrue(list.contains(createVnfc("SMP","Active-Passive","SMP_Name")));
+
+ Assert.assertThat(flowModel.toString(), CoreMatchers.containsString("Flow Model : Vnfc : vnfcType = FE"));
}
@Test
@@ -140,7 +145,7 @@ public class TestFlowBuilder {
@Test(expected = InvalidDependencyModelException.class)
public void testCyclicBuilder() throws InvalidDependencyModelException {
- FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.FORWARD);
+ FlowBuilder builder = FlowBuilderFactory.getInstance().getFlowBuilder(FlowStrategies.findByString("FORWARD"));
VnfcDependencyModel dependencyModel = readCyclicDependencyModel();
InventoryModel inventoryModel = readInventoryModel();
builder.buildFlowModel(dependencyModel,inventoryModel);
@@ -164,6 +169,9 @@ public class TestFlowBuilder {
Node bNode = new Node(b);
Node cNode = new Node(c);
+ Assert.assertTrue(aNode.equals(aNode));
+ Assert.assertFalse(aNode.equals(bNode));
+
bNode.addParent(c);
cNode.addParent(b);