summaryrefslogtreecommitdiffstats
path: root/common/onap-sdc-artifact-generator-lib/onap-sdc-artifact-generator-test/src/main/java/org
diff options
context:
space:
mode:
authoramitjai <amitjai@amdocs.com>2018-04-27 13:28:57 +0530
committerOren Kleks <orenkle@amdocs.com>2018-04-30 06:05:27 +0000
commit42c920baf4dbb9fe8775843a6d4c9f70fa29f064 (patch)
treeac2aff977e2b129e61d2166c4832842676e4f5c3 /common/onap-sdc-artifact-generator-lib/onap-sdc-artifact-generator-test/src/main/java/org
parentf487427a32f410ab5c97a4092865d32beb88ee27 (diff)
Rename packages from openecomp to onap.
This task is all about package name space change also make changes to pom for common module Change-Id: Ie9bda0f958a9a05826c0374830cc9cb7d6d196b6 Issue-ID: SDC-1272 Signed-off-by: amitjai <amitjai@amdocs.com>
Diffstat (limited to 'common/onap-sdc-artifact-generator-lib/onap-sdc-artifact-generator-test/src/main/java/org')
-rw-r--r--common/onap-sdc-artifact-generator-lib/onap-sdc-artifact-generator-test/src/main/java/org/onap/sdc/generator/ArtifactGenerationServiceTest.java696
-rw-r--r--common/onap-sdc-artifact-generator-lib/onap-sdc-artifact-generator-test/src/main/java/org/onap/sdc/generator/SampleJUnitTest.java1607
2 files changed, 2303 insertions, 0 deletions
diff --git a/common/onap-sdc-artifact-generator-lib/onap-sdc-artifact-generator-test/src/main/java/org/onap/sdc/generator/ArtifactGenerationServiceTest.java b/common/onap-sdc-artifact-generator-lib/onap-sdc-artifact-generator-test/src/main/java/org/onap/sdc/generator/ArtifactGenerationServiceTest.java
new file mode 100644
index 0000000000..b11c33ec9f
--- /dev/null
+++ b/common/onap-sdc-artifact-generator-lib/onap-sdc-artifact-generator-test/src/main/java/org/onap/sdc/generator/ArtifactGenerationServiceTest.java
@@ -0,0 +1,696 @@
+/*-
+ * ============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.onap.sdc.generator;
+
+import org.onap.sdc.generator.aai.model.*;
+import org.onap.sdc.generator.aai.model.Service;
+import org.onap.sdc.generator.aai.tosca.GroupDefinition;
+import org.onap.sdc.generator.aai.tosca.NodeTemplate;
+import org.onap.sdc.generator.aai.tosca.ToscaTemplate;
+import org.onap.sdc.generator.aai.xml.*;
+import org.onap.sdc.generator.aai.xml.Model;
+import org.onap.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.IOException;
+import java.io.InputStream;
+import java.util.*;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+@SuppressWarnings("Duplicates")
+public class ArtifactGenerationServiceTest {
+
+ public static final String RESOURCE_MAPPING_NOT_FOUND = "Resource mapping not found for ";
+ public static final String INV_UID = "-INV_UID";
+ public static final String VF_MODULE_NAMESPACE = "org.openecomp.groups.VfModule";
+ public static final String VF_MODULE_DESCRIPTION = "vf_module_description";
+ public static final String CATEGORY = "category";
+ static Map<String, String> resourcesVersion = new HashMap<>();
+ public static Properties properties = new Properties();
+
+ @SuppressWarnings("Since15")
+ public static void validateName(List<Artifact> artifactList) throws JAXBException {
+ 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) {
+
+ 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 + resourceNameVersionId);
+ }
+ }
+ }
+
+ public static void testAllottedResourceTosca(Map<String, Model> outputArtifactMap , ToscaTemplate
+ resourceTosca) {
+
+ 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 + resourceNameVersionId);
+ }
+ }
+ }
+
+ 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) {
+
+ 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 + resourceNameVersionId);
+ }
+ }
+ }
+
+ public static void testServiceTosca(Map<String, Model> outputArtifactMap,List<ToscaTemplate>
+ toscas) {
+
+ ToscaTemplate serviceTosca = getServiceTosca(toscas);
+ if (serviceTosca == null) {
+ org.testng.Assert.fail("Service Tosca not found");
+ }
+ serviceTosca.getMetadata().put("version", SampleJUnitTest.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 (Map.Entry<String, String> entry : nodeTemplateIdTypeStore.entrySet()) {
+ if (entry.getValue().contains("org.openecomp.resource.vf")) {
+ List<ModelElement> matchedResourceElements =
+ getModelElementbyRelationshipValue(baseServiceWidgetModelElements, entry.getKey());
+ if (entry.getValue().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(),entry.getKey());
+
+ org.testng.Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList().getRelationship().get(0)
+ .getRelationshipData().get(1).getRelationshipValue(), nodeTemplateIdTypeStore
+ .get(entry.getKey()+ INV_UID));
+ } else if(entry.getValue().contains("org.openecomp.resource.vl")){
+ //validate l3-network in service tosca
+ List<ModelElement> matchedResourceElements =
+ getModelElementbyRelationshipValue(baseServiceWidgetModelElements, entry.getKey());
+ 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(),entry.getKey());
+
+ org.testng.Assert.assertEquals(matchedResourceElements.get(0).getRelationshipList().getRelationship().get(0)
+ .getRelationshipData().get(1).getRelationshipValue(), nodeTemplateIdTypeStore
+ .get(entry.getKey() + INV_UID));
+ }
+ }
+ }
+ }
+
+ 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(VF_MODULE_NAMESPACE)) {
+ 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) throws JAXBException {
+ 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) throws JAXBException {
+ JAXBContext jaxbContext;
+
+ jaxbContext = JAXBContext.newInstance(Model.class);
+ Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+
+ try (InputStream aaiModelStream = new ByteArrayInputStream(aaiModel.getBytes())) {
+ return (Model) unmarshaller.unmarshal(aaiModelStream);
+ } catch (IOException ignored) { /* ignore */ }
+ throw new RuntimeException("could not resolve artifact model");
+ }
+
+ /**
+ * 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 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(VF_MODULE_NAMESPACE)) {
+ 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;
+ for (Map.Entry<String, GroupDefinition> e : groupDefinitionMap.entrySet()) {
+ if (e.getValue().getType().contains(VF_MODULE_NAMESPACE)) {
+ 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 VF_MODULE_NAMESPACE:
+ 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/onap-sdc-artifact-generator-lib/onap-sdc-artifact-generator-test/src/main/java/org/onap/sdc/generator/SampleJUnitTest.java b/common/onap-sdc-artifact-generator-lib/onap-sdc-artifact-generator-test/src/main/java/org/onap/sdc/generator/SampleJUnitTest.java
new file mode 100644
index 0000000000..9c4def4808
--- /dev/null
+++ b/common/onap-sdc-artifact-generator-lib/onap-sdc-artifact-generator-test/src/main/java/org/onap/sdc/generator/SampleJUnitTest.java
@@ -0,0 +1,1607 @@
+/*-
+ * ============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.onap.sdc.generator;
+
+import org.onap.sdc.generator.data.AdditionalParams;
+import org.onap.sdc.generator.data.Artifact;
+import org.onap.sdc.generator.data.ArtifactType;
+import org.onap.sdc.generator.data.GenerationData;
+import org.onap.sdc.generator.data.GeneratorConstants;
+import org.onap.sdc.generator.data.GeneratorUtil;
+import org.onap.sdc.generator.data.GroupType;
+import org.onap.sdc.generator.impl.ArtifactGenerationServiceImpl;
+import org.onap.sdc.generator.aai.model.Widget;
+import org.onap.sdc.generator.aai.tosca.ToscaTemplate;
+import org.onap.sdc.generator.aai.xml.Model;
+import org.onap.sdc.generator.data.*;
+
+import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.*;
+import java.util.*;
+
+import static org.onap.sdc.generator.ArtifactGenerationServiceTest.*;
+
+public class SampleJUnitTest extends TestCase {
+
+ private static final String AAI_ARTIFACT_TYPE = ArtifactType.AAI.name();
+ private static final String AAI_ARTIFACT_GROUP_TYPE = GroupType.DEPLOYMENT.name();
+ private static final String GENERATOR_CONFIG = "{\"artifactTypes\": [\"OTHER\",\"AAI\"]}";
+ private static final String ARTIFACT_GENERATOR_CONFIG = "artifactgenerator.config";
+ private static final String CONFIG_PATH = "/qa-test-repo/jmeter3/apache-jmeter-3" +
+ ".0/lib/junit/";
+ private static final String GENERATOR_AAI_CONFIGLPROP_NOT_FOUND =
+ "Cannot generate artifacts. Widget configuration not found for %s";
+ private static final String GENERATOR_AAI_CONFIGFILE_NOT_FOUND =
+ "Cannot generate artifacts. Artifact Generator Configuration file not found at %s";
+ private static final String GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND =
+ "Cannot generate artifacts. artifactgenerator.config system property not configured";
+ private static final String INVALID_VALUE_INVARIANT =
+ "Invalid value for mandatory attribute <invariantUUID> in Artifact";
+ private static final String INVALID_VALUE_UUID =
+ "Invalid value for mandatory attribute <UUID> in Artifact:";
+ static final Map<String, String> additionalParams = new HashMap<>();
+ public static final String ARTIFACT_GENERATOR_PROPERTIES = "Artifact-Generator.properties";
+ public static final String VF_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML = "vf_vmme_template_NoSystemPropConfigured.yml";
+ public static final String SERVICE_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML = "service_vmme_template_NoSystemPropConfigured.yml";
+
+ static{
+ additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1.0");
+ }
+
+ public SampleJUnitTest(String name) throws IOException {
+ super(name);
+ System.setProperty(ARTIFACT_GENERATOR_CONFIG,CONFIG_PATH + ARTIFACT_GENERATOR_PROPERTIES);
+ loadConfig(ArtifactGenerationServiceTest.properties);
+ }
+
+ private void loadConfig(Properties properties) throws IOException {
+ String configLocation = System.getProperty(ARTIFACT_GENERATOR_CONFIG);
+ if (configLocation != null) {
+ File file = new File(configLocation);
+ if (file.exists()) {
+
+ try (InputStream fis = new FileInputStream(file)) {
+ properties.load(fis);
+ }
+ }
+ }
+ }
+
+ public SampleJUnitTest() {
+ super();
+ System.setProperty(ARTIFACT_GENERATOR_CONFIG,CONFIG_PATH + ARTIFACT_GENERATOR_PROPERTIES);
+ }
+
+ @Test
+ public void testArtifactGenerationSingleVFSingleVFModule() {
+ try {
+ List<Artifact> inputArtifacts = new ArrayList();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_SingleVFVFMod.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_SingleVFVFMod.yml");
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_MissingVFInServiceTOSCA.yml");
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_SameWidgets1.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_SameWidget1.yml");
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+ readPayloadFromResource(inputArtifacts2, "vf_vmme_template_SameWidgets2.yml");
+
+ readPayloadFromResource(inputArtifacts2, "service_vmme_template_SameWidget2.yml");
+ ArtifactGenerationServiceImpl obj2 = new ArtifactGenerationServiceImpl();
+
+ GenerationData data2 = obj2.generateArtifact(inputArtifacts2, GENERATOR_CONFIG,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(Map.Entry<String, String> entry : map.entrySet()){
+ Assert.assertEquals(entry.getValue(), map2.get(entry.getKey()));
+ }
+
+ } catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testArtifactGenerationMulVFModule() {
+ try {
+ List<Artifact> inputArtifacts = new ArrayList();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_MulVFVFMod.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_MulVFVFMod.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "CMAUI_VF.yaml");
+
+ readPayloadFromResource(inputArtifacts, "ECA_OAM_VF.yaml");
+
+ readPayloadFromResource(inputArtifacts, "MMSC_Sevice_07_25_16.yaml");
+
+ readPayloadFromResource(inputArtifacts, "MMSC_VF.yaml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_DupVFUUID.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_DupVFUUID.yml");
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_DupVFModUUID.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_DupVFModUUID.yml");
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyVFModWithoutVNFC.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyVFModWithoutVNFC.yml");
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyVFModWithInvalidNo.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyVFModWithInvalidNo.yml");
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_NullFields.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_NullFields.yml");
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testArtifactGenerationInCorrectYmlFormat() {
+ try {
+ List<Artifact> inputArtifacts = new ArrayList();
+
+ readPayloadFromResource(inputArtifacts, "CMAUI_VFInvalidFormat.yaml");
+
+ readPayloadFromResource(inputArtifacts, "ECA_OAM_VFInvalidFormat.yaml");
+
+ readPayloadFromResource(inputArtifacts, "MMSC_Sevice_07_25_16InvalidFormat.yaml");
+
+ readPayloadFromResource(inputArtifacts, "MMSC_VFInvalidFormat.yaml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_MulComp.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_MulComp.yml");
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_Orphan.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_Orphan.yml");
+
+ readPayloadFromResource(inputArtifacts, "ECA_OAM_VFOrphan.yaml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_MissingVFTemplate.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "CMAUI_VFMissingVFModule.yaml");
+
+ readPayloadFromResource(inputArtifacts, "ECA_OAM_VFMissingVFModule.yaml");
+
+ readPayloadFromResource(inputArtifacts, "MMSC_Sevice_07_25_16MissingVFModule.yaml");
+
+ readPayloadFromResource(inputArtifacts, "MMSC_VFMissingVFModule.yaml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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 testArtifactGenerationEmptyArtifact() {
+ try {
+ List<Artifact> inputArtifacts = new ArrayList();
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_SingleVFVFMod.yml");
+
+ readPayloadFromResource(inputArtifacts, "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();
+
+ readPayloadFromResource(inputArtifacts, "ServiceWithNodetemplate.yml");
+
+ readPayloadFromResource(inputArtifacts, "Resource0-template.yml");
+
+ readPayloadFromResource(inputArtifacts, "Resource1-template.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "Service0-template.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "Service0-templateMoreThan256.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_DiffVerOfSameVF.yml");
+
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_DiffVerOfSameVF_1.yml");
+
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_DiffVerOfSameVF_2.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_DiffVerOfSameVFModWithSameInvId.yml");
+
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_DiffVerOfSameVFModWithSameInvId.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_WithL3Network.yml");
+
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithL3Network.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_WithL3Network.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-Extvl-template_WithL3Network.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_WithDupL3Network.yml");
+
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithDupL3Network.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_WithDupL3Network.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-Extvl-template_WithDupL3Network.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_WithL3NetworkInVFMod.yml");
+
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithL3NetworkInVFMod.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_WithL3NetworkInVFMod.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_WithDiffVersionOfSameL3Network.yml");
+
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithDiffVersionOfSameL3Network.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_WithDiffVersionOfSameL3Network.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-Extvl-template_WithDiffVersionOfSameL3Network.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-Extvl-template_1_WithDiffVersionOfSameL3Network.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithInvIdGreaterThanSpecifiedLimit.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_WithInvIdGreaterThanSpecifiedLimit.yml");
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testArtifactGenerationWithInvIdLesserThanSpecifiedLimit() {
+ try {
+ List<Artifact> inputArtifacts = new ArrayList();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithInvIdLesserThanSpecifiedLimit.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_WithInvIdLesserThanSpecifiedLimit.yml");
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+
+ @Test
+ public void testErrorWhenNoSystemPropConfigured() {
+ String configLoc = System.getProperty(ARTIFACT_GENERATOR_CONFIG);
+ try {
+ List<Artifact> inputArtifacts = new ArrayList();
+ readPayloadFromResource(inputArtifacts, VF_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
+
+ readPayloadFromResource(inputArtifacts, SERVICE_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
+
+ System.clearProperty(ARTIFACT_GENERATOR_CONFIG);
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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(ARTIFACT_GENERATOR_CONFIG,configLoc);
+ }
+ }
+
+ @Test
+ public void testErrorWhenNoFileAtConfigLocation() {
+ String configLoc = System.getProperty(ARTIFACT_GENERATOR_CONFIG);
+ try {
+ List<Artifact> inputArtifacts = new ArrayList();
+ readPayloadFromResource(inputArtifacts, VF_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
+
+ readPayloadFromResource(inputArtifacts, SERVICE_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
+
+ System.setProperty(ARTIFACT_GENERATOR_CONFIG,configLoc + File.separator + "testErrorWhenNoFileAtConfigLocation");
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
+ Assert.assertEquals(data.getErrorData().isEmpty(),false);
+ Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(
+ GENERATOR_AAI_CONFIGFILE_NOT_FOUND,System.getProperty
+ (ARTIFACT_GENERATOR_CONFIG)));
+ } catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ finally{
+ System.setProperty(ARTIFACT_GENERATOR_CONFIG,configLoc);
+ }
+ }
+
+ @Test
+ public void testErrorWhenNoWidgetInConfig() throws IOException {
+ System.setProperty(ARTIFACT_GENERATOR_CONFIG,CONFIG_PATH+"Artifact-Generator1.properties");
+ loadConfig(ArtifactGenerationServiceTest.properties);
+ try {
+ List<Artifact> inputArtifacts = new ArrayList();
+ readPayloadFromResource(inputArtifacts, VF_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
+
+ readPayloadFromResource(inputArtifacts, SERVICE_VMME_TEMPLATE_NO_SYSTEM_PROP_CONFIGURED_YML);
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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(ARTIFACT_GENERATOR_CONFIG, CONFIG_PATH + ARTIFACT_GENERATOR_PROPERTIES);
+ loadConfig(ArtifactGenerationServiceTest.properties);
+ }
+ }
+
+ @Test
+ public void testArtifactGenerationWithUpdatedUUIDInConfig() throws IOException {
+ try {
+ List<Artifact> inputArtifacts = new ArrayList();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_WithUpdatedUUIDInConfig.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_WithUpdatedUUIDInConfig.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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(ARTIFACT_GENERATOR_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, GENERATOR_CONFIG, 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(ARTIFACT_GENERATOR_CONFIG,CONFIG_PATH + ARTIFACT_GENERATOR_PROPERTIES);
+ loadConfig(ArtifactGenerationServiceTest.properties);
+ }
+ }
+
+ @Test
+ public void testArtifactGenerationVerifyMandatoryParameterServiceVersion() {
+ try {
+ List<Artifact> inputArtifacts = new ArrayList();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyMandatoryParameterServiceVersion.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyMandatoryParameterServiceVersion.yml");
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, new HashMap<String, String>());
+
+ Assert.assertEquals(data.getErrorData().isEmpty(),false);
+ Assert.assertEquals(data.getErrorData().get("AAI").get(0),
+ GeneratorConstants.GENERATOR_AAI_ERROR_MISSING_SERVICE_VERSION);
+ } catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testArtifactGenerationVerifyServiceVersionFormat() {
+ try {
+ List<Artifact> inputArtifacts = new ArrayList();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyServiceVersionFormat.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyServiceVersionFormat.yml");
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+
+ additionalParams.put(AdditionalParams.ServiceVersion.getName(),"1");
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
+ Assert.assertEquals(data.getErrorData().isEmpty(),false);
+ Assert.assertEquals(data.getErrorData().get("AAI").get(0),
+ GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION);
+
+ additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.1");
+ GenerationData data2 = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG,
+ additionalParams);
+ Assert.assertEquals(data2.getErrorData().isEmpty(),false);
+ Assert.assertEquals(data2.getErrorData().get("AAI").get(0),
+ GeneratorConstants.GENERATOR_AAI_INVALID_SERVICE_VERSION);
+
+ additionalParams.put(AdditionalParams.ServiceVersion.getName(),"0.0");
+ GenerationData data3 = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG,
+ additionalParams);
+ Assert.assertEquals(data3.getErrorData().isEmpty(),false);
+ Assert.assertEquals(data3.getErrorData().get("AAI").get(0),
+ GeneratorConstants.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();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyServiceVersion.yml");
+
+ readPayloadFromResource(inputArtifacts, "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, GENERATOR_CONFIG, 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();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyResourceVersionFormat.yml");
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyResourceVersionFormat1.yml");
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+
+ List<ToscaTemplate> toscas = new LinkedList();
+ for (Artifact inputArtifact : inputArtifacts) {
+ toscas.add(getToscaModel(inputArtifact));
+ }
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
+ Assert.assertEquals(data.getErrorData().isEmpty(),false);
+ Assert.assertEquals(data.getErrorData().get("AAI").get(0),
+ String.format(
+ GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_RESOURCE_VERSION_IN_SERVICE_TOSCA,
+ toscas.get(0).getMetadata().get("UUID")));
+
+ inputArtifacts.remove(1);
+
+ readPayloadFromResource(inputArtifacts, "service_vmme_template_VerifyResourceVersionFormat2.yml");
+ GenerationData data2 = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG,
+ additionalParams);
+ Assert.assertEquals(data2.getErrorData().isEmpty(),false);
+ Assert.assertEquals(data2.getErrorData().get("AAI").get(0),
+ String.format(
+ GeneratorConstants.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();
+ readPayloadFromResource(inputArtifacts, "vf_vmme_template_VerifyMandatoryParameterResourceVersion.yml");
+
+ readPayloadFromResource(inputArtifacts, "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, GENERATOR_CONFIG, additionalParams);
+ Assert.assertEquals(data.getErrorData().isEmpty(),false);
+ Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format(
+ GeneratorConstants.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();
+
+ readPayloadFromResource(inputArtifacts, "service-ServiceWithAllottedResourceIpmux-template.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_IpMux.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ for (Artifact inputArtifact : inputArtifacts) {
+ toscas.add(getToscaModel(inputArtifact));
+ }
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, additionalParams);
+
+ Assert.assertEquals(data.getErrorData().isEmpty(),false);
+ Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
+ (GeneratorConstants.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();
+
+ readPayloadFromResource(inputArtifacts, "service-ServiceWithAllottedResourceIpmux-template_WithGroups.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-AllottedResource-template_IpMux_WithGroups.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "service-ServiceWithAllottedResourcesIpMuxSameInvariant-template.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-AllottedResource1SameInvariant-IpMux-template.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-AllottedResource2SameInvariant-IpMux-template.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "service-ServiceWithAllottedResourcesIpMuxSameInvariantSameVers-template.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-AllottedResourceSameInvariantSameVers-IpMux-template.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "service-Allottedipmux-template.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-IpMuxDemux-template.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-TunnelXconn-template.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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();
+
+ readPayloadFromResource(inputArtifacts, "service-SdWan-template_WithOutDepSerId.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-VhnfNonHeat-template_WithOutDepSerId.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-TunnelXconn-template_WithOutDepSerId.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-ServiceAdmin-template_WithOutDepSerId.yml");
+
+ readPayloadFromResource(inputArtifacts, "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, GENERATOR_CONFIG, additionalParams);
+ Assert.assertEquals(data.getErrorData().isEmpty(),false);
+ Assert.assertEquals(data.getErrorData().get("AAI").get(0),String.format
+ (GeneratorConstants.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();
+
+ readPayloadFromResource(inputArtifacts, "service-SdWan-template_AllRes_VF.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-VhnfNonHeat-template_AllRes_VF.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-TunnelXconn-template_AllRes_VF.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-ServiceAdmin-template_AllRes_VF.yml");
+
+ readPayloadFromResource(inputArtifacts, "resource-IpMuxDemux-template_AllRes_VF.yml");
+
+ ArtifactGenerationServiceImpl obj = new ArtifactGenerationServiceImpl();
+ List<ToscaTemplate> toscas = new LinkedList();
+
+ GenerationData data = obj.generateArtifact(inputArtifacts, GENERATOR_CONFIG, 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(AAI_ARTIFACT_TYPE, AAI_ARTIFACT_GROUP_TYPE, checksum, encodedPayload);
+ artifact.setName(fileName);
+ artifact.setLabel(fileName);
+ artifact.setDescription(fileName);
+ 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) {
+ 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) {
+ throw new IllegalArgumentException(String.format(
+ GeneratorConstants.GENERATOR_AAI_ERROR_INVALID_TOSCA, input.getName()));
+ }
+ } else {
+ throw new SecurityException(String.format(
+ GeneratorConstants.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();
+ }
+ }
+ }
+
+ private void readPayloadFromResource(List<Artifact> inputArtifacts, String fileName) throws IOException {
+
+ try (InputStream fis = SampleJUnitTest.class.getResourceAsStream("/" + fileName)) {
+ readPayload(inputArtifacts, fis, fileName);
+ }
+ }
+}