summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/test')
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java174
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplate.yaml12
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterface.yaml109
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterfaceAndOperation.yaml112
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTemplateInterface.yaml112
5 files changed, 498 insertions, 21 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java
index 60f59dbd81..31dc3ab035 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/datatypes/ToscaModelTest.java
@@ -29,9 +29,12 @@ import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
import org.openecomp.sdc.tosca.datatypes.model.Constraint;
import org.openecomp.sdc.tosca.datatypes.model.Directive;
import org.openecomp.sdc.tosca.datatypes.model.Import;
+import org.openecomp.sdc.tosca.datatypes.model.InterfaceDefinition;
+import org.openecomp.sdc.tosca.datatypes.model.InterfaceType;
import org.openecomp.sdc.tosca.datatypes.model.NodeFilter;
import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.tosca.datatypes.model.NodeType;
+import org.openecomp.sdc.tosca.datatypes.model.OperationDefinition;
import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition;
import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
@@ -52,13 +55,23 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
public class ToscaModelTest {
+ private YamlUtil yamlUtil = new YamlUtil();
+ private static final String INTERFACE_ID = "inter_1";
+ private static final String NODE_TEMPLATE_ID = "firstNodeTemplate";
+ private static final String BASE_DIR = "/mock/model";
+ private static final String ST = "/serviceTemplate.yaml";
+ private static final String ST_WITH_INTERFACE = "/serviceTemplateWithInterface.yaml";
+ private static final String ST_WITH_OPERATIONS = "/serviceTemplateWithInterfaceAndOperation.yaml";
+ private static final String ST_WITH_INTERFACE_DEF =
+ "/serviceTemplateWithNodeTemplateInterface.yaml";
+
@Test
public void testServiceTemplateJavaToYaml() {
-
ServiceTemplate serviceTemplate = new ServiceTemplate();
Map<String, String> metadata = new HashMap<>();
metadata.put("Template_author", "OPENECOMP");
@@ -80,6 +93,14 @@ public class ToscaModelTest {
imports.add(importsMap);
serviceTemplate.setImports(imports);
+ OperationDefinition operationDefinition = new OperationDefinition();
+ operationDefinition.setDescription("test operation");
+ InterfaceType interfaceType = new InterfaceType();
+ interfaceType.setDerived_from("derived_from");
+ interfaceType.setDescription("desc");
+ interfaceType.addOperation("test", operationDefinition);
+ serviceTemplate.addInterfaceType("test_interface", interfaceType);
+
ArtifactType artifact = new ArtifactType();
artifact.setMime_type("application/java-archive");
ArrayList<String> ext = new ArrayList<>();
@@ -272,30 +293,163 @@ public class ToscaModelTest {
@Test
public void testYamlToServiceTemplateObj() throws IOException {
- try (InputStream yamlFile = new YamlUtil().loadYamlFileIs("/mock/model/serviceTemplate.yaml")) {
- ServiceTemplate serviceTemplateFromYaml =
- new YamlUtil().yamlToObject(yamlFile, ServiceTemplate.class);
- Assert.assertNotNull(serviceTemplateFromYaml);
- }
+ ServiceTemplate serviceTemplateFromYaml =
+ getServiceTemplate(BASE_DIR + ST);
+ Assert.assertNotNull(serviceTemplateFromYaml);
}
+ @Test
+ public void testYamlWithInterfaceToServiceTemplateObj() throws IOException {
+ ServiceTemplate serviceTemplateWithOperation =
+ getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS);
+ Assert.assertNotNull(serviceTemplateWithOperation);
+
+ InterfaceType expectedInterfaceType = getInterfaceType();
+
+ Map<String, InterfaceType> interfaceTypes =
+ DataModelUtil.getInterfaceTypes(serviceTemplateWithOperation);
+ Assert.assertEquals(1, interfaceTypes.size());
+ InterfaceType actualInterfaceType = interfaceTypes.get(INTERFACE_ID);
+ Assert.assertEquals(expectedInterfaceType, actualInterfaceType);
+ }
+
+ @Test
+ public void testAddOperationToInterface() throws IOException {
+ YamlUtil yamlUtil = new YamlUtil();
+ ServiceTemplate serviceTemplateWithInterface =
+ getServiceTemplate(BASE_DIR + ST_WITH_INTERFACE);
+ ServiceTemplate serviceTemplateWithOperation =
+ getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS);
+
+ OperationDefinition operationDefinition = getOperationDefinition();
+
+ DataModelUtil
+ .addInterfaceOperation(serviceTemplateWithInterface, INTERFACE_ID, "start",
+ operationDefinition);
+ String expectedServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithOperation);
+ String actualServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithInterface);
+ Assert.assertEquals(expectedServiceTemplate, actualServiceTemplate);
+ }
+
+ @Test
+ public void testInterfaceTypeToObjConversion() throws IOException {
+ ServiceTemplate serviceTemplateWithInterface =
+ getServiceTemplate(BASE_DIR + ST_WITH_INTERFACE);
+ ServiceTemplate serviceTemplateWithOperation =
+ getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS);
+ InterfaceType interfaceType = getInterfaceType();
+
+ Optional<Object> interfaceAsObj = DataModelUtil.convertInterfaceTypeToObj(interfaceType);
+ Assert.assertTrue(interfaceAsObj.isPresent());
+
+ Map<String, Object> interfaceTypes = new HashMap<>();
+ interfaceTypes.put(INTERFACE_ID, interfaceAsObj.get());
+ serviceTemplateWithInterface.setInterface_types(interfaceTypes);
+
+ String expectedServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithOperation);
+ String actualServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithInterface);
+ Assert.assertEquals(expectedServiceTemplate, actualServiceTemplate);
+ }
+
+ @Test
+ public void testObjToInterfaceTypeConversion() throws IOException, ReflectiveOperationException {
+ ServiceTemplate serviceTemplateWithOperation =
+ getServiceTemplate(BASE_DIR + ST_WITH_OPERATIONS);
+ Map<String, Object> interfaceTypes = serviceTemplateWithOperation.getInterface_types();
+ Object interfaceObj = interfaceTypes.get(INTERFACE_ID);
+ Optional<InterfaceType> actualInterfaceType =
+ DataModelUtil.convertObjToInterfaceType(INTERFACE_ID, interfaceObj);
+
+ Assert.assertTrue(actualInterfaceType.isPresent());
+ InterfaceType expectedInterfaceType = getInterfaceType();
+ Assert.assertEquals(expectedInterfaceType, actualInterfaceType.get());
+ }
+
+ @Test
+ public void testInterfaceDefinitionToObjConversion() throws IOException {
+ ServiceTemplate serviceTemplate =
+ getServiceTemplate(BASE_DIR + ST);
+ ServiceTemplate serviceTemplateWithInterfaceDef =
+ getServiceTemplate(BASE_DIR + ST_WITH_INTERFACE_DEF);
+
+ NodeTemplate nodeTemplate =
+ DataModelUtil.getNodeTemplate(serviceTemplate, NODE_TEMPLATE_ID);
+ InterfaceDefinition interfaceDefinition = getInterfaceDefinition();
+ Optional<Object> interfaceObj = DataModelUtil.convertInterfaceDefinitionToObj(interfaceDefinition);
+
+ Assert.assertTrue(interfaceObj.isPresent());
+ Map<String, Object> interfaces = new HashMap<>();
+ interfaces.put(INTERFACE_ID, interfaceObj.get());
+ nodeTemplate.setInterfaces(interfaces);
+
+ String expectedServiceTemplate = yamlUtil.objectToYaml(serviceTemplateWithInterfaceDef);
+ String actualServiceTemplate = yamlUtil.objectToYaml(serviceTemplate);
+ Assert.assertEquals(expectedServiceTemplate, actualServiceTemplate);
+ }
+
+ @Test
+ public void testObjToInterfaceDefinitionConversion()
+ throws IOException, ReflectiveOperationException {
+ ServiceTemplate serviceTemplateWithInterfaceDef =
+ getServiceTemplate(BASE_DIR + ST_WITH_INTERFACE_DEF);
+ NodeTemplate nodeTemplateWithInterface =
+ DataModelUtil.getNodeTemplate(serviceTemplateWithInterfaceDef, NODE_TEMPLATE_ID);
+ Map<String, Object> interfaces = nodeTemplateWithInterface.getInterfaces();
+ Object interfaceObj = interfaces.get(INTERFACE_ID);
+ Optional<InterfaceDefinition> actualInterfaceDefinition =
+ DataModelUtil.convertObjToInterfaceDefinition(INTERFACE_ID, interfaceObj);
+
+ Assert.assertTrue(actualInterfaceDefinition.isPresent());
+
+ InterfaceDefinition expectedInterfaceDefinition = getInterfaceDefinition();
+ Assert.assertEquals(expectedInterfaceDefinition, actualInterfaceDefinition.get());
+ }
@Test
public void testYamlToServiceTemplateIncludingHeatExtend() throws IOException {
ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
try (InputStream yamlFile =
- toscaExtensionYamlUtil.loadYamlFileIs("/mock/model/serviceTemplateHeatExtend.yaml")) {
+ toscaExtensionYamlUtil.loadYamlFileIs(BASE_DIR + "/serviceTemplateHeatExtend.yaml")) {
ServiceTemplate serviceTemplateFromYaml =
- toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
+ toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
ParameterDefinitionExt parameterDefinitionExt =
- (ParameterDefinitionExt) serviceTemplateFromYaml.getTopology_template().getInputs()
- .get("inParam1");
+ (ParameterDefinitionExt) serviceTemplateFromYaml.getTopology_template().getInputs()
+ .get("inParam1");
Assert.assertNotNull(parameterDefinitionExt.getLabel());
String backToYamlString = toscaExtensionYamlUtil.objectToYaml(serviceTemplateFromYaml);
Assert.assertNotNull(backToYamlString);
}
}
+ private ServiceTemplate getServiceTemplate(String inputPath) throws IOException {
+ try (InputStream yamlFile = yamlUtil.loadYamlFileIs(inputPath)) {
+ return yamlUtil.yamlToObject(yamlFile, ServiceTemplate.class);
+ }
+ }
+
+ private InterfaceType getInterfaceType() {
+ OperationDefinition operationDefinition = getOperationDefinition();
+ InterfaceType interfaceType = new InterfaceType();
+ interfaceType.setDescription("test interface");
+ interfaceType.addOperation("start", operationDefinition);
+ return interfaceType;
+ }
+
+ private OperationDefinition getOperationDefinition() {
+ OperationDefinition operationDefinition = new OperationDefinition();
+ operationDefinition.setDescription("start operation");
+ operationDefinition.setImplementation("start.sh");
+ return operationDefinition;
+ }
+
+ private InterfaceDefinition getInterfaceDefinition() {
+ OperationDefinition operationDefinition = getOperationDefinition();
+ InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setType("test interface");
+ interfaceDefinition.addOperation("start", operationDefinition);
+ return interfaceDefinition;
+ }
+
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplate.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplate.yaml
index c49f30f97b..a2bc15ea19 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplate.yaml
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplate.yaml
@@ -68,7 +68,7 @@ topology_template:
entry_schema:
type: tosca.myType
node_templates:
- firatNodeTemplate:
+ firstNodeTemplate:
type: nodeTypeRef
directives:
- selectable
@@ -98,16 +98,6 @@ topology_template:
capability: capA
node: nodeA
relationship: relationB
- capabilities:
- cap1:
- properties:
- num_cpus: '{ get_input: cpus }'
- attributes:
- num_cpus: '66'
- node_filter:
- properties:
- test1:
- - equal: 1 MB
substitution_mappings:
node_type: myNodeType.node
capabilities:
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterface.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterface.yaml
new file mode 100644
index 0000000000..46d61079a2
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterface.yaml
@@ -0,0 +1,109 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: Test
+ template_author: OPENECOMP
+ template_version: 1.0.0
+description: testing desc tosca service template
+imports:
+- myfile1:
+ file: path1/path2/file1.yaml
+- myfile2:
+ file: path1/path2/file2.yaml
+artifact_types:
+ one_artifact:
+ mime_type: application/java-archive
+ file_ext:
+ - yaml
+ - xml
+interface_types:
+ inter_1:
+ description: test interface
+node_types:
+ compute_node_type:
+ derived_from: tosca.nodes.Root
+ version: 1.0.0
+ description: tosca compute test
+ properties:
+ cpu_num:
+ type: integer
+ description: Number of CPUs requested for a software node instance
+ required: true
+ default: 1
+ status: SUPPORTED
+ constraints:
+ - greater_or_equal: 5.0
+ - equal: 5
+ - greater_than: 6.02
+ - in_range:
+ - 0
+ - UNBOUNDED
+ attributes:
+ attDef1:
+ type: string
+ default: hi
+ status: SUPPORTED
+ requirements:
+ - re1:
+ capability: tosca.cap1
+ occurrences:
+ - 5
+ - 1
+ capabilities:
+ cap1:
+ type: tosca.cap
+ valid_source_types:
+ - node1
+ - node2
+ occurrences:
+ - 1
+ - UNBOUNDED
+topology_template:
+ description: topologi template descroption
+ inputs:
+ inParam1:
+ type: string
+ description: desc
+ required: false
+ default: my default val
+ constraints:
+ - greater_than: 6
+ - greater_or_equal: 9
+ entry_schema:
+ type: tosca.myType
+ node_templates:
+ firstNodeTemplate:
+ type: nodeTypeRef
+ directives:
+ - selectable
+ - substitutable
+ properties:
+ prop2: '{ get_input: my_mysql_rootpw }'
+ prop1: abcd
+ attributes:
+ att2: '{ get_input: my_mysql_rootpw }'
+ att1: att1Val
+ requirements:
+ - req1:
+ capability: capA
+ node: nodeA
+ relationship: relationB
+ node_filter:
+ properties:
+ propName1:
+ - greater_or_equal: 9
+ propName2:
+ - min_length: 1
+ - max_length: 2
+ occurrences:
+ - 1
+ - 2
+ - req2:
+ capability: capA
+ node: nodeA
+ relationship: relationB
+ substitution_mappings:
+ node_type: myNodeType.node
+ capabilities:
+ database_endpoint:
+ - database
+ - database_endpoint
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterfaceAndOperation.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterfaceAndOperation.yaml
new file mode 100644
index 0000000000..90376b7205
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithInterfaceAndOperation.yaml
@@ -0,0 +1,112 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: Test
+ template_author: OPENECOMP
+ template_version: 1.0.0
+description: testing desc tosca service template
+imports:
+- myfile1:
+ file: path1/path2/file1.yaml
+- myfile2:
+ file: path1/path2/file2.yaml
+artifact_types:
+ one_artifact:
+ mime_type: application/java-archive
+ file_ext:
+ - yaml
+ - xml
+interface_types:
+ inter_1:
+ description: test interface
+ start:
+ description: start operation
+ implementation: start.sh
+node_types:
+ compute_node_type:
+ derived_from: tosca.nodes.Root
+ version: 1.0.0
+ description: tosca compute test
+ properties:
+ cpu_num:
+ type: integer
+ description: Number of CPUs requested for a software node instance
+ required: true
+ default: 1
+ status: SUPPORTED
+ constraints:
+ - greater_or_equal: 5.0
+ - equal: 5
+ - greater_than: 6.02
+ - in_range:
+ - 0
+ - UNBOUNDED
+ attributes:
+ attDef1:
+ type: string
+ default: hi
+ status: SUPPORTED
+ requirements:
+ - re1:
+ capability: tosca.cap1
+ occurrences:
+ - 5
+ - 1
+ capabilities:
+ cap1:
+ type: tosca.cap
+ valid_source_types:
+ - node1
+ - node2
+ occurrences:
+ - 1
+ - UNBOUNDED
+topology_template:
+ description: topologi template descroption
+ inputs:
+ inParam1:
+ type: string
+ description: desc
+ required: false
+ default: my default val
+ constraints:
+ - greater_than: 6
+ - greater_or_equal: 9
+ entry_schema:
+ type: tosca.myType
+ node_templates:
+ firstNodeTemplate:
+ type: nodeTypeRef
+ directives:
+ - selectable
+ - substitutable
+ properties:
+ prop2: '{ get_input: my_mysql_rootpw }'
+ prop1: abcd
+ attributes:
+ att2: '{ get_input: my_mysql_rootpw }'
+ att1: att1Val
+ requirements:
+ - req1:
+ capability: capA
+ node: nodeA
+ relationship: relationB
+ node_filter:
+ properties:
+ propName1:
+ - greater_or_equal: 9
+ propName2:
+ - min_length: 1
+ - max_length: 2
+ occurrences:
+ - 1
+ - 2
+ - req2:
+ capability: capA
+ node: nodeA
+ relationship: relationB
+ substitution_mappings:
+ node_type: myNodeType.node
+ capabilities:
+ database_endpoint:
+ - database
+ - database_endpoint
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTemplateInterface.yaml b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTemplateInterface.yaml
new file mode 100644
index 0000000000..6df071c570
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/resources/mock/model/serviceTemplateWithNodeTemplateInterface.yaml
@@ -0,0 +1,112 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+metadata:
+ template_name: Test
+ template_author: OPENECOMP
+ template_version: 1.0.0
+description: testing desc tosca service template
+imports:
+- myfile1:
+ file: path1/path2/file1.yaml
+- myfile2:
+ file: path1/path2/file2.yaml
+artifact_types:
+ one_artifact:
+ mime_type: application/java-archive
+ file_ext:
+ - yaml
+ - xml
+node_types:
+ compute_node_type:
+ derived_from: tosca.nodes.Root
+ version: 1.0.0
+ description: tosca compute test
+ properties:
+ cpu_num:
+ type: integer
+ description: Number of CPUs requested for a software node instance
+ required: true
+ default: 1
+ status: SUPPORTED
+ constraints:
+ - greater_or_equal: 5.0
+ - equal: 5
+ - greater_than: 6.02
+ - in_range:
+ - 0
+ - UNBOUNDED
+ attributes:
+ attDef1:
+ type: string
+ default: hi
+ status: SUPPORTED
+ requirements:
+ - re1:
+ capability: tosca.cap1
+ occurrences:
+ - 5
+ - 1
+ capabilities:
+ cap1:
+ type: tosca.cap
+ valid_source_types:
+ - node1
+ - node2
+ occurrences:
+ - 1
+ - UNBOUNDED
+topology_template:
+ description: topologi template descroption
+ inputs:
+ inParam1:
+ type: string
+ description: desc
+ required: false
+ default: my default val
+ constraints:
+ - greater_than: 6
+ - greater_or_equal: 9
+ entry_schema:
+ type: tosca.myType
+ node_templates:
+ firstNodeTemplate:
+ type: nodeTypeRef
+ directives:
+ - selectable
+ - substitutable
+ interfaces:
+ inter_1:
+ type: test interface
+ start:
+ description: start operation
+ implementation: start.sh
+ properties:
+ prop2: '{ get_input: my_mysql_rootpw }'
+ prop1: abcd
+ attributes:
+ att2: '{ get_input: my_mysql_rootpw }'
+ att1: att1Val
+ requirements:
+ - req1:
+ capability: capA
+ node: nodeA
+ relationship: relationB
+ node_filter:
+ properties:
+ propName1:
+ - greater_or_equal: 9
+ propName2:
+ - min_length: 1
+ - max_length: 2
+ occurrences:
+ - 1
+ - 2
+ - req2:
+ capability: capA
+ node: nodeA
+ relationship: relationB
+ substitution_mappings:
+ node_type: myNodeType.node
+ capabilities:
+ database_endpoint:
+ - database
+ - database_endpoint