diff options
author | AviZi <avi.ziv@amdocs.com> | 2017-06-09 02:39:56 +0300 |
---|---|---|
committer | AviZi <avi.ziv@amdocs.com> | 2017-06-09 02:39:56 +0300 |
commit | 280f8015d06af1f41a3ef12e8300801c7a5e0d54 (patch) | |
tree | 9c1d3978c04cd28068f02073038c936bb49ca9e0 /common/openecomp-sdc-artifact-generator-lib/openecomp-sdc-artifact-generator-test/src/main/java | |
parent | fd3821dad11780d33c5373d74c957c442489945e (diff) |
[SDC-29] Amdocs OnBoard 1707 initial commit.
Change-Id: Ie4d12a3f574008b792899b368a0902a8b46b5370
Signed-off-by: AviZi <avi.ziv@amdocs.com>
Diffstat (limited to 'common/openecomp-sdc-artifact-generator-lib/openecomp-sdc-artifact-generator-test/src/main/java')
2 files changed, 2533 insertions, 0 deletions
diff --git a/common/openecomp-sdc-artifact-generator-lib/openecomp-sdc-artifact-generator-test/src/main/java/org/openecomp/sdc/generator/ArtifactGenerationServiceTest.java b/common/openecomp-sdc-artifact-generator-lib/openecomp-sdc-artifact-generator-test/src/main/java/org/openecomp/sdc/generator/ArtifactGenerationServiceTest.java new file mode 100644 index 0000000000..85479e31da --- /dev/null +++ b/common/openecomp-sdc-artifact-generator-lib/openecomp-sdc-artifact-generator-test/src/main/java/org/openecomp/sdc/generator/ArtifactGenerationServiceTest.java @@ -0,0 +1,728 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T 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.openecomp.sdc.generator; + +import org.openecomp.sdc.generator.aai.model.*; +import org.openecomp.sdc.generator.aai.model.Service; +import org.openecomp.sdc.generator.aai.tosca.GroupDefinition; +import org.openecomp.sdc.generator.aai.tosca.NodeTemplate; +import org.openecomp.sdc.generator.aai.tosca.ToscaTemplate; +import org.openecomp.sdc.generator.aai.xml.*; +import org.openecomp.sdc.generator.aai.xml.Model; +import org.openecomp.sdc.generator.data.*; +import org.junit.Assert; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.*; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static org.openecomp.sdc.generator.SampleJUnitTest.additionalParams; + +@SuppressWarnings("Duplicates") +public class ArtifactGenerationServiceTest { + + static Map<String, String> resourcesVersion = new HashMap<>(); + public static Properties properties = new Properties(); + + @SuppressWarnings("Since15") + public static void validateName(List<Artifact> artifactList) { + for(Artifact artifact : artifactList){ + String xml = new String(Base64.getDecoder().decode(artifact.getPayload())); + Model model = getUnmarshalledArtifactModel(xml); + String xmlName = "AAI-"+ model.getModelVers().getModelVer().get(0).getModelName() + +"-"+model + .getModelType + ()+"-"+model.getModelVers().getModelVer().get(0) + .getModelVersion()+".xml"; + + Assert.assertEquals(true,artifact.getName().equals(xmlName)); + + } + } + + public static void checkArtifactName(String name){ + Assert.assertEquals(true,name.length()<=255); + } + + public static void checkArtifactLabel(String label){ + Pattern pattern = Pattern.compile("[a-zA-Z0-9-+\\s]+"); + Matcher matcher = pattern.matcher(label); + Assert.assertEquals(true,matcher.matches()); + } + + public static void checkArtifactDescription(String description){ + Pattern pattern = Pattern.compile("[a-zA-Z\\s\\t\\n]+"); + Matcher matcher = pattern.matcher(description); + Assert.assertEquals(true,matcher.matches()); + Assert.assertEquals(true,description.length()<=256); + + } + + public static void testResourceTosca(Iterator<ToscaTemplate> itr, Map<String, Model> + outputArtifactMap) { + while(itr.hasNext()){ + ToscaTemplate toscaTemplate = itr.next(); + String resourceVersion= resourcesVersion.get(toscaTemplate.getMetadata().get("UUID")); + toscaTemplate.getMetadata().put("version", resourceVersion); + if("VF".equals(toscaTemplate.getMetadata().get("type")) && !("Allotted Resource".equals + (toscaTemplate.getMetadata().get("category"))) ){ + testVfTosca(outputArtifactMap, toscaTemplate); + } else if("VF".equals(toscaTemplate.getMetadata().get("type")) && ("Allotted Resource".equals + (toscaTemplate.getMetadata().get("category"))) ){ + testAllottedResourceTosca(outputArtifactMap, toscaTemplate); + } else if("VL".equals(toscaTemplate.getMetadata().get("type"))){ + testL3NetworkResourceTosca(outputArtifactMap, toscaTemplate); + } + } + } + + public static void testVfTosca(Map<String, Model> outputArtifactMap , ToscaTemplate resourceTosca) { + try { + //ToscaTemplate resourceTosca = getResourceTosca(toscas); + //resourceTosca.getTopology_template().getGroups(). + if (resourceTosca != null) { + Resource resource = new Resource(); + resource.populateModelIdentificationInformation(resourceTosca.getMetadata()); + String resourceNameVersionId = resource.getModelNameVersionId(); + Model resourceAAIModel = + getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap); + if (resourceAAIModel != null) { + validateResourceModelMetadata(resource, resourceAAIModel); + //Validate Resource instance base widget + + ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0); + + List<ModelElement> matchedVFBaseWidgetElements = + getModelElementbyRelationshipValue(modelVersion.getModelElements(), + Widget.getWidget(Widget.Type.VF).getId()); + validateMatchedModelElementsInService(matchedVFBaseWidgetElements, + Widget.getWidget(Widget.Type.VF).getName()); + + validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.VF).getName(), + Widget.getWidget(Widget.Type.VF).getWidgetId()); + + ModelElements baseResourceWidgetModelElements = + matchedVFBaseWidgetElements.get(0).getModelElements(); + if (resourceTosca.getTopology_template() != null) { + Map<String, String> groupIdTypeStore = getGroupsTypeStore(resourceTosca); + + if (baseResourceWidgetModelElements.getModelElement().size() != + groupIdTypeStore.size()) { + org.testng.Assert.fail("Missing VFModule in VF model.xml"); + } + + for (String key : groupIdTypeStore.keySet()) { + + List<ModelElement> matchedResourceElements = + getModelElementbyRelationshipValue(baseResourceWidgetModelElements, key); + validateMatchedModelElementsInService(matchedResourceElements, + Widget.getWidget(Widget.Type.VFMODULE).getName()); + Model resourceAAIVFModel = getAAIModelByNameVersionId(key, outputArtifactMap); + Map<String, String> vfModuleModelMetadata = + getVFModuleMetadataTosca(resourceTosca, key); + Map<String, Object> vfModuleMembers = getVFModuleMembersTosca(resourceTosca, key); + + validateVFModelMetadata(vfModuleModelMetadata, resourceAAIVFModel); + + + ModelVer modelVfVersion = resourceAAIVFModel.getModelVers().getModelVer().get(0); + + List<ModelElement> matchedVFModuleBaseWidgetElements = + getModelElementbyRelationshipValue(modelVfVersion.getModelElements(), + Widget.getWidget(Widget.Type.VFMODULE).getId()); + validateMatchedModelElementsInService(matchedVFModuleBaseWidgetElements, + Widget.getWidget(Widget.Type.VFMODULE).getName()); + validateWidgetIds(matchedVFModuleBaseWidgetElements, Widget.getWidget(Widget.Type.VFMODULE) + .getName(), Widget.getWidget(Widget.Type.VFMODULE).getWidgetId()); + + ModelElements baseResourceVFModuleWidgetModelElements = + matchedVFModuleBaseWidgetElements.get(0).getModelElements(); + if (vfModuleMembers.containsKey("l3-network")) { + //Validate l3 + List<ModelElement> matchedL3NetworkElements = + getModelElementbyRelationshipValue(baseResourceVFModuleWidgetModelElements, + Widget.getWidget(Widget.Type.L3_NET).getId()); + validateMatchedModelElementsInService(matchedL3NetworkElements, + Widget.getWidget(Widget.Type.L3_NET).getName()); + validateWidgetIds(matchedL3NetworkElements, Widget.getWidget(Widget.Type.L3_NET) + .getName(), Widget.getWidget(Widget.Type.L3_NET).getWidgetId()); + } + if (vfModuleMembers.containsKey("vserver")) { + //Validate vserver + List<ModelElement> matchedVserverElements = + getModelElementbyRelationshipValue(baseResourceVFModuleWidgetModelElements, + Widget.getWidget(Widget.Type.VSERVER).getId()); + validateMatchedModelElementsInService(matchedVserverElements, + Widget.getWidget(Widget.Type.VSERVER).getName()); + ModelElements vserverWidgetModelElements = + matchedVserverElements.get(0).getModelElements(); + + validateWidgetIds(matchedVserverElements, Widget.getWidget(Widget.Type.VSERVER) + .getName(), Widget.getWidget(Widget.Type.VSERVER).getWidgetId()); + + + //Validate vserver->vfc + List<ModelElement> matchedVfcElements = + getModelElementbyRelationshipValue(vserverWidgetModelElements, + Widget.getWidget(Widget.Type.VFC).getId()); + validateMatchedModelElementsInService(matchedVfcElements, + Widget.getWidget(Widget.Type.VFC).getName()); + validateWidgetIds(matchedVfcElements, Widget.getWidget(Widget.Type.VFC).getName(), + Widget.getWidget(Widget.Type.VFC).getWidgetId()); + + //Validate vserver->Image + List<ModelElement> matchedImageElements = + getModelElementbyRelationshipValue(vserverWidgetModelElements, + Widget.getWidget(Widget.Type.IMAGE).getId()); + validateMatchedModelElementsInService(matchedImageElements, + Widget.getWidget(Widget.Type.IMAGE).getName()); + validateWidgetIds(matchedImageElements, Widget.getWidget(Widget.Type.IMAGE) + .getName(), Widget.getWidget(Widget.Type.IMAGE).getWidgetId()); + + + //Validate vserver->Flavor + List<ModelElement> matchedFlavorElements = + getModelElementbyRelationshipValue(vserverWidgetModelElements, + Widget.getWidget(Widget.Type.FLAVOR).getId()); + validateMatchedModelElementsInService(matchedFlavorElements, + Widget.getWidget(Widget.Type.FLAVOR).getName()); + validateWidgetIds(matchedFlavorElements, Widget.getWidget(Widget.Type.FLAVOR).getName(), + Widget.getWidget(Widget.Type.FLAVOR).getWidgetId()); + + //Validate vserver->Tenant + List<ModelElement> matchedTenantElements = + getModelElementbyRelationshipValue(vserverWidgetModelElements, + Widget.getWidget(Widget.Type.TENANT).getId()); + validateMatchedModelElementsInService(matchedTenantElements, + Widget.getWidget(Widget.Type.TENANT).getName()); + validateWidgetIds(matchedTenantElements, Widget.getWidget(Widget.Type.TENANT).getName(), + Widget.getWidget(Widget.Type.TENANT).getWidgetId()); + + //Validate vserver->l-interface + if (vfModuleMembers.containsKey("l-interface")) { + List<ModelElement> matchedLinterfaceElements = + getModelElementbyRelationshipValue(vserverWidgetModelElements, + Widget.getWidget(Widget.Type.LINT).getId()); + validateMatchedModelElementsInService(matchedLinterfaceElements, + Widget.getWidget(Widget.Type.LINT).getName()); + validateWidgetIds(matchedLinterfaceElements, Widget.getWidget(Widget.Type.LINT).getName(), + Widget.getWidget(Widget.Type.LINT).getWidgetId()); + } + //Validate vserver->volume + if (vfModuleMembers.containsKey("volume")) { + List<ModelElement> matchedVolumeElements = + getModelElementbyRelationshipValue(vserverWidgetModelElements, + Widget.getWidget(Widget.Type.VOLUME).getId()); + validateMatchedModelElementsInService(matchedVolumeElements, + Widget.getWidget(Widget.Type.VOLUME).getName()); + validateWidgetIds(matchedVolumeElements, Widget.getWidget(Widget.Type.VOLUME).getName(), + Widget.getWidget(Widget.Type.VOLUME).getWidgetId()); + } + } + } + } + } else { + System.out.println("Resource mapping not found for " + resourceNameVersionId); + } + } + + } catch (IllegalArgumentException e) { + org.testng.Assert.fail(e.getMessage()); //Can come while populating metadata + } + + } + + public static void testAllottedResourceTosca(Map<String, Model> outputArtifactMap , ToscaTemplate + resourceTosca) { + try { + if (resourceTosca != null) { + Resource resource = new Resource(); + resource.populateModelIdentificationInformation(resourceTosca.getMetadata()); + String resourceNameVersionId = resource.getModelNameVersionId(); + Model resourceAAIModel = + getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap); + if (resourceAAIModel != null) { + validateResourceModelMetadata(resource, resourceAAIModel); + //Validate Resource instance base widget + + ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0); + + List<ModelElement> matchedVFBaseWidgetElements = + getModelElementbyRelationshipValue(modelVersion.getModelElements(), + Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getId()); + validateMatchedModelElementsInService(matchedVFBaseWidgetElements, + Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName()); + + validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName(), + Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getWidgetId()); + + validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName(), + Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getWidgetId()); + + Map<String, Object> providingServiceDetails = getProvidingServiceDetails(resourceTosca); + + ModelElements containedModelElements = modelVersion.getModelElements().getModelElement(). + get(0).getModelElements(); + + org.testng.Assert.assertEquals(containedModelElements.getModelElement().get(0).getRelationshipList() + .getRelationship().get(0).getRelationshipData().get(0).getRelationshipValue(), + providingServiceDetails.get("providing_service_uuid")); + + org.testng.Assert.assertEquals(containedModelElements.getModelElement().get(0).getRelationshipList() + .getRelationship().get(0).getRelationshipData().get(1).getRelationshipValue(), + providingServiceDetails.get("providing_service_invariant_uuid")); + + + if("Allotted Resource".equals(resourceTosca.getMetadata().get("category")) && + "Tunnel XConnect".equals(resourceTosca.getMetadata().get("subcategory"))) { + + List<ModelElement> matchedTunnelXConnectWidgetElements = + getModelElementbyRelationshipValue(containedModelElements, + Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getId()); + validateMatchedModelElementsInService(matchedTunnelXConnectWidgetElements, + Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getName()); + + validateWidgetIds(matchedTunnelXConnectWidgetElements, Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getName(), + Widget.getWidget(Widget.Type.TUNNEL_XCONNECT).getWidgetId()); + } + + }else { + System.out.println("Resource mapping not found for " + resourceNameVersionId); + } + } + + }catch (IllegalArgumentException e) { + org.testng.Assert.fail(e.getMessage()); //Can come while populating metadata + } + + } + + public static Map<String, Object> getProvidingServiceDetails(ToscaTemplate resourceTemplate) { + Set<String> keys = resourceTemplate.getTopology_template().getNode_templates().keySet(); + + Map<String, Object> nodeProperties =null; + for(String key : keys) { + NodeTemplate node = resourceTemplate.getTopology_template().getNode_templates().get(key); + if(node.getType().contains("org.openecomp.resource.vfc") && + node.getMetadata().get("category").equals("Allotted Resource")) { + nodeProperties = node.getProperties(); + } + } + + return nodeProperties; + } + + public static void testL3NetworkResourceTosca(Map<String, Model> outputArtifactMap , ToscaTemplate + resourceTosca) { + try { + if (resourceTosca != null) { + Resource resource = new Resource(); + resource.populateModelIdentificationInformation(resourceTosca.getMetadata()); + String resourceNameVersionId = resource.getModelNameVersionId(); + Model resourceAAIModel = + getAAIModelByNameVersionId(resourceNameVersionId, outputArtifactMap); + if (resourceAAIModel != null) { + validateResourceModelMetadata(resource, resourceAAIModel); + //Validate Resource instance base widget + + ModelVer modelVersion = resourceAAIModel.getModelVers().getModelVer().get(0); + + List<ModelElement> matchedVFBaseWidgetElements = + getModelElementbyRelationshipValue(modelVersion.getModelElements(), + Widget.getWidget(Widget.Type.L3_NET).getId()); + validateMatchedModelElementsInService(matchedVFBaseWidgetElements, + Widget.getWidget(Widget.Type.L3_NET).getName()); + + validateWidgetIds(matchedVFBaseWidgetElements, Widget.getWidget(Widget.Type.L3_NET).getName(), + Widget.getWidget(Widget.Type.L3_NET).getWidgetId()); + + }else { + System.out.println("Resource mapping not found for " + resourceNameVersionId); + } + } + + }catch (IllegalArgumentException e) { + org.testng.Assert.fail(e.getMessage()); //Can come while populating metadata + } + + } + + public static void testServiceTosca(Map<String, Model> outputArtifactMap,List<ToscaTemplate> + toscas) { + try { + ToscaTemplate serviceTosca = getServiceTosca(toscas); + if (serviceTosca == null) { + org.testng.Assert.fail("Service Tosca not found"); + } + serviceTosca.getMetadata().put("version", additionalParams.get(AdditionalParams + .ServiceVersion.getName())); + Service service = new Service(); + service.populateModelIdentificationInformation(serviceTosca.getMetadata()); + String serviceNameVersionId = service.getModelNameVersionId(); + Model serviceAAIModel = getAAIModelByNameVersionId(serviceNameVersionId, outputArtifactMap); + validateServiceModelMetadata(service, serviceAAIModel); + //Validate Service instance base widget + ModelVer modelVersion = serviceAAIModel.getModelVers().getModelVer().get(0); + + List<ModelElement> matchedServiceBaseWidgetElements = + getModelElementbyRelationshipValue( modelVersion.getModelElements(), + Widget.getWidget(Widget.Type.SERVICE).getId()); + validateMatchedModelElementsInService(matchedServiceBaseWidgetElements, + Widget.getWidget(Widget.Type.SERVICE).getName()); + + validateWidgetIds(matchedServiceBaseWidgetElements, Widget.getWidget(Widget.Type.SERVICE).getName(), + Widget.getWidget(Widget.Type.SERVICE).getWidgetId()); + + ModelElements baseServiceWidgetModelElements = + matchedServiceBaseWidgetElements.get(0).getModelElements(); + + + Map<String, String> nodeTemplateIdTypeStore = getNodeTemplateTypeStore(serviceTosca); + if (nodeTemplateIdTypeStore != null) { + for (String key : nodeTemplateIdTypeStore.keySet()) { + if (nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vf")) { + List<ModelElement> matchedResourceElements = + getModelElementbyRelationshipValue(baseServiceWidgetModelElements, key); + if (nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vf.allottedResource")){ + validateMatchedModelElementsInService(matchedResourceElements, + Widget.getWidget(Widget.Type.ALLOTTED_RESOURCE).getName()); + }else { + validateMatchedModelElementsInService(matchedResourceElements, + Widget.getWidget(Widget.Type.VF).getName()); + } + + //Validate uuid and invariantuuid are populated in model-ver.model-version-id and model.model-invariant-id + org.testng.Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList() + .getRelationship().get(0) + .getRelationshipData().get(0).getRelationshipValue(),key); + + org.testng.Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList().getRelationship().get(0) + .getRelationshipData().get(1).getRelationshipValue(), nodeTemplateIdTypeStore + .get(key+"-INV_UID")); + } else if(nodeTemplateIdTypeStore.get(key).contains("org.openecomp.resource.vl")){ + //validate l3-network in service tosca + List<ModelElement> matchedResourceElements = + getModelElementbyRelationshipValue(baseServiceWidgetModelElements, key); + validateMatchedModelElementsInService(matchedResourceElements, + Widget.getWidget(Widget.Type.L3_NET).getName()); + //Validate uuid and invariantuuid are populated in model-ver.model-version-id and model.model-invariant-id + org.testng.Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList() + .getRelationship().get(0) + .getRelationshipData().get(0).getRelationshipValue(),key); + + org.testng.Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList().getRelationship().get(0) + .getRelationshipData().get(1).getRelationshipValue(), nodeTemplateIdTypeStore + .get(key+"-INV_UID")); + } + } + + + System.out.println(); + + } + } catch (IllegalArgumentException e) { + org.testng.Assert.fail(e.getMessage()); //Can come while populating metadata + } + } + + private static void validateWidgetIds(List<ModelElement> matchedServiceBaseWidgetElements, + String widgetName, String widgetInvUuId) { + org.testng.Assert.assertEquals(matchedServiceBaseWidgetElements.get(0).getRelationshipList().getRelationship().get(0) + .getRelationshipData().get(0).getRelationshipValue(), properties.getProperty(ArtifactType.AAI.name() + + ".model-version-id."+ widgetName)); + + org.testng.Assert.assertEquals(matchedServiceBaseWidgetElements.get(0).getRelationshipList().getRelationship().get(0) + .getRelationshipData().get(1).getRelationshipValue(), widgetInvUuId); + } + + + + private static void validateMatchedModelElementsInService(List<ModelElement> matchedModelElements, String modelType) { + if (matchedModelElements.isEmpty()) { + Assert.fail(modelType + " not present "); + } + if (matchedModelElements.size() > 1) { + Assert.fail("More than one " + modelType + " present "); + } + } + + private static Map<String, String> getNodeTemplateTypeStore(ToscaTemplate toscaTemplate) { + if (toscaTemplate.getTopology_template() != null) { + Map<String, NodeTemplate> nodeTemplateMap = + toscaTemplate.getTopology_template().getNode_templates(); + Map<String, String> nodeTemplateIdTypeStore = new LinkedHashMap<>(); + if (nodeTemplateMap != null) { + for (Map.Entry<String, NodeTemplate> e : nodeTemplateMap.entrySet()) { + String uuid = e.getValue().getMetadata().get("resourceUUID"); + if (GeneratorUtil.isEmpty(uuid)) { + uuid = e.getValue().getMetadata().get("UUID"); + if (GeneratorUtil.isEmpty(uuid)) { + Assert.fail("UUID Not found"); + } + } + if(e.getValue().getType().contains("org.openecomp.resource.vf.")&& (e.getValue() + .getMetadata().get("category").equals("Allotted Resource"))) + { + e.getValue().setType("org.openecomp.resource.vf.allottedResource"); + } + nodeTemplateIdTypeStore.put(uuid, e.getValue().getType()); + resourcesVersion.put(uuid,e.getValue().getMetadata().get + ("version")); + //Populate invraintUuId for V9 + String invUuId = e.getValue().getMetadata().get("invariantUUID"); + nodeTemplateIdTypeStore.put(uuid+"-INV_UID" , invUuId); + } + } + return nodeTemplateIdTypeStore; + } else { + return null; + } + } + + + private static Map<String, String> getGroupsTypeStore(ToscaTemplate toscaTemplate) { + if(toscaTemplate.getTopology_template() !=null) { + Map<String, GroupDefinition> groupDefinitionMap = toscaTemplate.getTopology_template().getGroups(); + Map<String, String> groupDefinitionIdTypeStore = new LinkedHashMap<>(); + if (groupDefinitionMap != null) { + for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) { + if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) { + String uuid = e.getValue().getMetadata().get("vfModuleModelUUID"); + if (GeneratorUtil.isEmpty(uuid)) { + uuid = e.getValue().getMetadata().get("UUID"); + if (GeneratorUtil.isEmpty(uuid)) + Assert.fail("UUID Not found"); + } + groupDefinitionIdTypeStore.put(uuid, e.getValue().getType()); + } + } + } + return groupDefinitionIdTypeStore; + } + else { + return null; + } + } + + private static void validateServiceModelMetadata(Service serviceToscaModel, Model generatedAAIModel) { + Assert.assertEquals(serviceToscaModel.getModelNameVersionId(), generatedAAIModel + .getModelVers().getModelVer().get(0).getModelVersionId()); + Assert.assertEquals(serviceToscaModel.getModelId(), generatedAAIModel.getModelInvariantId()); + Assert.assertEquals(serviceToscaModel.getModelName(), generatedAAIModel.getModelVers() + .getModelVer().get(0).getModelName()); + Assert.assertEquals(serviceToscaModel.getModelVersion(), generatedAAIModel.getModelVers() + .getModelVer().get(0).getModelVersion()); + Assert.assertEquals(serviceToscaModel.getModelDescription(), generatedAAIModel.getModelVers() + .getModelVer().get(0).getModelDescription()); + } + + private static void validateResourceModelMetadata(Resource resouerceToscaModel, Model generatedAAIModel) { + Assert.assertEquals(resouerceToscaModel.getModelNameVersionId(), generatedAAIModel + .getModelVers().getModelVer().get(0).getModelVersionId()); + Assert.assertEquals(resouerceToscaModel.getModelId(), generatedAAIModel.getModelInvariantId()); + Assert.assertEquals(resouerceToscaModel.getModelName(), generatedAAIModel.getModelVers() + .getModelVer().get(0).getModelName()); + Assert.assertEquals(resouerceToscaModel.getModelVersion(), generatedAAIModel.getModelVers() + .getModelVer().get(0).getModelVersion()); + Assert.assertEquals(resouerceToscaModel.getModelDescription(), generatedAAIModel.getModelVers() + .getModelVer().get(0).getModelDescription()); + } + + private static void validateVFModelMetadata(Map<String, String> vfModuleModelMetadata, Model generatedAAIModel) { + Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelUUID"), generatedAAIModel + .getModelVers().getModelVer().get(0).getModelVersionId()); + Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelInvariantUUID"), generatedAAIModel.getModelInvariantId()); + Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelName"), generatedAAIModel.getModelVers() + .getModelVer().get(0).getModelName()); + Assert.assertEquals(vfModuleModelMetadata.get("vfModuleModelVersion"), generatedAAIModel.getModelVers() + .getModelVer().get(0).getModelVersion()); + Assert.assertEquals(vfModuleModelMetadata.get("vf_module_description"), generatedAAIModel.getModelVers() + .getModelVer().get(0).getModelDescription()); + + } + + private static Model getAAIModelByNameVersionId(String nameVersionId, + Map<String, Model> outputArtifactMap) { + return outputArtifactMap.get(nameVersionId); + } + + private static List<ModelElement> getModelElementbyRelationshipValue(ModelElements modelElements, + String relationshipValue) { + List<ModelElement> matchedModelElements = new ArrayList<>(); + if (modelElements != null) { + List<ModelElement> modelElementList = modelElements.getModelElement(); + for (ModelElement element : modelElementList) { + List<Relationship> relationshipList = element.getRelationshipList().getRelationship(); + for (Relationship r : relationshipList) { + List<RelationshipData> relationshipDataList = r.getRelationshipData(); + for (RelationshipData relationshipData : relationshipDataList) { + if (relationshipData.getRelationshipValue().equals(relationshipValue)) + matchedModelElements.add(element); + } + } + } + } + return matchedModelElements; + } + + public static void populateAAIGeneratedModelStore(Map<String, Model> outputArtifactMap,List<Artifact> resultData) { + for (Artifact outputArtifact : resultData) { + if (outputArtifact.getType().equals(ArtifactType.MODEL_INVENTORY_PROFILE.name())) { + byte[] decodedPayload = GeneratorUtil.decoder(outputArtifact.getPayload()); + Model aaiModel = getUnmarshalledArtifactModel(new String(decodedPayload)); + outputArtifactMap.put(aaiModel.getModelVers().getModelVer().get(0).getModelVersionId(), aaiModel); + } + } + } + + private static Model getUnmarshalledArtifactModel(String aaiModel) { + JAXBContext jaxbContext; + try { + jaxbContext = JAXBContext.newInstance(Model.class); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + InputStream aaiModelStream = new ByteArrayInputStream(aaiModel.getBytes()); + return (Model) unmarshaller.unmarshal(aaiModelStream); + } catch (JAXBException e) { + e.printStackTrace(); + } + return null; + } + + /** + * Identify the service tosca artifact from the list of translated tosca inputs + * + * @param input List of translated {@link ToscaTemplate tosca} object models + * @return Identified service {@link ToscaTemplate tosca} + */ + private static ToscaTemplate getServiceTosca(List<ToscaTemplate> input) { + Iterator<ToscaTemplate> iter = input.iterator(); + while (iter.hasNext()) { + ToscaTemplate tosca = iter.next(); + if (tosca.isService()) { + iter.remove(); + return tosca; + } + } + return null; + } + + + private static ToscaTemplate getResourceTosca(List<ToscaTemplate> input) { + Iterator<ToscaTemplate> iter = input.iterator(); + while (iter.hasNext()) { + ToscaTemplate tosca = iter.next(); + if (!tosca.isService()) { + iter.remove(); + return tosca; + } + } + return null; + } + + + private static Map<String, String> getVFModuleMetadataTosca(ToscaTemplate toscaTemplate, String vfModuleModelUUID) { + Map<String, GroupDefinition> groupDefinitionMap = toscaTemplate.getTopology_template().getGroups(); + Map<String, String> vfModuleModelMetadata = new LinkedHashMap<>(); + for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) { + if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) { + String uuid = e.getValue().getMetadata().get("vfModuleModelUUID"); + if (uuid == vfModuleModelUUID) { + vfModuleModelMetadata = e.getValue().getMetadata(); + vfModuleModelMetadata.put("vf_module_description", (String) e.getValue().getProperties().get("vf_module_description")); + } + } + } + return vfModuleModelMetadata; + } + + private static Map<String, Object> getVFModuleMembersTosca(ToscaTemplate toscaTemplate, String vfModuleModelUUID) { + Map<String, GroupDefinition> groupDefinitionMap = toscaTemplate.getTopology_template().getGroups(); + Map<String, NodeTemplate> nodeTemplateMaps = toscaTemplate.getTopology_template().getNode_templates(); + Map<String, Object> vfModuleMembers = new LinkedHashMap<>(); + List<String> vfModuleModelMetadata = new ArrayList<>(); + for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) { + if (e.getValue().getType().contains("org.openecomp.groups.VfModule")) { + String uuid = e.getValue().getMetadata().get("vfModuleModelUUID"); + if (uuid == vfModuleModelUUID) { + vfModuleModelMetadata = e.getValue().getMembers(); + Iterator itr = vfModuleModelMetadata.iterator(); + while (itr.hasNext()) { + Object obj= itr.next(); + NodeTemplate nodeTemplate = nodeTemplateMaps.get(obj); + String nodetype = null; + if (nodeTemplate != null) + nodetype = nodeTemplate.getType(); + if (nodetype != null) { + String widgetType = membersType(nodetype); + if (widgetType != null) + vfModuleMembers.put(widgetType, obj); + } + } + + } + } + } + + return vfModuleMembers; + } + + + private static String membersType(String toscaType) { + String modelToBeReturned = null; + while (toscaType != null && toscaType.lastIndexOf(".") != -1 && modelToBeReturned == null) { + + switch (toscaType) { + + case "org.openecomp.resource.vfc": + modelToBeReturned = "vserver"; + break; + case "org.openecomp.resource.cp": + case "org.openecomp.cp": + modelToBeReturned = "l-interface"; + break; + case "org.openecomp.resource.vl": + modelToBeReturned = "l3-network"; + break; + case "org.openecomp.resource.vf": + modelToBeReturned = "generic-vnf"; + break; + case "org.openecomp.groups.VfModule": + modelToBeReturned = "vf-module"; + break; + case "org.openecomp.resource.vfc.nodes.heat.cinder": + modelToBeReturned = "volume"; + break; + default: + modelToBeReturned = null; + break; + } + + toscaType = toscaType.substring(0, toscaType.lastIndexOf(".")); + } + return modelToBeReturned; + } +} diff --git a/common/openecomp-sdc-artifact-generator-lib/openecomp-sdc-artifact-generator-test/src/main/java/org/openecomp/sdc/generator/SampleJUnitTest.java b/common/openecomp-sdc-artifact-generator-lib/openecomp-sdc-artifact-generator-test/src/main/java/org/openecomp/sdc/generator/SampleJUnitTest.java new file mode 100644 index 0000000000..bbbb74dc05 --- /dev/null +++ b/common/openecomp-sdc-artifact-generator-lib/openecomp-sdc-artifact-generator-test/src/main/java/org/openecomp/sdc/generator/SampleJUnitTest.java @@ -0,0 +1,1805 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T 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.openecomp.sdc.generator; + +import org.openecomp.sdc.generator.aai.model.Widget; +import org.openecomp.sdc.generator.aai.tosca.ToscaTemplate; +import org.openecomp.sdc.generator.aai.xml.Model; +import org.openecomp.sdc.generator.data.*; +import org.openecomp.sdc.generator.impl.ArtifactGenerationServiceImpl; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Test; + +import java.io.*; +import java.util.*; + +import static org.openecomp.sdc.generator.ArtifactGenerationServiceTest.*; +import static org.openecomp.sdc.generator.data.GeneratorConstants.*; + +public class SampleJUnitTest extends TestCase { + + public static final String aaiArtifactType = ArtifactType.AAI.name(); + public static final String aaiArtifactGroupType = GroupType.DEPLOYMENT.name(); + public static final String generatorConfig = "{\"artifactTypes\": [\"OTHER\",\"AAI\"]}"; + public static final String ARTIFACTGENERATOR_CONFIG = "artifactgenerator.config"; + public static final String CONFIG_PATH = "/qa-test-repo/jmeter3/apache-jmeter-3" + + ".0/lib/junit/"; + //public static final String CONFIG_PATH ="C:\\Jmeter-Copy\\jmeter3\\apache-jmeter-3" + + //".0\\lib\\junit\\"; + public static final String GENERATOR_AAI_CONFIGLPROP_NOT_FOUND = + "Cannot generate artifacts. Widget configuration not found for %s"; + public static final String GENERATOR_AAI_CONFIGFILE_NOT_FOUND = + "Cannot generate artifacts. Artifact Generator Configuration file not found at %s"; + public static final String GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND = + "Cannot generate artifacts. artifactgenerator.config system property not configured"; + public static final String INVALID_VALUE_INVARIANT = + "Invalid value for mandatory attribute <invariantUUID> in Artifact"; + public static final String INVALID_VALUE_UUID = + "Invalid value for mandatory attribute <UUID> in Artifact:"; + public static final Map<String, String> additionalParams = new HashMap<>(); + + static{ + additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0"); + } + + private void loadConfig(Properties properties) throws IOException { + String configLocation = System.getProperty(ARTIFACTGENERATOR_CONFIG); + if (configLocation != null) { + File file = new File(configLocation); + if (file.exists()) { + properties.load(new FileInputStream(file)); + } + } + } + public SampleJUnitTest(String name) throws Exception { + super(name); + System.setProperty(ARTIFACTGENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator.properties"); + loadConfig(ArtifactGenerationServiceTest.properties); + } + + public SampleJUnitTest() { + super(); + System.setProperty(ARTIFACTGENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator.properties"); + } + + @Test + public void testArtifactGenerationSingleVFSingleVFModule() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_SingleVFVFMod.yml"); + readPayload(inputArtifacts, fis1, "vf_vmme_template_SingleVFVFMod.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_SingleVFVFMod.yml"); + readPayload(inputArtifacts, fis2, "service_vmme_template_SingleVFVFMod.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas); + + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(5, data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationMissingVFInServiceTOSCA() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_MissingVFInServiceTOSCA.yml"); + readPayload(inputArtifacts, fis2, "service_vmme_template_MissingVFInServiceTOSCA.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas); + + Assert.assertEquals(3, data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationVerifySameStaticWidgetsForAllServices() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_SameWidgets1.yml"); + readPayload(inputArtifacts, fis1, "vf_vmme_template_SameWidgets1.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_SameWidget1.yml"); + readPayload(inputArtifacts, fis2, "service_vmme_template_SameWidget1.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData); + + removeMockArtifact(data.getResultData().iterator()); + + + List<Artifact> inputArtifacts2 = new ArrayList(); + InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_SameWidgets2.yml"); + readPayload(inputArtifacts2, fis3, "vf_vmme_template_SameWidgets2.yml"); + + InputStream fis4 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_SameWidget2.yml"); + readPayload(inputArtifacts2, fis4, "service_vmme_template_SameWidget2.yml"); + ArtifactGenerationServiceImpl obj2 = new ArtifactGenerationServiceImpl(); + + GenerationData data2 = obj2.generateArtifact(inputArtifacts2, generatorConfig,additionalParams); + List<Artifact> resultData2 = data2.getResultData(); + + List<ToscaTemplate> toscas2 = new LinkedList(); + + for (Artifact inputArtifact : inputArtifacts2) { + toscas2.add(getToscaModel(inputArtifact)); + } + + Map<String, Model> outputArtifactMap2 = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap2, resultData2); + removeMockArtifact(data2.getResultData().iterator()); + + Map<String,String> map = new HashMap<>(); + Iterator<Artifact> itr = data.getResultData().iterator(); + while(itr.hasNext()){ + Artifact artifact=itr.next(); + if(artifact.getLabel().contains("AAI-widget")){ + map.put(artifact.getName(),artifact.getChecksum()); + } + } + Map<String,String> map2 = new HashMap<>(); + Iterator<Artifact> itr2 = data2.getResultData().iterator(); + while(itr2.hasNext()){ + Artifact artifact=itr2.next(); + if(artifact.getLabel().contains("AAI-widget")){ + map2.put(artifact.getName(),artifact.getChecksum()); + } + } + Assert.assertEquals(map.size(),map2.size()); + for(String name : map.keySet()){ + Assert.assertEquals(map.get(name),map2.get(name)); + } + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationMulVFModule() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + String[] resourceFileList = {}; + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_MulVFVFMod.yml"); + readPayload(inputArtifacts,fis1, "vf_vmme_template_MulVFVFMod.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_MulVFVFMod.yml"); + readPayload(inputArtifacts,fis2, "service_vmme_template_MulVFVFMod.yml"); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(3,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationMulVFs() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/CMAUI_VF.yaml"); + readPayload(inputArtifacts,fis3, "CMAUI_VF.yaml"); + + InputStream fis4 = SampleJUnitTest.class.getResourceAsStream("/ECA_OAM_VF.yaml"); + readPayload(inputArtifacts,fis4, "ECA_OAM_VF.yaml"); + + InputStream fis5 = SampleJUnitTest.class.getResourceAsStream("/MMSC_Sevice_07_25_16.yaml"); + readPayload(inputArtifacts,fis5, "MMSC_Sevice_07_25_16.yaml"); + + InputStream fis6 = SampleJUnitTest.class.getResourceAsStream("/MMSC_VF.yaml"); + readPayload(inputArtifacts,fis6, "MMSC_VF.yaml"); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(8,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationDupVFUUID() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_DupVFUUID.yml"); + readPayload(inputArtifacts,fis1, "vf_vmme_template_DupVFUUID.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_DupVFUUID.yml"); + readPayload(inputArtifacts,fis2, "service_vmme_template_DupVFUUID.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(5,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationDupVFModUUID() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_DupVFModUUID.yml"); + readPayload(inputArtifacts,fis1, "vf_vmme_template_DupVFModUUID.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_DupVFModUUID.yml"); + readPayload(inputArtifacts,fis2, "service_vmme_template_DupVFModUUID.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(5,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationVerifyVFModWithoutVNFC() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyVFModWithoutVNFC.yml"); + readPayload(inputArtifacts,fis1, "vf_vmme_template_VerifyVFModWithoutVNFC.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyVFModWithoutVNFC.yml"); + readPayload(inputArtifacts,fis2, "service_vmme_template_VerifyVFModWithoutVNFC.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(5,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationVerifyVFModWithInvalidMember() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyVFModWithInvalidNo.yml"); + readPayload(inputArtifacts,fis1, "vf_vmme_template_VerifyVFModWithInvalidNo.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyVFModWithInvalidNo.yml"); + readPayload(inputArtifacts,fis2, "service_vmme_template_VerifyVFModWithInvalidNo.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(5,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationNullFields() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_NullFields.yml"); + readPayload(inputArtifacts,fis1, "vf_vmme_template_NullFields.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_NullFields.yml"); + readPayload(inputArtifacts,fis2, "service_vmme_template_NullFields.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + Assert.assertEquals(false,data.getErrorData().isEmpty()); + + Assert.assertEquals("Invalid Service/Resource definition mandatory attribute <UUID> missing in Artifact: <"+inputArtifacts.get(0).getName()+">",data.getErrorData().get("AAI").get(0)); + + Assert.assertEquals(2,data.getResultData().size()); + + } catch (Exception e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationInCorrectYmlFormat() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/CMAUI_VFInvalidFormat.yaml"); + readPayload(inputArtifacts,fis3, "CMAUI_VFInvalidFormat.yaml"); + + InputStream fis4 = SampleJUnitTest.class.getResourceAsStream("/ECA_OAM_VFInvalidFormat.yaml"); + readPayload(inputArtifacts,fis4, "ECA_OAM_VFInvalidFormat.yaml"); + + InputStream fis5 = SampleJUnitTest.class.getResourceAsStream("/MMSC_Sevice_07_25_16InvalidFormat.yaml"); + readPayload(inputArtifacts,fis5, "MMSC_Sevice_07_25_16InvalidFormat.yaml"); + + InputStream fis6 = SampleJUnitTest.class.getResourceAsStream("/MMSC_VFInvalidFormat.yaml"); + readPayload(inputArtifacts,fis6, "MMSC_VFInvalidFormat.yaml"); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + Assert.assertEquals(false,data.getErrorData().isEmpty()); + + Assert.assertEquals("Invalid format for Tosca YML : "+inputArtifacts.get(1).getName(),data.getErrorData().get("AAI").get(0)); + + Assert.assertEquals(2,data.getResultData().size()); + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationMulComp() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_MulComp.yml"); + readPayload(inputArtifacts,fis1, "vf_vmme_template_MulComp.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_MulComp.yml"); + readPayload(inputArtifacts,fis2, "service_vmme_template_MulComp.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(5,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationOrphan() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_Orphan.yml"); + readPayload(inputArtifacts,fis1, "vf_vmme_template_Orphan.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_Orphan.yml"); + readPayload(inputArtifacts,fis2, "service_vmme_template_Orphan.yml"); + + InputStream fis4 = SampleJUnitTest.class.getResourceAsStream("/ECA_OAM_VFOrphan.yaml"); + readPayload(inputArtifacts,fis4, "ECA_OAM_VFOrphan.yaml"); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(5,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationMissingVFTemplate() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_MissingVFTemplate.yml"); + readPayload(inputArtifacts,fis1, "service_vmme_template_MissingVFTemplate.yml"); + + fis1.close(); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + + + Assert.assertEquals(3,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationMissingVFModule() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/CMAUI_VFMissingVFModule.yaml"); + readPayload(inputArtifacts,fis3, "CMAUI_VFMissingVFModule.yaml"); + + InputStream fis4 = SampleJUnitTest.class.getResourceAsStream("/ECA_OAM_VFMissingVFModule.yaml"); + readPayload(inputArtifacts,fis4, "ECA_OAM_VFMissingVFModule.yaml"); + + InputStream fis5 = SampleJUnitTest.class.getResourceAsStream("/MMSC_Sevice_07_25_16MissingVFModule.yaml"); + readPayload(inputArtifacts,fis5, "MMSC_Sevice_07_25_16MissingVFModule.yaml"); + + InputStream fis6 = SampleJUnitTest.class.getResourceAsStream("/MMSC_VFMissingVFModule.yaml"); + readPayload(inputArtifacts,fis6, "MMSC_VFMissingVFModule.yaml"); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(8,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + } catch (Exception e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationEmptyArtifact() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + Assert.assertEquals(false,data.getErrorData().isEmpty()); + Assert.assertEquals("Service tosca missing from list of input artifacts",data.getErrorData().get("AAI").get(0)); + + Assert.assertEquals(2,data.getResultData().size()); + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationMissingConfigFile() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_SingleVFVFMod.yml"); + readPayload(inputArtifacts,fis1, "vf_vmme_template_SingleVFVFMod.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_SingleVFVFMod.yml"); + readPayload(inputArtifacts,fis2, "service_vmme_template_SingleVFVFMod.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + + GenerationData data = obj.generateArtifact(inputArtifacts, "",additionalParams); + Assert.assertEquals(false,data.getErrorData().isEmpty()); + Assert.assertEquals("Invalid Client Configuration",data.getErrorData().get("ARTIFACT_GENERATOR_INVOCATION_ERROR").get(0)); + + Assert.assertEquals(0,data.getResultData().size()); + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + + @Test + public void testArtifactGenerationWithNodeTemplates() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/ServiceWithNodetemplate.yml"); + readPayload(inputArtifacts,fis1, "ServiceWithNodetemplate.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/Resource0-template.yml"); + readPayload(inputArtifacts,fis2, "Resource0-template.yml"); + + InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/Resource1-template.yml"); + readPayload(inputArtifacts,fis3, "Resource1-template.yml"); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(5,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationWithoutNodeTemplates() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/Service0-template.yml"); + readPayload(inputArtifacts,fis1, "Service0-template.yml"); + + fis1.close(); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + + + Assert.assertEquals(3,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationWithArtifactNameAndDescMoreThan256() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/Service0-templateMoreThan256.yml"); + readPayload(inputArtifacts,fis1, "Service0-templateMoreThan256.yml"); + + fis1.close(); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + + + Assert.assertEquals(3,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + for(Artifact artifact : data.getResultData()){ + checkArtifactName(artifact.getName()); + checkArtifactLabel(artifact.getLabel()); + checkArtifactDescription(artifact.getDescription()); + + } + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationWithDifferentVersionOfSameVF() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_DiffVerOfSameVF.yml"); + readPayload(inputArtifacts,fis1, "service_vmme_template_DiffVerOfSameVF.yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_DiffVerOfSameVF_1.yml"); + readPayload(inputArtifacts,fis2, "vf_vmme_template_DiffVerOfSameVF_1.yml"); + fis2.close(); + + InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_DiffVerOfSameVF_2.yml"); + readPayload(inputArtifacts,fis3, "vf_vmme_template_DiffVerOfSameVF_2.yml"); + fis3.close(); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(6,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationWithDifferentVersionOfSameVFModWithSameInvId() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_DiffVerOfSameVFModWithSameInvId.yml"); + readPayload(inputArtifacts,fis1, "service_vmme_template_DiffVerOfSameVFModWithSameInvId.yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_DiffVerOfSameVFModWithSameInvId.yml"); + readPayload(inputArtifacts,fis2, "vf_vmme_template_DiffVerOfSameVFModWithSameInvId.yml"); + fis2.close(); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(6,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationWithServiceContainingL3Network() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithL3Network.yml"); + readPayload(inputArtifacts,fis1, "service_vmme_template_WithL3Network.yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithL3Network.yml"); + readPayload(inputArtifacts,fis2, "vf_vmme_template_WithL3Network.yml"); + fis2.close(); + + InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_WithL3Network.yml"); + readPayload(inputArtifacts,fis3, "resource-AllottedResource-template_WithL3Network.yml"); + fis3.close(); + + InputStream fis4 = SampleJUnitTest.class.getResourceAsStream + ("/resource-Extvl-template_WithL3Network.yml"); + readPayload(inputArtifacts,fis4, "resource-Extvl-template_WithL3Network.yml"); + fis4.close(); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(7,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationWithServiceContainingDupL3Network() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithDupL3Network.yml"); + readPayload(inputArtifacts,fis1, "service_vmme_template_WithDupL3Network.yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithDupL3Network.yml"); + readPayload(inputArtifacts,fis2, "vf_vmme_template_WithDupL3Network.yml"); + fis2.close(); + + InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_WithDupL3Network.yml"); + readPayload(inputArtifacts,fis3, "resource-AllottedResource-template_WithDupL3Network.yml"); + fis3.close(); + + InputStream fis4 = SampleJUnitTest.class.getResourceAsStream + ("/resource-Extvl-template_WithDupL3Network.yml"); + readPayload(inputArtifacts,fis4, "resource-Extvl-template_WithDupL3Network.yml"); + fis4.close(); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(7,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationWithL3NetworkInVFMod() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithL3NetworkInVFMod.yml"); + readPayload(inputArtifacts,fis1, "service_vmme_template_WithL3NetworkInVFMod.yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithL3NetworkInVFMod.yml"); + readPayload(inputArtifacts,fis2, "vf_vmme_template_WithL3NetworkInVFMod.yml"); + fis2.close(); + + InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_WithL3NetworkInVFMod.yml"); + readPayload(inputArtifacts,fis3, "resource-AllottedResource-template_WithL3NetworkInVFMod.yml"); + fis3.close(); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(6,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationWithDiffVersionOfSameL3Network() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithDiffVersionOfSameL3Network.yml"); + readPayload(inputArtifacts,fis1, "service_vmme_template_WithDiffVersionOfSameL3Network.yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithDiffVersionOfSameL3Network.yml"); + readPayload(inputArtifacts,fis2, "vf_vmme_template_WithDiffVersionOfSameL3Network.yml"); + fis2.close(); + + InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_WithDiffVersionOfSameL3Network.yml"); + readPayload(inputArtifacts,fis3, "resource-AllottedResource-template_WithDiffVersionOfSameL3Network.yml"); + fis3.close(); + + InputStream fis4 = SampleJUnitTest.class.getResourceAsStream + ("/resource-Extvl-template_WithDiffVersionOfSameL3Network.yml"); + readPayload(inputArtifacts,fis4, "resource-Extvl-template_WithDiffVersionOfSameL3Network.yml"); + fis4.close(); + + InputStream fis5 = SampleJUnitTest.class.getResourceAsStream + ("/resource-Extvl-template_1_WithDiffVersionOfSameL3Network.yml"); + readPayload(inputArtifacts,fis5, + "resource-Extvl-template_1_WithDiffVersionOfSameL3Network.yml"); + fis5.close(); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap,resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap,toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(8,data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationWithInvIdGreaterThanSpecifiedLimit() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithInvIdGreaterThanSpecifiedLimit.yml"); + readPayload(inputArtifacts,fis1, "vf_vmme_template_WithInvIdGreaterThanSpecifiedLimit" + + ".yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithInvIdGreaterThanSpecifiedLimit.yml"); + readPayload(inputArtifacts,fis2, "service_vmme_template_WithInvIdGreaterThanSpecifiedLimit.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + fis2.close(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + Assert.assertEquals(false,data.getErrorData().isEmpty()); + + Assert.assertEquals(INVALID_VALUE_INVARIANT + ": <" +inputArtifacts.get(1).getName()+">",data.getErrorData().get("AAI").get(0)); + + Assert.assertEquals(2,data.getResultData().size()); + + } catch (Exception e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationWithInvIdLesserThanSpecifiedLimit() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithInvIdLesserThanSpecifiedLimit.yml"); + readPayload(inputArtifacts,fis1, "vf_vmme_template_WithInvIdLesserThanSpecifiedLimit" + + ".yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithInvIdLesserThanSpecifiedLimit.yml"); + readPayload(inputArtifacts,fis2, "service_vmme_template_WithInvIdLesserThanSpecifiedLimit.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + fis2.close(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + Assert.assertEquals(false,data.getErrorData().isEmpty()); + + Assert.assertEquals(INVALID_VALUE_UUID + " <" + +inputArtifacts.get(1).getName()+">",data.getErrorData().get("AAI").get(0)); + + Assert.assertEquals(2,data.getResultData().size()); + + } catch (Exception e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } + } + + + @Test + public void testErrorWhenNoSystemPropConfigured() throws Exception { + String configLoc = System.getProperty(ARTIFACTGENERATOR_CONFIG); + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_NoSystemPropConfigured.yml"); + readPayload(inputArtifacts,fis1, "vf_vmme_template_NoSystemPropConfigured" + + ".yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_NoSystemPropConfigured.yml"); + readPayload(inputArtifacts,fis2, "service_vmme_template_NoSystemPropConfigured.yml"); + fis2.close(); + + System.clearProperty(ARTIFACTGENERATOR_CONFIG); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + Assert.assertEquals(false,data.getErrorData().isEmpty()); + Assert.assertEquals(data.getErrorData(). + get("AAI").get(0), GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + finally{ + System.setProperty(ARTIFACTGENERATOR_CONFIG,configLoc); + } + } + + @Test + public void testErrorWhenNoFileAtConfigLocation() throws Exception { + String configLoc = System.getProperty(ARTIFACTGENERATOR_CONFIG); + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_NoSystemPropConfigured.yml"); + readPayload(inputArtifacts,fis1, "vf_vmme_template_NoSystemPropConfigured" + + ".yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_NoSystemPropConfigured.yml"); + readPayload(inputArtifacts,fis2, "service_vmme_template_NoSystemPropConfigured.yml"); + fis2.close(); + + System.setProperty(ARTIFACTGENERATOR_CONFIG,configLoc + File.separator + "testErrorWhenNoFileAtConfigLocation"); + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + Assert.assertEquals(data.getErrorData().isEmpty(),false); + Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format( + GENERATOR_AAI_CONFIGFILE_NOT_FOUND,System.getProperty + (ARTIFACTGENERATOR_CONFIG))); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + finally{ + System.setProperty(ARTIFACTGENERATOR_CONFIG,configLoc); + } + } + + @Test + public void testErrorWhenNoWidgetInConfig() throws Exception { + System.setProperty(ARTIFACTGENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator1.properties"); + loadConfig(ArtifactGenerationServiceTest.properties); + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_NoSystemPropConfigured.yml"); + readPayload(inputArtifacts,fis1, "vf_vmme_template_NoSystemPropConfigured" + + ".yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_NoSystemPropConfigured.yml"); + readPayload(inputArtifacts,fis2, "service_vmme_template_NoSystemPropConfigured.yml"); + fis2.close(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + String assertMsg = ArtifactType.AAI.name() + ".model-version-id." + Widget.getWidget + (Widget.Type.SERVICE).getName(); + + Assert.assertEquals(false,data.getErrorData().isEmpty()); + String errMsg = String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,assertMsg); + Assert.assertEquals(data.getErrorData().get("AAI").get(0),errMsg); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } finally { + System.setProperty(ARTIFACTGENERATOR_CONFIG, CONFIG_PATH+"Artifact-Generator.properties"); + loadConfig(ArtifactGenerationServiceTest.properties); + } + } + + @Test + public void testArtifactGenerationWithUpdatedUUIDInConfig() throws Exception { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_WithUpdatedUUIDInConfig.yml"); + readPayload(inputArtifacts,fis1, "vf_vmme_template_WithUpdatedUUIDInConfig" + + ".yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_WithUpdatedUUIDInConfig.yml"); + readPayload(inputArtifacts,fis2, "service_vmme_template_WithUpdatedUUIDInConfig.yml"); + fis2.close(); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + List<ToscaTemplate> toscas = new LinkedList(); + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + System.setProperty(ARTIFACTGENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator2.properties"); + loadConfig(ArtifactGenerationServiceTest.properties); + + List<ToscaTemplate> toscas2 = new LinkedList(); + for (Artifact inputArtifact : inputArtifacts) { + toscas2.add(getToscaModel(inputArtifact)); + } + GenerationData data2 = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + Map<String, Model> outputArtifactMap2 = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap2, + data2.getResultData()); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap2, toscas2); + testResourceTosca(toscas2.iterator(), outputArtifactMap2); + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } finally { + System.setProperty(ARTIFACTGENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator.properties"); + loadConfig(ArtifactGenerationServiceTest.properties); + } + } + + @Test + public void testArtifactGenerationVerifyMandatoryParameterServiceVersion() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyMandatoryParameterServiceVersion.yml"); + readPayload(inputArtifacts, fis1, "vf_vmme_template_VerifyMandatoryParameterServiceVersion.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyMandatoryParameterServiceVersion.yml"); + readPayload(inputArtifacts, fis2, "service_vmme_template_VerifyMandatoryParameterServiceVersion.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, new HashMap<String, String>()); + List<Artifact> resultData = data.getResultData(); + + Assert.assertEquals(data.getErrorData().isEmpty(),false); + Assert.assertEquals(data.getErrorData().get("AAI").get(0),GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationVerifyServiceVersionFormat() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyServiceVersionFormat.yml"); + readPayload(inputArtifacts, fis1, "vf_vmme_template_VerifyServiceVersionFormat.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyServiceVersionFormat.yml"); + readPayload(inputArtifacts, fis2, "service_vmme_template_VerifyServiceVersionFormat.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + + additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1"); + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + List<Artifact> resultData = data.getResultData(); + Assert.assertEquals(data.getErrorData().isEmpty(),false); + Assert.assertEquals(data.getErrorData().get("AAI").get(0),GENERATOR_AAI_INVALID_SERVICE_VERSION); + + additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.1"); + GenerationData data2 = obj.generateArtifact(inputArtifacts, generatorConfig, + additionalParams); + List<Artifact> resultData2 = data.getResultData(); + Assert.assertEquals(data2.getErrorData().isEmpty(),false); + Assert.assertEquals(data2.getErrorData().get("AAI").get(0), + GENERATOR_AAI_INVALID_SERVICE_VERSION); + + additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.0"); + GenerationData data3 = obj.generateArtifact(inputArtifacts, generatorConfig, + additionalParams); + List<Artifact> resultData3 = data.getResultData(); + Assert.assertEquals(data3.getErrorData().isEmpty(),false); + Assert.assertEquals(data3.getErrorData().get("AAI").get(0), + GENERATOR_AAI_INVALID_SERVICE_VERSION); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } finally{ + additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0"); + } + } + + @Test + public void testArtifactGenerationVerifyServiceVersion() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyServiceVersion.yml"); + readPayload(inputArtifacts, fis1, "vf_vmme_template_VerifyServiceVersion.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyServiceVersion.yml"); + readPayload(inputArtifacts, fis2, "service_vmme_template_VerifyServiceVersion.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + additionalParams.put(AdditionalParams.ServiceVersion.getName(),"9.0"); + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas); + + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(5, data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } finally{ + additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0"); + } + } + + + @Test + public void testArtifactGenerationVerifyResourceVersionFormat() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyResourceVersionFormat.yml"); + readPayload(inputArtifacts, fis1, "vf_vmme_template_VerifyResourceVersionFormat.yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyResourceVersionFormat1.yml"); + readPayload(inputArtifacts, fis2, "service_vmme_template_VerifyResourceVersionFormat1.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + fis2.close(); + + List<ToscaTemplate> toscas = new LinkedList(); + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + List<Artifact> resultData = data.getResultData(); + Assert.assertEquals(data.getErrorData().isEmpty(),false); + Assert.assertEquals(data.getErrorData().get("AAI").get(0), + String.format(GENERATOR_AAI_ERROR_INVALID_RESOURCE_VERSION_IN_SERVICE_TOSCA, + toscas.get(0).getMetadata().get("UUID"))); + + inputArtifacts.remove(1); + + InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyResourceVersionFormat2.yml"); + readPayload(inputArtifacts, fis3, "service_vmme_template_VerifyResourceVersionFormat2.yml"); + fis3.close(); + GenerationData data2 = obj.generateArtifact(inputArtifacts, generatorConfig, + additionalParams); + List<Artifact> resultData2 = data2.getResultData(); + Assert.assertEquals(data2.getErrorData().isEmpty(),false); + Assert.assertEquals(data2.getErrorData().get("AAI").get(0), + String.format(GENERATOR_AAI_ERROR_INVALID_RESOURCE_VERSION_IN_SERVICE_TOSCA, + toscas.get(0).getMetadata().get("UUID"))); + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationVerifyMandatoryParameterResourceVersion() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/vf_vmme_template_VerifyMandatoryParameterResourceVersion.yml"); + readPayload(inputArtifacts, fis1, "vf_vmme_template_VerifyMandatoryParameterResourceVersion.yml"); + + fis1.close(); + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service_vmme_template_VerifyMandatoryParameterResourceVersion.yml"); + readPayload(inputArtifacts, fis2, "service_vmme_template_VerifyMandatoryParameterResourceVersion.yml"); + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + List<Artifact> resultData = data.getResultData(); + Assert.assertEquals(data.getErrorData().isEmpty(),false); + Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(GENERATOR_AAI_ERROR_NULL_RESOURCE_VERSION_IN_SERVICE_TOSCA,toscas.get(0).getMetadata().get("UUID"))); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationWithoutAllottedResource() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service-ServiceWithAllottedResourceIpmux-template.yml"); + readPayload(inputArtifacts, fis1, "service-ServiceWithAllottedResourceIpmux-template.yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_IpMux.yml"); + readPayload(inputArtifacts, fis2, "resource-AllottedResource-template_IpMux.yml"); + fis2.close(); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + List<Artifact> resultData = data.getResultData(); + Assert.assertEquals(data.getErrorData().isEmpty(),false); + Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format + (GENERATOR_AAI_PROVIDING_SERVICE_MISSING, toscas.get(1).getModelId())); + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationAllottedResourceIpmuxWithGroups() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream + ("/service-ServiceWithAllottedResourceIpmux-template_WithGroups.yml"); + readPayload(inputArtifacts, fis1, "service-ServiceWithAllottedResourceIpmux-template_WithGroups.yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource-template_IpMux_WithGroups.yml"); + readPayload(inputArtifacts, fis2, "resource-AllottedResource-template_IpMux_WithGroups.yml"); + fis2.close(); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(5, data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationAllottedResourceIpmuxSameInvariantDiffVersion() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service-ServiceWithAllottedResourcesIpMuxSameInvariant-template.yml"); + readPayload(inputArtifacts, fis1, "service-ServiceWithAllottedResourcesIpMuxSameInvariant-template.yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource1SameInvariant-IpMux-template.yml"); + readPayload(inputArtifacts, fis2, "resource-AllottedResource1SameInvariant-IpMux-template.yml"); + fis2.close(); + + InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResource2SameInvariant-IpMux-template.yml"); + readPayload(inputArtifacts, fis3, "resource-AllottedResource2SameInvariant-IpMux-template.yml"); + fis3.close(); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(5, data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationAllottedResourceIpmuxSameInvariantSameVersion() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/service-ServiceWithAllottedResourcesIpMuxSameInvariantSameVers-template.yml"); + readPayload(inputArtifacts, fis1, "service-ServiceWithAllottedResourcesIpMuxSameInvariantSameVers-template.yml"); + fis1.close(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/resource-AllottedResourceSameInvariantSameVers-IpMux-template.yml"); + readPayload(inputArtifacts, fis2, "resource-AllottedResourceSameInvariantSameVers-IpMux-template.yml"); + fis2.close(); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(4, data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationAllottedResourceWithIpMuxAndTunnelXConn() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service-Allottedipmux-template.yml"); + readPayload(inputArtifacts, fis2, "service-Allottedipmux-template.yml"); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/resource-IpMuxDemux-template.yml"); + readPayload(inputArtifacts, fis1, "resource-IpMuxDemux-template.yml"); + + InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-TunnelXconn-template.yml"); + readPayload(inputArtifacts, fis3, "resource-TunnelXconn-template.yml"); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(5, data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationAllottedResourceWithOutProvidingServiceId() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service-SdWan-template_WithOutDepSerId.yml"); + readPayload(inputArtifacts, fis2, "service-SdWan-template_WithOutDepSerId.yml"); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/resource-VhnfNonHeat-template_WithOutDepSerId.yml"); + readPayload(inputArtifacts, fis1, "resource-VhnfNonHeat-template_WithOutDepSerId.yml"); + + InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-TunnelXconn-template_WithOutDepSerId.yml"); + readPayload(inputArtifacts, fis3, "resource-TunnelXconn-template_WithOutDepSerId.yml"); + + InputStream fis4 = SampleJUnitTest.class.getResourceAsStream + ("/resource-ServiceAdmin-template_WithOutDepSerId.yml"); + readPayload(inputArtifacts, fis4, "resource-ServiceAdmin-template_WithOutDepSerId.yml"); + + InputStream fis5 = SampleJUnitTest.class.getResourceAsStream + ("/resource-IpMuxDemux-template_WithOutDepSerId.yml"); + readPayload(inputArtifacts, fis5, "resource-IpMuxDemux-template_WithOutDepSerId.yml"); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + List<Artifact> resultData = data.getResultData(); + Assert.assertEquals(data.getErrorData().isEmpty(),false); + Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format + (GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING, toscas.get(2).getModelId())); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + @Test + public void testArtifactGenerationAllottedResourceWithVF() { + try { + List<Artifact> inputArtifacts = new ArrayList(); + + InputStream fis2 = SampleJUnitTest.class.getResourceAsStream("/service-SdWan-template_AllRes_VF.yml"); + readPayload(inputArtifacts, fis2, "service-SdWan-template_AllRes_VF.yml"); + + InputStream fis1 = SampleJUnitTest.class.getResourceAsStream("/resource-VhnfNonHeat-template_AllRes_VF.yml"); + readPayload(inputArtifacts, fis1, "resource-VhnfNonHeat-template_AllRes_VF.yml"); + + InputStream fis3 = SampleJUnitTest.class.getResourceAsStream("/resource-TunnelXconn-template_AllRes_VF.yml"); + readPayload(inputArtifacts, fis3, "resource-TunnelXconn-template_AllRes_VF.yml"); + + InputStream fis4 = SampleJUnitTest.class.getResourceAsStream + ("/resource-ServiceAdmin-template_AllRes_VF.yml"); + readPayload(inputArtifacts, fis4, "resource-ServiceAdmin-template_AllRes_VF.yml"); + + InputStream fis5 = SampleJUnitTest.class.getResourceAsStream + ("/resource-IpMuxDemux-template_AllRes_VF.yml"); + readPayload(inputArtifacts, fis5, "resource-IpMuxDemux-template_AllRes_VF.yml"); + + ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl(); + List<ToscaTemplate> toscas = new LinkedList(); + + GenerationData data = obj.generateArtifact(inputArtifacts, generatorConfig, additionalParams); + for (Artifact inputArtifact : inputArtifacts) { + toscas.add(getToscaModel(inputArtifact)); + } + List<Artifact> resultData = data.getResultData(); + + Map<String, Model> outputArtifactMap = new HashMap<>(); + ArtifactGenerationServiceTest.populateAAIGeneratedModelStore(outputArtifactMap, resultData); + ArtifactGenerationServiceTest.testServiceTosca(outputArtifactMap, toscas); + testResourceTosca(toscas.iterator(), outputArtifactMap); + + Assert.assertEquals(7, data.getResultData().size()); + + removeMockArtifact(data.getResultData().iterator()); + + ArtifactGenerationServiceTest.validateName(data.getResultData()); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + + public static void readPayload(List<Artifact> inputArtifacts,InputStream fis, String fileName) throws IOException { + byte[] payload = new byte[fis.available()]; + fis.read(payload); + String checksum = GeneratorUtil.checkSum(payload); + byte[] encodedPayload = GeneratorUtil.encode(payload); + Artifact artifact = new Artifact(aaiArtifactType, aaiArtifactGroupType, checksum, encodedPayload); + artifact.setName(fileName); + artifact.setLabel(fileName); + artifact.setDescription(fileName); + //artifact.setVersion("1.0"); + System.out.println(artifact.getName()); + inputArtifacts.add(artifact); + } + + + /** + * Get the tosca java model from the tosca input artifact + * + * @param input Input tosca file and its metadata information as {@link Artifact} object + * @return Translated {@link ToscaTemplate tosca} object + * @throws SecurityException + */ + public static ToscaTemplate getToscaModel(Artifact input) throws SecurityException { + byte[] decodedInput = GeneratorUtil.decoder(input.getPayload()); + String checksum = GeneratorUtil.checkSum(decodedInput); + if (checksum.equals(input.getChecksum())) { + try { + return GeneratorUtil.translateTosca(new String(decodedInput), ToscaTemplate.class); + } catch (Exception e) { + e.printStackTrace(); + throw new IllegalArgumentException(String.format(GENERATOR_AAI_ERROR_INVALID_TOSCA, input.getName())); + } + } else { + throw new SecurityException(String.format(GENERATOR_AAI_ERROR_CHECKSUM_MISMATCH, input.getName())); + } + } + + public static void removeMockArtifact(Iterator<Artifact> itr) { + while (itr.hasNext()){ + if(itr.next().getType().equals("OTHER")){ + itr.remove(); + } + } + } + + /*public static void testResourceTosca(Iterator<ToscaTemplate> itr, Map<String, Model> outputArtifactMap) { + while(itr.hasNext()){ + ToscaTemplate toscaTemplate = itr.next(); + if("VF".equals(toscaTemplate.getMetadata().get("type"))){ + ArtifactGenerationServiceTest.testResourceTosca(outputArtifactMap, toscaTemplate); + } + } + }*/ + +} |