aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConverterImplTest.java298
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java80
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineParameterizedTest.java152
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java112
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfdQueryExecutorTest.java229
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParserTest.java69
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/NodeTemplateYamlParserTest.java46
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParserParametrizedTest.java68
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParserTest.java53
9 files changed, 729 insertions, 378 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConverterImplTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConverterImplTest.java
deleted file mode 100644
index c14b02b3a0..0000000000
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConverterImplTest.java
+++ /dev/null
@@ -1,298 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.core.converter.impl;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.junit.Assert;
-import org.junit.Test;
-import org.onap.sdc.tosca.datatypes.model.*;
-import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
-import org.onap.sdc.tosca.services.YamlUtil;
-import org.openecomp.core.converter.ToscaConverter;
-import org.openecomp.core.impl.ToscaConverterImpl;
-import org.openecomp.core.utilities.file.FileContentHandler;
-import org.openecomp.core.utilities.file.FileUtils;
-import org.openecomp.core.utilities.json.JsonUtil;
-import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.nio.file.NotDirectoryException;
-import java.util.*;
-
-import static org.junit.Assert.assertEquals;
-import static org.openecomp.core.converter.datatypes.Constants.globalStName;
-import static org.openecomp.core.converter.datatypes.Constants.mainStName;
-
-public class ToscaConverterImplTest {
-
- private static final ToscaConverter toscaConverter = new ToscaConverterImpl();
- private static final String VIRTUAL_LINK = "virtualLink";
- private static final String UNBOUNDED = "UNBOUNDED";
- private static final String BASE_DIR = "/mock/toscaConverter";
-
-
- @Test
- public void testConvertMainSt() throws IOException {
- String inputFilesPath = BASE_DIR + "/convertMainSt/in";
- String outputFilesPath = BASE_DIR + "/convertMainSt/out";
-
- convertAndValidate(inputFilesPath, outputFilesPath);
- }
-
- @Test
- public void testNodesConversion() throws IOException {
- String inputFilesPath = BASE_DIR + "/convertCsar/in";
- String outputFilesPath = BASE_DIR + "/convertCsar/out";
-
- convertAndValidate(inputFilesPath, outputFilesPath);
- }
-
- @Test
- public void testParameterConversion() throws IOException {
- String inputFilesPath = BASE_DIR + "/convertParameters/in";
- String outputFilesPath = BASE_DIR + "/convertParameters/out";
-
- convertAndValidate(inputFilesPath, outputFilesPath);
- }
-
- @Test
- public void testConversionWithInt() throws IOException {
- String inputFilesPath = BASE_DIR + "/conversionWithInt/in";
- String outputFilesPath = BASE_DIR + "/conversionWithInt/out";
-
- convertAndValidate(inputFilesPath, outputFilesPath);
- }
-
- @Test
- public void testOccurrencesUpperString() {
- Object[] occurrences = buildOccurrences("0", UNBOUNDED);
- Assert.assertEquals(occurrences[0], 0);
- Assert.assertEquals(occurrences[1], UNBOUNDED);
- }
-
- @Test
- public void testOccurrencesAsInts() {
- Object[] occurrences = buildOccurrences("0", "1");
- Assert.assertEquals(occurrences[0], 0);
- Assert.assertEquals(occurrences[1], 1);
- }
-
- @Test
- public void testOccurrencesAsStrings() {
- String test = "TEST_A";
- Object[] occurrences = buildOccurrences(UNBOUNDED, test);
- Assert.assertEquals(occurrences[0], UNBOUNDED);
- Assert.assertEquals(occurrences[1], test);
- }
-
- @Test
- public void testOccurrencesLowerString() {
- Object[] occurrences = buildOccurrences(UNBOUNDED, "100");
- Assert.assertEquals(occurrences[0], UNBOUNDED);
- Assert.assertEquals(occurrences[1], 100);
- }
-
- @Test
- public void testOccurrencesEmpty() {
- Object[] occurrences = buildOccurrences();
- Assert.assertEquals(occurrences.length, 0);
- }
-
- @Test
- public void testOccurrencesMany() {
- String test = "TEST_B";
- Object[] occurrences = buildOccurrences("1", "2", test);
- Assert.assertEquals(occurrences[0], 1);
- Assert.assertEquals(occurrences[1], 2);
- Assert.assertEquals(occurrences[2], test);
- }
-
- @Test
- public void testDefaultOccurrences() {
- Object[] occurrences = buildOccurrences((List<String>) null);
- Assert.assertEquals(1, occurrences[0]);
- Assert.assertEquals(1, occurrences[1]);
- }
-
- private Object[] buildOccurrences(String... bounds) {
- return buildOccurrences(Arrays.asList(bounds));
- }
-
- private void convertAndValidate(String inputFilesPath, String outputFilesPath)
- throws IOException {
- FileContentHandler fileContentHandler =
- createFileContentHandlerFromInput(inputFilesPath);
-
- ToscaServiceModel toscaServiceModel = toscaConverter.convert(fileContentHandler);
- validateConvertorOutput(outputFilesPath, toscaServiceModel);
- }
-
- private void validateConvertorOutput(String outputFilesPath, ToscaServiceModel toscaServiceModel)
- throws IOException {
- ServiceTemplate mainSt = toscaServiceModel.getServiceTemplates().get(mainStName);
- Map<String, ServiceTemplate> expectedOutserviceTemplates = new HashMap<>();
- loadServiceTemplates(outputFilesPath, new ToscaExtensionYamlUtil(),
- expectedOutserviceTemplates);
-
- checkSTResults(expectedOutserviceTemplates, null, mainSt);
- }
-
- private Object[] buildOccurrences(List<String> bounds) {
- NodeType nodeType = JsonUtil.json2Object("{derived_from=tosca.nodes.Root, description=MME_VFC, " +
- "properties={vendor={type=string, default=ERICSSON}, " +
- "csarVersion={type=string, default=v1.0}, csarProvider={type=string, default=ERICSSON}, " +
- "id={type=string, default=vMME}, version={type=string, default=v1.0}, csarType={type=string, default=NFAR}}, " +
- "requirements=[{virtualLink={" +
- (bounds == null ? "" : "occurrences=[" + String.join(", ", bounds) + "], ") +
- "capability=tosca.capabilities.network.Linkable}}]}", NodeType.class);
- List<Map<String, RequirementDefinition>> requirements = nodeType.getRequirements();
- return requirements.get(0).get(VIRTUAL_LINK).getOccurrences();
- }
-
- private FileContentHandler createFileContentHandlerFromInput(String inputFilesPath)
- throws IOException {
- URL inputFilesUrl = this.getClass().getResource(inputFilesPath);
- String path = inputFilesUrl.getPath();
- File directory = new File(path);
- File[] listFiles = directory.listFiles();
-
- FileContentHandler fileContentHandler = new FileContentHandler();
- insertFilesIntoFileContentHandler(listFiles, fileContentHandler);
- return fileContentHandler;
- }
-
- private void insertFilesIntoFileContentHandler(File[] listFiles,
- FileContentHandler fileContentHandler)
- throws IOException {
- byte[] fileContent;
- if(CollectionUtils.isEmpty(fileContentHandler.getFileList())) {
- fileContentHandler.setFiles(new HashMap<>());
- }
-
- for (File file : listFiles) {
- if(!file.isDirectory()) {
- try (FileInputStream fis = new FileInputStream(file)) {
- fileContent = FileUtils.toByteArray(fis);
- fileContentHandler.addFile(file.getPath(), fileContent);
- }
- }else{
- File[] currFileList = file.listFiles();
- insertFilesIntoFileContentHandler(currFileList, fileContentHandler);
- }
-
- }
- }
-
- private void checkSTResults(
- Map<String, ServiceTemplate> expectedOutserviceTemplates,
- ServiceTemplate gloablSubstitutionServiceTemplate, ServiceTemplate mainServiceTemplate) {
- YamlUtil yamlUtil = new YamlUtil();
- if (Objects.nonNull(gloablSubstitutionServiceTemplate)) {
- assertEquals("difference global substitution service template: ",
- yamlUtil.objectToYaml(expectedOutserviceTemplates.get(globalStName)),
- yamlUtil.objectToYaml(gloablSubstitutionServiceTemplate));
- }
- if (Objects.nonNull(mainServiceTemplate)) {
- assertEquals("difference main service template: ",
- yamlUtil.objectToYaml(expectedOutserviceTemplates.get(mainStName)),
- yamlUtil.objectToYaml(mainServiceTemplate));
- }
- }
-
- public static void loadServiceTemplates(String serviceTemplatesPath,
- ToscaExtensionYamlUtil toscaExtensionYamlUtil,
- Map<String, ServiceTemplate> serviceTemplates)
- throws IOException {
- URL urlFile = ToscaConverterImplTest.class.getResource(serviceTemplatesPath);
- if (urlFile != null) {
- File pathFile = new File(urlFile.getFile());
- File[] files = pathFile.listFiles();
- if (files != null) {
- addServiceTemplateFiles(serviceTemplates, files, toscaExtensionYamlUtil);
- } else {
- throw new NotDirectoryException(serviceTemplatesPath);
- }
- } else {
- throw new NotDirectoryException(serviceTemplatesPath);
- }
- }
-
- private static void addServiceTemplateFiles(Map<String, ServiceTemplate> serviceTemplates,
- File[] files,
- ToscaExtensionYamlUtil toscaExtensionYamlUtil) throws IOException {
-
- for (File file : files) {
-
- try (InputStream yamlFile = new FileInputStream(file)) {
- ServiceTemplate serviceTemplateFromYaml =
- toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
- createConcreteRequirementObjectsInServiceTemplate(serviceTemplateFromYaml, toscaExtensionYamlUtil);
- serviceTemplates.put(file.getName(), serviceTemplateFromYaml);
- }
- }
- }
-
- private static void createConcreteRequirementObjectsInServiceTemplate(ServiceTemplate
- serviceTemplateFromYaml,
- ToscaExtensionYamlUtil
- toscaExtensionYamlUtil) {
-
- if (serviceTemplateFromYaml == null
- || serviceTemplateFromYaml.getTopology_template() == null
- || serviceTemplateFromYaml.getTopology_template().getNode_templates() == null) {
- return;
- }
-
- //Creating concrete objects
- Map<String, NodeTemplate> nodeTemplates =
- serviceTemplateFromYaml.getTopology_template().getNode_templates();
- for (Map.Entry<String, NodeTemplate> entry : nodeTemplates.entrySet()) {
- NodeTemplate nodeTemplate = entry.getValue();
- List<Map<String, RequirementAssignment>> requirements = nodeTemplate.getRequirements();
- List<Map<String, RequirementAssignment>> concreteRequirementList = new ArrayList<>();
- if (requirements != null) {
- ListIterator<Map<String, RequirementAssignment>> reqListIterator = requirements
- .listIterator();
- while (reqListIterator.hasNext()){
- Map<String, RequirementAssignment> requirement = reqListIterator.next();
- Map<String, RequirementAssignment> concreteRequirement = new HashMap<>();
- for (Map.Entry<String, RequirementAssignment> reqEntry : requirement.entrySet()) {
- RequirementAssignment requirementAssignment = (toscaExtensionYamlUtil
- .yamlToObject(toscaExtensionYamlUtil.objectToYaml(reqEntry.getValue()),
- RequirementAssignment.class));
- concreteRequirement.put(reqEntry.getKey(), requirementAssignment);
- concreteRequirementList.add(concreteRequirement);
- reqListIterator.remove();
- }
- }
- requirements.clear();
- requirements.addAll(concreteRequirementList);
- nodeTemplate.setRequirements(requirements);
- }
- System.out.println();
- //toscaExtensionYamlUtil.yamlToObject(nodeTemplate, NodeTemplate.class);
- }
- }
-}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java
deleted file mode 100644
index 68318c7b73..0000000000
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/ToscaConvertorDefinitionsTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.core.converter.impl;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
-import org.openecomp.core.impl.GlobalSubstitutionServiceTemplate;
-import org.openecomp.core.impl.ToscaConverterImpl;
-import org.openecomp.core.utilities.file.FileContentHandler;
-import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
-import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-
-import java.net.URL;
-import java.util.Map;
-import java.util.Set;
-
-import static org.junit.Assert.*;
-import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX;
-import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.*;
-import static org.openecomp.sdc.common.utils.CommonUtil.validateAndUploadFileContent;
-public class ToscaConvertorDefinitionsTest {
-
-
- @Ignore
- @Test
- public void loadCsar() throws Exception {
- URL resource = ToscaConvertorDefinitionsTest.class.getResource("/csar/vCSCF.csar");
- byte[] bytes = IOUtils.toByteArray(resource);
- assertNotNull(bytes);
- FileContentHandler contentMap = validateAndUploadFileContent(OnboardingTypesEnum.CSAR, bytes);
- ToscaConverterImpl toscaConverter = new ToscaConverterImpl();
- ToscaServiceModel convert = toscaConverter.convert(contentMap);
- Map<String, ServiceTemplate> serviceTemplates = convert.getServiceTemplates();
- assertTrue(serviceTemplates.containsKey(GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME));
- ServiceTemplate serviceTemplate = serviceTemplates.get(GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME);
-
- assertNotNull(serviceTemplate);
- assertTrue(serviceTemplate instanceof GlobalSubstitutionServiceTemplate);
-
- assertNotNull(serviceTemplate.getMetadata());
- assertFalse(serviceTemplate.getMetadata().isEmpty());
- assertTrue(serviceTemplate.getMetadata().containsKey(TEMPLATE_NAME_PROPERTY));
-
- assertNotNull(serviceTemplate.getImports());
- assertFalse(serviceTemplate.getImports().isEmpty());
- assertEquals(1 ,serviceTemplate.getImports().size());
- assertTrue(((Map) serviceTemplate.getImports().get(0)).containsKey(HEAT_INDEX));
- assertTrue(((Map) serviceTemplate.getImports().get(0)).containsKey(ONAP_INDEX));
-
- assertEquals(DEFININTION_VERSION, serviceTemplate.getTosca_definitions_version());
-
-
- assertNotNull(serviceTemplate.getNode_types());
- assertEquals(1, serviceTemplate.getNode_types().size());
- Set<String> keys = serviceTemplate.getNode_types().keySet();
- assertTrue(keys.contains("tosca.nodes.nfv.ext.zte.VNF.vCSCF"));
- }
-
-
-}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineParameterizedTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineParameterizedTest.java
new file mode 100644
index 0000000000..e2cbc147ac
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineParameterizedTest.java
@@ -0,0 +1,152 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.impl.pnfd;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
+import org.onap.sdc.tosca.services.YamlUtil;
+import org.openecomp.core.converter.ServiceTemplateReaderService;
+import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl;
+
+@RunWith(Parameterized.class)
+public class PnfTransformationEngineParameterizedTest {
+
+ private static final String TEST_CASES_PATH = "transformation/pnfParseEngine";
+ private static final String TRANSFORMATION_DESCRIPTOR_FOLDER = "transformationDescriptor";
+ private static final String OUTPUT_FOLDER = "expectedOutput";
+ private static final String DEFAULT_OUTPUT_FILE_NAME = "defaultOutput.yaml";
+
+ private final String inputFileName;
+ private final Path inputFilePath;
+ private final String outputFileName;
+ private final Path outputFilePath;
+ private final String transformationDescriptorFileName;
+ private final Path transformationDescriptorFilePath;
+ private final YamlUtil yamlUtil = new YamlUtil();
+ private final ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+
+ public PnfTransformationEngineParameterizedTest(final String inputFileName, final Path inputFilePath,
+ final String outputFileName, final Path outputFilePath,
+ final String transformationDescriptorFileName, final Path transformationDescriptorFilePath) {
+ this.inputFileName = inputFileName;
+ this.inputFilePath = inputFilePath;
+ this.outputFileName = outputFileName;
+ this.outputFilePath = outputFilePath;
+ this.transformationDescriptorFileName = transformationDescriptorFileName;
+ this.transformationDescriptorFilePath = transformationDescriptorFilePath;
+ }
+
+
+ @Parameterized.Parameters(name = "{index}: input: {0}, descriptor: {4}, output: {2}")
+ public static Collection input() throws IOException {
+ return Files.list(getPathFromClasspath(TEST_CASES_PATH)).map(path -> {
+ try {
+ return buildTestCase(path);
+ } catch (final IOException e) {
+ return null;
+ }
+ }).filter(Objects::nonNull).flatMap(Collection::stream).collect(Collectors.toList());
+ }
+
+ private static Collection buildTestCase(final Path testCasePath) throws IOException {
+ final Path inputFilePath = Files.list(testCasePath)
+ .filter(path -> path.toFile().getName().endsWith("yaml"))
+ .findAny().orElse(null);
+
+ if (inputFilePath == null) {
+ return Collections.emptyList();
+ }
+ ;
+ final List<Path> transformationDescriptorList;
+ try (final Stream<Path> files = Files.walk(testCasePath.resolve(TRANSFORMATION_DESCRIPTOR_FOLDER))) {
+ transformationDescriptorList = files.filter(path -> Files.isRegularFile(path))
+ .map(path -> Paths.get(TEST_CASES_PATH, testCasePath.getFileName().toString()
+ , TRANSFORMATION_DESCRIPTOR_FOLDER, path.getFileName().toString()))
+ .collect(Collectors.toList());
+ }
+
+ final List<Path> outputList;
+ try (final Stream<Path> files = Files.walk(testCasePath.resolve(OUTPUT_FOLDER))) {
+ outputList = files.filter(path -> Files.isRegularFile(path)).collect(Collectors.toList());
+ }
+ final Path defaultOutput = outputList.stream()
+ .filter(path -> path.toFile().getName().equals(DEFAULT_OUTPUT_FILE_NAME))
+ .findFirst().orElse(null);
+
+ final List<Object[]> testCaseList = new ArrayList<>();
+
+ for (final Path transformationDescriptorPath : transformationDescriptorList) {
+ final Path outputPath = outputList.stream()
+ .filter(path -> path.toFile().getName().equals(transformationDescriptorPath.toFile().getName()))
+ .findFirst().orElse(defaultOutput);
+ if (outputPath != null) {
+ testCaseList.add(new Object[] {inputFilePath.toFile().getName(), inputFilePath,
+ outputPath.toFile().getName(), outputPath,
+ transformationDescriptorPath.toFile().getName(), transformationDescriptorPath});
+ }
+ }
+
+ return testCaseList;
+
+ }
+
+ @Test
+ public void testTopologyTemplateConversions() throws IOException {
+ final byte[] descriptor = Files.readAllBytes(inputFilePath);
+ final ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor);
+ final ServiceTemplate serviceTemplate = new ServiceTemplate();
+
+ final PnfdTransformationEngine pnfdTransformationEngine = new PnfdTransformationEngine(serviceTemplateReaderService, serviceTemplate
+ , transformationDescriptorFilePath.toString());
+ pnfdTransformationEngine.transform();
+
+ final String result = yamlUtil.objectToYaml(serviceTemplate);
+ final String expectedResult = parseToYaml(outputFilePath);
+ assertEquals(expectedResult, result);
+ }
+
+ private String parseToYaml(final Path filePath) throws IOException {
+ try (final InputStream inputStream = Files.newInputStream(filePath)) {
+ ServiceTemplate serviceTemplate = toscaExtensionYamlUtil.yamlToObject(inputStream, ServiceTemplate.class);
+ return yamlUtil.objectToYaml(serviceTemplate);
+ }
+ }
+
+ private static Path getPathFromClasspath(final String location) {
+ return Paths.get(Thread.currentThread().getContextClassLoader().getResource(location).getPath());
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java
new file mode 100644
index 0000000000..280d14888d
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java
@@ -0,0 +1,112 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.impl.pnfd;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
+import org.onap.sdc.tosca.services.YamlUtil;
+import org.openecomp.core.converter.ServiceTemplateReaderService;
+import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl;
+
+@RunWith(Parameterized.class)
+public class PnfTransformationEngineTest {
+
+ public static final String INPUT_DIR = "pnfDescriptor/in/";
+ public static final String OUTPUT_DIR = "pnfDescriptor/out/";
+ private String inputFilename;
+ private final YamlUtil yamlUtil = new YamlUtil();
+ private final ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+
+ public PnfTransformationEngineTest(final String inputFilename) {
+ this.inputFilename = inputFilename;
+ }
+
+ @Parameterized.Parameters(name = "{index}: {0}")
+ public static Collection<String> input() throws IOException {
+ try (final Stream<Path> files = Files.list(getPathFromClasspath(INPUT_DIR))) {
+ return files.map(path -> path.getFileName().toString())
+ .collect(Collectors.toList());
+ }
+ }
+
+ @Test
+ public void testTopologyTemplateConversions() throws IOException {
+ final byte[] descriptor = getInputFileResource(inputFilename);
+ final ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor);
+ final ServiceTemplate serviceTemplate = new ServiceTemplate();
+
+ final PnfdTransformationEngine pnfdTransformationEngine = new PnfdTransformationEngine(
+ serviceTemplateReaderService, serviceTemplate);
+ pnfdTransformationEngine.transform();
+
+ final String result = yamlUtil.objectToYaml(serviceTemplate);
+ final String expectedResult = getExpectedResultFor(inputFilename);
+ assertEquals(expectedResult, result);
+ }
+
+ private String getExpectedResultFor(final String inputFilename) throws IOException {
+ try (final InputStream inputStream = getOutputFileResourceCorrespondingTo(inputFilename)) {
+ final ServiceTemplate serviceTemplate = toscaExtensionYamlUtil.yamlToObject(inputStream, ServiceTemplate.class);
+ return yamlUtil.objectToYaml(serviceTemplate);
+ }
+ }
+
+ private static Path getPathFromClasspath(final String location) {
+ return Paths.get(Thread.currentThread().getContextClassLoader().getResource(location).getPath());
+ }
+
+ private byte[] getInputFileResource(final String inputFilename) throws IOException {
+ return getFileResource(INPUT_DIR + inputFilename);
+ }
+
+ private InputStream getOutputFileResourceCorrespondingTo(final String inputFilename) {
+ final String outputFilename = getOutputFilenameFrom(inputFilename);
+ return getFileResourceAsInputStream(OUTPUT_DIR + outputFilename);
+ }
+
+ private String getOutputFilenameFrom(final String inputFilename) {
+ return inputFilename.replace("pnfDescriptor", "topologyTemplate");
+ }
+
+ private byte[] getFileResource(final String filePath) throws IOException {
+ try (final InputStream inputStream = getFileResourceAsInputStream(filePath)) {
+ return IOUtils.toByteArray(inputStream);
+ }
+ }
+
+ private InputStream getFileResourceAsInputStream(final String filePath) {
+ return Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
+ }
+
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfdQueryExecutorTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfdQueryExecutorTest.java
new file mode 100644
index 0000000000..17f60ee43c
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfdQueryExecutorTest.java
@@ -0,0 +1,229 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.impl.pnfd;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.openecomp.core.converter.pnfd.exception.QueryOperationNotSupportedException;
+import org.openecomp.core.converter.pnfd.model.ConversionQuery;
+
+public class PnfdQueryExecutorTest {
+ @Rule
+ public ExpectedException expectedExceptionRule = ExpectedException.none();
+
+ private Map<String, Object> yamlToQuery;
+
+ @Before
+ public void setup() {
+ yamlToQuery = new HashMap<>();
+ final LinkedHashMap<String, Object> nodeTemplateMap = new LinkedHashMap<>();
+ yamlToQuery.put("topology_template", nodeTemplateMap);
+ final Map nodeTemplate1 = ImmutableMap.of("nodeTemplate1"
+ , ImmutableMap.of(
+ "type", "tosca.nodes.nfv.PNF",
+ "properties", ImmutableMap.of(
+ "layers_protocol", "",
+ "provider", "Mycompany",
+ "version", "1.0"
+ )
+ )
+ );
+
+ final Map nodeTemplate2 = ImmutableMap.of("nodeTemplate2"
+ , ImmutableMap.of(
+ "type", "tosca.nodes.nfv.PnfExtCp",
+ "properties", ImmutableMap.of(
+ "trunk_mode", "false",
+ "role", "leaf",
+ "description", "External connection point to access this pnf",
+ "layers_protocol", ImmutableList.of("ipv4", "ipv6", "otherProtocol")
+ )
+ )
+ );
+
+ nodeTemplateMap.putAll(nodeTemplate1);
+ nodeTemplateMap.putAll(nodeTemplate2);
+ }
+
+
+ @Test
+ public void queryNestedYaml() {
+ //given
+ final ImmutableMap<String, Object> query =
+ ImmutableMap.of("topology_template",
+ ImmutableMap.of("nodeTemplate2",
+ ImmutableMap.of("type", "tosca.nodes.nfv.PnfExtCp")
+ )
+ );
+ //when
+ final boolean queryResult = PnfdQueryExecutor.find(new ConversionQuery(query), yamlToQuery);
+ //then
+ assertThat("Element should be found", queryResult, is(true));
+ }
+
+ @Test
+ public void andQueryWithPropertiesInSameLevel() {
+ //given
+ final ImmutableMap<String, Object> query =
+ ImmutableMap.of(
+ "topology_template",
+ ImmutableMap.of(
+ "nodeTemplate2",
+ ImmutableMap.of(
+ "type", "tosca.nodes.nfv.PnfExtCp",
+ "properties", ImmutableMap.of(
+ "role", "leaf",
+ "description", "External connection point to access this pnf"
+ )
+ )
+ )
+ );
+ //when
+ final boolean queryResult = PnfdQueryExecutor.find(new ConversionQuery(query), yamlToQuery);
+ //then
+ assertThat("Element should be found", queryResult, is(true));
+ }
+
+ @Test
+ public void andQueryWithPropertiesDifferentLevel() {
+ //given
+ final ImmutableMap<String, Object> query =
+ ImmutableMap.of(
+ "topology_template",
+ ImmutableMap.of(
+ "nodeTemplate2",
+ ImmutableMap.of(
+ "type", "tosca.nodes.nfv.PnfExtCp"
+ ),
+ "nodeTemplate1",
+ ImmutableMap.of(
+ "type", "tosca.nodes.nfv.PNF"
+ )
+ )
+ );
+ //when
+ final boolean queryResult = PnfdQueryExecutor.find(new ConversionQuery(query), yamlToQuery);
+ //then
+ assertThat("Element should be found", queryResult, is(true));
+ }
+
+ @Test
+ public void queryListPropertyNotSupported() {
+ //then
+ expectedExceptionRule.expect(QueryOperationNotSupportedException.class);
+ expectedExceptionRule.expectMessage("Yaml list query is not supported yet");
+ //given query with a list instance
+ final ImmutableMap<String, Object> query =
+ ImmutableMap.of(
+ "topology_template",
+ ImmutableMap.of(
+ "nodeTemplate2",
+ ImmutableMap.of(
+ "type", "tosca.nodes.nfv.PnfExtCp",
+ "properties", ImmutableMap.of(
+ "layers_protocol", ImmutableList.of("ipv4", "ipv6", "otherProtocol")
+ )
+ )
+ )
+ );
+ //when
+ final boolean queryResult = PnfdQueryExecutor.find(new ConversionQuery(query), yamlToQuery);
+ }
+
+ @Test
+ public void queryStartingListPropertyNotSupported() {
+ //then
+ expectedExceptionRule.expect(QueryOperationNotSupportedException.class);
+ expectedExceptionRule.expectMessage("Yaml list query is not supported yet");
+ //given query with a list instance
+ final Object query = ImmutableSet.of("test", "test", "test");
+ //when
+ PnfdQueryExecutor.find(new ConversionQuery(query), yamlToQuery);
+ }
+
+ @Test
+ public void queryWithUnsupportedClassInstance() {
+ //given a query with unsupported class instance
+ final Object query = ImmutableMap.of("topology_template", new Object());
+ //then
+ expectedExceptionRule.expect(QueryOperationNotSupportedException.class);
+ expectedExceptionRule.expectMessage(String.format("Yaml query operation for '%s' is not supported yet", Object.class));
+ //when
+ PnfdQueryExecutor.find(new ConversionQuery(query), yamlToQuery);
+ }
+
+ @Test
+ public void queryAString() {
+ //given a query with string
+ final Object yaml = "query";
+ final Object query = "query";
+ //when
+ final boolean queryResult = PnfdQueryExecutor.find(new ConversionQuery(query), yaml);
+
+ //then
+ assertThat("Element should be found", queryResult, is(true));
+
+ }
+
+ @Test
+ public void queryWithNullPropertyValue() {
+ //given a query with string
+ final Map<String, Object> query1 = new HashMap<>();
+ query1.put("topology_template", null);
+
+ final Map<String, Object> topologyTemplate = new HashMap<>();
+ topologyTemplate.put("nodeTemplate1", null);
+ final Object query2 = ImmutableMap.of("topology_template", topologyTemplate);
+
+ final Map<String, Object> query3 = new HashMap<>();
+ query3.put("topology_template1", null);
+ //when
+ final boolean queryResult1 = PnfdQueryExecutor.find(new ConversionQuery(query1), yamlToQuery);
+ final boolean queryResult2 = PnfdQueryExecutor.find(new ConversionQuery(query2), yamlToQuery);
+ final boolean queryResult3 = PnfdQueryExecutor.find(new ConversionQuery(query3), yamlToQuery);
+ //then
+ assertThat("Element should be found", queryResult1, is(true));
+ assertThat("Element should be found", queryResult2, is(true));
+ assertThat("Element should be found", queryResult3, is(false));
+ }
+
+ @Test
+ public void nullQuery() {
+ //given a null query
+ final Object query = null;
+ //when
+ final boolean queryResult = PnfdQueryExecutor.find(new ConversionQuery(query), yamlToQuery);
+ //then
+ assertThat("Element should be found", queryResult, is(true));
+
+ }
+
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParserTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParserTest.java
new file mode 100644
index 0000000000..967081ba0f
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/ConversionDefinitionYamlParserTest.java
@@ -0,0 +1,69 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.impl.pnfd.parser;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.QUERY;
+import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.TO_NAME;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import org.junit.Test;
+import org.openecomp.core.converter.pnfd.model.ConversionDefinition;
+import org.openecomp.core.converter.pnfd.model.ConversionStrategyType;
+import org.openecomp.core.util.TestResourcesUtil;
+import org.openecomp.core.util.YamlTestUtil;
+
+public class ConversionDefinitionYamlParserTest {
+
+ @Test
+ public void shouldBuildDefinition() {
+ final Map<String, Object> definitionYaml;
+ final String definitionYamlFilePath = "transformation/conversionDefinition/conversionDefinitionWithReplaceStrategy.yaml";
+ try (final InputStream resourceInputStream = TestResourcesUtil.getFileResourceAsStream(definitionYamlFilePath)) {
+ definitionYaml = (Map<String, Object>) YamlTestUtil.read(resourceInputStream);
+ } catch (final IOException e) {
+ fail(String.format("Could not load %s", definitionYamlFilePath));
+ return;
+ }
+ final ConversionDefinition conversionDefinition = ConversionDefinitionYamlParser.parse(definitionYaml);
+ assertConversionDefinition(definitionYaml, conversionDefinition);
+ }
+
+ private void assertConversionDefinition(final Map<String, Object> definitionYaml,
+ final ConversionDefinition conversionDefinition) {
+ assertThat("The conversion definition should have been built"
+ , conversionDefinition, notNullValue());
+ assertThat("Should have initialized the conversion definition query"
+ , conversionDefinition.getConversionQuery(), notNullValue());
+ assertThat("The conversion definition should have been built"
+ , conversionDefinition.getConversionQuery().getQuery(), equalTo(definitionYaml.get(QUERY.getName())));
+ assertThat("Should have initialized the conversion definition to attribute name"
+ , conversionDefinition.getToAttributeName(), equalTo(definitionYaml.get(TO_NAME.getName())));
+ assertThat("Should have initialized the conversion definition strategy"
+ , conversionDefinition.getPnfdConversionStrategy(), notNullValue());
+ assertThat("Should have the expected strategy"
+ , conversionDefinition.getPnfdConversionStrategy().getStrategyType(), equalTo(ConversionStrategyType.REPLACE));
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/NodeTemplateYamlParserTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/NodeTemplateYamlParserTest.java
new file mode 100644
index 0000000000..5bb7ca360e
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/NodeTemplateYamlParserTest.java
@@ -0,0 +1,46 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.impl.pnfd.parser;
+
+import static org.hamcrest.Matchers.aMapWithSize;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertThat;
+
+import java.util.Map;
+import org.junit.Test;
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.openecomp.core.converter.impl.pnfd.parser.NodeTemplateYamlParser;
+import org.openecomp.core.util.YamlTestUtil;
+
+public class NodeTemplateYamlParserTest {
+
+ @Test
+ public void shouldParseNodeTemplate() {
+ final Map<String, Object> nodeTemplateYaml = (Map<String, Object>) YamlTestUtil.readOrFail("transformation/nodeTemplate/nodeTemplate.yaml");
+ final NodeTemplate nodeTemplate = NodeTemplateYamlParser.parse(nodeTemplateYaml);
+ assertThat("Should have the same type", nodeTemplate.getType(), equalTo(nodeTemplateYaml.get("type")));
+ assertThat("Should have a not null properties map", nodeTemplate.getProperties(), notNullValue());
+ assertThat("Should have a not empty properties map", nodeTemplate.getProperties(), is(not(aMapWithSize(0))));
+ assertThat("Should have the same properties", nodeTemplate.getProperties(), equalTo(nodeTemplateYaml.get("properties")));
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParserParametrizedTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParserParametrizedTest.java
new file mode 100644
index 0000000000..83b7620b42
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParserParametrizedTest.java
@@ -0,0 +1,68 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.impl.pnfd.parser;
+
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.openecomp.core.converter.pnfd.strategy.PnfdConversionStrategy;
+import org.openecomp.core.converter.impl.pnfd.strategy.ReplaceConversionStrategy;
+import org.openecomp.core.util.YamlTestUtil;
+
+@RunWith(Parameterized.class)
+public class PnfdConversionStrategyYamlParserParametrizedTest {
+
+ private final String strategyYamlFilePath;
+ private final Class expectedStrategyClass;
+
+ public PnfdConversionStrategyYamlParserParametrizedTest(final String strategyYamlFilePath, final Class expectedStrategyClass) {
+ this.strategyYamlFilePath = strategyYamlFilePath;
+ this.expectedStrategyClass = expectedStrategyClass;
+ }
+
+ @Parameters(name = "Run {index} for {0}, expecting {1}")
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ {"transformation/strategy/replaceStrategy.yaml", ReplaceConversionStrategy.class}
+ });
+ }
+
+ @Test
+ public void shouldBuildTheExpectedStrategy() {
+ final Object replaceStrategyYaml = YamlTestUtil.readOrFail(strategyYamlFilePath);
+ final Optional<PnfdConversionStrategy> actualStrategy = PnfdConversionStrategyYamlParser
+ .parse((Map<String, Object>) replaceStrategyYaml);
+
+ assertThat("The strategy should have been built"
+ , actualStrategy.isPresent(), is(true));
+ assertThat("The built strategy should be " + expectedStrategyClass.getName()
+ , actualStrategy.get(), instanceOf(expectedStrategyClass));
+ }
+
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParserTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParserTest.java
new file mode 100644
index 0000000000..1eab214980
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/parser/PnfdConversionStrategyYamlParserTest.java
@@ -0,0 +1,53 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.core.converter.impl.pnfd.parser;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.Test;
+import org.openecomp.core.converter.pnfd.strategy.PnfdConversionStrategy;
+import org.openecomp.core.util.TestResourcesUtil;
+import org.openecomp.core.util.YamlTestUtil;
+
+public class PnfdConversionStrategyYamlParserTest {
+
+ @Test
+ public void parseInvalidYamlObject() {
+ final Object replaceStrategyYaml;
+ final String strategyYamlFilePath = "transformation/strategy/strategyMissingStrategyAttribute.yaml";
+ try (final InputStream resourceInputStream = TestResourcesUtil.getFileResourceAsStream(strategyYamlFilePath)) {
+ replaceStrategyYaml = YamlTestUtil.read(resourceInputStream);
+ } catch (final IOException e) {
+ fail(String.format("Could not load %s", strategyYamlFilePath));
+ return;
+ }
+ final Optional<PnfdConversionStrategy> actualStrategy = PnfdConversionStrategyYamlParser
+ .parse((Map<String, Object>) replaceStrategyYaml);
+ assertThat("The strategy should not have been built"
+ , actualStrategy.isPresent(), is(false));
+ }
+
+} \ No newline at end of file