diff options
author | Max Benjamin <max.benjamin@att.com> | 2020-01-22 14:11:13 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-01-22 14:11:13 +0000 |
commit | 66781db64d1839f283ce99278393f2c65baf9263 (patch) | |
tree | 81645f586d0727181c3552a8a605ab3766d344b1 /bpmn/MSOCommonBPMN/src | |
parent | d9691b0c73b0d9cace84ca1ed7b0a30ccecc3fbd (diff) | |
parent | 48fbeba2e552d6de26ed1f638ec7736c35d18019 (diff) |
Merge "Add fluent setters for BuildingBlocks and ExecuteBuildingBlock"
Diffstat (limited to 'bpmn/MSOCommonBPMN/src')
16 files changed, 1161 insertions, 502 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/BuildingBlock.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/BuildingBlock.java index c1591ad984..aa1d845ef8 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/BuildingBlock.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/BuildingBlock.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. @@ -27,7 +27,7 @@ import com.fasterxml.jackson.annotation.JsonRootName; @JsonRootName("buildingBlock") public class BuildingBlock implements Serializable { - private static final long serialVersionUID = -1144315411128866052L; + private static final long serialVersionUID = -1144315411128866053L; @JsonProperty("mso-id") private String msoId; @@ -48,56 +48,62 @@ public class BuildingBlock implements Serializable { return bpmnFlowName; } - public void setBpmnFlowName(String bpmnFlowName) { + public BuildingBlock setBpmnFlowName(String bpmnFlowName) { this.bpmnFlowName = bpmnFlowName; + return this; } public String getMsoId() { return msoId; } - public void setMsoId(String msoId) { + public BuildingBlock setMsoId(String msoId) { this.msoId = msoId; + return this; } public String getKey() { return key; } - public void setKey(String key) { + public BuildingBlock setKey(String key) { this.key = key; + return this; } - public Boolean getIsVirtualLink() { + public Boolean isVirtualLink() { return isVirtualLink; } - public void setIsVirtualLink(Boolean isVirtualLink) { + public BuildingBlock setIsVirtualLink(Boolean isVirtualLink) { this.isVirtualLink = isVirtualLink; + return this; } public String getVirtualLinkKey() { return virtualLinkKey; } - public void setVirtualLinkKey(String virtualLinkKey) { + public BuildingBlock setVirtualLinkKey(String virtualLinkKey) { this.virtualLinkKey = virtualLinkKey; + return this; } public String getBpmnScope() { return bpmnScope; } - public void setBpmnScope(String scope) { + public BuildingBlock setBpmnScope(String scope) { this.bpmnScope = scope; + return this; } public String getBpmnAction() { return bpmnAction; } - public void setBpmnAction(String action) { + public BuildingBlock setBpmnAction(String action) { this.bpmnAction = action; + return this; } - } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ExecuteBuildingBlock.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ExecuteBuildingBlock.java index f1de0cc6f6..abd301fa4d 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ExecuteBuildingBlock.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ExecuteBuildingBlock.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. @@ -24,10 +24,8 @@ import java.io.Serializable; import org.onap.so.serviceinstancebeans.RequestDetails; public class ExecuteBuildingBlock implements Serializable { - /** - * - */ - private static final long serialVersionUID = 1L; + + private static final long serialVersionUID = 2L; private BuildingBlock buildingBlock; private String requestId; private String apiVersion; @@ -44,87 +42,98 @@ public class ExecuteBuildingBlock implements Serializable { return buildingBlock; } - public void setBuildingBlock(BuildingBlock buildingBlock) { + public ExecuteBuildingBlock setBuildingBlock(BuildingBlock buildingBlock) { this.buildingBlock = buildingBlock; + return this; } public String getRequestId() { return requestId; } - public void setRequestId(String requestId) { + public ExecuteBuildingBlock setRequestId(String requestId) { this.requestId = requestId; + return this; } public String getApiVersion() { return apiVersion; } - public void setApiVersion(String apiVersion) { + public ExecuteBuildingBlock setApiVersion(String apiVersion) { this.apiVersion = apiVersion; + return this; } public String getResourceId() { return resourceId; } - public void setResourceId(String resourceId) { + public ExecuteBuildingBlock setResourceId(String resourceId) { this.resourceId = resourceId; + return this; } public String getRequestAction() { return requestAction; } - public void setRequestAction(String requestAction) { + public ExecuteBuildingBlock setRequestAction(String requestAction) { this.requestAction = requestAction; + return this; } public Boolean isaLaCarte() { return aLaCarte; } - public void setaLaCarte(Boolean aLaCarte) { + public ExecuteBuildingBlock setaLaCarte(Boolean aLaCarte) { this.aLaCarte = aLaCarte; + return this; } public String getVnfType() { return vnfType; } - public void setVnfType(String vnfType) { + public ExecuteBuildingBlock setVnfType(String vnfType) { this.vnfType = vnfType; + return this; } public Boolean isHoming() { return homing; } - public void setHoming(Boolean homing) { + public ExecuteBuildingBlock setHoming(Boolean homing) { this.homing = homing; + return this; } public WorkflowResourceIds getWorkflowResourceIds() { return workflowResourceIds; } - public void setWorkflowResourceIds(WorkflowResourceIds workflowResourceIds) { + public ExecuteBuildingBlock setWorkflowResourceIds(WorkflowResourceIds workflowResourceIds) { this.workflowResourceIds = workflowResourceIds; + return this; } public RequestDetails getRequestDetails() { return requestDetails; } - public void setRequestDetails(RequestDetails requestDetails) { + public ExecuteBuildingBlock setRequestDetails(RequestDetails requestDetails) { this.requestDetails = requestDetails; + return this; } public ConfigurationResourceKeys getConfigurationResourceKeys() { return configurationResourceKeys; } - public void setConfigurationResourceKeys(ConfigurationResourceKeys configurationResourceKeys) { + public ExecuteBuildingBlock setConfigurationResourceKeys(ConfigurationResourceKeys configurationResourceKeys) { this.configurationResourceKeys = configurationResourceKeys; + return this; } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java index ac66fb1a41..8293cbc10e 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java @@ -1189,7 +1189,7 @@ public class BBInputSetup implements JavaDelegate { if (bbName.contains(NETWORK) && !bbName.contains(NETWORK_COLLECTION)) { String networkId = lookupKeyMap.get(ResourceKey.NETWORK_ID); ModelInfo networkModelInfo = new ModelInfo(); - if ((!Boolean.TRUE.equals(executeBB.getBuildingBlock().getIsVirtualLink()))) { + if ((!Boolean.TRUE.equals(executeBB.getBuildingBlock().isVirtualLink()))) { NetworkResourceCustomization networkCust = getNetworkCustomizationByKey(key, service); if (networkCust != null) { networkModelInfo.setModelCustomizationUuid(networkCust.getModelCustomizationUUID()); diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java index ea48c78dc0..28ec71b13f 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupMapperLayer.java @@ -22,12 +22,6 @@ package org.onap.so.bpmn.servicedecomposition.tasks; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; import org.modelmapper.ModelMapper; import org.modelmapper.convention.MatchingStrategies; import org.onap.so.bpmn.servicedecomposition.bbobjects.AggregateRoute; @@ -92,6 +86,12 @@ import org.onap.so.serviceinstancebeans.RequestDetails; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; @Component("BBInputSetupMapperLayer") public class BBInputSetupMapperLayer { diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/BBPojoTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/BBPojoTest.java index d7c5ec9d55..14bae82dde 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/BBPojoTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/BBPojoTest.java @@ -20,7 +20,6 @@ package org.onap.so.bpmn.servicedecomposition; -import org.junit.Test; import com.openpojo.reflection.PojoClass; import com.openpojo.reflection.PojoClassFilter; import com.openpojo.reflection.filters.FilterNonConcrete; @@ -32,6 +31,7 @@ import com.openpojo.validation.rule.impl.NoPrimitivesRule; import com.openpojo.validation.rule.impl.SerializableMustHaveSerialVersionUIDRule; import com.openpojo.validation.test.impl.GetterTester; import com.openpojo.validation.test.impl.SetterTester; +import org.junit.Test; public class BBPojoTest { diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/entities/ExecuteBuildingBlockTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/entities/ExecuteBuildingBlockTest.java new file mode 100644 index 0000000000..c8699d66e7 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/entities/ExecuteBuildingBlockTest.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * 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.so.bpmn.servicedecomposition.entities; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Test; +import java.io.File; +import java.io.IOException; +import static org.assertj.core.api.Assertions.assertThat; + +public class ExecuteBuildingBlockTest { + private static final String RESOURCE_PATH = "src/test/resources/__files/ExecuteBuildingBlock/"; + private ObjectMapper mapper = new ObjectMapper(); + + @Test + public void should_properlyDeserializeGivenJsonFile() throws IOException { + // given + // when + ExecuteBuildingBlock resultEBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockExtended.json"), + ExecuteBuildingBlock.class); + BuildingBlock resultBB = resultEBB.getBuildingBlock(); + // then + assertThat(resultBB.getMsoId()).isEqualTo("msoId"); + assertThat(resultBB.getBpmnFlowName()).isEqualTo("bbName"); + assertThat(resultEBB.getRequestId()).isEqualTo("requestId"); + assertThat(resultEBB.isaLaCarte()).isTrue(); + assertThat(resultEBB.getApiVersion()).isNull(); + assertThat(resultEBB.getResourceId()).isNull(); + assertThat(resultEBB.getRequestAction()).isNull(); + assertThat(resultEBB.getVnfType()).isNull(); + assertThat(resultEBB.isHoming()).isFalse(); + assertThat(resultEBB.getWorkflowResourceIds()).isNull(); + assertThat(resultEBB.getRequestDetails()).isNull(); + assertThat(resultEBB.getConfigurationResourceKeys()).isNull(); + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupExistingServiceTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupExistingServiceTest.java new file mode 100644 index 0000000000..fbb67cb923 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupExistingServiceTest.java @@ -0,0 +1,139 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * 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.so.bpmn.servicedecomposition.tasks; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.onap.aai.domain.yang.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.serviceinstancebeans.CloudConfiguration; +import org.onap.so.serviceinstancebeans.RequestDetails; +import java.io.File; +import java.util.Arrays; +import java.util.Collection; +import java.util.Map; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.onap.so.bpmn.servicedecomposition.tasks.BaseBBInputSetupTestHelper.prepareLookupKeyMap; + +@RunWith(Parameterized.class) +public class BBInputSetupExistingServiceTest { + private String requestAction; + private String bpmnFlowName; + private String key; + private static final String RESOURCE_PATH = "src/test/resources/__files/ExecuteBuildingBlock/"; + + protected ObjectMapper mapper = new ObjectMapper(); + + @Spy + @InjectMocks + private BBInputSetup SPY_bbInputSetup = new BBInputSetup(); + + @Mock + private BBInputSetupUtils bbInputSetupUtils; + + @Mock + private BBInputSetupMapperLayer bbInputSetupMapperLayer; + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + public BBInputSetupExistingServiceTest(String requestAction, String bpmnFlowName, String key) { + this.requestAction = requestAction; + this.bpmnFlowName = bpmnFlowName; + this.key = key; + } + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Parameterized.Parameters + public static Collection input() { + return Arrays + .asList(new Object[][] {{"deleteInstance", "DeleteNetworkBB", "ab153b6e-c364-44c0-bef6-1f2982117f04"}, + {"activateInstance", "ActivateNetworkBB", "ab153b6e-c364-44c0-bef6-1f2982117f04"}, + {"unassignInstance", "UnassignNetworkBB", "ab153b6e-c364-44c0-bef6-1f2982117f04"}, + {"activateFabricConfiguration", "ActivateFabricConfigurationBB", + "ab153b6e-c364-44c0-bef6-134534656234"}}); + } + + @Test + public void test_getGBBMacro_getGBBMacroExistingService_shouldBeCalled() throws Exception { + // given + String resourceId = "123"; + String vnfType = "vnfType"; + String requestAction = this.requestAction; + Service service = Mockito.mock(Service.class); + GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), + GeneralBuildingBlock.class); + ServiceInstance serviceInstance = gBB.getServiceInstance(); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = new org.onap.aai.domain.yang.ServiceInstance(); + aaiServiceInstance.setModelVersionId("modelVersionId"); + CloudConfiguration cloudConfig = new CloudConfiguration(); + cloudConfig.setLcpCloudRegionId("lcpCloudRegionId"); + CloudRegion aaiCloudRegion = Mockito.mock(CloudRegion.class); + + RequestDetails requestDetails = mapper + .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); + requestDetails.getRequestParameters().setUserParams(null); + requestDetails.setCloudConfiguration(cloudConfig); + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + executeBB.setRequestDetails(requestDetails); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName(this.bpmnFlowName).setKey(this.key); + + doReturn(service).when(bbInputSetupUtils).getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId()); + doReturn(aaiServiceInstance).when(bbInputSetupUtils) + .getAAIServiceInstanceById(lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); + doReturn(serviceInstance).when(SPY_bbInputSetup).getExistingServiceInstance(aaiServiceInstance); + doReturn(gBB).when(SPY_bbInputSetup).populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, + executeBB, requestAction, null); + doReturn(aaiCloudRegion).when(bbInputSetupUtils).getCloudRegion(requestDetails.getCloudConfiguration()); + // when + SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); + // then + verify(SPY_bbInputSetup, times(1)).getGBBMacroExistingService(isA(ExecuteBuildingBlock.class), any(), + any(String.class), isA(String.class), isA(CloudConfiguration.class)); + } +} + diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupPopulateMethodsTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupPopulateMethodsTest.java new file mode 100644 index 0000000000..7d45b643e3 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupPopulateMethodsTest.java @@ -0,0 +1,283 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * 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.so.bpmn.servicedecomposition.tasks; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.mockito.ArgumentMatchers; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.entities.ServiceModel; +import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.serviceinstancebeans.CloudConfiguration; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.RequestDetails; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.onap.so.bpmn.servicedecomposition.tasks.BaseBBInputSetupTestHelper.prepareConfigurationResourceKeys; +import static org.onap.so.bpmn.servicedecomposition.tasks.BaseBBInputSetupTestHelper.prepareLookupKeyMap; + +@RunWith(Parameterized.class) +public class BBInputSetupPopulateMethodsTest { + private static final String RESOURCE_PATH = "src/test/resources/__files/ExecuteBuildingBlock/"; + + private String resourceId; + private String requestAction; + private Service service; + private String vnfType; + + protected ObjectMapper mapper = new ObjectMapper(); + + @Spy + @InjectMocks + private BBInputSetup SPY_bbInputSetup = new BBInputSetup(); + + @Mock + private BBInputSetupUtils bbInputSetupUtils; + + @Spy + private BBInputSetupMapperLayer SPY_bbInputSetupMapperLayer; + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + public BBInputSetupPopulateMethodsTest(String vnfType) { + this.vnfType = vnfType; + } + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Parameterized.Parameters + public static Collection input() { + return Arrays.asList(new Object[] {"vnfType", null}); + } + + @Before + public void init() { + resourceId = "123"; + requestAction = "createInstance"; + service = Mockito.mock(Service.class); + } + + @Test + public void test_getGBBMacro_populateL3Network_shouldBeCalled() throws Exception { + // given + GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), + GeneralBuildingBlock.class); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + + ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys(); + RequestDetails requestDetails = mapper + .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + executeBB.setConfigurationResourceKeys(configResourceKeys).setRequestDetails(requestDetails); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName(AssignFlows.NETWORK_MACRO.toString()) + .setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); + + doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, + requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); + doReturn(service).when(bbInputSetupUtils) + .getCatalogServiceByModelUUID(gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid()); + // when + SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); + // then + verify(SPY_bbInputSetup, times(1)).populateL3Network(any(String.class), isA(ModelInfo.class), + isA(Service.class), any(String.class), isA(ServiceInstance.class), any(), any(String.class), any()); + } + + @Test + public void test_getGBBMacro_populateGenericVnf_shouldBeCalled() throws Exception { + // given + GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), + GeneralBuildingBlock.class); + RequestDetails requestDetails = mapper + .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); + InfraActiveRequests request = Mockito.mock(InfraActiveRequests.class); + GenericVnf aaiVnf = new GenericVnf(); + aaiVnf.setModelCustomizationId("modelCustId"); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName(AssignFlows.VNF.toString()).setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); + + doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, + requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); + doReturn(request).when(bbInputSetupUtils).getInfraActiveRequest(executeBB.getRequestId()); + doReturn(service).when(bbInputSetupUtils) + .getCatalogServiceByModelUUID(gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid()); + doNothing().when(bbInputSetupUtils).updateInfraActiveRequestVnfId(request, + lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID)); + doReturn(aaiVnf).when(bbInputSetupUtils).getAAIGenericVnf(any(String.class)); + + // when + SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); + // then + verify(SPY_bbInputSetup, times(1)).populateGenericVnf(isA(ModelInfo.class), any(String.class), + isA(org.onap.so.serviceinstancebeans.Platform.class), + isA(org.onap.so.serviceinstancebeans.LineOfBusiness.class), isA(Service.class), any(String.class), + isA(ServiceInstance.class), any(), any(), any(String.class), eq(vnfType), any(), any(String.class), + any(String.class), eq(false)); + } + + @Test + public void test_getGBBMacro_populateVfModule_shouldBeCalled() throws Exception { + // given + GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockWithVnf.json"), + GeneralBuildingBlock.class); + RequestDetails requestDetails = mapper + .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); + GenericVnf aaiVnf = new GenericVnf(); + aaiVnf.setModelCustomizationId("modelCustId"); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, null); + + ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys(); + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + executeBB.setConfigurationResourceKeys(configResourceKeys).setRequestDetails(requestDetails); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName(AssignFlows.VF_MODULE.toString()).setKey("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + + doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, + requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); + doReturn(service).when(bbInputSetupUtils) + .getCatalogServiceByModelUUID(gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid()); + doReturn("vnfId").when(SPY_bbInputSetup).getVnfId(executeBB, lookupKeyMap); + doReturn(aaiVnf).when(bbInputSetupUtils).getAAIGenericVnf(any(String.class)); + // when + SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); + // then + verify(SPY_bbInputSetup, times(1)).populateVfModule(isA(ModelInfo.class), isA(Service.class), any(String.class), + isA(ServiceInstance.class), any(), any(String.class), any(), any(String.class), any(), + isA(CloudConfiguration.class), Mockito.anyBoolean(), isA(ServiceModel.class)); + } + + @Test + public void test_getGBBMacro_populateVolumeGroup_shouldBeCalled() throws Exception { + // given + GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockWithVnf.json"), + GeneralBuildingBlock.class); + RequestDetails requestDetails = mapper + .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); + GenericVnf aaiVnf = new GenericVnf(); + aaiVnf.setModelCustomizationId("modelCustId"); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, null); + + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName(AssignFlows.VOLUME_GROUP.toString()) + .setKey("72d9d1cd-f46d-447a-abdb-451d6fb05fa8"); + + doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, + requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); + doReturn(service).when(bbInputSetupUtils) + .getCatalogServiceByModelUUID(gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid()); + doReturn("vnfId").when(SPY_bbInputSetup).getVnfId(executeBB, lookupKeyMap); + doReturn(aaiVnf).when(bbInputSetupUtils).getAAIGenericVnf(any(String.class)); + // when + SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); + // then + verify(SPY_bbInputSetup, times(1)).populateVolumeGroup(isA(ModelInfo.class), isA(Service.class), + any(String.class), isA(ServiceInstance.class), any(), any(String.class), ArgumentMatchers.isNull(), + ArgumentMatchers.isNull(), eq(vnfType), any()); + } + + @Test + public void test_getGBBMacro_populateConfiguration_shouldBeCalled() throws Exception { + // given + String requestAction = "createInstance"; + Service service = Mockito.mock(Service.class); + GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), + GeneralBuildingBlock.class); + RequestDetails requestDetails = mapper + .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); + GenericVnf aaiVnf = new GenericVnf(); + aaiVnf.setModelCustomizationId("modelCustId"); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + + ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys(); + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + executeBB.setConfigurationResourceKeys(configResourceKeys).setRequestDetails(requestDetails); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName("AssignFabricConfigurationBB").setKey("72d9d1cd-f46d-447a-abdb-451d6fb05fa9"); + + Configuration configuration = new Configuration(); + configuration.setConfigurationId("configurationId"); + gBB.getServiceInstance().getConfigurations().add(configuration); + List<ConfigurationResourceCustomization> configurationCustList = new ArrayList<>(); + ConfigurationResourceCustomization configurationCust = new ConfigurationResourceCustomization(); + configurationCust.setModelCustomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa9"); + configurationCustList.add(configurationCust); + + doReturn(configurationCustList).when(service).getConfigurationCustomizations(); + doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, + requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); + doReturn(service).when(bbInputSetupUtils) + .getCatalogServiceByModelUUID(gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid()); + doNothing().when(SPY_bbInputSetup).populateConfiguration(isA(ModelInfo.class), isA(Service.class), + any(String.class), isA(ServiceInstance.class), any(), any(String.class), ArgumentMatchers.isNull(), + isA(ConfigurationResourceKeys.class), isA(RequestDetails.class)); + // when + SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); + // then + verify(SPY_bbInputSetup, times(1)).populateConfiguration(isA(ModelInfo.class), isA(Service.class), + any(String.class), isA(ServiceInstance.class), any(), any(String.class), ArgumentMatchers.isNull(), + isA(ConfigurationResourceKeys.class), isA(RequestDetails.class)); + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java index e0ee918ead..16cdb7a3e9 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupTest.java @@ -6,6 +6,8 @@ * ================================================================================ * Modifications Copyright (c) 2019 Samsung * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ * 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 @@ -22,30 +24,12 @@ package org.onap.so.bpmn.servicedecomposition.tasks; -import static com.shazam.shazamcrest.MatcherAssert.assertThat; -import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.ArgumentMatchers.isA; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.junit.Assert; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -114,7 +98,6 @@ import org.onap.so.db.catalog.beans.VfModuleCustomization; import org.onap.so.db.catalog.beans.VnfResourceCustomization; import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization; import org.onap.so.db.request.beans.InfraActiveRequests; -import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.serviceinstancebeans.CloudConfiguration; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.ModelType; @@ -125,10 +108,28 @@ import org.onap.so.serviceinstancebeans.RequestInfo; import org.onap.so.serviceinstancebeans.RequestParameters; import org.onap.so.serviceinstancebeans.Resources; import org.onap.so.serviceinstancebeans.SubscriberInfo; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.onap.so.bpmn.servicedecomposition.tasks.BaseBBInputSetupTestHelper.prepareConfigurationResourceKeys; +import static org.onap.so.bpmn.servicedecomposition.tasks.BaseBBInputSetupTestHelper.prepareLookupKeyMap; @RunWith(MockitoJUnitRunner.class) public class BBInputSetupTest { @@ -136,7 +137,6 @@ public class BBInputSetupTest { protected ObjectMapper mapper = new ObjectMapper(); private static final String CLOUD_OWNER = "CloudOwner"; - private static final String REQUEST_ID = "b20bbd26-af25-4a50-a9fe-222a3c0f9771"; @Spy @InjectMocks @@ -151,19 +151,9 @@ public class BBInputSetupTest { @Spy private BBInputSetupMapperLayer bbInputSetupMapperLayer; - @Mock - private RequestsDbClient requestsDbClient; - @Rule public ExpectedException expectedException = ExpectedException.none(); - @Before - public void setup() { - SPY_bbInputSetup.setBbInputSetupUtils(SPY_bbInputSetupUtils); - SPY_bbInputSetup.setMapperLayer(bbInputSetupMapperLayer); - SPY_bbInputSetup.setCloudInfoFromAAI(SPY_cloudInfoFromAAI); - } - @Test public void testGetVolumeGroupIdRelatedToVfModule() { String expected = "volumeGroupId"; @@ -292,7 +282,7 @@ public class BBInputSetupTest { } @Test - public void testSetHomingFlag() throws JsonParseException, JsonMappingException, IOException { + public void testSetHomingFlag() throws IOException { GeneralBuildingBlock expected = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), GeneralBuildingBlock.class); Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); @@ -315,11 +305,9 @@ public class BBInputSetupTest { @Test public void testGetExecuteBBFromExecution() throws IOException { - ExecuteBuildingBlock expected = new ExecuteBuildingBlock(); - BuildingBlock bb = new BuildingBlock(); - bb.setBpmnFlowName("AssignServiceInstanceBB"); - expected.setBuildingBlock(bb); - expected.setRequestId("00032ab7-3fb3-42e5-965d-8ea592502017"); + BuildingBlock bb = new BuildingBlock().setBpmnFlowName("AssignServiceInstanceBB"); + ExecuteBuildingBlock expected = + new ExecuteBuildingBlock().setBuildingBlock(bb).setRequestId("00032ab7-3fb3-42e5-965d-8ea592502017"); DelegateExecution execution = Mockito.mock(DelegateExecution.class); doReturn(expected).when(execution).getVariable(any(String.class)); ExecuteBuildingBlock actual = SPY_bbInputSetup.getExecuteBBFromExecution(execution); @@ -331,8 +319,7 @@ public class BBInputSetupTest { GeneralBuildingBlock expected = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), GeneralBuildingBlock.class); - ExecuteBuildingBlock executeBB = new ExecuteBuildingBlock(); - executeBB.setRequestId("requestId"); + ExecuteBuildingBlock executeBB = new ExecuteBuildingBlock().setRequestId("requestId"); RequestDetails requestDetails = new RequestDetails(); ModelInfo modelInfo = new ModelInfo(); modelInfo.setModelType(ModelType.service); @@ -360,8 +347,7 @@ public class BBInputSetupTest { GeneralBuildingBlock expected = mapper .readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockCMExpected.json"), GeneralBuildingBlock.class); - ExecuteBuildingBlock executeBB = new ExecuteBuildingBlock(); - executeBB.setRequestId("requestId"); + ExecuteBuildingBlock executeBB = new ExecuteBuildingBlock().setRequestId("requestId"); RequestDetails requestDetails = new RequestDetails(); requestDetails.setModelInfo(null); RequestParameters requestParams = new RequestParameters(); @@ -1038,11 +1024,8 @@ public class BBInputSetupTest { OwningEntity owningEntity = mapper.readValue(new File(RESOURCE_PATH + "OwningEntity.json"), OwningEntity.class); Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); - ExecuteBuildingBlock executeBB = new ExecuteBuildingBlock(); - executeBB.setaLaCarte(true); - BuildingBlock buildingBlock = new BuildingBlock(); - buildingBlock.setBpmnFlowName(AssignFlows.SERVICE_INSTANCE.toString()); - executeBB.setBuildingBlock(buildingBlock); + BuildingBlock buildingBlock = new BuildingBlock().setBpmnFlowName(AssignFlows.SERVICE_INSTANCE.toString()); + ExecuteBuildingBlock executeBB = new ExecuteBuildingBlock().setaLaCarte(true).setBuildingBlock(buildingBlock); RequestDetails requestDetails = new RequestDetails(); RequestInfo reqInfo = new RequestInfo(); reqInfo.setInstanceName("serviceInstanceName"); @@ -1343,10 +1326,7 @@ public class BBInputSetupTest { Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, "configurationId"); String bbName = AssignFlows.FABRIC_CONFIGURATION.toString(); - ConfigurationResourceKeys configResourceKeys = new ConfigurationResourceKeys(); - configResourceKeys.setCvnfcCustomizationUUID("cvnfcCustomizationUUID"); - configResourceKeys.setVfModuleCustomizationUUID("vfModuleCustomizationUUID"); - configResourceKeys.setVnfResourceCustomizationUUID("vnfResourceCustomizationUUID"); + ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys(); configResourceKeys.setVnfcName(vnfcName); Vnfc vnfc = new Vnfc(); vnfc.setVnfcName(vnfcName); @@ -1420,10 +1400,7 @@ public class BBInputSetupTest { Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, "configurationId"); String bbName = AssignFlows.FABRIC_CONFIGURATION.toString(); - ConfigurationResourceKeys configResourceKeys = new ConfigurationResourceKeys(); - configResourceKeys.setCvnfcCustomizationUUID("cvnfcCustomizationUUID"); - configResourceKeys.setVfModuleCustomizationUUID("vfModuleCustomizationUUID"); - configResourceKeys.setVnfResourceCustomizationUUID("vnfResourceCustomizationUUID"); + ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys(); configResourceKeys.setVnfcName(vnfcName); Vnfc vnfc = new Vnfc(); vnfc.setVnfcName(vnfcName); @@ -2017,122 +1994,25 @@ public class BBInputSetupTest { } @Test - public void testgetGBBMacro() throws Exception { - GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), - GeneralBuildingBlock.class); - ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), - ExecuteBuildingBlock.class); - RequestDetails requestDetails = mapper - .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); - InfraActiveRequests request = Mockito.mock(InfraActiveRequests.class); - org.onap.aai.domain.yang.GenericVnf aaiVnf = new org.onap.aai.domain.yang.GenericVnf(); - aaiVnf.setModelCustomizationId("modelCustId"); - Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); - lookupKeyMap.put(ResourceKey.NETWORK_ID, "networkId"); - lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, "vnfId"); - lookupKeyMap.put(ResourceKey.VF_MODULE_ID, "vfModuleId"); - lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, "volumeGroupId"); - lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "serviceInstanceId"); - lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, "configurationId"); + public void testGBBMacroNoUserParamsVrfConfiguration() throws Exception { String resourceId = "123"; String vnfType = "vnfType"; - Service service = Mockito.mock(Service.class); String requestAction = "createInstance"; - - ConfigurationResourceKeys configResourceKeys = new ConfigurationResourceKeys(); - configResourceKeys.setCvnfcCustomizationUUID("cvnfcCustomizationUUID"); - configResourceKeys.setVfModuleCustomizationUUID("vfModuleCustomizationUUID"); - configResourceKeys.setVnfResourceCustomizationUUID("vnfResourceCustomizationUUID"); - executeBB.setConfigurationResourceKeys(configResourceKeys); - executeBB.setRequestDetails(requestDetails); - doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, - requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); - doReturn(request).when(SPY_bbInputSetupUtils).getInfraActiveRequest(executeBB.getRequestId()); - doReturn(service).when(SPY_bbInputSetupUtils) - .getCatalogServiceByModelUUID(gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid()); - doNothing().when(SPY_bbInputSetupUtils).updateInfraActiveRequestVnfId(request, - lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID)); - doReturn("vnfId").when(SPY_bbInputSetup).getVnfId(executeBB, lookupKeyMap); - doReturn(aaiVnf).when(SPY_bbInputSetupUtils).getAAIGenericVnf(any(String.class)); - - - executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.NETWORK_MACRO.toString()); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(1)).populateL3Network(any(String.class), isA(ModelInfo.class), - isA(Service.class), any(String.class), isA(ServiceInstance.class), any(), any(String.class), any()); - - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); - executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.VNF.toString()); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(1)).populateGenericVnf(isA(ModelInfo.class), any(String.class), - isA(org.onap.so.serviceinstancebeans.Platform.class), - isA(org.onap.so.serviceinstancebeans.LineOfBusiness.class), isA(Service.class), any(String.class), - isA(ServiceInstance.class), any(), any(), any(String.class), any(String.class), any(), - any(String.class), any(String.class), Mockito.anyBoolean()); - - lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, null); - executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.VF_MODULE.toString()); - executeBB.getBuildingBlock().setKey("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(1)).populateVfModule(isA(ModelInfo.class), isA(Service.class), any(String.class), - isA(ServiceInstance.class), any(), any(String.class), any(), any(String.class), any(), - isA(CloudConfiguration.class), Mockito.anyBoolean(), isA(ServiceModel.class)); - - lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, null); - executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.VOLUME_GROUP.toString()); - executeBB.getBuildingBlock().setKey("72d9d1cd-f46d-447a-abdb-451d6fb05fa8"); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(1)).populateVolumeGroup(isA(ModelInfo.class), isA(Service.class), - any(String.class), isA(ServiceInstance.class), any(), any(String.class), ArgumentMatchers.isNull(), - ArgumentMatchers.isNull(), any(String.class), any()); - - Configuration configuration = new Configuration(); - configuration.setConfigurationId("configurationId"); - gBB.getServiceInstance().getConfigurations().add(configuration); - List<ConfigurationResourceCustomization> configurationCustList = new ArrayList<>(); - ConfigurationResourceCustomization configurationCust = new ConfigurationResourceCustomization(); - configurationCust.setModelCustomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa9"); - doReturn(configurationCustList).when(service).getConfigurationCustomizations(); - configurationCustList.add(configurationCust); - doNothing().when(SPY_bbInputSetup).populateConfiguration(isA(ModelInfo.class), isA(Service.class), - any(String.class), isA(ServiceInstance.class), any(), any(String.class), ArgumentMatchers.isNull(), - isA(ConfigurationResourceKeys.class), isA(RequestDetails.class)); - - executeBB.getBuildingBlock().setBpmnFlowName("AssignFabricConfigurationBB"); - executeBB.getBuildingBlock().setKey("72d9d1cd-f46d-447a-abdb-451d6fb05fa9"); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(1)).populateConfiguration(isA(ModelInfo.class), isA(Service.class), - any(String.class), isA(ServiceInstance.class), any(), any(String.class), ArgumentMatchers.isNull(), - isA(ConfigurationResourceKeys.class), isA(RequestDetails.class)); - - - } - - @Test - public void testGBBMacroNoUserParamsVrfConfiguration() throws Exception { + Service service = Mockito.mock(Service.class); GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), GeneralBuildingBlock.class); ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), ExecuteBuildingBlock.class); RequestDetails requestDetails = mapper .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacroVrf.json"), RequestDetails.class); - InfraActiveRequests request = Mockito.mock(InfraActiveRequests.class); - Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); - lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "serviceInstanceId"); - lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, "configurationId"); - String resourceId = "123"; - String vnfType = "vnfType"; - Service service = Mockito.mock(Service.class); - String requestAction = "createInstance"; + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); - ConfigurationResourceKeys configResourceKeys = new ConfigurationResourceKeys(); - configResourceKeys.setCvnfcCustomizationUUID("cvnfcCustomizationUUID"); - configResourceKeys.setVfModuleCustomizationUUID("vfModuleCustomizationUUID"); - configResourceKeys.setVnfResourceCustomizationUUID("vnfResourceCustomizationUUID"); - executeBB.setConfigurationResourceKeys(configResourceKeys); + ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys(); + executeBB.setConfigurationResourceKeys(configResourceKeys).setRequestDetails(requestDetails); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName("AssignVrfConfigurationBB"); + buildingBlock.setKey("72d9d1cd-f46d-447a-abdb-451d6fb05fa9"); - executeBB.setRequestDetails(requestDetails); doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); doReturn(service).when(SPY_bbInputSetupUtils) @@ -2174,8 +2054,6 @@ public class BBInputSetupTest { any(String.class), isA(ServiceInstance.class), any(), any(String.class), ArgumentMatchers.isNull(), isA(ConfigurationResourceKeys.class), isA(RequestDetails.class)); - executeBB.getBuildingBlock().setBpmnFlowName("AssignVrfConfigurationBB"); - executeBB.getBuildingBlock().setKey("72d9d1cd-f46d-447a-abdb-451d6fb05fa9"); gBB = SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); verify(SPY_bbInputSetup, times(1)).populateConfiguration(isA(ModelInfo.class), isA(Service.class), any(String.class), isA(ServiceInstance.class), any(), any(String.class), ArgumentMatchers.isNull(), @@ -2253,6 +2131,10 @@ public class BBInputSetupTest { @Test public void testgetGBBMacroWithEmptyUserParams() throws Exception { + String resourceId = "123"; + String vnfType = "vnfType"; + String requestAction = "createInstance"; + Service service = Mockito.mock(Service.class); GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), GeneralBuildingBlock.class); ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), @@ -2260,28 +2142,18 @@ public class BBInputSetupTest { RequestDetails requestDetails = mapper .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); requestDetails.getRequestParameters().getUserParams().clear(); - InfraActiveRequests request = Mockito.mock(InfraActiveRequests.class); org.onap.aai.domain.yang.GenericVnf aaiVnf = new org.onap.aai.domain.yang.GenericVnf(); aaiVnf.setModelCustomizationId("modelCustId"); - Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); - lookupKeyMap.put(ResourceKey.NETWORK_ID, "networkId"); - lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, "vnfId"); - lookupKeyMap.put(ResourceKey.VF_MODULE_ID, "vfModuleId"); - lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, "volumeGroupId"); - lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "serviceInstanceId"); - String resourceId = "123"; - String vnfType = "vnfType"; - Service service = Mockito.mock(Service.class); - String requestAction = "createInstance"; + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName(AssignFlows.NETWORK_MACRO.toString()) + .setKey("ab153b6e-c364-44c0-bef6-1f2982117f04").setIsVirtualLink(false); doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); doReturn(service).when(SPY_bbInputSetupUtils) .getCatalogServiceByModelUUID(gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid()); - executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.NETWORK_MACRO.toString()); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); - executeBB.getBuildingBlock().setIsVirtualLink(Boolean.FALSE); SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); verify(SPY_bbInputSetup, times(1)).getGBBMacroNoUserParamsCreate(any(ExecuteBuildingBlock.class), any(), any(String.class), any(String.class), any(GeneralBuildingBlock.class), any(Service.class)); @@ -2289,8 +2161,6 @@ public class BBInputSetupTest { @Test(expected = Exception.class) public void testgetGBBMacroException() throws Exception { - GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), - GeneralBuildingBlock.class); ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), ExecuteBuildingBlock.class); RequestDetails requestDetails = mapper @@ -2298,146 +2168,52 @@ public class BBInputSetupTest { Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); String resourceId = "123"; String vnfType = "vnfType"; - Service service = Mockito.mock(Service.class); String requestAction = "createInstance"; - executeBB.getBuildingBlock().setBpmnFlowName("Network"); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName("Network").setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); + SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); } @Test - public void testgetGBBMacroWithVnfTypeNull() throws Exception { - GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), - GeneralBuildingBlock.class); - ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), - ExecuteBuildingBlock.class); - RequestDetails requestDetails = mapper - .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); - Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); - lookupKeyMap.put(ResourceKey.NETWORK_ID, "networkId"); - lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, "vnfId"); - lookupKeyMap.put(ResourceKey.VF_MODULE_ID, "vfModuleId"); - lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, "volumeGroupId"); - lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "serviceInstanceId"); - org.onap.aai.domain.yang.GenericVnf aaiVnf = new org.onap.aai.domain.yang.GenericVnf(); - aaiVnf.setModelCustomizationId("modelCustId"); - InfraActiveRequests request = Mockito.mock(InfraActiveRequests.class); + public void test_getGBBMacroForVnfTypeNull_populateL3Network_shouldBeCalled() throws Exception { + // given String resourceId = "123"; - String vnfType = null; - Service service = Mockito.mock(Service.class); + String vnfType = "null"; String requestAction = "createInstance"; - - executeBB.setRequestDetails(requestDetails); - doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, - requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); - doReturn(request).when(SPY_bbInputSetupUtils).getInfraActiveRequest(executeBB.getRequestId()); - doReturn(service).when(SPY_bbInputSetupUtils) - .getCatalogServiceByModelUUID(gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid()); - doNothing().when(SPY_bbInputSetupUtils).updateInfraActiveRequestVnfId(request, - lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID)); - doReturn("vnfId").when(SPY_bbInputSetup).getVnfId(executeBB, lookupKeyMap); - doReturn(aaiVnf).when(SPY_bbInputSetupUtils).getAAIGenericVnf(any(String.class)); - - executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.NETWORK_MACRO.toString()); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(1)).populateL3Network(any(String.class), isA(ModelInfo.class), - isA(Service.class), any(String.class), isA(ServiceInstance.class), any(), any(String.class), any()); - - executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.VNF.toString()); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(1)).populateGenericVnf(isA(ModelInfo.class), any(String.class), - isA(org.onap.so.serviceinstancebeans.Platform.class), - isA(org.onap.so.serviceinstancebeans.LineOfBusiness.class), isA(Service.class), any(String.class), - isA(ServiceInstance.class), any(), ArgumentMatchers.isNull(), any(String.class), - ArgumentMatchers.isNull(), any(), any(String.class), any(), Mockito.anyBoolean()); - - lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, null); - executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.VF_MODULE.toString()); - executeBB.getBuildingBlock().setKey("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(1)).populateVfModule(isA(ModelInfo.class), isA(Service.class), any(String.class), - isA(ServiceInstance.class), any(), any(String.class), any(), any(String.class), any(), - isA(CloudConfiguration.class), Mockito.anyBoolean(), isA(ServiceModel.class)); - - lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, null); - executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.VOLUME_GROUP.toString()); - executeBB.getBuildingBlock().setKey("72d9d1cd-f46d-447a-abdb-451d6fb05fa8"); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(1)).populateVolumeGroup(isA(ModelInfo.class), isA(Service.class), - any(String.class), isA(ServiceInstance.class), any(), any(String.class), ArgumentMatchers.isNull(), - ArgumentMatchers.isNull(), ArgumentMatchers.isNull(), any()); - } - - @Test - public void testgetGBBMacroGetServiceWithInvariantId() throws Exception { + Service service = Mockito.mock(Service.class); GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), GeneralBuildingBlock.class); - ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), - ExecuteBuildingBlock.class); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + + ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys(); RequestDetails requestDetails = mapper .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); - Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); - lookupKeyMap.put(ResourceKey.NETWORK_ID, "networkId"); - lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, "vnfId"); - lookupKeyMap.put(ResourceKey.VF_MODULE_ID, "vfModuleId"); - lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, "volumeGroupId"); - lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "serviceInstanceId"); - org.onap.aai.domain.yang.GenericVnf aaiVnf = new org.onap.aai.domain.yang.GenericVnf(); - aaiVnf.setModelCustomizationId("modelCustId"); - InfraActiveRequests request = Mockito.mock(InfraActiveRequests.class); - String resourceId = "123"; - String vnfType = "vnfType"; - Service service = Mockito.mock(Service.class); - String requestAction = "createInstance"; + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + executeBB.setConfigurationResourceKeys(configResourceKeys).setRequestDetails(requestDetails); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName(AssignFlows.NETWORK_MACRO.toString()) + .setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); - executeBB.setRequestDetails(requestDetails); doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); - doReturn(request).when(SPY_bbInputSetupUtils).getInfraActiveRequest(executeBB.getRequestId()); doReturn(service).when(SPY_bbInputSetupUtils) .getCatalogServiceByModelUUID(gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid()); - doNothing().when(SPY_bbInputSetupUtils).updateInfraActiveRequestVnfId(request, - lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID)); - doReturn("vnfId").when(SPY_bbInputSetup).getVnfId(executeBB, lookupKeyMap); - doReturn(aaiVnf).when(SPY_bbInputSetupUtils).getAAIGenericVnf(any(String.class)); - - executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.NETWORK_MACRO.toString()); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); + // when SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); + // then verify(SPY_bbInputSetup, times(1)).populateL3Network(any(String.class), isA(ModelInfo.class), isA(Service.class), any(String.class), isA(ServiceInstance.class), any(), any(String.class), any()); - - executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.VNF.toString()); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(1)).populateGenericVnf(isA(ModelInfo.class), any(String.class), - isA(org.onap.so.serviceinstancebeans.Platform.class), - isA(org.onap.so.serviceinstancebeans.LineOfBusiness.class), isA(Service.class), any(String.class), - isA(ServiceInstance.class), any(), any(), any(String.class), any(String.class), any(), - any(String.class), any(String.class), Mockito.anyBoolean()); - - lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, null); - executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.VF_MODULE.toString()); - executeBB.getBuildingBlock().setKey("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(1)).populateVfModule(isA(ModelInfo.class), isA(Service.class), any(String.class), - isA(ServiceInstance.class), any(), any(String.class), any(), any(String.class), any(), - isA(CloudConfiguration.class), Mockito.anyBoolean(), isA(ServiceModel.class)); - - lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, null); - executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.VOLUME_GROUP.toString()); - executeBB.getBuildingBlock().setKey("72d9d1cd-f46d-447a-abdb-451d6fb05fa8"); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(1)).populateVolumeGroup(isA(ModelInfo.class), isA(Service.class), - any(String.class), isA(ServiceInstance.class), any(), any(String.class), ArgumentMatchers.isNull(), - ArgumentMatchers.isNull(), any(String.class), any()); } @Test public void testgetGBBMacroNoUserParamsDeactivateInstnace() throws Exception { + String resourceId = "123"; + String vnfType = "vnfType"; + String requestAction = "deactivateInstance"; + Service service = Mockito.mock(Service.class); GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), GeneralBuildingBlock.class); ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), @@ -2453,171 +2229,147 @@ public class BBInputSetupTest { lookupKeyMap.put(ResourceKey.VF_MODULE_ID, "vfModuleId"); lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, "volumeGroupId"); lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "serviceInstanceId"); - String resourceId = "123"; - String vnfType = "vnfType"; - Service service = Mockito.mock(Service.class); - String requestAction = "deactivateInstance"; + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName("DeactivateServiceInstanceBB").setKey("3c40d244-808e-42ca-b09a-256d83d19d0a"); + doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); doReturn(service).when(SPY_bbInputSetupUtils) .getCatalogServiceByModelUUID(gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid()); - String generatedId = "12131"; - executeBB.getBuildingBlock().setBpmnFlowName("DeactivateServiceInstanceBB"); - executeBB.getBuildingBlock().setKey("3c40d244-808e-42ca-b09a-256d83d19d0a"); GeneralBuildingBlock actual = SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); assertThat(actual, sameBeanAs(gBB)); } @Test - public void testgetGBBMacroNoUserParamsCreateInstance() throws Exception { + public void test_getGBBMacroNoUserParamsCreate_shouldBeCalled() throws Exception { + // given + String resourceId = "123"; + String vnfType = "vnfType"; + String requestAction = "createInstance"; + Service service = Mockito.mock(Service.class); GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), GeneralBuildingBlock.class); - ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), - ExecuteBuildingBlock.class); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + List<NetworkResourceCustomization> networkCustList = new ArrayList<>(); + NetworkResourceCustomization networkCust = Mockito.mock(NetworkResourceCustomization.class); + networkCustList.add(networkCust); + + ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys(); RequestDetails requestDetails = mapper .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); - InfraActiveRequests request = Mockito.mock(InfraActiveRequests.class); requestDetails.getRequestParameters().setUserParams(null); - org.onap.aai.domain.yang.GenericVnf aaiVnf = new org.onap.aai.domain.yang.GenericVnf(); - aaiVnf.setModelCustomizationId("modelCustId"); - Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); - lookupKeyMap.put(ResourceKey.NETWORK_ID, "networkId"); - lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, "vnfId"); - lookupKeyMap.put(ResourceKey.VF_MODULE_ID, "vfModuleId"); - lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, "volumeGroupId"); - lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "serviceInstanceId"); - lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, "configurationId"); - - ConfigurationResourceKeys configResourceKeys = new ConfigurationResourceKeys(); - configResourceKeys.setCvnfcCustomizationUUID("cvnfcCustomizationUUID"); - configResourceKeys.setVfModuleCustomizationUUID("vfModuleCustomizationUUID"); - configResourceKeys.setVnfResourceCustomizationUUID("vnfResourceCustomizationUUID"); - executeBB.setConfigurationResourceKeys(configResourceKeys); + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + executeBB.setConfigurationResourceKeys(configResourceKeys).setRequestDetails(requestDetails); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName(AssignFlows.NETWORK_MACRO.toString()) + .setKey("ab153b6e-c364-44c0-bef6-1f2982117f04").setIsVirtualLink(false); - String resourceId = "123"; - String vnfType = "vnfType"; - Service service = Mockito.mock(Service.class); - String requestAction = "createInstance"; doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); - - doReturn(service).when(SPY_bbInputSetupUtils) .getCatalogServiceByModelUUID(gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid()); - List<NetworkResourceCustomization> networkCustList = new ArrayList<>(); - NetworkResourceCustomization networkCust = Mockito.mock(NetworkResourceCustomization.class); - doReturn("ab153b6e-c364-44c0-bef6-1f2982117f04").when(networkCust).getModelCustomizationUUID(); - networkCustList.add(networkCust); doReturn(networkCustList).when(service).getNetworkCustomizations(); + doReturn("ab153b6e-c364-44c0-bef6-1f2982117f04").when(networkCust).getModelCustomizationUUID(); doNothing().when(SPY_bbInputSetup).populateL3Network(any(), isA(ModelInfo.class), isA(Service.class), any(String.class), isA(ServiceInstance.class), any(), any(String.class), any()); - - executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.NETWORK_MACRO.toString()); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); - executeBB.getBuildingBlock().setIsVirtualLink(false); + // when SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); + // then verify(SPY_bbInputSetup, times(1)).getGBBMacroNoUserParamsCreate(executeBB, lookupKeyMap, executeBB.getBuildingBlock().getBpmnFlowName(), "ab153b6e-c364-44c0-bef6-1f2982117f04", gBB, service); + } + @Test + public void test_getGBBMacroNoUserParamsCreate_shouldBeCalled_whenBBhasVirtualLink() throws Exception { + // given + String resourceId = "123"; + String vnfType = "vnfType"; + String requestAction = "createInstance"; + Service service = Mockito.mock(Service.class); + GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), + GeneralBuildingBlock.class); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + List<NetworkResourceCustomization> networkCustList = new ArrayList<>(); + NetworkResourceCustomization networkCust = Mockito.mock(NetworkResourceCustomization.class); + networkCustList.add(networkCust); CollectionNetworkResourceCustomization collectionNetworkResourceCust = Mockito.mock(CollectionNetworkResourceCustomization.class); + org.onap.aai.domain.yang.GenericVnf aaiVnf = new org.onap.aai.domain.yang.GenericVnf(); + aaiVnf.setModelCustomizationId("modelCustId"); + ModelInfoNetwork modelInfoNetwork = Mockito.mock(ModelInfoNetwork.class); + NetworkResourceCustomization networkResourceCustomization = Mockito.mock(NetworkResourceCustomization.class); + + ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys(); + RequestDetails requestDetails = mapper + .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); + requestDetails.getRequestParameters().setUserParams(null); + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + executeBB.setConfigurationResourceKeys(configResourceKeys).setRequestDetails(requestDetails); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName(AssignFlows.NETWORK_MACRO.toString()) + .setKey("ab153b6e-c364-44c0-bef6-1f2982117f04").setIsVirtualLink(true); + + doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, + requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); + doReturn(service).when(SPY_bbInputSetupUtils) + .getCatalogServiceByModelUUID(gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid()); doReturn(collectionNetworkResourceCust).when(SPY_bbInputSetupUtils) .getCatalogCollectionNetworkResourceCustByID(any(String.class)); - NetworkResourceCustomization networkResourceCustomization = Mockito.mock(NetworkResourceCustomization.class); doReturn(networkResourceCustomization).when(bbInputSetupMapperLayer) .mapCollectionNetworkResourceCustToNetworkResourceCust(collectionNetworkResourceCust); - ModelInfoNetwork modelInfoNetwork = Mockito.mock(ModelInfoNetwork.class); doReturn(modelInfoNetwork).when(bbInputSetupMapperLayer) .mapCatalogNetworkToNetwork(networkResourceCustomization); - - executeBB.getBuildingBlock().setBpmnFlowName(AssignFlows.NETWORK_MACRO.toString()); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); - executeBB.getBuildingBlock().setIsVirtualLink(true); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(2)).getGBBMacroNoUserParamsCreate(executeBB, lookupKeyMap, - executeBB.getBuildingBlock().getBpmnFlowName(), "ab153b6e-c364-44c0-bef6-1f2982117f04", gBB, service); - - executeBB.getBuildingBlock().setBpmnFlowName("CreateNetworkBB"); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); - executeBB.getBuildingBlock().setIsVirtualLink(true); + // when SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); + // then verify(SPY_bbInputSetup, times(1)).getGBBMacroNoUserParamsCreate(executeBB, lookupKeyMap, executeBB.getBuildingBlock().getBpmnFlowName(), "ab153b6e-c364-44c0-bef6-1f2982117f04", gBB, service); } @Test - public void testgetGBBMacroNoUserParamsOther() throws Exception { + public void test_getGBBMacroNoUserParamsCreate_shouldBeCalled_whenBBhasVirtualLinkAndOtherFlowName() + throws Exception { + // given + String otherFlowName = "CreateNetworkBB"; + String resourceId = "123"; + String vnfType = "vnfType"; + String requestAction = "createInstance"; + Service service = Mockito.mock(Service.class); GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), GeneralBuildingBlock.class); - ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), - ExecuteBuildingBlock.class); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + List<NetworkResourceCustomization> networkCustList = new ArrayList<>(); + NetworkResourceCustomization networkCust = Mockito.mock(NetworkResourceCustomization.class); + networkCustList.add(networkCust); + CollectionNetworkResourceCustomization collectionNetworkResourceCust = + Mockito.mock(CollectionNetworkResourceCustomization.class); + + ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys(); RequestDetails requestDetails = mapper .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); requestDetails.getRequestParameters().setUserParams(null); - org.onap.aai.domain.yang.GenericVnf aaiVnf = new org.onap.aai.domain.yang.GenericVnf(); - aaiVnf.setModelCustomizationId("modelCustId"); - Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); - lookupKeyMap.put(ResourceKey.NETWORK_ID, "networkId"); - lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, "vnfId"); - lookupKeyMap.put(ResourceKey.VF_MODULE_ID, "vfModuleId"); - lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, "volumeGroupId"); - lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "serviceInstanceId"); - String resourceId = "123"; - String vnfType = "vnfType"; - Service service = Mockito.mock(Service.class); - String requestAction = "deleteInstance"; + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + executeBB.setConfigurationResourceKeys(configResourceKeys).setRequestDetails(requestDetails); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName(otherFlowName).setKey("ab153b6e-c364-44c0-bef6-1f2982117f04") + .setIsVirtualLink(true); - executeBB.setRequestDetails(requestDetails); - ServiceInstance serviceInstance = gBB.getServiceInstance(); - org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = new org.onap.aai.domain.yang.ServiceInstance(); - aaiServiceInstance.setModelVersionId("modelVersionId"); + doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, + requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); doReturn(service).when(SPY_bbInputSetupUtils) - .getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId()); - doReturn(aaiServiceInstance).when(SPY_bbInputSetupUtils) - .getAAIServiceInstanceById(lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); - doReturn(serviceInstance).when(SPY_bbInputSetup).getExistingServiceInstance(aaiServiceInstance); - doReturn(gBB).when(SPY_bbInputSetup).populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, - executeBB, requestAction, null); - - CloudConfiguration cloudConfig = new CloudConfiguration(); - cloudConfig.setLcpCloudRegionId("lcpCloudRegionId"); - requestDetails.setCloudConfiguration(cloudConfig); - org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = Mockito.mock(org.onap.aai.domain.yang.CloudRegion.class); - doReturn(aaiCloudRegion).when(SPY_bbInputSetupUtils).getCloudRegion(requestDetails.getCloudConfiguration()); - executeBB.getBuildingBlock().setBpmnFlowName("DeleteNetworkBB"); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(1)).getGBBMacroExistingService(isA(ExecuteBuildingBlock.class), any(), - any(String.class), isA(String.class), isA(CloudConfiguration.class)); - - requestAction = "activateInstance"; - doReturn(gBB).when(SPY_bbInputSetup).populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, - executeBB, requestAction, null); - executeBB.getBuildingBlock().setBpmnFlowName("ActivateNetworkBB"); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(2)).getGBBMacroExistingService(isA(ExecuteBuildingBlock.class), any(), - any(String.class), isA(String.class), isA(CloudConfiguration.class)); - - requestAction = "unassignInstance"; - doReturn(gBB).when(SPY_bbInputSetup).populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, - executeBB, requestAction, null); - executeBB.getBuildingBlock().setBpmnFlowName("UnassignNetworkBB"); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); - SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(3)).getGBBMacroExistingService(isA(ExecuteBuildingBlock.class), any(), - any(String.class), isA(String.class), isA(CloudConfiguration.class)); - - requestAction = "activateFabricConfiguration"; - doReturn(gBB).when(SPY_bbInputSetup).populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, - executeBB, requestAction, null); - executeBB.getBuildingBlock().setBpmnFlowName("ActivateFabricConfigurationBB"); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-134534656234"); + .getCatalogServiceByModelUUID(gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid()); + doReturn(collectionNetworkResourceCust).when(SPY_bbInputSetupUtils) + .getCatalogCollectionNetworkResourceCustByID(any(String.class)); + // when SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); - verify(SPY_bbInputSetup, times(4)).getGBBMacroExistingService(isA(ExecuteBuildingBlock.class), any(), - any(String.class), isA(String.class), isA(CloudConfiguration.class)); + // then + verify(SPY_bbInputSetup, times(1)).getGBBMacroNoUserParamsCreate(executeBB, lookupKeyMap, + executeBB.getBuildingBlock().getBpmnFlowName(), "ab153b6e-c364-44c0-bef6-1f2982117f04", gBB, service); } @Test(expected = IllegalArgumentException.class) @@ -2647,40 +2399,37 @@ public class BBInputSetupTest { .getCatalogServiceByModelUUID(gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid()); String generatedId = "12131"; - executeBB.getBuildingBlock().setKey("3c40d244-808e-42ca-b09a-256d83d19d0a"); SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType); } @Test - public void testgetGBBMacroNoUserParamsExistingService() throws Exception { + public void test_getGBBMacroNoUserParamsExistingService_forCatalogNetwork() throws Exception { + // given + String requestAction = "unassignInstance"; GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), GeneralBuildingBlock.class); + L3Network network = new L3Network(); + network.setNetworkId("networkId"); + gBB.getServiceInstance().getNetworks().add(network); + ServiceInstance serviceInstance = gBB.getServiceInstance(); ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), ExecuteBuildingBlock.class); RequestDetails requestDetails = mapper .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); requestDetails.getRequestParameters().setUserParams(null); - Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); - lookupKeyMap.put(ResourceKey.NETWORK_ID, "networkId"); - lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, "vnfId"); - lookupKeyMap.put(ResourceKey.VF_MODULE_ID, "vfModuleId"); - lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, "volumeGroupId"); - lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "serviceInstanceId"); - lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, "configurationId"); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); Service service = Mockito.mock(Service.class); CloudConfiguration cloudConfiguration = new CloudConfiguration(); cloudConfiguration.setLcpCloudRegionId("cloudRegionId"); - String requestAction = "unassignInstance"; - executeBB.setRequestDetails(requestDetails); + org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = new org.onap.aai.domain.yang.ServiceInstance(); + org.onap.aai.domain.yang.L3Network aaiNetwork = new org.onap.aai.domain.yang.L3Network(); + aaiNetwork.setModelCustomizationId("modelCustId"); - ConfigurationResourceKeys configResourceKeys = new ConfigurationResourceKeys(); - configResourceKeys.setCvnfcCustomizationUUID("cvnfcCustomizationUUID"); - configResourceKeys.setVfModuleCustomizationUUID("vfModuleCustomizationUUID"); - configResourceKeys.setVnfResourceCustomizationUUID("vnfResourceCustomizationUUID"); - executeBB.setConfigurationResourceKeys(configResourceKeys); + ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys(); + executeBB.setConfigurationResourceKeys(configResourceKeys).setRequestDetails(requestDetails); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName("DeleteNetworkBB").setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); - ServiceInstance serviceInstance = gBB.getServiceInstance(); - org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = new org.onap.aai.domain.yang.ServiceInstance(); aaiServiceInstance.setModelVersionId("modelVersionId"); doReturn(service).when(SPY_bbInputSetupUtils) .getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId()); @@ -2689,89 +2438,252 @@ public class BBInputSetupTest { doReturn(serviceInstance).when(SPY_bbInputSetup).getExistingServiceInstance(aaiServiceInstance); doReturn(gBB).when(SPY_bbInputSetup).populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, null); - - L3Network network = new L3Network(); - network.setNetworkId("networkId"); - gBB.getServiceInstance().getNetworks().add(network); - org.onap.aai.domain.yang.L3Network aaiNetwork = new org.onap.aai.domain.yang.L3Network(); - aaiNetwork.setModelCustomizationId("modelCustId"); doReturn(aaiNetwork).when(SPY_bbInputSetupUtils).getAAIL3Network(network.getNetworkId()); doNothing().when(SPY_bbInputSetup).mapCatalogNetwork(any(L3Network.class), any(ModelInfo.class), any(Service.class)); - - executeBB.getBuildingBlock().setBpmnFlowName("DeleteNetworkBB"); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); + // when SPY_bbInputSetup.getGBBMacroExistingService(executeBB, lookupKeyMap, executeBB.getBuildingBlock().getBpmnFlowName(), requestAction, null); + // then verify(SPY_bbInputSetup, times(1)).mapCatalogNetwork(any(L3Network.class), any(ModelInfo.class), any(Service.class)); + } + @Test + public void test_getGBBMacroNoUserParamsExistingService_forActivateVnfBB() throws Exception { + // given + String requestAction = "unassignInstance"; + GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), + GeneralBuildingBlock.class); + L3Network network = new L3Network(); + network.setNetworkId("networkId"); + gBB.getServiceInstance().getNetworks().add(network); + ServiceInstance serviceInstance = gBB.getServiceInstance(); + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + RequestDetails requestDetails = mapper + .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); + requestDetails.getRequestParameters().setUserParams(null); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + Service service = Mockito.mock(Service.class); + CloudConfiguration cloudConfiguration = new CloudConfiguration(); + cloudConfiguration.setLcpCloudRegionId("cloudRegionId"); + org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = new org.onap.aai.domain.yang.ServiceInstance(); + org.onap.aai.domain.yang.L3Network aaiNetwork = new org.onap.aai.domain.yang.L3Network(); + aaiNetwork.setModelCustomizationId("modelCustId"); GenericVnf vnf = new GenericVnf(); vnf.setVnfId("vnfId"); gBB.getServiceInstance().getVnfs().add(vnf); org.onap.aai.domain.yang.GenericVnf aaiVnf = new org.onap.aai.domain.yang.GenericVnf(); aaiVnf.setModelCustomizationId("modelCustId"); + + ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys(); + executeBB.setConfigurationResourceKeys(configResourceKeys).setRequestDetails(requestDetails); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName("ActivateVnfBB").setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); + + aaiServiceInstance.setModelVersionId("modelVersionId"); + doReturn(service).when(SPY_bbInputSetupUtils) + .getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId()); + doReturn(aaiServiceInstance).when(SPY_bbInputSetupUtils) + .getAAIServiceInstanceById(lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); + doReturn(serviceInstance).when(SPY_bbInputSetup).getExistingServiceInstance(aaiServiceInstance); + doReturn(gBB).when(SPY_bbInputSetup).populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, + executeBB, requestAction, null); doReturn(aaiVnf).when(SPY_bbInputSetupUtils).getAAIGenericVnf(vnf.getVnfId()); doNothing().when(SPY_bbInputSetup).mapCatalogVnf(any(GenericVnf.class), any(ModelInfo.class), any(Service.class)); - - executeBB.getBuildingBlock().setBpmnFlowName("ActivateVnfBB"); - executeBB.getBuildingBlock().setKey("ab153b6e-c364-44c0-bef6-1f2982117f04"); + // when SPY_bbInputSetup.getGBBMacroExistingService(executeBB, lookupKeyMap, executeBB.getBuildingBlock().getBpmnFlowName(), requestAction, cloudConfiguration); + // then verify(SPY_bbInputSetup, times(1)).mapCatalogVnf(any(GenericVnf.class), any(ModelInfo.class), any(Service.class)); + } + @Test + public void test_getGBBMacroNoUserParamsExistingService_forUnassignVfModuleBB() throws Exception { + // given + String requestAction = "unassignInstance"; + GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), + GeneralBuildingBlock.class); + L3Network network = new L3Network(); + network.setNetworkId("networkId"); + gBB.getServiceInstance().getNetworks().add(network); + ServiceInstance serviceInstance = gBB.getServiceInstance(); + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + RequestDetails requestDetails = mapper + .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); + requestDetails.getRequestParameters().setUserParams(null); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + Service service = Mockito.mock(Service.class); + CloudConfiguration cloudConfiguration = new CloudConfiguration(); + cloudConfiguration.setLcpCloudRegionId("cloudRegionId"); + org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = new org.onap.aai.domain.yang.ServiceInstance(); + org.onap.aai.domain.yang.L3Network aaiNetwork = new org.onap.aai.domain.yang.L3Network(); + aaiNetwork.setModelCustomizationId("modelCustId"); + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("vnfId"); + gBB.getServiceInstance().getVnfs().add(vnf); + org.onap.aai.domain.yang.GenericVnf aaiVnf = new org.onap.aai.domain.yang.GenericVnf(); + aaiVnf.setModelCustomizationId("modelCustId"); VfModule vfModule = new VfModule(); vfModule.setVfModuleId("vfModuleId"); gBB.getServiceInstance().getVnfs().get(0).getVfModules().add(vfModule); org.onap.aai.domain.yang.VfModule aaiVfModule = new org.onap.aai.domain.yang.VfModule(); aaiVfModule.setModelCustomizationId("modelCustId"); - doReturn(aaiVfModule).when(SPY_bbInputSetupUtils).getAAIVfModule(vnf.getVnfId(), vfModule.getVfModuleId()); - executeBB.getBuildingBlock().setBpmnFlowName("UnassignVfModuleBB"); - executeBB.getBuildingBlock().setKey("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys(); + executeBB.setConfigurationResourceKeys(configResourceKeys).setRequestDetails(requestDetails); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName("UnassignVfModuleBB").setKey("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + + aaiServiceInstance.setModelVersionId("modelVersionId"); + doReturn(service).when(SPY_bbInputSetupUtils) + .getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId()); + doReturn(aaiServiceInstance).when(SPY_bbInputSetupUtils) + .getAAIServiceInstanceById(lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); + doReturn(serviceInstance).when(SPY_bbInputSetup).getExistingServiceInstance(aaiServiceInstance); + doReturn(gBB).when(SPY_bbInputSetup).populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, + executeBB, requestAction, null); + doReturn(aaiVnf).when(SPY_bbInputSetupUtils).getAAIGenericVnf(vnf.getVnfId()); + doNothing().when(SPY_bbInputSetup).mapCatalogVnf(any(GenericVnf.class), any(ModelInfo.class), + any(Service.class)); + doReturn(aaiVfModule).when(SPY_bbInputSetupUtils).getAAIVfModule(vnf.getVnfId(), vfModule.getVfModuleId()); + // when SPY_bbInputSetup.getGBBMacroExistingService(executeBB, lookupKeyMap, executeBB.getBuildingBlock().getBpmnFlowName(), requestAction, cloudConfiguration); - verify(SPY_bbInputSetup, times(2)).mapCatalogVnf(any(GenericVnf.class), any(ModelInfo.class), + // then + verify(SPY_bbInputSetup, times(1)).mapCatalogVnf(any(GenericVnf.class), any(ModelInfo.class), any(Service.class)); verify(SPY_bbInputSetup, times(1)).mapCatalogVfModule(any(VfModule.class), any(ModelInfo.class), any(Service.class), any(String.class)); + } + @Test + public void test_getGBBMacroNoUserParamsExistingService_forUnassignVolumeGroupBB() throws Exception { + // given + String requestAction = "unassignInstance"; + GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), + GeneralBuildingBlock.class); + L3Network network = new L3Network(); + network.setNetworkId("networkId"); + gBB.getServiceInstance().getNetworks().add(network); + ServiceInstance serviceInstance = gBB.getServiceInstance(); + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + RequestDetails requestDetails = mapper + .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); + requestDetails.getRequestParameters().setUserParams(null); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + Service service = Mockito.mock(Service.class); + org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = new org.onap.aai.domain.yang.ServiceInstance(); + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("vnfId"); + gBB.getServiceInstance().getVnfs().add(vnf); + org.onap.aai.domain.yang.GenericVnf aaiVnf = new org.onap.aai.domain.yang.GenericVnf(); + aaiVnf.setModelCustomizationId("modelCustId"); + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("vfModuleId"); + gBB.getServiceInstance().getVnfs().get(0).getVfModules().add(vfModule); CloudRegion cloudRegion = new CloudRegion(); cloudRegion.setLcpCloudRegionId("cloudRegionId"); cloudRegion.setCloudOwner("CloudOwner"); - doReturn(Optional.of(cloudRegion)).when(SPY_cloudInfoFromAAI).getCloudInfoFromAAI(gBB.getServiceInstance()); VolumeGroup volumeGroup = new VolumeGroup(); volumeGroup.setVolumeGroupId("volumeGroupId"); gBB.getServiceInstance().getVnfs().get(0).getVolumeGroups().add(volumeGroup); org.onap.aai.domain.yang.VolumeGroup aaiVolumeGroup = new org.onap.aai.domain.yang.VolumeGroup(); aaiVolumeGroup.setModelCustomizationId("modelCustId"); + + ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys(); + executeBB.setConfigurationResourceKeys(configResourceKeys).setRequestDetails(requestDetails); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName("UnassignVolumeGroupBB").setKey("72d9d1cd-f46d-447a-abdb-451d6fb05fa8"); + + aaiServiceInstance.setModelVersionId("modelVersionId"); + doReturn(service).when(SPY_bbInputSetupUtils) + .getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId()); + doReturn(aaiServiceInstance).when(SPY_bbInputSetupUtils) + .getAAIServiceInstanceById(lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); + doReturn(serviceInstance).when(SPY_bbInputSetup).getExistingServiceInstance(aaiServiceInstance); + doReturn(gBB).when(SPY_bbInputSetup).populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, + executeBB, requestAction, null); + doReturn(aaiVnf).when(SPY_bbInputSetupUtils).getAAIGenericVnf(vnf.getVnfId()); + doNothing().when(SPY_bbInputSetup).mapCatalogVnf(any(GenericVnf.class), any(ModelInfo.class), + any(Service.class)); doReturn(aaiVolumeGroup).when(SPY_bbInputSetupUtils).getAAIVolumeGroup(cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId(), volumeGroup.getVolumeGroupId()); + doReturn(Optional.of(cloudRegion)).when(SPY_cloudInfoFromAAI).getCloudInfoFromAAI(gBB.getServiceInstance()); - executeBB.getBuildingBlock().setBpmnFlowName("UnassignVolumeGroupBB"); - executeBB.getBuildingBlock().setKey("72d9d1cd-f46d-447a-abdb-451d6fb05fa8"); + // when SPY_bbInputSetup.getGBBMacroExistingService(executeBB, lookupKeyMap, executeBB.getBuildingBlock().getBpmnFlowName(), requestAction, null); - verify(SPY_bbInputSetup, times(3)).mapCatalogVnf(any(GenericVnf.class), any(ModelInfo.class), + // then + verify(SPY_bbInputSetup, times(1)).mapCatalogVnf(any(GenericVnf.class), any(ModelInfo.class), any(Service.class)); verify(SPY_bbInputSetup, times(1)).mapCatalogVolumeGroup(isA(VolumeGroup.class), isA(ModelInfo.class), isA(Service.class), isA(String.class)); + } + @Test + public void test_getGBBMacroNoUserParamsExistingService_forActivateFabricConfigurationBB() throws Exception { + // given + String requestAction = "unassignInstance"; + GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), + GeneralBuildingBlock.class); + L3Network network = new L3Network(); + network.setNetworkId("networkId"); + gBB.getServiceInstance().getNetworks().add(network); + ServiceInstance serviceInstance = gBB.getServiceInstance(); + ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), + ExecuteBuildingBlock.class); + RequestDetails requestDetails = mapper + .readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class); + requestDetails.getRequestParameters().setUserParams(null); + Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap(); + Service service = Mockito.mock(Service.class); + org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = new org.onap.aai.domain.yang.ServiceInstance(); + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("vnfId"); + gBB.getServiceInstance().getVnfs().add(vnf); + org.onap.aai.domain.yang.GenericVnf aaiVnf = new org.onap.aai.domain.yang.GenericVnf(); + aaiVnf.setModelCustomizationId("modelCustId"); + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("vfModuleId"); + gBB.getServiceInstance().getVnfs().get(0).getVfModules().add(vfModule); + VolumeGroup volumeGroup = new VolumeGroup(); + volumeGroup.setVolumeGroupId("volumeGroupId"); + gBB.getServiceInstance().getVnfs().get(0).getVolumeGroups().add(volumeGroup); + CloudConfiguration cloudConfiguration = new CloudConfiguration(); + cloudConfiguration.setLcpCloudRegionId("cloudRegionId"); Configuration configuration = new Configuration(); configuration.setConfigurationId("configurationId"); gBB.getServiceInstance().getConfigurations().add(configuration); org.onap.aai.domain.yang.Configuration aaiConfiguration = new org.onap.aai.domain.yang.Configuration(); aaiConfiguration.setModelCustomizationId("modelCustId"); + + ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys(); + executeBB.setConfigurationResourceKeys(configResourceKeys).setRequestDetails(requestDetails); + BuildingBlock buildingBlock = executeBB.getBuildingBlock(); + buildingBlock.setBpmnFlowName("ActivateFabricConfigurationBB").setKey("72d9d1cd-f46d-447a-abdb-451d6fb05fa9"); + + aaiServiceInstance.setModelVersionId("modelVersionId"); + doReturn(service).when(SPY_bbInputSetupUtils) + .getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId()); + doReturn(aaiServiceInstance).when(SPY_bbInputSetupUtils) + .getAAIServiceInstanceById(lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID)); + doReturn(serviceInstance).when(SPY_bbInputSetup).getExistingServiceInstance(aaiServiceInstance); + doReturn(gBB).when(SPY_bbInputSetup).populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, + executeBB, requestAction, null); doReturn(aaiConfiguration).when(SPY_bbInputSetupUtils).getAAIConfiguration(configuration.getConfigurationId()); doNothing().when(SPY_bbInputSetup).mapCatalogConfiguration(isA(Configuration.class), isA(ModelInfo.class), isA(Service.class), isA(ConfigurationResourceKeys.class)); - executeBB.getBuildingBlock().setBpmnFlowName("ActivateFabricConfigurationBB"); - executeBB.getBuildingBlock().setKey("72d9d1cd-f46d-447a-abdb-451d6fb05fa9"); + // when SPY_bbInputSetup.getGBBMacroExistingService(executeBB, lookupKeyMap, executeBB.getBuildingBlock().getBpmnFlowName(), requestAction, cloudConfiguration); + // then verify(SPY_bbInputSetup, times(1)).mapCatalogConfiguration(any(Configuration.class), any(ModelInfo.class), any(Service.class), isA(ConfigurationResourceKeys.class)); } @@ -2821,9 +2733,8 @@ public class BBInputSetupTest { @Test public void testGetVnfId() { String expected = "vnfId"; - ExecuteBuildingBlock executeBB = new ExecuteBuildingBlock(); + ExecuteBuildingBlock executeBB = new ExecuteBuildingBlock().setRequestId("requestId"); Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); - executeBB.setRequestId("requestId"); InfraActiveRequests request = new InfraActiveRequests(); request.setVnfId(expected); doReturn(request).when(SPY_bbInputSetupUtils).getInfraActiveRequest(executeBB.getRequestId()); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BaseBBInputSetupTestHelper.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BaseBBInputSetupTestHelper.java new file mode 100644 index 0000000000..adeb4d0eb0 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BaseBBInputSetupTestHelper.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * 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.so.bpmn.servicedecomposition.tasks; + +import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import java.util.HashMap; +import java.util.Map; + +public class BaseBBInputSetupTestHelper { + + public static Map<ResourceKey, String> prepareLookupKeyMap() { + Map<ResourceKey, String> lookupKeyMap = new HashMap<>(); + lookupKeyMap.put(ResourceKey.NETWORK_ID, "networkId"); + lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, "vnfId"); + lookupKeyMap.put(ResourceKey.VF_MODULE_ID, "vfModuleId"); + lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, "volumeGroupId"); + lookupKeyMap.put(ResourceKey.SERVICE_INSTANCE_ID, "serviceInstanceId"); + lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, "configurationId"); + return lookupKeyMap; + } + + public static ConfigurationResourceKeys prepareConfigurationResourceKeys() { + ConfigurationResourceKeys configResourceKeys = new ConfigurationResourceKeys(); + configResourceKeys.setCvnfcCustomizationUUID("cvnfcCustomizationUUID"); + configResourceKeys.setVfModuleCustomizationUUID("vfModuleCustomizationUUID"); + configResourceKeys.setVnfResourceCustomizationUUID("vnfResourceCustomizationUUID"); + return configResourceKeys; + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BuildingBlockTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BuildingBlockTest.java new file mode 100644 index 0000000000..f87382aa98 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BuildingBlockTest.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * 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.so.bpmn.servicedecomposition.tasks; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Test; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import java.io.File; +import java.io.IOException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +public class BuildingBlockTest { + private static final String RESOURCE_PATH = "src/test/resources/__files/BuildingBlock/"; + private ObjectMapper mapper = new ObjectMapper(); + + @Test + public void simpleJson_shouldBeProperlyDeserialized() throws IOException { + // given + BuildingBlock expectedBuildingBlock = new BuildingBlock(); + expectedBuildingBlock.setMsoId("msoId").setBpmnFlowName("bbName"); + // when + BuildingBlock result = + mapper.readValue(new File(RESOURCE_PATH + "BuildingBlockSimple.json"), BuildingBlock.class); + // then + assertEquals(expectedBuildingBlock.getBpmnFlowName(), result.getBpmnFlowName()); + assertEquals(expectedBuildingBlock.getMsoId(), result.getMsoId()); + assertNull(result.getKey()); + assertNull(result.getVirtualLinkKey()); + assertNull(result.isVirtualLink()); + } + + @Test + public void fullJson_shouldBeProperlyDeserialized() throws IOException { + // given + BuildingBlock expectedBuildingBlock = new BuildingBlock().setMsoId("msoId").setBpmnFlowName("bbName") + .setVirtualLinkKey("sampleVirtualLinkKey").setIsVirtualLink(true).setKey("sampleKey") + .setBpmnScope("sampleScope").setBpmnAction("sampleAction"); + // when + BuildingBlock result = + mapper.readValue(new File(RESOURCE_PATH + "BuildingBlockAllParameters.json"), BuildingBlock.class); + // then + assertEquals(expectedBuildingBlock.getBpmnFlowName(), result.getBpmnFlowName()); + assertEquals(expectedBuildingBlock.getMsoId(), result.getMsoId()); + assertEquals(true, result.isVirtualLink()); + assertEquals(expectedBuildingBlock.getVirtualLinkKey(), result.getVirtualLinkKey()); + assertEquals(expectedBuildingBlock.getKey(), result.getKey()); + assertEquals(expectedBuildingBlock.getBpmnScope(), result.getBpmnScope()); + assertEquals(expectedBuildingBlock.getBpmnAction(), result.getBpmnAction()); + } +} 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/ExecuteBuildingBlockRainyDayTest.java index 18e08917ed..ee47b514d1 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/ExecuteBuildingBlockRainyDayTest.java @@ -42,15 +42,13 @@ import org.onap.so.constants.Status; import org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus; import org.springframework.beans.factory.annotation.Autowired; -public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { +public class ExecuteBuildingBlockRainyDayTest extends BaseTest { @Autowired private ExecuteBuildingBlockRainyDay executeBuildingBlockRainyDay; private ServiceInstance serviceInstance; private Customer customer; // will build service sub private GenericVnf vnf; - private BuildingBlock buildingBlock; - private ExecuteBuildingBlock executeBuildingBlock; private static final String ASTERISK = "*"; @Before @@ -59,11 +57,8 @@ public class ExecuteBuildlingBlockRainyDayTest extends BaseTest { customer = setCustomer(); vnf = setGenericVnf(); - buildingBlock = new BuildingBlock(); - buildingBlock.setBpmnFlowName("AssignServiceInstanceBB"); - - executeBuildingBlock = new ExecuteBuildingBlock(); - executeBuildingBlock.setBuildingBlock(buildingBlock); + BuildingBlock buildingBlock = new BuildingBlock().setBpmnFlowName("AssignServiceInstanceBB"); + ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock); delegateExecution.setVariable("gBBInput", gBBInput); delegateExecution.setVariable("WorkflowException", new WorkflowException("", 7000, "")); diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlock/BuildingBlockAllParameters.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlock/BuildingBlockAllParameters.json new file mode 100644 index 0000000000..f99fea62db --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlock/BuildingBlockAllParameters.json @@ -0,0 +1,9 @@ +{ + "mso-id": "msoId", + "bpmn-flow-name": "bbName", + "key": "sampleKey", + "is-virtual-link": true, + "virtual-link-key": "sampleVirtualLinkKey", + "scope": "sampleScope", + "action": "sampleAction" +}
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlock/BuildingBlockSimple.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlock/BuildingBlockSimple.json new file mode 100644 index 0000000000..3ffc18da16 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/BuildingBlock/BuildingBlockSimple.json @@ -0,0 +1,4 @@ +{ + "mso-id": "msoId", + "bpmn-flow-name": "bbName" +}
\ No newline at end of file diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/ExecuteBuildingBlockExtended.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/ExecuteBuildingBlockExtended.json new file mode 100644 index 0000000000..defe40b50a --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/ExecuteBuildingBlockExtended.json @@ -0,0 +1,8 @@ +{ + "buildingBlock":{ + "mso-id":"msoId", + "bpmn-flow-name":"bbName" + }, + "requestId":"requestId", + "aLaCarte":true +} diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockWithVnf.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockWithVnf.json new file mode 100644 index 0000000000..ca2b76e4bf --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockWithVnf.json @@ -0,0 +1,127 @@ +{ + "requestContext": { + "product-family-id": "productFamilyId", + "source": "source", + "requestor-id": "requestorId", + "mso-request-id": "requestId", + "subscription-service-type": "subscriptionServiceType", + "user-params": { + "name1": "value1", + "name2": "value2" + }, + "action": "createInstance", + "callback-url": "callbackURL", + "requestParameters": { + "subscriptionServiceType": "subscriptionServiceType", + "userParams": [ + { + "name": "name1", + "value": "value1" + }, + { + "name": "name2", + "value": "value2" + }, + { + "ignore": "false", + "skip": "ignore" + } + ] + }, + "configurationParameters": [ + { + "availability-zone":"$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]", + "xtz-123":"$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]" + } + ] + }, + "orchContext": { + "is-rollback-enabled": false + }, + "cloudRegion": { + "lcp-cloud-region-id": "lcpCloudRegionId", + "cloud-owner": "test-owner-name", + "tenant-id": "tenantId", + "complex": "complexName" + }, + "tenant": { + "tenant-name": "tenantName", + "tenant-context": "tenantContext", + "tenant-id": "tenantId" + }, + "userInput": null, + "customer": { + "global-customer-id": "globalCustomerId", + "subscriber-name": "subscriberName", + "subscriber-type": "subscriberType", + "service-subscription": { + "service-type": "subscriptionServiceType", + "service-instances": [ + { + "service-instance-id": "3655a595-05d1-433c-93c0-3afd6b572545", + "service-instance-name": "serviceInstanceName", + "orchestration-status": "PRECREATED", + "owning-entity": { + "owning-entity-id": "owningEntityId", + "owning-entity-name": "owningEntityName" + }, + "project": { + "project-name": "projectName" + }, + "vnfs": [], + "allotted-resources": [], + "networks": [], + "vhn-portal-url": null, + "service-instance-location-id": null, + "selflink": null, + "metadata": null, + "configurations": [], + "model-info-service-instance": { + "description": "description", + "created": null, + "model-name": "modelName", + "model-uuid": "modelUUID", + "model-invariant-uuid": "modelInvariantUUID", + "model-version": "modelVersion", + "service-type": "serviceType", + "service-role": "serviceRole", + "environment-context": "environmentContext", + "workload-context": "workloadContext" + } + } + ] + } + }, + "serviceInstance": { + "service-instance-id": "3655a595-05d1-433c-93c0-3afd6b572545", + "service-instance-name": "serviceInstanceName", + "orchestration-status": "PRECREATED", + "owning-entity": { + "owning-entity-id": "owningEntityId", + "owning-entity-name": "owningEntityName" + }, + "project": { + "project-name": "projectName" + }, + "vnfs": [{"vnf-id": "vnfId" }], + "allotted-resources": [], + "networks": [], + "vhn-portal-url": null, + "service-instance-location-id": null, + "selflink": null, + "metadata": null, + "configurations": [], + "model-info-service-instance": { + "description": "description", + "created": null, + "model-name": "modelName", + "model-uuid": "modelUUID", + "model-invariant-uuid": "modelInvariantUUID", + "model-version": "modelVersion", + "service-type": "serviceType", + "service-role": "serviceRole", + "environment-context": "environmentContext", + "workload-context": "workloadContext" + } + } +} |