From 3d51989fd3559babafeb0ca1d0d0ca8b40ee46a3 Mon Sep 17 00:00:00 2001 From: sebdet Date: Fri, 15 Mar 2019 15:50:06 +0100 Subject: Fix policy Tosca converter Fix converter so that it can understand the new Policy Yaml model Issue-ID: CLAMP-306 Change-Id: I4d2f8640b2344e7ceee2cfec2d7e3175777f591b Signed-off-by: sebdet --- .../clamp/clds/tosca/ToscaSchemaConstants.java | 91 ++++---- .../clds/tosca/ToscaYamlToJsonConvertorTest.java | 3 +- .../org/onap/clamp/loop/CsarInstallerItCase.java | 3 +- src/test/resources/tosca/policy-yaml-to-json.json | 192 +++++++++++++++++ src/test/resources/tosca/tosca_example.yaml | 234 ++++++++++++++------- 5 files changed, 395 insertions(+), 128 deletions(-) create mode 100644 src/test/resources/tosca/policy-yaml-to-json.json diff --git a/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java b/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java index f5b5a8d2b..f1344723e 100644 --- a/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java +++ b/src/main/java/org/onap/clamp/clds/tosca/ToscaSchemaConstants.java @@ -18,59 +18,56 @@ * limitations under the License. * ============LICENSE_END============================================ * =================================================================== - * + * */ package org.onap.clamp.clds.tosca; public class ToscaSchemaConstants { - //Data types in TOSCA Schema - public static final String TYPE_LIST = "list"; - public static final String TYPE_MAP = "map"; - public static final String TYPE_STRING = "string"; - public static final String TYPE_INTEGER = "integer"; - public static final String TYPE_FLOAT = "float"; - public static final String TYPE_BOOLEAN = "boolean"; - - //Key elements in Tosca - public static final String NODE_TYPES = "node_types"; - public static final String DATA_TYPES = "data_types"; - public static final String TYPE = "type"; - public static final String DESCRIPTION = "description"; - public static final String DEFAULT = "default"; - public static final String PROPERTIES = "properties"; - public static final String REQUIRED = "required"; - public static final String ENTRY_SCHEMA = "entry_schema"; + // Data types in TOSCA Schema + public static final String TYPE_LIST = "list"; + public static final String TYPE_MAP = "map"; + public static final String TYPE_STRING = "string"; + public static final String TYPE_INTEGER = "integer"; + public static final String TYPE_FLOAT = "float"; + public static final String TYPE_BOOLEAN = "boolean"; + + // Key elements in Tosca + public static final String NODE_TYPES = "policy_types"; + public static final String DATA_TYPES = "data_types"; + public static final String TYPE = "type"; + public static final String DESCRIPTION = "description"; + public static final String DEFAULT = "default"; + public static final String PROPERTIES = "properties"; + public static final String REQUIRED = "required"; + public static final String ENTRY_SCHEMA = "entry_schema"; + + // Constraints + public static final String CONSTRAINTS = "constraints"; + public static final String VALID_VALUES = "valid_values"; + public static final String EQUAL = "equal"; + public static final String GREATER_THAN = "greater_than"; + public static final String GREATER_OR_EQUAL = "greater_or_equal"; + public static final String LESS_THAN = "less_than"; + public static final String LESS_OR_EQUAL = "less_or_equal"; + public static final String IN_RANGE = "in_range"; + public static final String LENGTH = "length"; + public static final String MIN_LENGTH = "min_length"; + public static final String MAX_LENGTH = "max_length"; + public static final String PATTERN = "pattern"; + + // Prefix for policy nodes + public static final String POLICY_NODE = "onap.policy."; + + // Prefix for data nodes + public static final String POLICY_DATA = "onap.datatypes."; + + // Prefix for dictionary elements + public static final String DICTIONARY = "Dictionary:"; - //Constraints - public static final String CONSTRAINTS = "constraints"; - public static final String VALID_VALUES = "valid_values"; - public static final String EQUAL = "equal"; - public static final String GREATER_THAN = "greater_than"; - public static final String GREATER_OR_EQUAL = "greater_or_equal"; - public static final String LESS_THAN = "less_than"; - public static final String LESS_OR_EQUAL = "less_or_equal"; - public static final String IN_RANGE = "in_range"; - public static final String LENGTH = "length"; - public static final String MIN_LENGTH = "min_length"; - public static final String MAX_LENGTH = "max_length"; - public static final String PATTERN = "pattern"; - - //Prefix for policy nodes - public static final String POLICY_NODE = "policy.nodes."; - - //Prefix for data nodes - public static final String POLICY_DATA = "policy.data."; - - //Prefix for dictionary elements - public static final String DICTIONARY = "Dictionary:"; - - //Custom Elements that must exist in the Tosca models - public static final String NAME = "name"; - public static final String CONTEXT = "context"; + // Custom Elements that must exist in the Tosca models + public static final String NAME = "name"; + public static final String CONTEXT = "context"; - - - } diff --git a/src/test/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertorTest.java b/src/test/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertorTest.java index d94ffabaf..199d05370 100644 --- a/src/test/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertorTest.java +++ b/src/test/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertorTest.java @@ -47,8 +47,7 @@ public class ToscaYamlToJsonConvertorTest { String parsedJsonSchema = convertor.parseToscaYaml(toscaModelYaml); assertNotNull(parsedJsonSchema); - JSONAssert.assertEquals( - ResourceFileUtil.getResourceAsString("example/json-editor-schema/tca-policy-json-editor-schema.json"), + JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/policy-yaml-to-json.json"), parsedJsonSchema, true); } } diff --git a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java index afa07236d..fcef5b79e 100644 --- a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java +++ b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java @@ -135,7 +135,7 @@ public class CsarInstallerItCase { // Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(csarHelper); Mockito.when(csarHandler.getPolicyModelYaml()) - .thenReturn(Optional.ofNullable(ResourceFileUtil.getResourceAsString("tosca/tca-policy-test.yaml"))); + .thenReturn(Optional.ofNullable(ResourceFileUtil.getResourceAsString("tosca/tosca_example.yaml"))); return csarHandler; } @@ -173,6 +173,7 @@ public class CsarInstallerItCase { assertThat(loop.getSvgRepresentation()).startsWith("