aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-converter-lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/AbstractPnfdTransformationEngine.java15
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/converter/impl/pnfd/PnfTransformationEngineTest.java73
2 files changed, 34 insertions, 54 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/AbstractPnfdTransformationEngine.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/AbstractPnfdTransformationEngine.java
index f97b1d37b2..94f7531310 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/AbstractPnfdTransformationEngine.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/converter/impl/pnfd/AbstractPnfdTransformationEngine.java
@@ -16,12 +16,14 @@
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.core.converter.impl.pnfd;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
+import lombok.Getter;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.core.converter.ServiceTemplateReaderService;
import org.openecomp.core.converter.pnfd.PnfdTransformationEngine;
@@ -37,19 +39,23 @@ import org.openecomp.sdc.logging.api.LoggerFactory;
public abstract class AbstractPnfdTransformationEngine implements PnfdTransformationEngine {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractPnfdTransformationEngine.class);
+
protected final ServiceTemplate templateTo;
protected final ServiceTemplateReaderService templateFrom;
private final PnfdTransformationDescriptorReader pnfdTransformationDescriptorReader = new PnfdTransformationDescriptorReader();
- private final String descriptorResourcePath;
protected TransformationDescription transformationDescription;
protected Map<TransformationBlock, List<Transformation>> transformationGroupByBlockMap;
+ @Getter
+ private final String descriptorResourcePath;
- public AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo) {
+ public AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom,
+ final ServiceTemplate templateTo) {
this(templateFrom, templateTo, "pnfdTransformationTemplate/model-driven-conversion.yaml");
}
//used for tests purposes
- AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom, final ServiceTemplate templateTo,
+ AbstractPnfdTransformationEngine(final ServiceTemplateReaderService templateFrom,
+ final ServiceTemplate templateTo,
final String descriptorResourcePath) {
this.templateFrom = templateFrom;
this.templateTo = templateTo;
@@ -61,7 +67,7 @@ public abstract class AbstractPnfdTransformationEngine implements PnfdTransforma
*/
protected void readDefinition() {
try (final InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(descriptorResourcePath)) {
- if (resourceAsStream == null) {
+ if (resourceAsStream == null) {
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Could not find resource '{}'", descriptorResourcePath);
}
@@ -77,4 +83,5 @@ public abstract class AbstractPnfdTransformationEngine implements PnfdTransforma
* Executes all transformations specified in the descriptor.
*/
protected abstract void executeTransformations();
+
}
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
index 63a7d890d0..e5a10105a3 100644
--- 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
@@ -19,65 +19,46 @@
package org.openecomp.core.converter.impl.pnfd;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.spy;
-
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.HashMap;
-import java.util.Map;
-import java.util.Optional;
+import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import mockit.Deencapsulation;
import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.mockito.Mockito;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
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.converter.impl.pnfd.parser.PnfdCustomNodeTypeBlockParser;
import org.openecomp.core.converter.pnfd.PnfdTransformationEngine;
-import org.openecomp.core.converter.pnfd.model.ConversionDefinition;
import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl;
-@RunWith(Parameterized.class)
-public class PnfTransformationEngineTest {
+class PnfTransformationEngineTest {
- public static final String INPUT_DIR = "pnfDescriptor/in/";
- public static final String OUTPUT_DIR = "pnfDescriptor/out/";
- private String inputFilename;
+ private static final String INPUT_DIR = "pnfDescriptor/in/";
+ private static final String OUTPUT_DIR = "pnfDescriptor/out/";
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 {
+ private static List<String> input() throws IOException {
try (final Stream<Path> files = Files.list(getPathFromClasspath(INPUT_DIR))) {
- return files.map(path -> path.getFileName().toString())
- .collect(Collectors.toList());
+ return files.map(path -> path.getFileName().toString()).collect(Collectors.toList());
}
}
- @Test
- public void testTopologyTemplateConversions() throws IOException {
+ @ParameterizedTest(name = "{index}: {0}")
+ @MethodSource("input")
+ void testTopologyTemplateConversions(final String inputFilename) throws IOException {
final byte[] descriptor = getInputFileResource(inputFilename);
final ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor);
final ServiceTemplate serviceTemplate = new ServiceTemplate();
- PnfdTransformationEngine pnfdTransformationEngine = new PnfdNodeTypeTransformationEngine(
- serviceTemplateReaderService, serviceTemplate);
+ PnfdTransformationEngine pnfdTransformationEngine = new PnfdNodeTypeTransformationEngine(serviceTemplateReaderService, serviceTemplate);
pnfdTransformationEngine.transform();
pnfdTransformationEngine = new PnfdNodeTemplateTransformationEngine(serviceTemplateReaderService, serviceTemplate);
pnfdTransformationEngine.transform();
@@ -85,26 +66,18 @@ public class PnfTransformationEngineTest {
final String yamlContent = yamlUtil.objectToYaml(serviceTemplate);
final String result = yamlUtil.objectToYaml(yamlUtil.yamlToObject(yamlContent, ServiceTemplate.class));
final String expectedResult = getExpectedResultFor(inputFilename);
- assertEquals(expectedResult, result);
- }
-
- @Test
- public void testBuildParseBlock() {
- final PnfdCustomNodeTypeBlockParser blockParser = spy(new PnfdCustomNodeTypeBlockParser(null));
- final ConversionDefinition conversionDefinition = Mockito.mock(ConversionDefinition.class);
- final Map<String, Object> stringObjectMap = new HashMap<>();
- stringObjectMap.put("type", null);
- stringObjectMap.put("name", null);
- assertEquals(Optional.empty(), Deencapsulation.invoke(blockParser, "buildParsedBlock",
- stringObjectMap, stringObjectMap, conversionDefinition));
+ Assertions.assertEquals(expectedResult, result);
}
- @Test
- public void testReadDefinition() {
- final PnfdTransformationEngine engine = spy(
- new PnfdNodeTemplateTransformationEngine(null, null, "test.txt"));
- Deencapsulation.invoke(engine, "readDefinition");
- assertNull(Deencapsulation.getField(engine, "transformationDescription"));
+ @ParameterizedTest(name = "{index}: {0}")
+ @MethodSource("input")
+ void testReadDefinition(final String inputFilename) throws IOException {
+ final byte[] descriptor = getInputFileResource(inputFilename);
+ final ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor);
+ final ServiceTemplate serviceTemplate = new ServiceTemplate();
+ AbstractPnfdTransformationEngine engine = new PnfdNodeTemplateTransformationEngine(serviceTemplateReaderService, serviceTemplate, "test.txt");
+ engine.transform();
+ Assertions.assertNotNull(engine.getDescriptorResourcePath());
}
private String getExpectedResultFor(final String inputFilename) throws IOException {