diff options
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/test/java')
6 files changed, 328 insertions, 278 deletions
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/BuildingBlockTestDataSetup.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/BuildingBlockTestDataSetup.java index 79a94d5298..3bb417741f 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/BuildingBlockTestDataSetup.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/BuildingBlockTestDataSetup.java @@ -325,6 +325,7 @@ public class BuildingBlockTestDataSetup { gBBInput.setCustomer(buildCustomer()); } gBBInput.getCustomer().getServiceSubscription().getServiceInstances().add(serviceInstance); + gBBInput.setServiceInstance(serviceInstance); lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstance.getServiceInstanceId()); return serviceInstance; 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 new file mode 100644 index 0000000000..3be67c965c --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/InstnaceResourceListTest.java @@ -0,0 +1,46 @@ +package org.onap.so.bpmn.common.resource; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.so.bpmn.core.domain.GroupResource; +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 java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class InstnaceResourceListTest { + + public static String RESOURCE_PATH = "src/test/resources/__files/InstanceResourceList/"; + + @Test + public void testInstanceResourceList() throws IOException { + String uuiRequest = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "InstanceResourceList" + ".json"))); + List<Resource> instanceResourceList = + InstanceResourceList.getInstanceResourceList(createResourceSequence(), uuiRequest); + Assert.assertEquals(4, instanceResourceList.size()); + Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(0).getResourceType()); + Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(1).getResourceType()); + Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(2).getResourceType()); + Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(3).getResourceType()); + } + + private List<Resource> createResourceSequence() { + List<Resource> resourceList = new ArrayList<>(); + 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 = new GroupResource(); + groupResource.setVnfcs(Arrays.asList(vnfcResource)); + + return Arrays.asList(vnfResource, groupResource); + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilderTest.java index c7c181744f..557ae6df51 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilderTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilderTest.java @@ -19,232 +19,93 @@ */ package org.onap.so.bpmn.common.resource; +import java.util.ArrayList; +import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import org.onap.so.BaseTest; import java.util.HashMap; import java.util.List; import java.util.Map; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.so.bpmn.core.domain.GroupResource; +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.mock.FileUtil; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.ok; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.junit.Assert.assertEquals; - +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class ResourceRequestBuilderTest extends BaseTest { - @Test - public void getResourceInputTest() throws Exception { + private Map<String, Object> userInputMap = null; + private Map<String, Object> serviceInput = null; + @Before + public void initializeMockObjects() { - wireMockServer.stubFor(get(urlEqualTo( - "/ecomp/mso/catalog/v2/serviceResources?serviceModelUuid=c3954379-4efe-431c-8258-f84905b158e5")) - .willReturn(ok("{ \"serviceResources\" : {\n" + "\t\"modelInfo\" : {\n" - + "\t\t\"modelName\" : \"demoVFWCL\",\n" - + "\t\t\"modelUuid\" : \"c3954379-4efe-431c-8258-f84905b158e5\",\n" - + "\t\t\"modelInvariantUuid\" : \"0cbff61e-3b0a-4eed-97ce-b1b4faa03493\",\n" - + "\t\t\"modelVersion\" : \"1.0\"\n" + "\t},\n" - + "\t\"serviceType\" : \"\",\n" + "\t\"serviceRole\" : \"\",\n" - + "\t\"environmentContext\" : null,\n" + "\t\"resourceOrder\" : \"res1,res2\",\n" - + "\t\"workloadContext\" : \"Production\",\n" + "\t\"serviceVnfs\": [\n" + "\t\n" - + "\t\t{ \"modelInfo\" : {\n" - + "\t\t\t\"modelName\" : \"15968a6e-2fe5-41bf-a481\",\n" - + "\t\t\t\"modelUuid\" : \"808abda3-2023-4105-92d2-e62644b61d53\",\n" - + "\t\t\t\"modelInvariantUuid\" : \"6e4ffc7c-497e-4a77-970d-af966e642d31\",\n" - + "\t\t\t\"modelVersion\" : \"1.0\",\n" - + "\t\t\t\"modelCustomizationUuid\" : \"a00404d5-d7eb-4c46-b6b6-9cf2d087e545\",\n" - + "\t\t\t\"modelInstanceName\" : \"15968a6e-2fe5-41bf-a481 0\"\n" + "\t\t\t},\n" - + "\t\t\"toscaNodeType\" : \"org.openecomp.resource.vf.15968a6e2fe541bfA481\",\n" - + "\t\t\"nfFunction\" \t: null,\n" - + "\"resourceInput\":\"{\\\"a\\\":\\\"b\\\"}\"," - + "\t\t\"nfType\" \t\t: null,\n" - + "\t\t\"nfRole\" \t\t: null,\n" - + "\t\t\"nfNamingCode\" \t: null,\n" - + "\t\t\"multiStageDesign\" : \"false\",\n" + "\t\t\t\"vfModules\": [\n" - + "\t\t\t\t{\n" + "\t\t\t\t\t\"modelInfo\" : { \n" - + "\t\t\t\t\t\t\"modelName\" : \"15968a6e2fe541bfA481..base_vfw..module-0\",\n" - + "\t\t\t\t\t\t\"modelUuid\" : \"ec7fadde-1e5a-42f7-8255-cb19e475ff45\",\n" - + "\t\t\t\t\t\t\"modelInvariantUuid\" : \"61ab8b64-a014-4cf3-8a5a-b5ef388f8819\",\n" - + "\t\t\t\t\t\t\"modelVersion\" : \"1\",\n" - + "\t\t\t\t\t\t\"modelCustomizationUuid\" : \"123aff6b-854f-4026-ae1e-cc74a3924576\"\n" - + "\t\t\t\t\t},\t\t\"isBase\" : true,\n" - + "\t\t\t\t\t\"vfModuleLabel\" : \"base_vfw\",\n" - + "\t\t\t\t\t\"initialCount\" : 1,\n" - + "\t\t\t\t\t\"hasVolumeGroup\" : true\n" + "\t\t\t\t}\n" + "\t\t\t]\n" - + "\t\t},\n" + "\t\n" + "\t\t{ \"modelInfo\" : {\n" - + "\t\t\t\"modelName\" : \"f971106a-248f-4202-9d1f\",\n" - + "\t\t\t\"modelUuid\" : \"4fbc08a4-35ed-4a59-9e47-79975e4add7e\",\n" - + "\t\t\t\"modelInvariantUuid\" : \"c669799e-adf1-46ae-8c70-48b326fe89f3\",\n" - + "\t\t\t\"modelVersion\" : \"1.0\",\n" - + "\t\t\t\"modelCustomizationUuid\" : \"e776449e-2b10-45c5-9217-2775c88ca1a0\",\n" - + "\t\t\t\"modelInstanceName\" : \"f971106a-248f-4202-9d1f 0\"\n" + "\t\t\t},\n" - + "\t\t\"toscaNodeType\" : \"org.openecomp.resource.vf.F971106a248f42029d1f\",\n" - + "\t\t\"nfFunction\" \t: null,\n" - + "\t\t\"nfType\" \t\t: null,\n" - + "\t\t\"nfRole\" \t\t: null,\n" - + "\"resourceInput\":\"{\\\"a\\\":\\\"key|default_value\\\"}\"," - + "\t\t\"nfNamingCode\" \t: null,\n" - + "\t\t\"multiStageDesign\" : \"false\",\n" + "\t\t\t\"vfModules\": [\n" - + "\t\t\t\t{\n" + "\t\t\t\t\t\"modelInfo\" : { \n" - + "\t\t\t\t\t\t\"modelName\" : \"F971106a248f42029d1f..base_vpkg..module-0\",\n" - + "\t\t\t\t\t\t\"modelUuid\" : \"47d5273a-7456-4786-9035-b3911944cc35\",\n" - + "\t\t\t\t\t\t\"modelInvariantUuid\" : \"0ea3e57e-ac7a-425a-928b-b4aee8806c15\",\n" - + "\t\t\t\t\t\t\"modelVersion\" : \"1\",\n" - + "\t\t\t\t\t\t\"modelCustomizationUuid\" : \"9ed9fef6-d3f8-4433-9807-7e23393a16bc\"\n" - + "\t\t\t\t\t},\t\t\"isBase\" : true,\n" - + "\t\t\t\t\t\"vfModuleLabel\" : \"base_vpkg\",\n" - + "\t\t\t\t\t\"initialCount\" : 1,\n" - + "\t\t\t\t\t\"hasVolumeGroup\" : true\n" + "\t\t\t\t}\n" + "\t\t\t]\n" - + "\t\t}\n" + "\t],\n" + "\t\"serviceNetworks\": [],\n" - + "\t\"serviceAllottedResources\": []\n" + "\t}}"))); + if (null == this.userInputMap) { + ObjectMapper mapper = new ObjectMapper(); - // when(UrnPropertiesReader.getVariable(anyString())).thenReturn("http://localhost:8080"); + try { + String serviceInputRequest = FileUtil.readResourceFile("__files/UUI-SO-REQ.json"); + this.userInputMap = mapper.readValue(serviceInputRequest, new TypeReference<Map<String, Object>>() {}); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + if (null == this.serviceInput) { + + try { + ObjectMapper mapper = new ObjectMapper(); + String serviceInputRequest = FileUtil.readResourceFile("__files/SERVICE-SO-REQ-INPUT.json"); + this.serviceInput = mapper.readValue(serviceInputRequest, new TypeReference<Map<String, Object>>() {}); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + } + + @Test + public void getResourceInputTest() throws Exception { + + VnfResource resource = new VnfResource(); + resource.setResourceType(ResourceType.VNF); + resource.setResourceInput("{\"a\":\"key|default_value\"}"); HashMap serviceInput = new HashMap(); serviceInput.put("key", "value"); - Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest( - "c3954379-4efe-431c-8258-f84905b158e5", "e776449e-2b10-45c5-9217-2775c88ca1a0", serviceInput); + Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resource, serviceInput, null); assertEquals(stringObjectMap.get("a"), "value"); } @Test public void getResourceInputDefaultValueTest() throws Exception { - - wireMockServer.stubFor(get(urlEqualTo( - "/ecomp/mso/catalog/v2/serviceResources?serviceModelUuid=c3954379-4efe-431c-8258-f84905b158e5")) - .willReturn(ok("{ \"serviceResources\" : {\n" + "\t\"modelInfo\" : {\n" - + "\t\t\"modelName\" : \"demoVFWCL\",\n" - + "\t\t\"modelUuid\" : \"c3954379-4efe-431c-8258-f84905b158e5\",\n" - + "\t\t\"modelInvariantUuid\" : \"0cbff61e-3b0a-4eed-97ce-b1b4faa03493\",\n" - + "\t\t\"modelVersion\" : \"1.0\"\n" + "\t},\n" - + "\t\"serviceType\" : \"\",\n" + "\t\"serviceRole\" : \"\",\n" - + "\t\"environmentContext\" : null,\n" + "\t\"workloadContext\" : \"Production\",\n" - + "\t\"serviceVnfs\": [\n" + "\t\n" + "\t\t{ \"modelInfo\" : {\n" - + "\t\t\t\"modelName\" : \"15968a6e-2fe5-41bf-a481\",\n" - + "\t\t\t\"modelUuid\" : \"808abda3-2023-4105-92d2-e62644b61d53\",\n" - + "\t\t\t\"modelInvariantUuid\" : \"6e4ffc7c-497e-4a77-970d-af966e642d31\",\n" - + "\t\t\t\"modelVersion\" : \"1.0\",\n" - + "\t\t\t\"modelCustomizationUuid\" : \"a00404d5-d7eb-4c46-b6b6-9cf2d087e545\",\n" - + "\t\t\t\"modelInstanceName\" : \"15968a6e-2fe5-41bf-a481 0\"\n" + "\t\t\t},\n" - + "\t\t\"toscaNodeType\" : \"org.openecomp.resource.vf.15968a6e2fe541bfA481\",\n" - + "\t\t\"nfFunction\" \t: null,\n" - + "\"resourceInput\":\"{\\\"a\\\":\\\"b\\\"}\"," - + "\t\t\"nfType\" \t\t: null,\n" - + "\t\t\"nfRole\" \t\t: null,\n" - + "\t\t\"nfNamingCode\" \t: null,\n" - + "\t\t\"multiStageDesign\" : \"false\",\n" + "\t\t\t\"vfModules\": [\n" - + "\t\t\t\t{\n" + "\t\t\t\t\t\"modelInfo\" : { \n" - + "\t\t\t\t\t\t\"modelName\" : \"15968a6e2fe541bfA481..base_vfw..module-0\",\n" - + "\t\t\t\t\t\t\"modelUuid\" : \"ec7fadde-1e5a-42f7-8255-cb19e475ff45\",\n" - + "\t\t\t\t\t\t\"modelInvariantUuid\" : \"61ab8b64-a014-4cf3-8a5a-b5ef388f8819\",\n" - + "\t\t\t\t\t\t\"modelVersion\" : \"1\",\n" - + "\t\t\t\t\t\t\"modelCustomizationUuid\" : \"123aff6b-854f-4026-ae1e-cc74a3924576\"\n" - + "\t\t\t\t\t},\t\t\"isBase\" : true,\n" - + "\t\t\t\t\t\"vfModuleLabel\" : \"base_vfw\",\n" - + "\t\t\t\t\t\"initialCount\" : 1,\n" - + "\t\t\t\t\t\"hasVolumeGroup\" : true\n" + "\t\t\t\t}\n" + "\t\t\t]\n" - + "\t\t},\n" + "\t\n" + "\t\t{ \"modelInfo\" : {\n" - + "\t\t\t\"modelName\" : \"f971106a-248f-4202-9d1f\",\n" - + "\t\t\t\"modelUuid\" : \"4fbc08a4-35ed-4a59-9e47-79975e4add7e\",\n" - + "\t\t\t\"modelInvariantUuid\" : \"c669799e-adf1-46ae-8c70-48b326fe89f3\",\n" - + "\t\t\t\"modelVersion\" : \"1.0\",\n" - + "\t\t\t\"modelCustomizationUuid\" : \"e776449e-2b10-45c5-9217-2775c88ca1a0\",\n" - + "\t\t\t\"modelInstanceName\" : \"f971106a-248f-4202-9d1f 0\"\n" + "\t\t\t},\n" - + "\t\t\"toscaNodeType\" : \"org.openecomp.resource.vf.F971106a248f42029d1f\",\n" - + "\t\t\"nfFunction\" \t: null,\n" - + "\t\t\"nfType\" \t\t: null,\n" - + "\t\t\"nfRole\" \t\t: null,\n" - + "\"resourceInput\":\"{\\\"a\\\":\\\"key|default_value\\\"}\"," - + "\t\t\"nfNamingCode\" \t: null,\n" - + "\t\t\"multiStageDesign\" : \"false\",\n" + "\t\t\t\"vfModules\": [\n" - + "\t\t\t\t{\n" + "\t\t\t\t\t\"modelInfo\" : { \n" - + "\t\t\t\t\t\t\"modelName\" : \"F971106a248f42029d1f..base_vpkg..module-0\",\n" - + "\t\t\t\t\t\t\"modelUuid\" : \"47d5273a-7456-4786-9035-b3911944cc35\",\n" - + "\t\t\t\t\t\t\"modelInvariantUuid\" : \"0ea3e57e-ac7a-425a-928b-b4aee8806c15\",\n" - + "\t\t\t\t\t\t\"modelVersion\" : \"1\",\n" - + "\t\t\t\t\t\t\"modelCustomizationUuid\" : \"9ed9fef6-d3f8-4433-9807-7e23393a16bc\"\n" - + "\t\t\t\t\t},\t\t\"isBase\" : true,\n" - + "\t\t\t\t\t\"vfModuleLabel\" : \"base_vpkg\",\n" - + "\t\t\t\t\t\"initialCount\" : 1,\n" - + "\t\t\t\t\t\"hasVolumeGroup\" : true\n" + "\t\t\t\t}\n" + "\t\t\t]\n" - + "\t\t}\n" + "\t],\n" + "\t\"serviceNetworks\": [],\n" - + "\t\"serviceAllottedResources\": []\n" + "\t}}"))); - - // when(UrnPropertiesReader.getVariable(anyString())).thenReturn("http://localhost:8080"); + VnfResource resource = new VnfResource(); + resource.setResourceType(ResourceType.VNF); + resource.setResourceInput("{\"a\":\"key|default_value\"}"); HashMap serviceInput = new HashMap(); serviceInput.put("key1", "value"); - Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest( - "c3954379-4efe-431c-8258-f84905b158e5", "e776449e-2b10-45c5-9217-2775c88ca1a0", serviceInput); + Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resource, serviceInput, null); assertEquals(stringObjectMap.get("a"), "default_value"); } @Test public void getResourceInputValueNoDefaultTest() throws Exception { - - wireMockServer.stubFor(get(urlEqualTo( - "/ecomp/mso/catalog/v2/serviceResources?serviceModelUuid=c3954379-4efe-431c-8258-f84905b158e5")) - .willReturn(ok("{ \"serviceResources\" : {\n" + "\t\"modelInfo\" : {\n" - + "\t\t\"modelName\" : \"demoVFWCL\",\n" - + "\t\t\"modelUuid\" : \"c3954379-4efe-431c-8258-f84905b158e5\",\n" - + "\t\t\"modelInvariantUuid\" : \"0cbff61e-3b0a-4eed-97ce-b1b4faa03493\",\n" - + "\t\t\"modelVersion\" : \"1.0\"\n" + "\t},\n" - + "\t\"serviceType\" : \"\",\n" + "\t\"serviceRole\" : \"\",\n" - + "\t\"environmentContext\" : null,\n" + "\t\"workloadContext\" : \"Production\",\n" - + "\t\"serviceVnfs\": [\n" + "\t\n" + "\t\t{ \"modelInfo\" : {\n" - + "\t\t\t\"modelName\" : \"15968a6e-2fe5-41bf-a481\",\n" - + "\t\t\t\"modelUuid\" : \"808abda3-2023-4105-92d2-e62644b61d53\",\n" - + "\t\t\t\"modelInvariantUuid\" : \"6e4ffc7c-497e-4a77-970d-af966e642d31\",\n" - + "\t\t\t\"modelVersion\" : \"1.0\",\n" - + "\t\t\t\"modelCustomizationUuid\" : \"a00404d5-d7eb-4c46-b6b6-9cf2d087e545\",\n" - + "\t\t\t\"modelInstanceName\" : \"15968a6e-2fe5-41bf-a481 0\"\n" + "\t\t\t},\n" - + "\t\t\"toscaNodeType\" : \"org.openecomp.resource.vf.15968a6e2fe541bfA481\",\n" - + "\t\t\"nfFunction\" \t: null,\n" - + "\"resourceInput\":\"{\\\"a\\\":\\\"b\\\"}\"," - + "\t\t\"nfType\" \t\t: null,\n" - + "\t\t\"nfRole\" \t\t: null,\n" - + "\t\t\"nfNamingCode\" \t: null,\n" - + "\t\t\"multiStageDesign\" : \"false\",\n" + "\t\t\t\"vfModules\": [\n" - + "\t\t\t\t{\n" + "\t\t\t\t\t\"modelInfo\" : { \n" - + "\t\t\t\t\t\t\"modelName\" : \"15968a6e2fe541bfA481..base_vfw..module-0\",\n" - + "\t\t\t\t\t\t\"modelUuid\" : \"ec7fadde-1e5a-42f7-8255-cb19e475ff45\",\n" - + "\t\t\t\t\t\t\"modelInvariantUuid\" : \"61ab8b64-a014-4cf3-8a5a-b5ef388f8819\",\n" - + "\t\t\t\t\t\t\"modelVersion\" : \"1\",\n" - + "\t\t\t\t\t\t\"modelCustomizationUuid\" : \"123aff6b-854f-4026-ae1e-cc74a3924576\"\n" - + "\t\t\t\t\t},\t\t\"isBase\" : true,\n" - + "\t\t\t\t\t\"vfModuleLabel\" : \"base_vfw\",\n" - + "\t\t\t\t\t\"initialCount\" : 1,\n" - + "\t\t\t\t\t\"hasVolumeGroup\" : true\n" + "\t\t\t\t}\n" + "\t\t\t]\n" - + "\t\t},\n" + "\t\n" + "\t\t{ \"modelInfo\" : {\n" - + "\t\t\t\"modelName\" : \"f971106a-248f-4202-9d1f\",\n" - + "\t\t\t\"modelUuid\" : \"4fbc08a4-35ed-4a59-9e47-79975e4add7e\",\n" - + "\t\t\t\"modelInvariantUuid\" : \"c669799e-adf1-46ae-8c70-48b326fe89f3\",\n" - + "\t\t\t\"modelVersion\" : \"1.0\",\n" - + "\t\t\t\"modelCustomizationUuid\" : \"e776449e-2b10-45c5-9217-2775c88ca1a0\",\n" - + "\t\t\t\"modelInstanceName\" : \"f971106a-248f-4202-9d1f 0\"\n" + "\t\t\t},\n" - + "\t\t\"toscaNodeType\" : \"org.openecomp.resource.vf.F971106a248f42029d1f\",\n" - + "\t\t\"nfFunction\" \t: null,\n" - + "\t\t\"nfType\" \t\t: null,\n" - + "\t\t\"nfRole\" \t\t: null,\n" - + "\"resourceInput\":\"{\\\"a\\\":\\\"value\\\"}\"," - + "\t\t\"nfNamingCode\" \t: null,\n" - + "\t\t\"multiStageDesign\" : \"false\",\n" + "\t\t\t\"vfModules\": [\n" - + "\t\t\t\t{\n" + "\t\t\t\t\t\"modelInfo\" : { \n" - + "\t\t\t\t\t\t\"modelName\" : \"F971106a248f42029d1f..base_vpkg..module-0\",\n" - + "\t\t\t\t\t\t\"modelUuid\" : \"47d5273a-7456-4786-9035-b3911944cc35\",\n" - + "\t\t\t\t\t\t\"modelInvariantUuid\" : \"0ea3e57e-ac7a-425a-928b-b4aee8806c15\",\n" - + "\t\t\t\t\t\t\"modelVersion\" : \"1\",\n" - + "\t\t\t\t\t\t\"modelCustomizationUuid\" : \"9ed9fef6-d3f8-4433-9807-7e23393a16bc\"\n" - + "\t\t\t\t\t},\t\t\"isBase\" : true,\n" - + "\t\t\t\t\t\"vfModuleLabel\" : \"base_vpkg\",\n" - + "\t\t\t\t\t\"initialCount\" : 1,\n" - + "\t\t\t\t\t\"hasVolumeGroup\" : true\n" + "\t\t\t\t}\n" + "\t\t\t]\n" - + "\t\t}\n" + "\t],\n" + "\t\"serviceNetworks\": [],\n" - + "\t\"serviceAllottedResources\": []\n" + "\t}}"))); - - // when(UrnPropertiesReader.getVariable(anyString())).thenReturn("http://localhost:8080"); + VnfResource resource = new VnfResource(); + resource.setResourceType(ResourceType.VNF); + resource.setResourceInput("{\"a\":\"value\"}"); HashMap serviceInput = new HashMap(); serviceInput.put("key1", "value"); - Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest( - "c3954379-4efe-431c-8258-f84905b158e5", "e776449e-2b10-45c5-9217-2775c88ca1a0", serviceInput); + Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resource, serviceInput, null); assertEquals(stringObjectMap.get("a"), "value"); } @@ -322,68 +183,138 @@ public class ResourceRequestBuilderTest extends BaseTest { @Test public void getResourceInputWithEmptyServiceResourcesTest() throws Exception { - wireMockServer.stubFor(get(urlEqualTo( - "/ecomp/mso/catalog/v2/serviceResources?serviceModelUuid=c3954379-4efe-431c-8258-f84905b158e5")) - .willReturn(ok("{ \"serviceResources\" : {\n" + "\t\"modelInfo\" : {\n" - + "\t\t\"modelName\" : \"demoVFWCL\",\n" - + "\t\t\"modelUuid\" : \"c3954379-4efe-431c-8258-f84905b158e5\",\n" - + "\t\t\"modelInvariantUuid\" : \"0cbff61e-3b0a-4eed-97ce-b1b4faa03493\",\n" - + "\t\t\"modelVersion\" : \"1.0\"\n" + "\t},\n" - + "\t\"serviceType\" : \"\",\n" + "\t\"serviceRole\" : \"\",\n" - + "\t\"environmentContext\" : null,\n" + "\t\"workloadContext\" : \"Production\",\n" - + "\t\"serviceVnfs\": [], \n" + "\t\"serviceNetworks\": [],\n" - + "\t\"serviceAllottedResources\": []\n" + "\t}}"))); + VnfResource resource = new VnfResource(); + resource.setResourceType(ResourceType.VNF); + resource.setResourceInput(null); HashMap serviceInput = new HashMap(); serviceInput.put("key1", "value"); - Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest( - "c3954379-4efe-431c-8258-f84905b158e5", "e776449e-2b10-45c5-9217-2775c88ca1a0", serviceInput); + Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resource, serviceInput, null); assertEquals(0, stringObjectMap.size()); } @Test public void testGetResourceInputEmptyValue() { - wireMockServer.stubFor(get(urlEqualTo( - "/ecomp/mso/catalog/v2/serviceResources?serviceModelUuid=c3954379-4efe-431c-8258-f84905b158e5")) - .willReturn(ok("{ \"serviceResources\" : {\n" + "\t\"modelInfo\" : {\n" - + "\t\t\"modelName\" : \"demoVFWCL\",\n" - + "\t\t\"modelUuid\" : \"c3954379-4efe-431c-8258-f84905b158e5\",\n" - + "\t\t\"modelInvariantUuid\" : \"0cbff61e-3b0a-4eed-97ce-b1b4faa03493\",\n" - + "\t\t\"modelVersion\" : \"1.0\"\n" + "\t},\n" - + "\t\"serviceType\" : \"\",\n" + "\t\"serviceRole\" : \"\",\n" - + "\t\"environmentContext\" : null,\n" + "\t\"resourceOrder\" : \"res1,res2\",\n" - + "\t\"workloadContext\" : \"Production\",\n" + "\t\"serviceVnfs\": [\n" + "\t\n" - + "\t\t{ \"modelInfo\" : {\n" - + "\t\t\t\"modelName\" : \"15968a6e-2fe5-41bf-a481\",\n" - + "\t\t\t\"modelUuid\" : \"808abda3-2023-4105-92d2-e62644b61d53\",\n" - + "\t\t\t\"modelInvariantUuid\" : \"6e4ffc7c-497e-4a77-970d-af966e642d31\",\n" - + "\t\t\t\"modelVersion\" : \"1.0\",\n" - + "\t\t\t\"modelCustomizationUuid\" : \"a00404d5-d7eb-4c46-b6b6-9cf2d087e545\",\n" - + "\t\t\t\"modelInstanceName\" : \"15968a6e-2fe5-41bf-a481 0\"\n" + "\t\t\t},\n" - + "\t\t\"toscaNodeType\" : \"org.openecomp.resource.vf.15968a6e2fe541bfA481\",\n" - + "\t\t\"nfFunction\" \t: null,\n" - + "\"resourceInput\":\"{\\\"a\\\":\\\"key1|\\\"}\"," - + "\t\t\"nfType\" \t\t: null,\n" - + "\t\t\"nfRole\" \t\t: null,\n" - + "\t\t\"nfNamingCode\" \t: null,\n" - + "\t\t\"multiStageDesign\" : \"false\",\n" + "\t\t\t\"vfModules\": [\n" - + "\t\t\t\t{\n" + "\t\t\t\t\t\"modelInfo\" : { \n" - + "\t\t\t\t\t\t\"modelName\" : \"15968a6e2fe541bfA481..base_vfw..module-0\",\n" - + "\t\t\t\t\t\t\"modelUuid\" : \"ec7fadde-1e5a-42f7-8255-cb19e475ff45\",\n" - + "\t\t\t\t\t\t\"modelInvariantUuid\" : \"61ab8b64-a014-4cf3-8a5a-b5ef388f8819\",\n" - + "\t\t\t\t\t\t\"modelVersion\" : \"1\",\n" - + "\t\t\t\t\t\t\"modelCustomizationUuid\" : \"123aff6b-854f-4026-ae1e-cc74a3924576\"\n" - + "\t\t\t\t\t},\t\t\"isBase\" : true,\n" - + "\t\t\t\t\t\"vfModuleLabel\" : \"base_vfw\",\n" - + "\t\t\t\t\t\"initialCount\" : 1,\n" - + "\t\t\t\t\t\"hasVolumeGroup\" : true\n" + "\t\t\t\t}\n" + "\t\t\t]\n" - + "\t\t}]}}"))); + + VnfResource resource = new VnfResource(); + resource.setResourceType(ResourceType.VNF); + resource.setResourceInput("{\"a\":\"key1|\"}"); HashMap serviceInput = new HashMap(); serviceInput.put("key2", "value"); - Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest( - "c3954379-4efe-431c-8258-f84905b158e5", "a00404d5-d7eb-4c46-b6b6-9cf2d087e545", serviceInput); + Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest(resource, serviceInput, null); assertEquals(stringObjectMap.get("a"), ""); } + @Test + public void getListResourceInputTest() throws Exception { + + List<Map> vnfdata = null; + + List<Resource> resources = new ArrayList<>(); + if (this.serviceInput.containsKey("serviceResources")) { + vnfdata = (List<Map>) ((Map) this.serviceInput.get("serviceResources")).get("serviceVnfs"); + } + assertNotNull(vnfdata); + vnfdata.forEach(e -> { + if (e.get("resourceType").equals("VNF")) { + VnfResource r = new VnfResource(); + r.setResourceInput(e.get("resourceInput").toString()); + resources.add(r); + } else if (e.get("resourceType").equals("GROUP")) { + GroupResource r = new GroupResource(); + VnfcResource vfc = new VnfcResource(); + vfc.setResourceInput(e.get("resourceInput").toString()); + List<VnfcResource> vfcList = new ArrayList(); + vfcList.add(vfc); + r.setVnfcs(vfcList); + resources.add(r); + } + }); + + assertEquals(9, resources.size()); + + // VF level request + Map<String, Object> currentVFData = new HashMap<>(); + Map<String, Object> stringObjectMap = + ResourceRequestBuilder.buildResouceRequest(resources.get(0), this.userInputMap, currentVFData); + assertEquals("b", stringObjectMap.get("a")); + assertEquals("hub_spoke", stringObjectMap.get("topology")); + assertEquals("defaultvpn", stringObjectMap.get("name")); + assertTrue(((String) stringObjectMap.get("sitelist")).contains("[")); + + // vfc level request + stringObjectMap = + ResourceRequestBuilder.buildResouceRequest(resources.get(1), this.userInputMap, currentVFData); + assertEquals("", stringObjectMap.get("a")); + assertEquals("layer3-port", stringObjectMap.get("portswitch")); + assertEquals("192.168.10.1", stringObjectMap.get("ipAddress")); + assertEquals("vCPE", stringObjectMap.get("deviceName")); + + // vfc level request + stringObjectMap = + ResourceRequestBuilder.buildResouceRequest(resources.get(2), this.userInputMap, currentVFData); + assertEquals("", stringObjectMap.get("a")); + assertEquals("layer2-port", stringObjectMap.get("portswitch")); + assertEquals("192.168.11.1", stringObjectMap.get("ipAddress")); + assertEquals("CPE_Beijing", stringObjectMap.get("deviceName")); + + // VF level request + stringObjectMap = + ResourceRequestBuilder.buildResouceRequest(resources.get(3), this.userInputMap, currentVFData); + assertEquals("Huawei Private Cloud", stringObjectMap.get("address")); + assertEquals("dsvpn_hub1", stringObjectMap.get("role")); + assertTrue(((String) stringObjectMap.get("wanlist")).contains("[")); + assertTrue(((String) stringObjectMap.get("devlist")).contains("[")); + + // VFC request + stringObjectMap = + ResourceRequestBuilder.buildResouceRequest(resources.get(4), this.userInputMap, currentVFData); + assertEquals("Huawei Private Cloud", stringObjectMap.get("address")); + assertEquals("20000", stringObjectMap.get("postcode")); + assertEquals("single_gateway", stringObjectMap.get("type")); + assertEquals("vCPE", stringObjectMap.get("deviceName")); + assertEquals("DHCP", stringObjectMap.get("ipMode")); + + // VFC request again + stringObjectMap = + ResourceRequestBuilder.buildResouceRequest(resources.get(5), this.userInputMap, currentVFData); + assertEquals("Huawei Private Cloud", stringObjectMap.get("address")); + assertEquals("20000", stringObjectMap.get("postcode")); + assertEquals("single_gateway", stringObjectMap.get("type")); + assertEquals("20.20.20.1", stringObjectMap.get("systemip")); + assertEquals("default_ipv6", stringObjectMap.get("systemipv6")); + assertEquals("VNF", stringObjectMap.get("devclass")); + + // VF level request + stringObjectMap = + ResourceRequestBuilder.buildResouceRequest(resources.get(6), this.userInputMap, currentVFData); + assertEquals("Huawei Public Cloud", stringObjectMap.get("address")); + assertEquals("dsvpn_hub", stringObjectMap.get("role")); + assertTrue(((String) stringObjectMap.get("wanlist")).contains("[")); + assertTrue(((String) stringObjectMap.get("devlist")).contains("[")); + + // VFC request + stringObjectMap = + ResourceRequestBuilder.buildResouceRequest(resources.get(7), this.userInputMap, currentVFData); + assertEquals("Huawei Public Cloud", stringObjectMap.get("address")); + assertEquals("20001", stringObjectMap.get("postcode")); + assertEquals("multiple_gateway", stringObjectMap.get("type")); + assertEquals("CPE_Beijing", stringObjectMap.get("deviceName")); + assertEquals("Static", stringObjectMap.get("ipMode")); + + // VFC request again + stringObjectMap = + ResourceRequestBuilder.buildResouceRequest(resources.get(8), this.userInputMap, currentVFData); + assertEquals("Huawei Public Cloud", stringObjectMap.get("address")); + assertEquals("20001", stringObjectMap.get("postcode")); + assertEquals("multiple_gateway", stringObjectMap.get("type")); + assertEquals("20.20.20.2", stringObjectMap.get("systemip")); + assertEquals("default_ipv6", stringObjectMap.get("systemipv6")); + assertEquals("PNF", stringObjectMap.get("devclass")); + + + } + + } diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayerTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayerTest.java index 39650a2142..13d2b7d3d3 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayerTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayerTest.java @@ -398,10 +398,12 @@ public class BBInputSetupMapperLayerTest { @Test public void testMapAAIL3NetworkIntoL3Network() throws IOException { - L3Network expected = mapper.readValue(new File(RESOURCE_PATH + "l3NetworkExpected.json"), L3Network.class); + L3Network expected = + mapper.readValue(new File(RESOURCE_PATH + "l3NetworkExpectedWithSubnet.json"), L3Network.class); - org.onap.aai.domain.yang.L3Network aaiL3Network = mapper.readValue( - new File(RESOURCE_PATH + "aaiL3NetworkInput.json"), org.onap.aai.domain.yang.L3Network.class); + org.onap.aai.domain.yang.L3Network aaiL3Network = + mapper.readValue(new File(RESOURCE_PATH + "aaiL3NetworkInputWithSubnets.json"), + org.onap.aai.domain.yang.L3Network.class); L3Network actual = bbInputSetupMapperLayer.mapAAIL3Network(aaiL3Network); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java index e8d597a823..c5da3cbd51 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/ExecuteBuildlingBlockRainyDayTest.java @@ -68,6 +68,8 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { delegateExecution.setVariable("WorkflowException", new WorkflowException("", 7000, "")); delegateExecution.setVariable("buildingBlock", executeBuildingBlock); delegateExecution.setVariable("lookupKeyMap", lookupKeyMap); + + delegateExecution.setVariable("WorkflowException", new WorkflowException("processKey", 7000, "errorMessage")); } @Test @@ -101,12 +103,10 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { rainyDayHandlerStatus.setPolicy("Rollback"); rainyDayHandlerStatus.setWorkStep(ASTERISK); - doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient) - .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep( - "AssignServiceInstanceBB", "st1", "vnft1", "7000", "*"); + doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatus("AssignServiceInstanceBB", + "st1", "vnft1", "7000", "*", "errorMessage"); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true); - assertEquals("Rollback", delegateExecution.getVariable("handlingCode")); } @@ -126,15 +126,9 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { rainyDayHandlerStatus.setPolicy("Rollback"); rainyDayHandlerStatus.setWorkStep(ASTERISK); - doReturn(null).when(MOCK_catalogDbClient) - .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep( - "AssignServiceInstanceBB", "st1", "vnft1", "7000", ASTERISK); - doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient) - .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep( - "AssignServiceInstanceBB", ASTERISK, ASTERISK, ASTERISK, ASTERISK); - + doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatus("AssignServiceInstanceBB", + "st1", "vnft1", ASTERISK, ASTERISK, "errorMessage"); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true); - assertEquals("Rollback", delegateExecution.getVariable("handlingCode")); assertEquals(5, delegateExecution.getVariable("maxRetries")); } @@ -145,9 +139,8 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { serviceInstance.getModelInfoServiceInstance().setServiceType("st1"); vnf.setVnfType("vnft1"); delegateExecution.setVariable("aLaCarte", true); - doReturn(null).when(MOCK_catalogDbClient) - .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(isA(String.class), - isA(String.class), isA(String.class), isA(String.class), isA(String.class)); + doReturn(null).when(MOCK_catalogDbClient).getRainyDayHandlerStatus(isA(String.class), isA(String.class), + isA(String.class), isA(String.class), isA(String.class), isA(String.class)); delegateExecution.setVariable("suppressRollback", false); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true); @@ -157,9 +150,8 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { @Test public void queryRainyDayTableExceptionTest() { - doThrow(RuntimeException.class).when(MOCK_catalogDbClient) - .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep(isA(String.class), - isA(String.class), isA(String.class), isA(String.class), isA(String.class)); + doThrow(RuntimeException.class).when(MOCK_catalogDbClient).getRainyDayHandlerStatus(isA(String.class), + isA(String.class), isA(String.class), isA(String.class), isA(String.class), isA(String.class)); delegateExecution.setVariable("aLaCarte", true); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true); delegateExecution.setVariable("suppressRollback", false); @@ -184,9 +176,8 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { rainyDayHandlerStatus.setWorkStep(ASTERISK); rainyDayHandlerStatus.setSecondaryPolicy("Abort"); - doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient) - .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep( - "AssignServiceInstanceBB", "st1", "vnft1", "7000", "*"); + doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatus("AssignServiceInstanceBB", + "st1", "vnft1", "7000", "*", "errorMessage"); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, false); @@ -210,9 +201,8 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { rainyDayHandlerStatus.setWorkStep(ASTERISK); rainyDayHandlerStatus.setSecondaryPolicy("Abort"); - doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient) - .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep( - "AssignServiceInstanceBB", "st1", "vnft1", "7000", "*"); + doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatus("AssignServiceInstanceBB", + "st1", "vnft1", "7000", "*", "errorMessage"); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true); @@ -236,9 +226,8 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { rainyDayHandlerStatus.setWorkStep(ASTERISK); rainyDayHandlerStatus.setSecondaryPolicy("Abort"); - doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient) - .getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAndWorkStep( - "AssignServiceInstanceBB", "st1", "vnft1", "7000", "*"); + doReturn(rainyDayHandlerStatus).when(MOCK_catalogDbClient).getRainyDayHandlerStatus("AssignServiceInstanceBB", + "st1", "vnft1", "7000", "*", "errorMessage"); executeBuildingBlockRainyDay.queryRainyDayTable(delegateExecution, true); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderTest.java index ef066853ca..5f9aef67e6 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/exception/ExceptionBuilderTest.java @@ -7,9 +7,9 @@ * 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. @@ -21,17 +21,67 @@ package org.onap.so.client.exception; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; import org.junit.Test; -import org.onap.so.bpmn.mock.FileUtil; +import org.mockito.ArgumentMatchers; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.onap.aai.domain.yang.Vserver; import org.onap.so.BaseTest; +import org.onap.so.bpmn.common.DelegateExecutionImpl; +import org.onap.so.bpmn.core.WorkflowException; +import org.onap.so.bpmn.mock.FileUtil; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider; +import org.onap.so.objects.audit.AAIObjectAudit; +import org.onap.so.objects.audit.AAIObjectAuditList; +import org.springframework.beans.BeanUtils; +import com.fasterxml.jackson.core.JsonProcessingException; public class ExceptionBuilderTest extends BaseTest { private static final String RESOURCE_PATH = "__files/"; private static final String VALID_ERROR_MESSAGE = "{test error message}"; + @Mock + protected ExtractPojosForBB extractPojosForBB; + + @Spy + @InjectMocks + private ExceptionBuilder exceptionBuilder = new ExceptionBuilder(); + + GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); + + @Before + public void before() throws BBObjectNotFoundException, JsonProcessingException { + setCloudRegion(); + when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))) + .thenReturn(buildVfModule()); + AAIObjectAuditList auditList = new AAIObjectAuditList(); + auditList.setAuditType("create"); + auditList.setHeatStackName("testStackName"); + AAIObjectAudit vserver = new AAIObjectAudit(); + vserver.setAaiObjectType(AAIObjectType.VSERVER.typeName()); + vserver.setDoesObjectExist(false); + Vserver vs = new Vserver(); + vs.setVserverId("testVServerId"); + Vserver vServerShallow = new Vserver(); + BeanUtils.copyProperties(vs, vServerShallow, "LInterfaces"); + vserver.setAaiObject(vServerShallow); + auditList.getAuditList().add(vserver); + + execution.setVariable("auditInventoryResult", objectMapper.getMapper().writeValueAsString(auditList)); + } + @Test public void buildAndThrowWorkflowExceptionTest() { @@ -77,4 +127,35 @@ public class ExceptionBuilderTest extends BaseTest { assertEquals("MSOWorkflowException", bpmnException.getErrorCode()); } } + + @Test + public void processAuditExceptionTest() { + try { + Mockito.doReturn(extractPojosForBB).when(exceptionBuilder).getExtractPojosForBB(); + exceptionBuilder.processAuditException((DelegateExecutionImpl) execution, false); + } catch (BpmnError bpmnException) { + assertEquals("AAIInventoryFailure", bpmnException.getErrorCode()); + WorkflowException we = execution.getVariable("WorkflowException"); + assertNotNull(we); + assertEquals( + "create VF-Module testVfModuleId1 failed due to incomplete AAI vserver inventory population after stack testStackName was successfully created in cloud region testLcpCloudRegionId. MSO Audit indicates that the following was not created in AAI: vserver testVServerId.", + we.getErrorMessage()); + } + } + + @Test + public void processAuditExceptionContinueTest() { + try { + Mockito.doReturn(extractPojosForBB).when(exceptionBuilder).getExtractPojosForBB(); + exceptionBuilder.processAuditException((DelegateExecutionImpl) execution, true); + String sm = execution.getVariable("StatusMessage"); + assertNotNull(sm); + assertEquals( + "create VF-Module testVfModuleId1 failed due to incomplete AAI vserver inventory population after stack testStackName was successfully created in cloud region testLcpCloudRegionId. MSO Audit indicates that the following was not created in AAI: vserver testVServerId.", + sm); + } catch (BpmnError bpmnException) { + fail(); + } + } + } |