summaryrefslogtreecommitdiffstats
path: root/javatoscachecker/checker
diff options
context:
space:
mode:
authorSerban Jora <sj2381@att.com>2018-04-10 15:33:46 -0400
committerSerban Jora <sj2381@att.com>2018-04-10 16:02:37 -0400
commitfd3287187e487d8b0789484def296074e985b7cb (patch)
treedb5e50544ac9fa515be5a647a8489815131ab711 /javatoscachecker/checker
parentdc3ecc22915249d0fb542ab23b400abd6b5ef620 (diff)
Add more unit testing
Unit testing for kwalify parser and validator and for domain model representation. Fix oparent reference in pom in datse format in docker image tag. Change-Id: Icca11ae7fc773cae3de910acb10fcacd51b909a4 Signed-off-by: Serban Jora <sj2381@att.com> Issue-ID: MODELING-53 Signed-off-by: Serban Jora <sj2381@att.com>
Diffstat (limited to 'javatoscachecker/checker')
-rw-r--r--javatoscachecker/checker/pom.xml2
-rw-r--r--javatoscachecker/checker/src/main/java/org/onap/tosca/checker/model/Capability.java4
-rw-r--r--javatoscachecker/checker/src/main/java/org/onap/tosca/checker/model/Constraint.java6
-rw-r--r--javatoscachecker/checker/src/main/java/org/onap/tosca/checker/model/TOSCAProxy.java7
-rw-r--r--javatoscachecker/checker/src/test/java/org/onap/tosca/checker/test/ModelTest.java87
-rw-r--r--javatoscachecker/checker/src/test/resources/models/full.yaml48
6 files changed, 124 insertions, 30 deletions
diff --git a/javatoscachecker/checker/pom.xml b/javatoscachecker/checker/pom.xml
index fc2a2c1..ee1d37b 100644
--- a/javatoscachecker/checker/pom.xml
+++ b/javatoscachecker/checker/pom.xml
@@ -18,7 +18,7 @@
<parent>
<groupId>org.onap.modeling.toscaparsers</groupId>
<artifactId>checker</artifactId>
- <version>1.1.0-SNAPSHOT</version>
+ <version>1.2.0-SNAPSHOT</version>
</parent>
<artifactId>Checker</artifactId>
<packaging>jar</packaging>
diff --git a/javatoscachecker/checker/src/main/java/org/onap/tosca/checker/model/Capability.java b/javatoscachecker/checker/src/main/java/org/onap/tosca/checker/model/Capability.java
index 72df0b7..eaf72c9 100644
--- a/javatoscachecker/checker/src/main/java/org/onap/tosca/checker/model/Capability.java
+++ b/javatoscachecker/checker/src/main/java/org/onap/tosca/checker/model/Capability.java
@@ -20,6 +20,10 @@ import java.util.List;
public interface Capability extends TOSCAObject<Capability> {
/**
+ */
+ public String name();
+
+ /**
* The required name of the Capability Type the capability definition is based upon.
*/
public String type();
diff --git a/javatoscachecker/checker/src/main/java/org/onap/tosca/checker/model/Constraint.java b/javatoscachecker/checker/src/main/java/org/onap/tosca/checker/model/Constraint.java
index 03c8d20..622b75c 100644
--- a/javatoscachecker/checker/src/main/java/org/onap/tosca/checker/model/Constraint.java
+++ b/javatoscachecker/checker/src/main/java/org/onap/tosca/checker/model/Constraint.java
@@ -17,7 +17,11 @@ package org.onap.tosca.checker.model;
*/
public interface Constraint extends TOSCAObject<Constraint> {
- public Constraint.Type name();
+ public String name();
+
+ public default Constraint.Type type() {
+ return Type.valueOf(Type.class, name());
+ }
/* this is a one entry map so here we pick the single
*/
diff --git a/javatoscachecker/checker/src/main/java/org/onap/tosca/checker/model/TOSCAProxy.java b/javatoscachecker/checker/src/main/java/org/onap/tosca/checker/model/TOSCAProxy.java
index bce8675..c5339e4 100644
--- a/javatoscachecker/checker/src/main/java/org/onap/tosca/checker/model/TOSCAProxy.java
+++ b/javatoscachecker/checker/src/main/java/org/onap/tosca/checker/model/TOSCAProxy.java
@@ -95,9 +95,12 @@ public class TOSCAProxy
* This is targeted at lists of one entry maps seen in in the TOSCA spec
*/
public static <T extends TOSCASeq> T buildSeq(final List<Map> theInfo, Class<T> theType) {
- theInfo.replaceAll((value) -> { Map.Entry<String,Map> entry = (Map.Entry<String,Map>)
+ theInfo.replaceAll((value) -> { Map.Entry<String,?> entry = (Map.Entry<String,?>)
value.entrySet().iterator().next();
- return buildObject(entry.getKey(), entry.getValue(), typeArgument(theType));
+
+ return entry.getValue() instanceof Map ?
+ buildObject(entry.getKey(), (Map)entry.getValue(), typeArgument(theType)) :
+ buildObject(entry.getKey(), Collections.singletonMap("value", entry.getValue()), typeArgument(theType));
});
return (T)java.lang.reflect.Proxy.newProxyInstance(
TOSCAProxy.class.getClassLoader(),
diff --git a/javatoscachecker/checker/src/test/java/org/onap/tosca/checker/test/ModelTest.java b/javatoscachecker/checker/src/test/java/org/onap/tosca/checker/test/ModelTest.java
index d6b3d8b..b01b387 100644
--- a/javatoscachecker/checker/src/test/java/org/onap/tosca/checker/test/ModelTest.java
+++ b/javatoscachecker/checker/src/test/java/org/onap/tosca/checker/test/ModelTest.java
@@ -71,14 +71,29 @@ public class ModelTest {
assertTrue(template.data_types() != null);
- for (Map.Entry<String, DataType> type: template.data_types().entrySet()) {
- assertTrue(type.getKey().startsWith("data_type_"));
+ for (DataType type: template.data_types().values()) {
+ assertTrue(type.name().startsWith("data_type_"));
+ assertTrue(type.description().startsWith("test data type"));
+ assertTrue(type.version().equals("1.0"));
- Properties props = type.getValue().properties();
+ Properties props = type.properties();
assertTrue(props != null);
- for (Map.Entry<String, Property> prop: props.entrySet()) {
- assertTrue(prop.getKey().startsWith("data_field_"));
+ for (Property prop: props.values()) {
+ assertTrue("property name prefix " + prop.name(), prop.name().startsWith("data_field_"));
+ assertTrue("property description prefix " + prop.description(), prop.description().startsWith("test data field"));
+ assertTrue(prop.required());
+
+ String propType = prop.type();
+ assertTrue(propType != null && (propType.equals("string") || propType.equals("integer")));
+
+ Constraints constraints = prop.constraints();
+ if (constraints != null) {
+ if ("integer".equals(propType))
+ assertTrue("integer constraints", constraints.get(0).name().equals("valid_values"));
+ if ("string".equals(propType))
+ assertTrue("string constraints", constraints.get(0).name().equals("max_length"));
+ }
}
}
}
@@ -104,13 +119,13 @@ public class ModelTest {
assertTrue(template.interface_types() != null);
for (Map.Entry<String, InterfaceType> type: template.interface_types().entrySet()) {
- assertTrue(type.getKey().matches("interface_type_[0-9]"));
+ assertTrue(type.getKey(), type.getKey().matches("interface_type_[0-9]"));
Operations ops = type.getValue().operations();
- assertTrue(ops != null);
-
- for (Map.Entry<String, Operation> op: ops.entrySet()) {
- assertTrue(op.getKey().matches("interface_type_[0-9]_op_[0-9]"));
+ if(ops != null) {
+ for (Map.Entry<String, Operation> op: ops.entrySet()) {
+ assertTrue(op.getKey().matches("interface_type_[0-9]_op_[0-9]"));
+ }
}
}
}
@@ -120,13 +135,13 @@ public class ModelTest {
assertTrue(template.relationship_types() != null);
for (Map.Entry<String, RelationshipType> type: template.relationship_types().entrySet()) {
- assertTrue(type.getKey().matches("relationship_type_[0-9]"));
+ assertTrue(type.getKey().matches("relationship_type_[0-9][0-9]"));
TypeInterfaces infs = type.getValue().interfaces();
assertTrue(infs != null);
for (Map.Entry<String, TypeInterface> inf: infs.entrySet()) {
- assertTrue(inf.getKey().matches("relationship_type_[0-9]_interface_[0-9]"));
+ assertTrue(inf.getKey().matches("relationship_type_[0-9]+_interface_[0-9]+"));
}
}
}
@@ -135,15 +150,42 @@ public class ModelTest {
public void testServiceTemplateNodeTypes() {
assertTrue(template.node_types() != null);
- for (Map.Entry<String, NodeType> type: template.node_types().entrySet()) {
- assertTrue(type.getKey().matches("node_type_[0-9]"));
+ for (NodeType nodeType: template.node_types().values()) {
+ assertTrue(nodeType.name().matches("node_type_[0-9]"));
- Capabilities caps = type.getValue().capabilities();
+ Capabilities caps = nodeType.capabilities();
assertTrue(caps != null);
- for (Map.Entry<String, Capability> cap: caps.entrySet()) {
- assertTrue(cap.getKey().matches("node_type_[0-9]_capability_[0-9]"));
+ for (Capability cap: caps.values()) {
+ assertTrue(cap.name().matches("node_type_[0-9]_capability_[0-9]"));
}
+
+ Requirements reqs = nodeType.requirements();
+ if (reqs != null) {
+ for (Requirement req: reqs) {
+ assertTrue(req.name().startsWith(nodeType.name() + "_requirement"));
+ assertTrue(req.capability() != null);
+ assertTrue(req.node() != null);
+ assertTrue(req.relationship() != null);
+ }
+ }
+
+ Artifacts arts = nodeType.artifacts();
+ if (arts != null) {
+ for (Artifact art: arts.values()) {
+ assertTrue(art.name().startsWith(nodeType.name() + "_artifact"));
+ assertTrue(art.type().startsWith("artifact_type"));
+ }
+ }
+
+ TypeInterfaces itfs = nodeType.interfaces();
+ if (itfs != null) {
+ for (TypeInterface itf: itfs.values()) {
+ assertTrue(itf.name().startsWith(nodeType.name() + "_interface"));
+ assertTrue(itf.type().startsWith("interface_type"));
+ }
+ }
+
}
}
@@ -164,15 +206,20 @@ public class ModelTest {
assertTrue(template.topology_template().node_templates() != null);
- for (Map.Entry<String, NodeTemplate> node: template.topology_template().node_templates().entrySet()) {
- assertTrue(node.getKey().matches("node_[0-9]"));
+ for (NodeTemplate node: template.topology_template().node_templates().values()) {
+ assertTrue(node.name().matches("node_[0-9]"));
- PropertiesAssignments props = node.getValue().properties();
+ PropertiesAssignments props = node.properties();
assertTrue(props != null);
for (Map.Entry<String, Object> prop: props.entrySet()) {
assertTrue(prop.getKey().matches("node_type_[0-9]_property_[0-9]"));
}
+
+ NodeType nodeType = template.node_types().get(node.type());
+ if (nodeType.capabilities() != null) {
+ assertTrue(node.capabilities() != null);
+ }
}
}
diff --git a/javatoscachecker/checker/src/test/resources/models/full.yaml b/javatoscachecker/checker/src/test/resources/models/full.yaml
index 3792be7..ded4c26 100644
--- a/javatoscachecker/checker/src/test/resources/models/full.yaml
+++ b/javatoscachecker/checker/src/test/resources/models/full.yaml
@@ -17,17 +17,39 @@ data_types:
data_type_1:
derived_from: tosca.datatypes.Root
+ description: test data type 1
+ version: "1.0"
properties:
data_field_11:
type: string
+ required: true
+ description: test data field 11
data_field_12:
type: integer
+ required: true
+ description: test data field 12
+ constraints:
+ - valid_values: [ 1, 12,24 ]
data_type_2:
derived_from: data_type_1
+ description: test data type 2
+ version: "1.0"
properties:
data_field_21:
type: string
+ required: true
+ description: test data field 21
+ constraints:
+ - max_length: 128
+
+artifact_types:
+
+ artifact_type_1:
+ derived_from: tosca.artifacts.File
+ description: Some test bytes
+ mime_type: application/octet-stream
+ file_ext: [ tst ]
capability_types:
@@ -55,7 +77,8 @@ node_types:
requirements:
- node_type_1_requirement_2:
capability: capability_type_2
-# relationship:
+ node: node_type_2
+ relationship: relationship_type_12
node_type_2:
properties:
@@ -64,6 +87,12 @@ node_types:
capabilities:
node_type_2_capability_2:
type: capability_type_2
+ artifacts:
+ node_type_2_artifact_1:
+ type: artifact_type_1
+ interfaces:
+ node_type_2_interface_1:
+ type: interface_type_1
interface_types:
@@ -75,15 +104,18 @@ interface_types:
# type: string
interface_type_1_op_1:
description: test interface operation
+
+ interface_type_2:
+ derived_from: tosca.interfaces.node.lifecycle.Standard
relationship_types:
- relationship_type_1:
+ relationship_type_12:
derived_from: tosca.relationships.ConnectsTo
description: test relationship type
interfaces:
- relationship_type_1_interface_1:
- type: interface_type_1
+ relationship_type_12_interface_1:
+ type: interface_type_2
topology_template:
@@ -93,11 +125,15 @@ topology_template:
type: node_type_1
properties:
node_type_1_property_1: { data_field_11: "11", data_field_12: 12 }
+ capabilities:
+ node_type_1_capability_1:
+ properties:
+ capability_type_1_property_1: value_1
requirements:
- node_type_1_requirement_2:
node_filter:
capabilities:
- - two:
+ - node_type_2_capability_2:
properties:
- capability_type_2_property_1: { equal: "value2" }
@@ -113,7 +149,7 @@ topology_template:
relationship_templates:
relationship_1:
- type: relationship_type_1
+ type: relationship_type_12
# interfaces:
# relationship_type_1_interface_1: