From 86671624c83f8d6af7523d1527858e9f93b35f11 Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Fri, 15 Oct 2021 14:52:43 +0100 Subject: Update service import to import self properties Issue-ID: SDC-3764 Signed-off-by: KrupaNagabhushan Change-Id: I6d6c3a40484b0a5df2611c036740ad9965e6a73d --- .../components/impl/ResourceBusinessLogicTest.java | 4 +- .../impl/ServiceImportBusinessLogicTest.java | 1 - .../impl/utils/YamlTemplateParsingHandlerTest.java | 44 +++++++++++++++++++-- .../src/test/resources/csars/with_groups.csar | Bin 65647 -> 66187 bytes 4 files changed, 43 insertions(+), 6 deletions(-) (limited to 'catalog-be/src/test') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java index 0453dc7fef..334bffd342 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java @@ -1475,7 +1475,7 @@ public class ResourceBusinessLogicTest { String resourceYml = new String(csar.get("Definitions/my_vnf.yaml")); YamlTemplateParsingHandler yamlTemplateParser = new YamlTemplateParsingHandler(mockJanusGraphDao, null, Mockito.mock(AnnotationBusinessLogic.class), null); - final ParsedToscaYamlInfo parsedToscaYamlInfo = yamlTemplateParser.parseResourceInfoFromYAML("Definitions/my_vnf.yml", resourceYml, Collections.EMPTY_MAP, Collections.EMPTY_MAP, "myVnf", resourceResponse); + final ParsedToscaYamlInfo parsedToscaYamlInfo = yamlTemplateParser.parseResourceInfoFromYAML("Definitions/my_vnf.yml", resourceYml, Collections.EMPTY_MAP, Collections.EMPTY_MAP, "myVnf", resourceResponse, ""); when(propertyOperation.getDataTypeByName("tosca.datatypes.testDataType.FromMainTemplate", "testModel")).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); @@ -1510,7 +1510,7 @@ public class ResourceBusinessLogicTest { vduCp.getProperties().add(roleProp); when(toscaOperationFacade.getLatestByToscaResourceNameAndModel("tosca.nodes.nfv.VduCp", "testModel_myVnf1.0")).thenReturn(Either.left(vduCp)); - when(yamlTemplateParsingHandler.parseResourceInfoFromYAML(any(), any(), any(), any(), any(), any())).thenReturn(parsedToscaYamlInfo); + when(yamlTemplateParsingHandler.parseResourceInfoFromYAML(any(), any(), any(), any(), any(), any(), any())).thenReturn(parsedToscaYamlInfo); UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); uploadComponentInstanceInfo.setType("myType"); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java index 6fcdd1373c..ee52431a4f 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java @@ -208,7 +208,6 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest Service oldService = createServiceObject(true); Resource resource = createOldResource(); String topologyTemplateYaml = getMainTemplateContent("service_import_template.yml"); - ; String yamlName = "group.yml"; CsarInfo csarInfo = getCsarInfo(); Map>> nodeTypesArtifactsToCreate = new HashMap<>(); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java index 65ad5fc1a6..5f85b5134a 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java @@ -47,6 +47,7 @@ import org.openecomp.sdc.be.model.ParsedToscaYamlInfo; import org.openecomp.sdc.be.model.PolicyDefinition; import org.openecomp.sdc.be.model.PolicyTypeDefinition; import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.model.UploadArtifactInfo; import org.openecomp.sdc.be.model.UploadComponentInstanceInfo; import org.openecomp.sdc.be.model.User; @@ -65,7 +66,9 @@ import java.util.stream.Collectors; import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -149,18 +152,37 @@ public class YamlTemplateParsingHandlerTest { Resource resource = new Resource(); ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(), - csarInfo.extractTypesInfo(), NODE_NAME, resource); + csarInfo.extractTypesInfo(), NODE_NAME, resource, getInterfaceTemplateYaml(csarInfo).get()); validateParsedYaml(parsedYaml, NESTED_GROUP_NAME, Lists.newArrayList("heat_file", "description")); } + @Test + public void parseServicePropertiesInfoFromYamlTest() { + String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME)); + CsarInfo csarInfo = new CsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME, + MAIN_TEMPLATE_NAME, main_template_content, true); + + Service service = new Service(); + ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(), + csarInfo.extractTypesInfo(), NODE_NAME, service, getInterfaceTemplateYaml(csarInfo).get()); + + assertThat(parsedYaml.getProperties()).isNotNull(); + assertEquals(5, parsedYaml.getProperties().size()); + assertTrue(parsedYaml.getProperties().containsKey("skip_post_instantiation_configuration")); + assertTrue(parsedYaml.getProperties().containsKey("controller_actor")); + assertTrue(parsedYaml.getProperties().containsKey("cds_model_version")); + assertTrue(parsedYaml.getProperties().containsKey("cds_model_name")); + assertTrue(parsedYaml.getProperties().containsKey("default_software_version")); + } + @Test public void parseResourceInfoFromYAMLTest() { Resource resource = new Resource(); ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(), - new HashMap<>(), "", resource); + new HashMap<>(), "", resource, null); validateParsedYamlWithCapability(parsedYaml); } @@ -234,7 +256,7 @@ public class YamlTemplateParsingHandlerTest { public void parseResourceWithPoliciesDefined() { Resource resource = new Resource(); ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(), - new HashMap<>(), "", resource); + new HashMap<>(), "", resource, ""); validateParsedYamlWithPolicies(parsedYaml); } @@ -393,4 +415,20 @@ public class YamlTemplateParsingHandlerTest { } return policyTypeDefinition; } + + private Optional getInterfaceTemplateYaml(CsarInfo csarInfo) { + String[] yamlFile; + String interfaceTemplateYaml = ""; + if (csarInfo.getMainTemplateName().contains(".yml")) { + yamlFile = csarInfo.getMainTemplateName().split(".yml"); + interfaceTemplateYaml = yamlFile[0] + "-interface.yml"; + } else if (csarInfo.getMainTemplateName().contains(".yaml")) { + yamlFile = csarInfo.getMainTemplateName().split(".yaml"); + interfaceTemplateYaml = yamlFile[0] + "-interface.yaml"; + } + if (csarInfo.getCsar().containsKey(interfaceTemplateYaml)) { + return Optional.of(new String(csarInfo.getCsar().get(interfaceTemplateYaml))); + } + return Optional.empty(); + } } diff --git a/catalog-be/src/test/resources/csars/with_groups.csar b/catalog-be/src/test/resources/csars/with_groups.csar index 9259a81de0..49b5a440ea 100644 Binary files a/catalog-be/src/test/resources/csars/with_groups.csar and b/catalog-be/src/test/resources/csars/with_groups.csar differ -- cgit 1.2.3-korg