aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test')
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfTest.java71
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withLayerProtocolsAndDuplicatedGetInput.yaml45
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withLayerProtocolsGetInput.yaml39
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/other/pnfDescriptor_PnfAnd2ExtCps.yaml15
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withLayerProtocolsAndDuplicatedGetInput.yaml17
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withLayerProtocolsGetInput.yaml13
6 files changed, 168 insertions, 32 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfTest.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfTest.java
index c3f38fe3cd..4d59d6bfe9 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfTest.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/java/org/openecomp/core/impl/ToscaSolConverterPnfTest.java
@@ -22,15 +22,9 @@
package org.openecomp.core.impl;
-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;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.InputStream;
@@ -40,14 +34,21 @@ import java.nio.file.Paths;
import java.util.Collection;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-
-import static org.junit.Assert.assertEquals;
+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 ToscaSolConverterPnfTest {
- public static final String INPUT_DIR = "pnfDescriptor/in/";
- public static final String OUTPUT_DIR = "pnfDescriptor/out/";
+ private static final String INPUT_DIR = "pnfDescriptor/in/";
+ private static final String OUTPUT_DIR = "pnfDescriptor/out/";
private String inputFilename;
private YamlUtil yamlUtil = new YamlUtil();
private ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
@@ -65,49 +66,59 @@ public class ToscaSolConverterPnfTest {
}
@Test
- public void testTopologyTemplateConversions() throws IOException {
+ public void testTopologyTemplateConversions() {
final byte[] descriptor = getInputFileResource(inputFilename);
- ServiceTemplateReaderService serviceTemplateReaderService = new ServiceTemplateReaderServiceImpl(descriptor);
- ServiceTemplate serviceTemplate = new ServiceTemplate();
- ToscaSolConverterPnf toscaSolConverter = new ToscaSolConverterPnf();
+ final ServiceTemplateReaderService serviceTemplateReaderService =
+ new ServiceTemplateReaderServiceImpl(descriptor);
+ final ServiceTemplate serviceTemplate = new ServiceTemplate();
+ final ToscaSolConverterPnf toscaSolConverter = new ToscaSolConverterPnf();
toscaSolConverter.convertTopologyTemplate(serviceTemplate, serviceTemplateReaderService);
- String result = yamlUtil.objectToYaml(serviceTemplate);
- String expectedResult = getExpectedResultFor(inputFilename);
- assertEquals(expectedResult, result);
+ final String actualYaml = yamlUtil.objectToYaml(serviceTemplate);
+ final String expectedYaml = getExpectedResultFor(inputFilename);
+ assertThat("Converted PNF descriptor should be the same as the expected topology template", actualYaml,
+ equalTo(expectedYaml));
}
- private String getExpectedResultFor(String inputFilename) throws IOException {
- try (InputStream inputStream = getOutputFileResourceCorrespondingTo(inputFilename)) {
- ServiceTemplate serviceTemplate = toscaExtensionYamlUtil.yamlToObject(inputStream, ServiceTemplate.class);
+ private String getExpectedResultFor(final String inputFilename) {
+ try (final InputStream inputStream = getOutputFileResourceCorrespondingTo(inputFilename)) {
+ final ServiceTemplate serviceTemplate = toscaExtensionYamlUtil.yamlToObject(inputStream, ServiceTemplate.class);
return yamlUtil.objectToYaml(serviceTemplate);
+ } catch (final IOException e) {
+ fail(String.format("Could not find file '%s'", inputFilename));
}
+
+ return null;
}
- private static Path getPathFromClasspath(String location) {
+ private static Path getPathFromClasspath(final String location) {
return Paths.get(Thread.currentThread().getContextClassLoader().getResource(location).getPath());
}
- private byte[] getInputFileResource(String inputFilename) throws IOException {
+ private byte[] getInputFileResource(final String inputFilename) {
return getFileResource(INPUT_DIR + inputFilename);
}
- private InputStream getOutputFileResourceCorrespondingTo(String inputFilename) {
- String outputFilename = getOutputFilenameFrom(inputFilename);
+ private InputStream getOutputFileResourceCorrespondingTo(final String inputFilename) {
+ final String outputFilename = getOutputFilenameFrom(inputFilename);
return getFileResourceAsInputStream(OUTPUT_DIR + outputFilename);
}
- private String getOutputFilenameFrom(String inputFilename) {
+ private String getOutputFilenameFrom(final String inputFilename) {
return inputFilename.replace("pnfDescriptor", "topologyTemplate");
}
- private byte[] getFileResource(String filePath) throws IOException {
+ private byte[] getFileResource(final String filePath) {
try (InputStream inputStream = getFileResourceAsInputStream(filePath)) {
return IOUtils.toByteArray(inputStream);
+ } catch (final IOException e) {
+ fail(String.format("Could not find file '%s'", filePath));
}
+
+ return null;
}
- private InputStream getFileResourceAsInputStream(String filePath) {
+ private InputStream getFileResourceAsInputStream(final String filePath) {
return Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withLayerProtocolsAndDuplicatedGetInput.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withLayerProtocolsAndDuplicatedGetInput.yaml
new file mode 100644
index 0000000000..8549da09b2
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withLayerProtocolsAndDuplicatedGetInput.yaml
@@ -0,0 +1,45 @@
+tosca_definitions_version: tosca_simple_yaml_1_2
+
+description: service template of an Acme PNF
+
+imports:
+ - etsi_nfv_sol001_pnfd_2_5_1_types.yaml
+
+topology_template:
+ inputs:
+ protocols:
+ type: list
+ description: IP protocols
+ entry_schema:
+ type: string
+ default: [ ipv4, ipv6 ]
+ node_templates:
+ myPnf:
+ type: tosca.nodes.nfv.PNF
+ properties:
+ descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233
+ function_description: Acme PNF
+ provider: Acme
+ version: 1.0
+ descriptor_invariant_id: 1111-2222-ccaa-bbdd
+ name: Acme PNF
+
+ pnfExtCp_1:
+ type: tosca.nodes.nfv.PnfExtCp
+ properties:
+ trunk_mode: false
+ layer_protocols: { get_input: protocols }
+ role: leaf
+ description: External connection point to access Acme myPnf
+ requirements:
+ - dependency: myPnf
+
+ pnfExtCp_2:
+ type: tosca.nodes.nfv.PnfExtCp
+ properties:
+ trunk_mode: false
+ layer_protocols: { get_input: protocols }
+ role: leaf
+ description: External connection point to access Acme myPnf
+ requirements:
+ - dependency: myPnf
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withLayerProtocolsGetInput.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withLayerProtocolsGetInput.yaml
new file mode 100644
index 0000000000..bb4dd9c87b
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/in/pnfDescriptor_withLayerProtocolsGetInput.yaml
@@ -0,0 +1,39 @@
+tosca_definitions_version: tosca_simple_yaml_1_2
+
+description: service template of an Acme PNF
+
+imports:
+ - etsi_nfv_sol001_pnfd_2_5_1_types.yaml
+
+topology_template:
+ inputs:
+ anyOtherInput:
+ type: string
+ description: this is input1
+ default: defaultValue
+ protocols:
+ type: list
+ description: IP protocols
+ entry_schema:
+ type: string
+ default: [ ipv4, ipv6 ]
+ node_templates:
+ myPnf:
+ type: tosca.nodes.nfv.PNF
+ properties:
+ descriptor_id: b1bb0ce7-ebca-4fa7-95ed-4840d70a2233
+ function_description: Acme PNF
+ provider: Acme
+ version: 1.0
+ descriptor_invariant_id: 1111-2222-ccaa-bbdd
+ name: Acme PNF
+
+ pnfExtCp_1:
+ type: tosca.nodes.nfv.PnfExtCp
+ properties:
+ trunk_mode: false
+ layer_protocols: { get_input: protocols }
+ role: leaf
+ description: External connection point to access Acme myPnf
+ requirements:
+ - dependency: myPnf
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/other/pnfDescriptor_PnfAnd2ExtCps.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/other/pnfDescriptor_PnfAnd2ExtCps.yaml
index 26255ddd84..b37334496c 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/other/pnfDescriptor_PnfAnd2ExtCps.yaml
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/other/pnfDescriptor_PnfAnd2ExtCps.yaml
@@ -3,6 +3,17 @@ tosca_definitions_version: tosca_simple_yaml_1_1
description: service template of a PNF
topology_template:
+ inputs:
+ role:
+ type: string
+ description: Role
+ default: leaf
+ layer_protocols:
+ type: list
+ description: IP protocols
+ entry_schema:
+ type: string
+ default: [ipv4, ipv6, otherProtocol]
node_templates:
pnf_mainPart:
type: tosca.nodes.nfv.PNF
@@ -28,6 +39,6 @@ topology_template:
type: tosca.nodes.nfv.PnfExtCp
properties:
trunk_mode: false
- layer_protocols: [ ipv4, ipv6, otherProtocol ]
- role: leaf
+ layer_protocols: {get_input: layer_protocols}
+ role: {get_input: role}
description: External connection point to access this pnf \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withLayerProtocolsAndDuplicatedGetInput.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withLayerProtocolsAndDuplicatedGetInput.yaml
new file mode 100644
index 0000000000..637ccd3eae
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withLayerProtocolsAndDuplicatedGetInput.yaml
@@ -0,0 +1,17 @@
+topology_template:
+ inputs:
+ protocols:
+ type: list
+ description: IP protocols
+ entry_schema:
+ type: org.openecomp.datatypes.network.IpRequirements
+ default: [{assingment_method: dhcp, ip_version: 4}, {assingment_method: dhcp, ip_version: 6}]
+ node_templates:
+ pnfExtCp_2:
+ type: org.openecomp.resource.cp.v2.extCP
+ properties:
+ ip_requirements: { get_input: protocols }
+ pnfExtCp_1:
+ type: org.openecomp.resource.cp.v2.extCP
+ properties:
+ ip_requirements: { get_input: protocols } \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withLayerProtocolsGetInput.yaml b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withLayerProtocolsGetInput.yaml
new file mode 100644
index 0000000000..ca1a236101
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/test/resources/pnfDescriptor/out/topologyTemplate_withLayerProtocolsGetInput.yaml
@@ -0,0 +1,13 @@
+topology_template:
+ inputs:
+ protocols:
+ type: list
+ description: IP protocols
+ entry_schema:
+ type: org.openecomp.datatypes.network.IpRequirements
+ default: [{assingment_method: dhcp, ip_version: 4}, {assingment_method: dhcp, ip_version: 6}]
+ node_templates:
+ pnfExtCp_1:
+ type: org.openecomp.resource.cp.v2.extCP
+ properties:
+ ip_requirements: { get_input: protocols } \ No newline at end of file