summaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src
diff options
context:
space:
mode:
authorKrzysztof Gajewski <krzysztof.gajewski@nokia.com>2020-05-29 16:05:13 +0200
committerKrzysztof Gajewski <krzysztof.gajewski@nokia.com>2020-05-29 16:05:13 +0200
commita30ad49b5434b0a2670d51e6aa54ee6ea82deb62 (patch)
tree05d8e88e0fdd22be50917e2d3f66b240445d1bff /bpmn/MSOCommonBPMN/src
parent6c1869316041e314007acb2f777ea89631c890b8 (diff)
Add JUnit code coverage for InstanceResourceList:
Issue-ID: SO-1576 Signed-off-by: Krzysztof Gajewski <krzysztof.gajewski@nokia.com> Change-Id: I51496fce24acdb8a9fc1b9fedde20b9cbbb8af68
Diffstat (limited to 'bpmn/MSOCommonBPMN/src')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/InstanceResourceList.java12
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/InstnaceResourceListTest.java115
-rw-r--r--bpmn/MSOCommonBPMN/src/test/resources/__files/InstanceResourceList/InstanceResourceList.json9
3 files changed, 103 insertions, 33 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/InstanceResourceList.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/InstanceResourceList.java
index 3a4df68f02..963210b993 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/InstanceResourceList.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/InstanceResourceList.java
@@ -109,16 +109,20 @@ public class InstanceResourceList {
}
// check if the resource contains vf-module
- if (vnfResource != null && vnfResource.getVfModules() != null) {
+ if (isVnfResourceWithVfModule(vnfResource)) {
sequencedResourceList.addAll(vnfResource.getVfModules());
}
return sequencedResourceList;
}
+ private static boolean isVnfResourceWithVfModule(VnfResource vnfResource) {
+ return vnfResource != null && vnfResource.getVfModules() != null;
+ }
+
private static List<Resource> getGroupResourceInstanceList(VnfResource vnfResource, JsonObject vfObj) {
List<Resource> sequencedResourceList = new ArrayList<>();
- if (vnfResource.getGroupOrder() != null && !StringUtils.isEmpty(vnfResource.getGroupOrder())) {
+ if (isVnfGroupOrderFilled(vnfResource)) {
String[] grpSequence = vnfResource.getGroupOrder().split(",");
for (String grpType : grpSequence) {
for (GroupResource gResource : vnfResource.getGroups()) {
@@ -150,4 +154,8 @@ public class InstanceResourceList {
}
return sequencedResourceList;
}
+
+ private static boolean isVnfGroupOrderFilled(VnfResource vnfResource) {
+ return vnfResource.getGroupOrder() != null && !StringUtils.isEmpty(vnfResource.getGroupOrder());
+ }
}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/InstnaceResourceListTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/InstnaceResourceListTest.java
index f3233f2350..19e678d6b7 100644
--- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/InstnaceResourceListTest.java
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/InstnaceResourceListTest.java
@@ -8,6 +8,7 @@ import org.onap.so.bpmn.core.domain.Resource;
import org.onap.so.bpmn.core.domain.ResourceType;
import org.onap.so.bpmn.core.domain.VnfResource;
import org.onap.so.bpmn.core.domain.VnfcResource;
+import org.onap.so.bpmn.core.domain.ModuleResource;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
@@ -24,7 +25,7 @@ public class InstnaceResourceListTest {
String uuiRequest = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "InstanceResourceList" + ".json")));
List<Resource> instanceResourceList =
InstanceResourceList.getInstanceResourceList(createResourceSequence(), uuiRequest);
- Assert.assertEquals(7, instanceResourceList.size());
+ Assert.assertEquals(9, instanceResourceList.size());
Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(0).getResourceType());
Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(1).getResourceType());
Assert.assertEquals("device", instanceResourceList.get(1).getModelInfo().getModelName());
@@ -32,9 +33,12 @@ public class InstnaceResourceListTest {
Assert.assertEquals("sitewan", instanceResourceList.get(2).getModelInfo().getModelName());
Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(3).getResourceType());
Assert.assertEquals("sitewan", instanceResourceList.get(3).getModelInfo().getModelName());
- Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(4).getResourceType());
- Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(5).getResourceType());
+ Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(4).getResourceType());
+ Assert.assertEquals("dummy", instanceResourceList.get(4).getModelInfo().getModelName());
+ Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(5).getResourceType());
Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(6).getResourceType());
+ Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(7).getResourceType());
+ Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(8).getResourceType());
}
// Test when PK is empty
@@ -48,6 +52,63 @@ public class InstnaceResourceListTest {
Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(0).getResourceType());
}
+ @Test
+ public void testSimpleVFResourceWithGroup() throws IOException {
+ String uuiRequest = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "InstanceResourceList" + ".json")));
+ VnfResource vnfResource = new VnfResource();
+ vnfResource.setResourceInput("{\"a\":\"ipaddress|127.0.0.1\"}");
+
+ createGroupKeyResource(vnfResource);
+
+ List<Resource> instanceResourceList = InstanceResourceList.getInstanceResourceList(vnfResource, uuiRequest);
+ Assert.assertEquals(2, instanceResourceList.size());
+ Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(0).getResourceType());
+ Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(1).getResourceType());
+ Assert.assertEquals("wan", instanceResourceList.get(1).getModelInfo().getModelName());
+ }
+
+ @Test
+ public void testVFResourceWithEmptyGroup() throws IOException {
+ String uuiRequest = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "InstanceResourceList" + ".json")));
+ VnfResource vnfResource = new VnfResource();
+ vnfResource.setResourceInput("{\"a\":\"[emptygroup_list2,INDEX,name]\"}");
+
+ List<Resource> instanceResourceList = InstanceResourceList.getInstanceResourceList(vnfResource, uuiRequest);
+ Assert.assertEquals(1, instanceResourceList.size());
+ Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(0).getResourceType());
+ }
+
+ @Test
+ public void testVFResourceWithModule() throws IOException {
+ String uuiRequest = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "InstanceResourceList" + ".json")));
+ VnfResource vnfResource = new VnfResource();
+ vnfResource.setResourceInput("{\"a\":\"ipaddress|127.0.0.1\"}");
+
+ // Come from package org.onap.so.bpmn.core.domain.VnfResourceTest
+ List<ModuleResource> moduleResources;
+ moduleResources = new ArrayList<>();
+ ModuleResource moduleresource = getModuleResource();
+ moduleResources.add(moduleresource);
+ vnfResource.setModules(moduleResources);
+
+ List<Resource> instanceResourceList = InstanceResourceList.getInstanceResourceList(vnfResource, uuiRequest);
+ Assert.assertEquals(2, instanceResourceList.size());
+ Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(0).getResourceType());
+ Assert.assertEquals(ResourceType.MODULE, instanceResourceList.get(1).getResourceType());
+ }
+
+ private ModuleResource getModuleResource() {
+ ModuleResource moduleresource = new ModuleResource();
+ moduleresource.setVfModuleName("vfModuleName");
+ moduleresource.setHeatStackId("heatStackId");
+ moduleresource.setIsBase(true);
+ moduleresource.setVfModuleLabel("vfModuleLabel");
+ moduleresource.setInitialCount(0);
+ moduleresource.setVfModuleType("vfModuleType");
+ moduleresource.setHasVolumeGroup(true);
+ return moduleresource;
+ }
+
// Test when PK is not empty and PK does not contain any groups
@Test
public void testVFWithEmptyGroupResource() throws IOException {
@@ -66,16 +127,7 @@ public class InstnaceResourceListTest {
VnfResource vnfResource = new VnfResource();
vnfResource.setResourceInput("{\"a\":\"[emptygroup_list,INDEX,name]\"}");
- VnfcResource vnfcResource = new VnfcResource();
- vnfcResource.setResourceInput("{\"a\":\"test|default_value\"}");
- GroupResource groupResource = new GroupResource();
- groupResource.setVnfcs(Arrays.asList(vnfcResource));
- ModelInfo wanModel = new ModelInfo();
- wanModel.setModelName("wan");
- groupResource.setModelInfo(wanModel);
-
- vnfResource.setGroupOrder("wan");
- vnfResource.setGroups(Arrays.asList(groupResource));
+ createGroupKeyResource(vnfResource);
List<Resource> instanceResourceList = InstanceResourceList.getInstanceResourceList(vnfResource, uuiRequest);
Assert.assertEquals(2, instanceResourceList.size());
@@ -84,29 +136,34 @@ public class InstnaceResourceListTest {
Assert.assertEquals("wan", instanceResourceList.get(1).getModelInfo().getModelName());
}
+ private void createGroupKeyResource(VnfResource vnfResource) {
+ GroupResource groupResource = prepareGroupResource("{\"a\":\"test|default_value\"}", "wan");
+
+ vnfResource.setGroupOrder("wan");
+ vnfResource.setGroups(Arrays.asList(groupResource));
+ }
+
private VnfResource createResourceSequence() {
VnfResource vnfResource = new VnfResource();
vnfResource.setResourceInput("{\"a\":\"[sdwansiteresource_list,INDEX,sdwansiteresource_list]\"}");
- VnfcResource vnfcResource = new VnfcResource();
- vnfcResource.setResourceInput("{\"a\":\"[sdwansitewan_list,INDEX,test]\"}");
+ GroupResource groupResource = prepareGroupResource("{\"a\":\"[sdwansitewan_list,INDEX,test]\"}", "sitewan");
+ GroupResource groupResource2 = prepareGroupResource("{\"a\":\"[sdwandevice_list,INDEX,test]\"}", "device");
+ GroupResource groupDummyResource = prepareGroupResource("{\"a\":\"[dummy,INDEX,test]\"}", "dummy");
- GroupResource groupResource = new GroupResource();
- groupResource.setVnfcs(Arrays.asList(vnfcResource));
- ModelInfo wanModel = new ModelInfo();
- wanModel.setModelName("sitewan");
- groupResource.setModelInfo(wanModel);
+ vnfResource.setGroupOrder("device,sitewan,dummy");
+ vnfResource.setGroups(Arrays.asList(groupResource, groupResource2, groupDummyResource));
+ return vnfResource;
+ }
+ private GroupResource prepareGroupResource(String sourceInput, String modelName) {
VnfcResource vnfcDeviceResource = new VnfcResource();
- vnfcDeviceResource.setResourceInput("{\"a\":\"[sdwandevice_list,INDEX,test]\"}");
- GroupResource groupResource2 = new GroupResource();
- groupResource2.setVnfcs(Arrays.asList(vnfcDeviceResource));
+ vnfcDeviceResource.setResourceInput(sourceInput);
+ GroupResource groupResource = new GroupResource();
+ groupResource.setVnfcs(Arrays.asList(vnfcDeviceResource));
ModelInfo deviceModel = new ModelInfo();
- deviceModel.setModelName("device");
- groupResource2.setModelInfo(deviceModel);
-
- vnfResource.setGroupOrder("device,sitewan");
- vnfResource.setGroups(Arrays.asList(groupResource, groupResource2));
- return vnfResource;
+ deviceModel.setModelName(modelName);
+ groupResource.setModelInfo(deviceModel);
+ return groupResource;
}
}
diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/InstanceResourceList/InstanceResourceList.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/InstanceResourceList/InstanceResourceList.json
index a111ae2646..cf0f2d1933 100644
--- a/bpmn/MSOCommonBPMN/src/test/resources/__files/InstanceResourceList/InstanceResourceList.json
+++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/InstanceResourceList/InstanceResourceList.json
@@ -80,6 +80,9 @@
"portNumer":"0/0/1"
}
],
+ "emptygroup_list2": [
+
+ ],
"sdwanvpnresource_list":[
{
"sdwanvpn_topology":"hub_spoke",
@@ -155,7 +158,8 @@
"class":"VNF",
"systemIp":"20.20.20.1"
}
- ]
+ ],
+ "dummy":""
},
{
"sdwansite_emails":"chenchuanyu@huawei.com",
@@ -192,7 +196,8 @@
"class":"PNF",
"systemIp":"20.20.20.2"
}
- ]
+ ],
+ "dummy":""
}
]
}