diff options
Diffstat (limited to 'asdc-controller/src')
4 files changed, 230 insertions, 92 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java index bb70e3c65c..dc30b0e7de 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java @@ -189,7 +189,6 @@ public class ASDCController { */ public void initASDC () throws ASDCControllerException { String event = "Initialize the ASDC Controller"; - MsoLogger.setServiceName ("InitASDC"); logger.debug(event); if (this.getControllerStatus () != ASDCControllerStatus.STOPPED) { String endEvent = "The controller is already initialized, call the closeASDC method first"; @@ -237,7 +236,6 @@ public class ASDCController { */ public void closeASDC () throws ASDCControllerException { - MsoLogger.setServiceName ("CloseController"); if (this.getControllerStatus () == ASDCControllerStatus.BUSY) { throw new ASDCControllerException ("Cannot close the ASDC controller as it's currently in BUSY state"); } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/NotificationDataImpl.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/NotificationDataImpl.java index a1c660f75f..cbe16d864a 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/NotificationDataImpl.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/NotificationDataImpl.java @@ -30,19 +30,31 @@ import org.onap.sdc.api.notification.INotificationData; import org.onap.sdc.api.notification.IResourceInstance; import org.springframework.stereotype.Component; -import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; @Component +@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) public class NotificationDataImpl implements INotificationData { + @JsonProperty("distributionID") private String distributionID; + @JsonProperty("serviceName") private String serviceName; + @JsonProperty("serviceVersion") private String serviceVersion; + @JsonProperty("serviceUUID") private String serviceUUID; + @JsonProperty("serviceDescription") private String serviceDescription; + @JsonProperty("serviceInvariantUUID") private String serviceInvariantUUID; + @JsonProperty("resources") private List<ResourceInfoImpl> resources; + @JsonProperty("serviceArtifacts") private List<ArtifactInfoImpl> serviceArtifacts; + @JsonProperty("workloadContext") private String workloadContext; @Override @@ -118,7 +130,6 @@ public class NotificationDataImpl implements INotificationData { return ret; } - @JsonIgnore public List<ResourceInfoImpl> getResourcesImpl(){ return resources; } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java index 56784ba475..6d9e2fbb0c 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java @@ -53,6 +53,7 @@ import org.onap.sdc.toscaparser.api.Property; import org.onap.sdc.toscaparser.api.RequirementAssignment; import org.onap.sdc.toscaparser.api.RequirementAssignments; import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.onap.sdc.toscaparser.api.elements.StatefulEntityType; import org.onap.sdc.toscaparser.api.functions.GetInput; import org.onap.sdc.toscaparser.api.parameters.Input; import org.onap.sdc.utils.DistributionStatusEnum; @@ -138,6 +139,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Component public class ToscaResourceInstaller { + protected static final String NODES_VRF_ENTRY = "org.openecomp.nodes.VRFEntry"; + + protected static final String VLAN_NETWORK_RECEPTOR = "org.openecomp.nodes.VLANNetworkReceptor"; + protected static final String ALLOTTED_RESOURCE = "Allotted Resource"; protected static final String MULTI_STAGE_DESIGN = "multi_stage_design"; @@ -295,8 +300,7 @@ public class ToscaResourceInstaller { List<ASDCElementInfo> artifactListForLogging = new ArrayList<>(); try { createToscaCsar(toscaResourceStruct); - createService(toscaResourceStruct, vfResourceStruct); - Service service = toscaResourceStruct.getCatalogService(); + Service service = createService(toscaResourceStruct, vfResourceStruct); processResourceSequence(toscaResourceStruct, service); processVFResources(toscaResourceStruct, service, vfResourceStructure); @@ -524,6 +528,62 @@ public class ToscaResourceInstaller { } } } + + + protected ConfigurationResource getConfigurationResource(NodeTemplate nodeTemplate) { + Metadata metadata = nodeTemplate.getMetaData(); + ConfigurationResource configResource = new ConfigurationResource(); + configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); + configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); + configResource.setToscaNodeType(nodeTemplate.getType()); + return configResource; + } + + protected ConfigurationResourceCustomization getConfigurationResourceCustomization(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, + ServiceProxyResourceCustomization spResourceCustomization ) { + Metadata metadata = nodeTemplate.getMetaData(); + + ConfigurationResource configResource = getConfigurationResource(nodeTemplate); + + ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization(); + + Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>(); + + configCustomizationResource.setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + configCustomizationResource.setModelInstanceName(nodeTemplate.getName()); + + configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)); + configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)); + configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); + configCustomizationResource.setServiceProxyResourceCustomizationUUID(spResourceCustomization.getModelCustomizationUUID()); + + configCustomizationResource.setConfigurationResource(configResource); + configResourceCustomizationSet.add(configCustomizationResource); + + configResource.setConfigurationResourceCustomization(configResourceCustomizationSet); + return configCustomizationResource; + } + + + protected Optional<ConfigurationResourceCustomization> getVnrNodeTemplate(List<NodeTemplate> configurationNodeTemplatesList, + ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) { + Optional<ConfigurationResourceCustomization> configurationResourceCust = Optional.empty(); + for (NodeTemplate nodeTemplate : configurationNodeTemplatesList) { + StatefulEntityType entityType = nodeTemplate.getTypeDefinition(); + String type = entityType.getType(); + + if(VLAN_NETWORK_RECEPTOR.equals(type)) { + configurationResourceCust= Optional.of(getConfigurationResourceCustomization(nodeTemplate, + toscaResourceStructure,spResourceCustomization)); + break; + } + } + + return configurationResourceCust; + } protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) { @@ -538,16 +598,16 @@ public class ToscaResourceInstaller { if (serviceProxyResourceList != null) { for (NodeTemplate spNode : serviceProxyResourceList) { - serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct); - + serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct); serviceProxyList.add(serviceProxy); - + Optional<ConfigurationResourceCustomization> vnrResourceCustomization = getVnrNodeTemplate(configurationNodeTemplatesList,toscaResourceStruct,serviceProxy); + for (NodeTemplate configNode : configurationNodeTemplatesList) { List<RequirementAssignment> requirementsList = toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll(); for (RequirementAssignment requirement : requirementsList) { if (requirement.getNodeTemplateName().equals(spNode.getName())) { - ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, toscaResourceStruct, serviceProxy); + ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, toscaResourceStruct, serviceProxy, vnrResourceCustomization); Optional<ConfigurationResourceCustomization> matchingObject = configurationResourceList.stream() .filter(configurationResourceCustomization -> configNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).equals(configurationResource.getModelCustomizationUUID())) @@ -881,8 +941,6 @@ public class ToscaResourceInstaller { protected Service createService(ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure) { - toscaResourceStructure.getServiceMetadata(); - Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata(); Service service = new Service(); @@ -945,32 +1003,26 @@ public class ToscaResourceInstaller { return spCustomizationResource; } - protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) { + protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, + ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization, + Optional<ConfigurationResourceCustomization> vnrResourceCustomization) { - Metadata metadata = nodeTemplate.getMetaData(); + ConfigurationResourceCustomization configCustomizationResource = getConfigurationResourceCustomization(nodeTemplate, + toscaResourceStructure,spResourceCustomization); - ConfigurationResource configResource = new ConfigurationResource(); - - configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); - configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)); - configResource.setToscaNodeType(nodeTemplate.getType()); - - ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization(); + ConfigurationResource configResource = getConfigurationResource(nodeTemplate); Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>(); - configCustomizationResource.setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - configCustomizationResource.setModelInstanceName(nodeTemplate.getName()); - - configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)); - configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)); - configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); - configCustomizationResource.setServiceProxyResourceCustomizationUUID(spResourceCustomization.getModelCustomizationUUID()); - configCustomizationResource.setConfigResourceCustomization(configCustomizationResource); + StatefulEntityType entityType = nodeTemplate.getTypeDefinition(); + String type = entityType.getType(); + + if(NODES_VRF_ENTRY.equals(type)) { + configCustomizationResource.setConfigResourceCustomization(vnrResourceCustomization.orElse(null)); + } + configCustomizationResource.setConfigurationResource(configResource); + configResourceCustomizationSet.add(configCustomizationResource); configResource.setConfigurationResourceCustomization(configResourceCustomizationSet); @@ -1431,7 +1483,6 @@ public class ToscaResourceInstaller { vfModuleMemberName = node.getName(); } - // Extract CVFC lists List<NodeTemplate> cvfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(vfTemplate, SdcTypes.CVFC); @@ -1439,7 +1490,7 @@ public class ToscaResourceInstaller { CvnfcCustomization existingCvnfcCustomization = findExistingCvfc(existingCvnfcSet, cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - if(existingCvnfcCustomization == null && (vfModuleMemberName != null && vfModuleMemberName.equalsIgnoreCase(cvfcTemplate.getName()))){ + if(vfModuleMemberName != null && vfModuleMemberName.equalsIgnoreCase(cvfcTemplate.getName())){ //Extract associated VFC - Should always be just one List<NodeTemplate> vfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC); @@ -1450,6 +1501,12 @@ public class ToscaResourceInstaller { VnfcCustomization existingVnfcCustomization = null; existingVnfcCustomization = findExistingVfc(existingVnfcSet, vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + + if(existingVnfcCustomization == null){ + vnfcCustomization = new VnfcCustomization(); + } else { + vnfcCustomization = existingVnfcCustomization; + } // Only Add Abstract VNFC's to our DB, ignore all others if(existingVnfcCustomization == null && vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY).equalsIgnoreCase("Abstract")){ @@ -1472,32 +1529,40 @@ public class ToscaResourceInstaller { // This check is needed incase the VFC subcategory is something other than Abstract. In that case we want to skip adding that record to our DB. if(vnfcCustomization.getModelCustomizationUUID() != null){ - CvnfcCustomization cvnfcCustomization = new CvnfcCustomization(); - cvnfcCustomization.setModelCustomizationUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); - cvnfcCustomization.setModelInstanceName(cvfcTemplate.getName()); - cvnfcCustomization.setModelInvariantUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); - cvnfcCustomization.setModelName(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - cvnfcCustomization.setModelUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - - cvnfcCustomization.setModelVersion( - testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); - cvnfcCustomization.setDescription( - testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); - cvnfcCustomization.setToscaNodeType(testNull(cvfcTemplate.getType())); + CvnfcCustomization cvnfcCustomization = null; - if(existingVnfcCustomization != null){ - cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization); - }else{ - cvnfcCustomization.setVnfcCustomization(vnfcCustomization); + if(existingCvnfcCustomization != null){ + cvnfcCustomization = existingCvnfcCustomization; } + else{ - cvnfcCustomization.setNfcFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_function")); - cvnfcCustomization.setNfcNamingCode(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_naming_code")); - cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization); - cvnfcCustomization.setVnfResourceCustomization(vnfResource); - - cvnfcCustomizations.add(cvnfcCustomization); - existingCvnfcSet.add(cvnfcCustomization); + cvnfcCustomization = new CvnfcCustomization(); + cvnfcCustomization.setModelCustomizationUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + cvnfcCustomization.setModelInstanceName(cvfcTemplate.getName()); + cvnfcCustomization.setModelInvariantUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + cvnfcCustomization.setModelName(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + cvnfcCustomization.setModelUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + + cvnfcCustomization.setModelVersion( + testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); + cvnfcCustomization.setDescription( + testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); + cvnfcCustomization.setToscaNodeType(testNull(cvfcTemplate.getType())); + + if(existingVnfcCustomization != null){ + cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization); + }else{ + cvnfcCustomization.setVnfcCustomization(vnfcCustomization); + } + + cvnfcCustomization.setNfcFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_function")); + cvnfcCustomization.setNfcNamingCode(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_naming_code")); + cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization); + cvnfcCustomization.setVnfResourceCustomization(vnfResource); + + cvnfcCustomizations.add(cvnfcCustomization); + existingCvnfcSet.add(cvnfcCustomization); + } //***************************************************************************************************************************************** //* Extract Fabric Configuration @@ -1543,8 +1608,7 @@ public class ToscaResourceInstaller { VnfResourceCustomization vnfResource, VfModuleCustomization vfModuleCustomization, CvnfcCustomization cvnfcCustomization, ConfigurationResource configResource, NodeTemplate vfTemplate, String vfModuleMemberName) { - Metadata fabricMetadata = fabricTemplate.getMetaData(); - + Metadata fabricMetadata = fabricTemplate.getMetaData(); VnfVfmoduleCvnfcConfigurationCustomization vfModuleToCvnfc = new VnfVfmoduleCvnfcConfigurationCustomization(); diff --git a/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java b/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java index 9ab4c5ecb2..e4eb09782a 100644 --- a/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java +++ b/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java @@ -23,71 +23,48 @@ package org.onap.so.asdc.installer.heat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; - -import static org.junit.Assert.assertNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doNothing; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; 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.FileInputStream; import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; import java.util.List; +import java.util.Optional; -import javax.transaction.Transactional; - -import org.apache.commons.io.IOUtils; import org.hibernate.exception.LockAcquisitionException; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.sdc.api.notification.IResourceInstance; -import org.onap.sdc.api.results.IDistributionClientDownloadResult; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcCsarHelperImpl; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; -import org.onap.sdc.toscaparser.api.CapabilityAssignment; -import org.onap.sdc.toscaparser.api.CapabilityAssignments; import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.onap.sdc.toscaparser.api.elements.StatefulEntityType; import org.onap.sdc.utils.DistributionStatusEnum; import org.onap.so.asdc.BaseTest; -import org.onap.so.asdc.client.ASDCConfiguration; import org.onap.so.asdc.client.exceptions.ArtifactInstallerException; import org.onap.so.asdc.client.test.emulators.ArtifactInfoImpl; import org.onap.so.asdc.client.test.emulators.JsonStatusData; import org.onap.so.asdc.client.test.emulators.NotificationDataImpl; -import org.onap.so.asdc.installer.VfModuleArtifact; -import org.onap.so.asdc.installer.VfResourceStructure; -import org.onap.so.db.catalog.beans.AllottedResource; -import org.onap.so.db.catalog.beans.AllottedResourceCustomization; -import org.onap.so.db.catalog.beans.ExternalServiceToInternalService; -import org.onap.so.db.catalog.beans.HeatTemplate; -import org.onap.so.db.catalog.beans.NetworkResource; -import org.onap.so.db.catalog.beans.NetworkResourceCustomization; -import org.onap.so.db.catalog.beans.Service; -import org.onap.so.db.catalog.beans.VnfResource; -import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.asdc.installer.ToscaResourceStructure; +import org.onap.so.db.catalog.beans.ConfigurationResource; +import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization; +import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization; import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository; import org.onap.so.db.catalog.data.repository.AllottedResourceRepository; -import org.onap.so.db.catalog.data.repository.ExternalServiceToInternalServiceRepository; import org.onap.so.db.catalog.data.repository.ServiceRepository; import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus; -import org.onap.so.db.request.beans.WatchdogDistributionStatus; -import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup; import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository; import org.springframework.beans.factory.annotation.Autowired; @@ -114,6 +91,16 @@ public class ToscaResourceInstallerTest extends BaseTest { private IResourceInstance resourceInstance; @Rule public ExpectedException expectedException = ExpectedException.none(); + @Mock + private NodeTemplate nodeTemplate; + @Mock + private ToscaResourceStructure toscaResourceStructure; + @Mock + private ServiceProxyResourceCustomization spResourceCustomization; + @Mock + private ISdcCsarHelper csarHelper; + @Mock + private StatefulEntityType entityType; private NotificationDataImpl notificationData; private JsonStatusData statusData; @@ -310,4 +297,82 @@ public class ToscaResourceInstallerTest extends BaseTest { } return actualWatchdogComponentDistributionStatus; } + + + + + private void prepareConfigurationResource() { + doReturn(metadata).when(nodeTemplate).getMetaData(); + doReturn(MockConstants.TEMPLATE_TYPE).when(nodeTemplate).getType(); + + doReturn(MockConstants.MODEL_NAME).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_NAME); + doReturn(MockConstants.MODEL_INVARIANT_UUID).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID); + doReturn(MockConstants.MODEL_UUID).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_UUID); + doReturn(MockConstants.MODEL_VERSION).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_VERSION); + doReturn(MockConstants.MODEL_DESCRIPTION).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION); + doReturn(MockConstants.MODEL_NAME).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_NAME); + doReturn(MockConstants.MODEL_NAME).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_NAME); + } + + @Test + public void getConfigurationResourceTest() { + prepareConfigurationResource(); + + ConfigurationResource configResource=toscaInstaller.getConfigurationResource(nodeTemplate); + + assertNotNull(configResource); + assertEquals(MockConstants.MODEL_NAME, configResource.getModelName()); + assertEquals(MockConstants.MODEL_INVARIANT_UUID, configResource.getModelInvariantUUID()); + assertEquals(MockConstants.MODEL_UUID, configResource.getModelUUID()); + assertEquals(MockConstants.MODEL_VERSION, configResource.getModelVersion()); + assertEquals(MockConstants.MODEL_DESCRIPTION, configResource.getDescription()); + assertEquals(MockConstants.TEMPLATE_TYPE, nodeTemplate.getType()); + } + + private void prepareConfigurationResourceCustomization() { + prepareConfigurationResource(); + doReturn(MockConstants.MODEL_CUSTOMIZATIONUUID).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + doReturn(csarHelper).when(toscaResourceStructure).getSdcCsarHelper(); + doReturn(null).when(csarHelper).getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION); + doReturn(null).when(csarHelper).getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE); + doReturn(null).when(csarHelper).getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE); + doReturn(MockConstants.MODEL_CUSTOMIZATIONUUID).when(spResourceCustomization).getModelCustomizationUUID(); + } + + + @Test + public void getConfigurationResourceCustomizationTest() { + prepareConfigurationResourceCustomization(); + + ConfigurationResourceCustomization configurationResourceCustomization = toscaInstaller.getConfigurationResourceCustomization( + nodeTemplate, toscaResourceStructure, spResourceCustomization); + assertNotNull(configurationResourceCustomization); + assertNotNull(configurationResourceCustomization.getConfigurationResource()); + assertEquals(MockConstants.MODEL_CUSTOMIZATIONUUID, configurationResourceCustomization.getServiceProxyResourceCustomizationUUID()); + } + + @Test + public void getVnrNodeTemplateTest() { + prepareConfigurationResourceCustomization(); + List<NodeTemplate> nodeTemplateList = new ArrayList<>(); + doReturn(ToscaResourceInstaller.VLAN_NETWORK_RECEPTOR).when(entityType).getType(); + doReturn(entityType).when(nodeTemplate).getTypeDefinition(); + nodeTemplateList.add(nodeTemplate); + Optional<ConfigurationResourceCustomization> vnrResourceCustomization= + toscaInstaller.getVnrNodeTemplate(nodeTemplateList, toscaResourceStructure, spResourceCustomization); + assertTrue(vnrResourceCustomization.isPresent()); + assertEquals(ToscaResourceInstaller.VLAN_NETWORK_RECEPTOR, entityType.getType()); + } + + class MockConstants{ + public final static String MODEL_NAME = "VLAN Network Receptor Configuration"; + public final static String MODEL_INVARIANT_UUID = "1608eef4-de53-4334-a8d2-ba79cab4bde0"; + public final static String MODEL_UUID = "212ca27b-554c-474c-96b9-ddc2f1b1ddba"; + public final static String MODEL_VERSION = "30.0"; + public final static String MODEL_DESCRIPTION = "VLAN network receptor configuration object"; + public final static String MODEL_CUSTOMIZATIONUUID = "2db953e8-679d-437b-bff7-cb262638a8cd"; + public final static String TEMPLATE_TYPE = "org.openecomp.nodes.VLANNetworkReceptor"; + public final static String TEMPLATE_NAME = "VLAN Network Receptor Configuration 0"; + + } } |