From 1419e6066cc5ce7a47bb2916e165d6f90dc8bc55 Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Tue, 4 Sep 2018 22:42:09 -0400 Subject: SDNC Blueprints Processor Model Service Creating SDN Controller Blueprints Processor Model Service JUnit Tests - 1 Change-Id: Ib13d6132bc024ca6e43d2088b5c577130a305479 Issue-ID: CCSDK-516 Signed-off-by: Singal, Kapil (ks220y) --- .../config/model/ResourceDictionaryUtilsTest.java | 216 +++++++++++++++ .../config/model/utils/JsonParserUtilsTest.java | 43 +++ .../ccsdk/config/model/utils/JsonUtilsTest.java | 103 +++++++ .../model/utils/ResourceAssignmentUtilsTest.java | 198 ++++++++++++++ .../model/utils/ServiceTemplateUtilsTest.java | 77 ++++++ .../model/utils/TransformationUtilsTest.java | 90 +++++++ .../validator/ServiceTemplateValidationTest.java | 51 ++++ .../config/params/service/ComponentNodeTest.java | 140 ++++++++++ .../params/service/ConfigModelServiceTest.java | 219 +++++++++++++++ .../config/params/service/ExpressionUtilsTest.java | 76 ++++++ .../config/params/service/MockComponentNode.java | 62 +++++ .../params/service/ServiceTemplateCreateUtils.java | 295 +++++++++++++++++++++ 12 files changed, 1570 insertions(+) create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/ResourceDictionaryUtilsTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonParserUtilsTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonUtilsTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ResourceAssignmentUtilsTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ServiceTemplateUtilsTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/TransformationUtilsTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/validator/ServiceTemplateValidationTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ComponentNodeTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ConfigModelServiceTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ExpressionUtilsTest.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/MockComponentNode.java create mode 100644 blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ServiceTemplateCreateUtils.java (limited to 'blueprints-processor/plugin/model-provider') diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/ResourceDictionaryUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/ResourceDictionaryUtilsTest.java new file mode 100644 index 000000000..1b3dc9c1f --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/ResourceDictionaryUtilsTest.java @@ -0,0 +1,216 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.config.model; + +import java.util.Arrays; +import java.util.HashMap; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.config.model.data.PropertyDefinition; +import org.onap.ccsdk.config.model.data.ResourceAssignment; +import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.config.model.data.dict.SourcesDefinition; +import org.onap.ccsdk.config.model.data.dict.SourcesProperties; +import org.onap.ccsdk.config.model.utils.ResourceDictionaryUtils; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ResourceDictionaryUtilsTest { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceDictionaryUtilsTest.class); + + @Test + public void validateSingleInputSource() { + try { + logger.info(" **************** Validating validateSingleInputSource *****************"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("test-input-key"); + + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType(ValidTypes.DATA_TYPE_STRING); + + SourcesProperties sourcesProp = new SourcesProperties(); + sourcesProp.setDependencies(Arrays.asList(new String[] {"vnf-id", "vnf-name"})); + + SourcesDefinition sourceDef = new SourcesDefinition(); + sourceDef.setProperties(sourcesProp); + + HashMap sources = new HashMap<>(); + sources.put("input", sourceDef); + + ResourceDefinition resourceDefinition = new ResourceDefinition(); + resourceDefinition.setProperty(propertyDefinition); + resourceDefinition.setSources(sources); + + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + + Assert.assertNotNull("Resource assignment input sourceName is missing ", + resourceAssignment.getDictionarySource()); + Assert.assertNotNull("Resource assignment input sourceName property is missing ", + resourceAssignment.getProperty()); + Assert.assertNotNull("Resource assignment input sourceName property type is missing ", + resourceAssignment.getProperty().getType()); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void validateSingleDbSource() { + try { + logger.info(" **************** Validating validateSingleDbSource *****************"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("test-db-key"); + + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType(ValidTypes.DATA_TYPE_STRING); + + SourcesProperties sourcesProp = new SourcesProperties(); + sourcesProp.setDependencies(Arrays.asList(new String[] {"vnf-id", "vnf-name"})); + + SourcesDefinition sourceDef = new SourcesDefinition(); + sourceDef.setProperties(sourcesProp); + + HashMap sources = new HashMap<>(); + sources.put("db", sourceDef); + + ResourceDefinition resourceDefinition = new ResourceDefinition(); + resourceDefinition.setProperty(propertyDefinition); + resourceDefinition.setSources(sources); + + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertNotNull("Resource assignment db sourceName sourceName is missing ", + resourceAssignment.getDictionarySource()); + Assert.assertNotNull("Resource assignment db sourceName sourceName property is missing ", + resourceAssignment.getProperty()); + Assert.assertNotNull("Resource assignment db sourceName sourceName property type is missing ", + resourceAssignment.getProperty().getType()); + + Assert.assertNotNull("Resource assignment db dependecy is missing ", resourceAssignment.getDependencies()); + Assert.assertEquals("Resource assignment db dependecy count mismatch ", 2, + resourceAssignment.getDependencies().size()); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void validateMultiSource() { + try { + logger.info(" **************** Validating validateMultiSource *****************"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("test-multi-key"); + + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType(ValidTypes.DATA_TYPE_STRING); + + SourcesProperties sourcesProp = new SourcesProperties(); + sourcesProp.setDependencies(Arrays.asList(new String[] {"vnf-id", "vnf-name"})); + + SourcesDefinition sourceDef = new SourcesDefinition(); + sourceDef.setProperties(sourcesProp); + + HashMap sources = new HashMap<>(); + sources.put("input", sourceDef); + sources.put("mdsal", sourceDef); + + ResourceDefinition resourceDefinition = new ResourceDefinition(); + resourceDefinition.setProperty(propertyDefinition); + resourceDefinition.setSources(sources); + + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + Assert.assertNotNull("Resource assignment db sourceName sourceName property is missing ", + resourceAssignment.getProperty()); + Assert.assertNotNull("Resource assignment db sourceName sourceName property type is missing ", + resourceAssignment.getProperty().getType()); + Assert.assertNull("Resource assignment multi sourceName sourceName definition is present ", + resourceAssignment.getDictionarySource()); + Assert.assertNull("Resource assignment multi sourceName dependecy is present ", + resourceAssignment.getDependencies()); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Test + public void testSourceDefault() { + logger.info(" **************** Validating testSourceDefault *****************"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("test-input-key"); + + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType(ValidTypes.DATA_TYPE_STRING); + + SourcesProperties sourcesProp = new SourcesProperties(); + sourcesProp.setDependencies(Arrays.asList(new String[] {"vnf-id", "vnf-name"})); + + SourcesDefinition sourceDef = new SourcesDefinition(); + sourceDef.setProperties(sourcesProp); + + HashMap sources = new HashMap<>(); + sources.put("default", sourceDef); + + ResourceDefinition resourceDefinition = new ResourceDefinition(); + resourceDefinition.setProperty(propertyDefinition); + resourceDefinition.setSources(sources); + + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + + Assert.assertNotNull("Resource assignment default sourceName is missing ", + resourceAssignment.getDictionarySource()); + Assert.assertNotNull("Resource assignment default sourceName property is missing ", + resourceAssignment.getProperty()); + Assert.assertNotNull("Resource assignment default sourceName property type is missing ", + resourceAssignment.getProperty().getType()); + } + + @Test + public void testSourceMdsal() { + logger.info(" **************** Validating testSourceMdsal *****************"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName("test-input-key"); + + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setType(ValidTypes.DATA_TYPE_STRING); + + SourcesProperties sourcesProp = new SourcesProperties(); + sourcesProp.setDependencies(Arrays.asList(new String[] {"vnf-id", "vnf-name"})); + + SourcesDefinition sourceDef = new SourcesDefinition(); + sourceDef.setProperties(sourcesProp); + + HashMap sources = new HashMap<>(); + sources.put("mdsal", sourceDef); + + ResourceDefinition resourceDefinition = new ResourceDefinition(); + resourceDefinition.setProperty(propertyDefinition); + resourceDefinition.setSources(sources); + + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, resourceDefinition); + + Assert.assertNotNull("Resource assignment mdsal sourceName is missing ", + resourceAssignment.getDictionarySource()); + Assert.assertNotNull("Resource assignment mdsal sourceName property is missing ", + resourceAssignment.getProperty()); + Assert.assertNotNull("Resource assignment mdsal sourceName property type is missing ", + resourceAssignment.getProperty().getType()); + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonParserUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonParserUtilsTest.java new file mode 100644 index 000000000..693c505e3 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonParserUtilsTest.java @@ -0,0 +1,43 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.config.model.utils; + +import org.junit.Assert; +import org.junit.Test; +import com.fasterxml.jackson.databind.JsonNode; + +public class JsonParserUtilsTest { + + @Test + public void testParse() { + final String jsonExample = "{\"key\":\"value\"}"; + + JsonNode rootJsonNode = JsonParserUtils.parse(jsonExample, "$"); + Assert.assertEquals(jsonExample, rootJsonNode.toString()); + + JsonNode keyJsonNode = JsonParserUtils.parse(rootJsonNode, "$['key']"); + Assert.assertEquals("value", keyJsonNode.asText()); + + Assert.assertEquals(jsonExample, + JsonParserUtils.parseNSet("{\"key\":\"NOT_VALUE\"}", "$['key']", keyJsonNode).toString()); + + rootJsonNode = JsonParserUtils.parse("{\"key\":\"NOT_VALUE\"}", "$"); + Assert.assertEquals(jsonExample, JsonParserUtils.parseNSet(rootJsonNode, "$['key']", keyJsonNode).toString()); + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonUtilsTest.java new file mode 100644 index 000000000..5dd0fae27 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/JsonUtilsTest.java @@ -0,0 +1,103 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.config.model.utils; + +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.onap.ccsdk.config.model.ValidTypes; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +public class JsonUtilsTest { + + @Test + public void testPopulatePrimitiveValues() { + ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); + JsonUtils.populatePrimitiveValues("key1", "value", "", objectNode); + JsonUtils.populatePrimitiveValues("key2", true, ValidTypes.DATA_TYPE_BOOLEAN, objectNode); + JsonUtils.populatePrimitiveValues("key3", 1, ValidTypes.DATA_TYPE_INTEGER, objectNode); + JsonUtils.populatePrimitiveValues("key4", 1.1f, ValidTypes.DATA_TYPE_FLOAT, objectNode); + JsonUtils.populatePrimitiveValues("key5", "13213123131", ValidTypes.DATA_TYPE_TIMESTAMP, objectNode); + + assertTrue("value".equals(objectNode.get("key1").asText())); + assertTrue(objectNode.get("key2").asBoolean()); + assertTrue(objectNode.get("key3").asInt() == 1); + assertTrue(objectNode.get("key4").floatValue() == 1.1f); + assertTrue("13213123131".equals(objectNode.get("key5").asText())); + } + + @Test + public void testPopulatePrimitiveValuesArrayNode() { + ArrayNode objectNode = JsonNodeFactory.instance.arrayNode(); + JsonUtils.populatePrimitiveValues("value", "", objectNode); + JsonUtils.populatePrimitiveValues(true, ValidTypes.DATA_TYPE_BOOLEAN, objectNode); + JsonUtils.populatePrimitiveValues(1, ValidTypes.DATA_TYPE_INTEGER, objectNode); + JsonUtils.populatePrimitiveValues(1.1f, ValidTypes.DATA_TYPE_FLOAT, objectNode); + JsonUtils.populatePrimitiveValues("13213123131", ValidTypes.DATA_TYPE_TIMESTAMP, objectNode); + + assertTrue(objectNode.size() == 5); + } + + @Test + public void testPopulatePrimitiveDefaultValues() { + ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); + JsonUtils.populatePrimitiveDefaultValues("key1", "", objectNode); + JsonUtils.populatePrimitiveDefaultValues("key2", ValidTypes.DATA_TYPE_BOOLEAN, objectNode); + JsonUtils.populatePrimitiveDefaultValues("key3", ValidTypes.DATA_TYPE_INTEGER, objectNode); + JsonUtils.populatePrimitiveDefaultValues("key4", ValidTypes.DATA_TYPE_FLOAT, objectNode); + + assertTrue("".equals(objectNode.get("key1").asText())); + assertTrue(objectNode.get("key2").asBoolean() == false); + assertTrue(objectNode.get("key3").asInt() == 0); + assertTrue(objectNode.get("key4").floatValue() == 0.0f); + } + + @Test + public void testPopulatePrimitiveDefaultValuesForArrayNode() { + ArrayNode objectNode = JsonNodeFactory.instance.arrayNode(); + JsonUtils.populatePrimitiveDefaultValuesForArrayNode("", objectNode); + JsonUtils.populatePrimitiveDefaultValuesForArrayNode(ValidTypes.DATA_TYPE_BOOLEAN, objectNode); + JsonUtils.populatePrimitiveDefaultValuesForArrayNode(ValidTypes.DATA_TYPE_INTEGER, objectNode); + JsonUtils.populatePrimitiveDefaultValuesForArrayNode(ValidTypes.DATA_TYPE_FLOAT, objectNode); + + assertTrue(objectNode.size() == 4); + } + + @Test + public void testPopulateJsonNodeValues() { + ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); + JsonUtils.populateJsonNodeValues("key1", JsonNodeFactory.instance.textNode("value"), + ValidTypes.DATA_TYPE_STRING, objectNode); + JsonUtils.populateJsonNodeValues("key2", JsonNodeFactory.instance.booleanNode(true), + ValidTypes.DATA_TYPE_BOOLEAN, objectNode); + JsonUtils.populateJsonNodeValues("key3", JsonNodeFactory.instance.numberNode(1), ValidTypes.DATA_TYPE_INTEGER, + objectNode); + JsonUtils.populateJsonNodeValues("key4", JsonNodeFactory.instance.numberNode(1.1f), ValidTypes.DATA_TYPE_FLOAT, + objectNode); + JsonUtils.populateJsonNodeValues("key5", JsonNodeFactory.instance.textNode("13213123131"), + ValidTypes.DATA_TYPE_TIMESTAMP, objectNode); + assertTrue(objectNode.get("key2").asBoolean()); + + assertTrue("value".equals(objectNode.get("key1").asText())); + assertTrue(objectNode.get("key2").asBoolean()); + assertTrue(objectNode.get("key3").asInt() == 1); + assertTrue(objectNode.get("key4").floatValue() == 1.1f); + assertTrue("13213123131".equals(objectNode.get("key5").asText())); + } +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ResourceAssignmentUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ResourceAssignmentUtilsTest.java new file mode 100644 index 000000000..034d70d7d --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ResourceAssignmentUtilsTest.java @@ -0,0 +1,198 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.config.model.utils; + +import static org.junit.Assert.assertTrue; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Test; +import org.onap.ccsdk.config.model.ConfigModelConstant; +import org.onap.ccsdk.config.model.ConfigModelException; +import org.onap.ccsdk.config.model.ValidTypes; +import org.onap.ccsdk.config.model.data.PropertyDefinition; +import org.onap.ccsdk.config.model.data.ResourceAssignment; +import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ResourceAssignmentUtilsTest { + + @Test + public void testGetArtifactNodeContent() { + String nodeTemplateName = "nodeTemplateNmae"; + String templateContent = "content"; + Map context = new HashMap(); + context.put(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateName + ".content", templateContent); + + String retrievedContent = ResourceAssignmentUtils.getArtifactNodeContent(nodeTemplateName, context); + + assertTrue(templateContent.equals(retrievedContent)); + } + + @Test + public void testGetArtifactNodeMapping() { + String nodeTemplateName = "nodeTemplateNmae"; + String templateContent = "[]"; + Map context = new HashMap(); + context.put(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + nodeTemplateName + ".mapping", templateContent); + + List map = ResourceAssignmentUtils.getArtifactNodeMapping(nodeTemplateName, context); + assertTrue(map.size() == 0); + } + + @Test + public void testCleanContextTemplateNDictionaryKeys() { + String recipeName = "recipe"; + Map componentContext = new HashMap(); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".", "value1"); + componentContext.put(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + ".", "value2"); + ResourceAssignmentUtils.cleanContextTemplateNDictionaryKeys(componentContext); + + assertTrue(componentContext.size() == 1); + } + + @Test + public void testGetDictionaryKeyValue() { + String recipeName = "recipe"; + String dictionaryName = "dictionaryKey"; + Map componentContext = new HashMap(); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + "." + dictionaryName, + "value1"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setDictionaryName(dictionaryName); + + String value = (String) ResourceAssignmentUtils.getDictionaryKeyValue(componentContext, resourceAssignment); + assertTrue("value1".equals(value)); + } + + @Test + public void testGetDictionaryKeyValueWithDictionaryDefinition() { + String recipeName = "recipe"; + String dictionaryName = "dictionaryKey"; + Map componentContext = new HashMap(); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + "." + dictionaryName, + "value1"); + ResourceDefinition resourceDefinition = new ResourceDefinition(); + resourceDefinition.setName(dictionaryName); + + String value = (String) ResourceAssignmentUtils.getDictionaryKeyValue(componentContext, resourceDefinition); + assertTrue("value1".equals(value)); + } + + @Test + public void testGetTemplateKeyValue() { + String recipeName = "recipe"; + String templateKeyName = "templateKey"; + Map componentContext = new HashMap(); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + "." + templateKeyName, + "value1"); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName(templateKeyName); + + String value = (String) ResourceAssignmentUtils.getTemplateKeyValue(componentContext, resourceAssignment); + assertTrue("value1".equals(value)); + } + + @Test + public void testSetResourceDataValue() throws Exception { + String recipeName = "recipe"; + Map componentContext = new HashMap(); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + + ResourceAssignment resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_STRING, null); + Object value = "value"; + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); + assertTrue(value.equals(resourceAssignment.getProperty().getValue())); + + resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_INTEGER, null); + value = "1"; + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); + assertTrue((int) resourceAssignment.getProperty().getValue() == 1); + + resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_BOOLEAN, null); + value = "true"; + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); + assertTrue((boolean) resourceAssignment.getProperty().getValue()); + + resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_FLOAT, null); + value = "1.1"; + ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value); + assertTrue((float) resourceAssignment.getProperty().getValue() == 1.1f); + } + + @Test + public void testSetFailedResourceDataValue() throws Exception { + ResourceAssignment resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_STRING, "value"); + String message = "message"; + ResourceAssignmentUtils.setFailedResourceDataValue(null, resourceAssignment, message); + + assertTrue(message.equals(resourceAssignment.getMessage())); + assertTrue(ConfigModelConstant.STATUS_FAILURE.equals(resourceAssignment.getStatus())); + } + + @Test(expected = ConfigModelException.class) + public void testAssertTemplateKeyValueNotNull() throws Exception { + Map componentContext = null; + ResourceAssignment resourceAssignment = createResourceAssignment("name1", ValidTypes.DATA_TYPE_STRING, "value"); + ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment); + } + + @Test + public void testGenerateResourceDataForAssignments() throws Exception { + List assignments = new ArrayList(); + assignments.add(createResourceAssignment("name1", ValidTypes.DATA_TYPE_STRING, "string")); + assignments.add(createResourceAssignment("name2", ValidTypes.DATA_TYPE_BOOLEAN, true)); + assignments.add(createResourceAssignment("name3", ValidTypes.DATA_TYPE_INTEGER, 1)); + assignments.add(createResourceAssignment("name4", ValidTypes.DATA_TYPE_FLOAT, 1.1f)); + assignments.add(createResourceAssignment("name5", ValidTypes.DATA_TYPE_TIMESTAMP, "1523908097735")); + assignments.add(createResourceAssignment("name6", "", new HashMap())); + ResourceAssignmentUtils.generateResourceDataForAssignments(assignments); + } + + public void testResourceAssignmentForNullEmptyValues() throws Exception { + + ObjectMapper mapper = new ObjectMapper(); + JsonNode raContent = + mapper.readTree(new File("src/test/resources/service_templates/ra-content-with-mising-value.json")); + + List assignments = + mapper.readValue(raContent.toString(), new TypeReference>() {}); + + ResourceAssignmentUtils.generateResourceDataForAssignments(assignments); + } + + private ResourceAssignment createResourceAssignment(String name, String dataType, Object value) { + PropertyDefinition property = new PropertyDefinition(); + property.setType(dataType); + property.setValue(value); + property.setRequired(true); + ResourceAssignment ra = new ResourceAssignment(); + ra.setName(name); + ra.setProperty(property); + return ra; + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ServiceTemplateUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ServiceTemplateUtilsTest.java new file mode 100644 index 000000000..5364ae924 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/ServiceTemplateUtilsTest.java @@ -0,0 +1,77 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.config.model.utils; + +import java.util.HashMap; +import java.util.Map; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.config.model.data.ArtifactDefinition; +import org.onap.ccsdk.config.model.data.CapabilityAssignment; +import org.onap.ccsdk.config.model.data.NodeTemplate; + +public class ServiceTemplateUtilsTest { + + ServiceTemplateUtils serviceTemplateUtils = new ServiceTemplateUtils(); + + @Test + public void testPopulateVnfNodeProperties() { + NodeTemplate nodeTemplate = createNodeTemplate(); + + String nodeTemplateKey = "nodeTemplateKey"; + Map context = new HashMap(); + + Map result = + serviceTemplateUtils.populateVnfNodeProperties(nodeTemplateKey, nodeTemplate, context, null); + + Assert.assertTrue(result.size() > 0); + } + + @Test + public void testPopulateNodeTemplateArtifacts() { + String nodeTemplateKey = "nodeTemplateKey"; + NodeTemplate nodeTemplate = createNodeTemplate(); + Map context = new HashMap(); + + Map result = + serviceTemplateUtils.populateNodeTemplateArtifacts(nodeTemplateKey, nodeTemplate, context); + + Assert.assertTrue(result.size() > 0); + } + + private NodeTemplate createNodeTemplate() { + NodeTemplate nodeTemplate = new NodeTemplate(); + Map properties = new HashMap(); + properties.put("prop1", "value"); + CapabilityAssignment capabilityAssignment = new CapabilityAssignment(); + capabilityAssignment.setProperties(properties); + Map capabilities = new HashMap(); + capabilities.put("key", capabilityAssignment); + nodeTemplate.setCapabilities(capabilities); + + ArtifactDefinition artifactDefinition = new ArtifactDefinition(); + artifactDefinition.setFile("file"); + artifactDefinition.setDeployPath("deployPath"); + artifactDefinition.setContent("content"); + Map artifacts = new HashMap(); + artifacts.put("artifactName1", artifactDefinition); + nodeTemplate.setArtifacts(artifacts); + + return nodeTemplate; + } +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/TransformationUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/TransformationUtilsTest.java new file mode 100644 index 000000000..ca57e5fab --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/utils/TransformationUtilsTest.java @@ -0,0 +1,90 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.config.model.utils; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import java.util.HashMap; +import java.util.Map; +import org.junit.Test; +import com.fasterxml.jackson.databind.JsonNode; + +public class TransformationUtilsTest { + + @Test + public void testGetJson() { + Map configparameters = new HashMap(); + configparameters.put("key", "value"); + String json = TransformationUtils.getJson(configparameters); + assertTrue("{\"key\":\"value\"}".equals(json)); + } + + @Test + public void testGetJsonNodeForString() { + String content = "{\"key\":\"value\"}"; + JsonNode jsonNodeForString = TransformationUtils.getJsonNodeForString(content); + assertNotNull(jsonNodeForString); + } + + @Test + public void testGetMapfromJson() { + String content = "{\"key\":\"value\"}"; + Map mapfromJson = TransformationUtils.getMapfromJson(content); + assertTrue(mapfromJson.size() == 1); + assertTrue("value".equals(mapfromJson.get("key"))); + } + + @Test + public void testGetMapfromJsonString() { + String content = "{\"key\":\"value\"}"; + Map mapfromJson = TransformationUtils.getMapfromJsonString(content); + assertTrue(mapfromJson.size() == 1); + assertTrue("value".equals(mapfromJson.get("key"))); + } + + @Test + public void testConvertJson2RootProperties() throws Exception { + Map context = new HashMap(); + String jsonContent = "{\"key\":\"value\"}"; + Map convertJson2RootProperties = + TransformationUtils.convertJson2RootProperties(context, jsonContent); + assertTrue(convertJson2RootProperties.size() == 1); + assertTrue("value".equals(convertJson2RootProperties.get("key"))); + } + + @SuppressWarnings("unchecked") + @Test + public void testGetJsonNodeAndTreeToValueAndConvertJson2Properties() throws Exception { + Map configparameters = new HashMap(); + configparameters.put("key", "value"); + JsonNode jsonNode = TransformationUtils.getJsonNode(configparameters); + assertNotNull(jsonNode); + + Map result = TransformationUtils.treeToValue(jsonNode, HashMap.class); + assertTrue("value".equals(result.get("key"))); + + result = TransformationUtils.convertJson2Properties(null, jsonNode, null); + assertTrue("value".equals(result.get("key"))); + } + + @Test + public void testGetJsonSchema() { + String jsonSchema = TransformationUtils.getJsonSchema(String.class); + assertNotNull(jsonSchema); + } +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/validator/ServiceTemplateValidationTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/validator/ServiceTemplateValidationTest.java new file mode 100644 index 000000000..5776b51a7 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/model/validator/ServiceTemplateValidationTest.java @@ -0,0 +1,51 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.config.model.validator; + +import java.nio.charset.Charset; +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class ServiceTemplateValidationTest { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ServiceTemplateValidationTest.class); + + @Test + public void validateServiceTemplate() { + try { + logger.info(" **************** Validating Default *****************"); + String serviceTemplateContent = IOUtils.toString(ServiceTemplateValidationTest.class.getClassLoader() + .getResourceAsStream("service_templates/default.json"), Charset.defaultCharset()); + ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator(); + serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent); + logger.info(" **************** Reqource Assignment *****************"); + serviceTemplateContent = IOUtils.toString(ServiceTemplateValidationTest.class.getClassLoader() + .getResourceAsStream("service_templates/resource_assignment.json"), Charset.defaultCharset()); + serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent); + logger.info(" **************** Activate Netconf *****************"); + serviceTemplateContent = IOUtils.toString(ServiceTemplateValidationTest.class.getClassLoader() + .getResourceAsStream("service_templates/download_config.json"), Charset.defaultCharset()); + serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent); + } catch (Exception e) { + e.printStackTrace(); + } + + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ComponentNodeTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ComponentNodeTest.java new file mode 100644 index 000000000..d73a622c6 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ComponentNodeTest.java @@ -0,0 +1,140 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.config.params.service; + +import static org.mockito.Matchers.any; +import java.io.File; +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.sling.testing.mock.osgi.MockOsgi; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; +import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.config.model.ConfigModelConstant; +import org.onap.ccsdk.config.model.service.ComponentNodeDelegate; +import org.onap.ccsdk.config.model.service.ComponentNodeServiceImpl; +import org.onap.ccsdk.config.model.service.ConfigModelService; +import org.onap.ccsdk.config.model.service.ConfigModelServiceImpl; +import org.onap.ccsdk.config.model.utils.TransformationUtils; +import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.osgi.framework.BundleContext; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class ComponentNodeTest { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ComponentNodeTest.class); + @Mock + private ConfigResourceService configResourceService; + + @Mock + private ConfigRestAdaptorService configRestAdaptorService; + + BundleContext bundleContext = MockOsgi.newBundleContext(); + + @Before + public void before() { + MockitoAnnotations.initMocks(this); + + MockComponentNode mockSvcLogicPlugin = new MockComponentNode(); + bundleContext.registerService(MockComponentNode.class, mockSvcLogicPlugin, null); + + try { + Mockito.doAnswer(new Answer() { + @Override + public Void answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + if (args != null) { + logger.trace("Transaction info " + Arrays.asList(args)); + } + return null; + } + }).when(configResourceService).save(any(TransactionLog.class)); + } catch (SvcLogicException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @After + public void after() { + + } + + @Test + public void testProcess() { + + try { + String serviceTemplateContent = FileUtils.readFileToString( + new File("src/test/resources/componentnode/default.json"), Charset.defaultCharset()); + ConfigModelService configModelService = new ConfigModelServiceImpl(configRestAdaptorService); + + Map map = new HashMap<>(); + configModelService.convertServiceTemplate2Properties(serviceTemplateContent, map); + + SvcLogicContext ctx = new SvcLogicContext(); + map.forEach((name, value) -> { + if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(value)) { + ctx.setAttribute(name, value); + } + }); + ctx.setAttribute("vnf-id", "1234"); + + ComponentNodeServiceImpl componentNodeService = + new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); + + ComponentNodeDelegate componentNodeDelegate = new ComponentNodeDelegate(componentNodeService); + Map inParams = new HashMap<>(); + inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "generate-configuration"); + + componentNodeDelegate.process(inParams, ctx); + TransformationUtils.printMap(inParams); + + } catch (Exception e) { + e.printStackTrace(); + } + + } + + @Test(expected = SvcLogicException.class) + public void testFailure() throws Exception { + ComponentNodeServiceImpl componentNodeService = + new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); + ComponentNodeDelegate componentNodeDelegate = new ComponentNodeDelegate(componentNodeService); + + Map inParams = new HashMap(); + inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "generate-configuration"); + SvcLogicContext ctx = new SvcLogicContext(); + componentNodeDelegate.process(inParams, ctx); + } +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ConfigModelServiceTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ConfigModelServiceTest.java new file mode 100644 index 000000000..77972a63e --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ConfigModelServiceTest.java @@ -0,0 +1,219 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.config.params.service; + +import static org.junit.Assert.fail; +import java.io.File; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.ccsdk.config.model.ConfigModelConstant; +import org.onap.ccsdk.config.model.data.ServiceTemplate; +import org.onap.ccsdk.config.model.domain.ConfigModel; +import org.onap.ccsdk.config.model.domain.ConfigModelContent; +import org.onap.ccsdk.config.model.service.ConfigModelService; +import org.onap.ccsdk.config.model.service.ConfigModelServiceImpl; +import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class ConfigModelServiceTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigModelServiceTest.class); + + @Mock + private ConfigRestAdaptorService configRestAdaptorService; + + @Test + public void testConfigAssignmentInputOutputParams() throws Exception { + + String fileContent = FileUtils.readFileToString( + new File("src/test/resources/service_templates/resource_assignment.json"), Charset.defaultCharset()); + + Map context = new HashMap<>(); + ConfigModelServiceImpl configModelServiceImpl = new ConfigModelServiceImpl(configRestAdaptorService); + context = configModelServiceImpl.convertServiceTemplate2Properties(fileContent, context); + + Assert.assertNotNull("Failed to Prepare Context : ", context); + + context.put("request-id", "12345"); + context.put("vnf-id", "vnf12345"); + + Map inparams = new HashMap(); + inparams.put(ConfigModelConstant.PROPERTY_SELECTOR, "resource-assignment"); + + SvcLogicContext inputContext = new SvcLogicContext(); + context.forEach((name, value) -> { + inputContext.setAttribute(name, value); + }); + + // TransformationUtils.printProperty(inputContext.toProperties()); + + configModelServiceImpl.assignInParamsFromModel(inputContext, inparams); + Assert.assertNotNull("In Param is Null : ", inparams); + Assert.assertNotNull("Failed to get entity-id in Inparms : ", inparams.get("resource-id")); + Assert.assertEquals("Failed to get entity-id vlaue in Inparms ", String.valueOf("vnf12345"), + inparams.get("resource-id")); + Assert.assertNotNull("Failed to get request-id in Inparms : ", inparams.get("request-id")); + Assert.assertEquals("Failed to get request-id vlaue in Inparms ", String.valueOf("12345"), + inparams.get("request-id")); + + configModelServiceImpl.assignOutParamsFromModel(inputContext, inparams); + logger.info("*************** Output Params *************"); + // TransformationUtils.printProperty(inputContext.toProperties()); + + } + + @Test + public void testConvertServiceTemplate2PropertiesComplex() throws Exception { + String fileContent = FileUtils.readFileToString( + new File("src/test/resources/service_templates/resource_assignment.json"), Charset.defaultCharset()); + + Map context = new HashMap<>(); + context.put("host-password", "1234"); + context.put("host-ip-address", "[123.23.34.45, 123.23.34.45]"); + + ConfigModelServiceImpl configModelServiceImpl = new ConfigModelServiceImpl(configRestAdaptorService); + configModelServiceImpl.convertServiceTemplate2Properties(fileContent, context); + + // TransformationUtils.printMap(context); + + Map inparams = new HashMap(); + inparams.put(ConfigModelConstant.PROPERTY_SELECTOR, "resource-assignment"); + logger.info("Before Input Result: " + inparams); + + SvcLogicContext inputContext = new SvcLogicContext(); + context.forEach((name, value) -> { + inputContext.setAttribute(name, value); + }); + + configModelServiceImpl.assignInParamsFromModel(inputContext, inparams); + logger.info("----------Input Result: " + inparams); + + inputContext.setAttribute("assignment-params", "default-assigned"); + configModelServiceImpl.assignOutParamsFromModel(inputContext, inparams); + + // TransformationUtils.printProperty(inputContext.toProperties()); + + } + + @Test + public void testGetNodeTemplateContent() throws Exception { + String templateContent = "{\"id\":\"id\"}"; + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + templateContent + ".content", + templateContent); + + ConfigModelServiceImpl configModelServiceImpl = new ConfigModelServiceImpl(configRestAdaptorService); + String content = configModelServiceImpl.getNodeTemplateContent(context, templateContent); + + Assert.assertEquals(content, templateContent); + } + + @Test + public void testGetNodeTemplateMapping() throws Exception { + String templateContent = "{\"capabilities\":{\"mapping\":{\"properties\":{\"mapping\":[\"test\"]}}}}"; + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute(ConfigModelConstant.PROPERTY_NODE_TEMPLATES_DOT + templateContent, templateContent); + + ConfigModelServiceImpl configModelServiceImpl = new ConfigModelServiceImpl(configRestAdaptorService); + configModelServiceImpl.getNodeTemplateMapping(context, templateContent); + // Assert.assertEquals(content, templateContent); + } + + @Test + public void testValidateServiceTemplate() throws Exception { + ConfigModelServiceImpl configModelServiceImpl = new ConfigModelServiceImpl(configRestAdaptorService); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + + try { + configModelServiceImpl.validateServiceTemplate(null); + fail("Should have thrown exception"); + } catch (SvcLogicException e) { + } + + try { + configModelServiceImpl.validateServiceTemplate(serviceTemplate); + fail("Should have thrown exception"); + } catch (SvcLogicException e) { + } + + Map metadata = new HashMap(); + metadata.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_AUTHOR, "author"); + metadata.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "name"); + metadata.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "version"); + serviceTemplate.setMetadata(metadata); + + Assert.assertTrue(configModelServiceImpl.validateServiceTemplate(serviceTemplate)); + } + + @Test + public void testPrepareContext() throws Exception { + Mockito.when(configRestAdaptorService.getResource(Matchers.anyString(), Matchers.anyString(), Matchers.any())) + .thenReturn(createConfigModel()); + + String input = "{\"action-name\": \"resource-assignment-action\"}"; + ConfigModelService configModelService = new ConfigModelServiceImpl(configRestAdaptorService); + + Map ctx = + configModelService.prepareContext(null, input, "serviceTemplateName", "serviceTemplateVersion"); + Assert.assertEquals("resource-assignment-action", ctx.get(ConfigModelConstant.PROPERTY_ACTION_NAME)); + + ctx = configModelService.prepareContext(null, input, "{}"); + Assert.assertEquals("resource-assignment-action", ctx.get(ConfigModelConstant.PROPERTY_ACTION_NAME)); + } + + @Test + public void testConvertServiceTemplate2Properties() throws Exception { + Map metadata = new HashMap(); + metadata.put("key", "value"); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + serviceTemplate.setMetadata(metadata); + Map context = new HashMap(); + + ConfigModelService configModelService = new ConfigModelServiceImpl(configRestAdaptorService); + Map ctx = configModelService.convertServiceTemplate2Properties(serviceTemplate, context); + + Assert.assertEquals("value", ctx.get("key")); + } + + private ConfigModel createConfigModel() { + ConfigModel configModel = new ConfigModel(); + List configModelContents = new ArrayList(); + ConfigModelContent configModelContent = new ConfigModelContent(); + configModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON); + configModelContent.setContent("{\"description\": \"description\"}"); + configModelContents.add(configModelContent); + configModel.setConfigModelContents(configModelContents); + configModel.setPublished("Y"); + return configModel; + } +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ExpressionUtilsTest.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ExpressionUtilsTest.java new file mode 100644 index 000000000..e72b0531f --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ExpressionUtilsTest.java @@ -0,0 +1,76 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.config.params.service; + +import java.io.File; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.junit.Test; +import org.onap.ccsdk.config.model.utils.ExpressionUtils; +import org.onap.ccsdk.config.model.utils.TransformationUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class ExpressionUtilsTest { + private static EELFLogger logger = EELFManager.getInstance().getLogger(ExpressionUtilsTest.class); + + @Test + public void testProcessJsonExpression() throws Exception { + String fileContent = FileUtils.readFileToString(new File("src/test/resources/properties/default.json"), + Charset.defaultCharset()); + + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("host-password", "1234"); + context.setAttribute("host-ip-address", "[\"123.23.34.45\", \"123.23.34.45\"]"); + context.setAttribute("loopback-default", "[\"Sample\", \"Brinda\"]"); + + Map inparams = new HashMap(); + ExpressionUtils jsonExpressionUtils = new ExpressionUtils(context, inparams); + ObjectMapper mapper = new ObjectMapper(); + JsonNode rootArray = mapper.readTree(fileContent); + jsonExpressionUtils.processJsonExpression(rootArray); + + } + + @Test + public void testJson2Property() throws Exception { + String fileContent = FileUtils.readFileToString(new File("src/test/resources/properties/convert.json"), + Charset.defaultCharset()); + + List blockKeys = new ArrayList(); + blockKeys.add( + "interfaces.ResourceAssignmentService.operations.getResourceAssignment.inputs.assignment-mappings"); + blockKeys.add("interfaces.ResourceAssignmentService.operations.getResourceAssignment.outputs"); + blockKeys.add("type"); + + Map workflowMap = new HashMap<>(); + Map propertyMap = + TransformationUtils.convertJson2Properties(workflowMap, fileContent, blockKeys); + + TransformationUtils.printMap(propertyMap); + + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/MockComponentNode.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/MockComponentNode.java new file mode 100644 index 000000000..00260c9e3 --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/MockComponentNode.java @@ -0,0 +1,62 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.config.params.service; + +import java.util.Map; +import org.onap.ccsdk.config.model.service.ComponentNode; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class MockComponentNode implements ComponentNode { + private static EELFLogger logger = EELFManager.getInstance().getLogger(MockComponentNode.class); + + @Override + public Boolean preCondition(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + logger.info("Received preCondition "); + componentContext.put("test-key", "test"); + return true; + } + + @Override + public void process(Map inParams, SvcLogicContext ctx) throws SvcLogicException { + + } + + @Override + public void process(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + logger.info("Received Request " + componentContext); + } + + @Override + public void preProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + logger.info("Received preProcess "); + + } + + @Override + public void postProcess(Map inParams, SvcLogicContext ctx, Map componentContext) + throws SvcLogicException { + logger.info("Received postProcess "); + } + +} diff --git a/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ServiceTemplateCreateUtils.java b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ServiceTemplateCreateUtils.java new file mode 100644 index 000000000..6bfa9033e --- /dev/null +++ b/blueprints-processor/plugin/model-provider/src/test/java/org/onap/ccsdk/config/params/service/ServiceTemplateCreateUtils.java @@ -0,0 +1,295 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.config.params.service; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.config.model.ConfigModelConstant; +import org.onap.ccsdk.config.model.data.DataType; +import org.onap.ccsdk.config.model.data.NodeTemplate; +import org.onap.ccsdk.config.model.data.NodeType; +import org.onap.ccsdk.config.model.data.ServiceTemplate; +import org.onap.ccsdk.config.model.data.TopologyTemplate; +import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.config.model.utils.TransformationUtils; + +public class ServiceTemplateCreateUtils { + + public void createNodeTypes(String serviceTemplateFileName) throws IOException { + if (StringUtils.isNotBlank(serviceTemplateFileName)) { + String fileContent = + FileUtils.readFileToString(new File(serviceTemplateFileName), Charset.defaultCharset()); + if (StringUtils.isNotBlank(fileContent)) { + // System.out.println("NodeTypeCreateUtils.createNodeTypes()" +fileContent ); + ServiceTemplate serviceTemplate = TransformationUtils.readValue(fileContent, ServiceTemplate.class); + + String formattedServiceTemplateContent = TransformationUtils.getJson(serviceTemplate, true); + + FileUtils.writeStringToFile(new File("src/test/resources/service_templates/_default.json"), + formattedServiceTemplateContent, Charset.defaultCharset()); + + createNetconfdownloadNodeTemplate(serviceTemplate); + createRestconfdownloadNodeTemplate(serviceTemplate); + // createResourceAssignmentNodeTemplate(serviceTemplate); + createVrrNodeTemplate(serviceTemplate); + createDictionarySchema(); + + } + } + } + + public void createNodeTypes(ServiceTemplate serviceTemplate) throws IOException { + + if (serviceTemplate != null && serviceTemplate.getNodeTypes() != null) { + serviceTemplate.getNodeTypes().forEach((nodeTypeKey, node_types) -> { + + if (node_types != null && StringUtils.isNotBlank(node_types.getDerivedFrom())) { + + try { + String fileName = "src/test/resources/node_types/"; + if (ConfigModelConstant.MODEL_TYPE_NODE_VNF.equalsIgnoreCase(node_types.getDerivedFrom())) { + fileName = fileName + "vnf/" + nodeTypeKey + ".json"; + } + if (ConfigModelConstant.MODEL_TYPE_NODE_DG.equalsIgnoreCase(node_types.getDerivedFrom())) { + fileName = fileName + "dg/" + nodeTypeKey + ".json"; + } + if (ConfigModelConstant.MODEL_TYPE_NODE_COMPONENT + .equalsIgnoreCase(node_types.getDerivedFrom())) { + fileName = fileName + "component/" + nodeTypeKey + ".json"; + } + String content = TransformationUtils.getJson(node_types, true); + FileUtils.write(new File(fileName), content, Charset.defaultCharset()); + } catch (IOException e) { + e.printStackTrace(); + } + + } + System.out.println("NodeTypeCreateUtils.createNodeTypes()" + nodeTypeKey); + }); + } + + } + + public void createNetconfdownloadNodeTemplate(ServiceTemplate serviceTemplate) throws IOException { + if (serviceTemplate != null) { + ServiceTemplate workingServiceTemplate = new ServiceTemplate(); + workingServiceTemplate.setMetadata(serviceTemplate.getMetadata()); + + Map data_types = new HashMap(); + data_types.put("datatype-property", serviceTemplate.getDataTypes().get("datatype-property")); + data_types.put("datatype-resource-assignment", + serviceTemplate.getDataTypes().get("datatype-resource-assignment")); + workingServiceTemplate.setDataTypes(data_types); + + TopologyTemplate topology_template = new TopologyTemplate(); + Map node_templates = new HashMap(); + + Map node_Templates = serviceTemplate.getTopologyTemplate().getNodeTemplates(); + + node_templates.put("activate-action", node_Templates.get("activate-action")); + node_templates.put("base-config-template", node_Templates.get("base-config-template")); + node_templates.put("vrr-netconf-device", node_Templates.get("vrr-netconf-device")); + node_templates.put("get-netconf-config", node_Templates.get("get-netconf-config")); + node_templates.put("edit-netconf-config", node_Templates.get("edit-netconf-config")); + node_templates.put("transaction-netconf-baseconfig", node_Templates.get("transaction-netconf-baseconfig")); + + topology_template.setNodeTemplates(node_templates); + topology_template.setInputs(serviceTemplate.getTopologyTemplate().getInputs()); + + Map node_types = new HashMap(); + node_types.put("dg-activate-netconf", serviceTemplate.getNodeTypes().get("dg-activate-netconf")); + node_types.put("artifact-config-template", serviceTemplate.getNodeTypes().get("artifact-config-template")); + node_types.put("component-transaction-netconf", + serviceTemplate.getNodeTypes().get("component-transaction-netconf")); + node_types.put("component-netconf-edit", serviceTemplate.getNodeTypes().get("component-netconf-edit")); + node_types.put("component-netconf-get", serviceTemplate.getNodeTypes().get("component-netconf-get")); + node_types.put("vnf-netconf-device", serviceTemplate.getNodeTypes().get("vnf-netconf-device")); + + workingServiceTemplate.setNodeTypes(node_types); + workingServiceTemplate.setTopologyTemplate(topology_template); + + String workingServiceTemplateContent = TransformationUtils.getJson(workingServiceTemplate, true); + + FileUtils.writeStringToFile(new File("src/test/resources/service_templates/download_config.json"), + workingServiceTemplateContent, Charset.defaultCharset()); + + File lcmFile = new File( + "../../../adaptors/netconf-adaptor/provider/src/test/resources/service_templates/download_config.json"); + FileUtils.writeStringToFile(lcmFile, workingServiceTemplateContent, Charset.defaultCharset()); + + } + } + + public void createRestconfdownloadNodeTemplate(ServiceTemplate serviceTemplate) throws IOException { + if (serviceTemplate != null) { + ServiceTemplate workingServiceTemplate = new ServiceTemplate(); + workingServiceTemplate.setMetadata(serviceTemplate.getMetadata()); + + Map data_types = new HashMap(); + data_types.put("datatype-property", serviceTemplate.getDataTypes().get("datatype-property")); + data_types.put("datatype-resource-assignment", + serviceTemplate.getDataTypes().get("datatype-resource-assignment")); + workingServiceTemplate.setDataTypes(data_types); + + TopologyTemplate topology_template = new TopologyTemplate(); + Map node_templates = new HashMap(); + + Map node_Templates = serviceTemplate.getTopologyTemplate().getNodeTemplates(); + node_templates.put("activate-restconf-action", node_Templates.get("activate-restconf-action")); + node_templates.put("base-config-template", node_Templates.get("base-config-template")); + node_templates.put("vrr-restconf-device", node_Templates.get("vrr-restconf-device")); + node_templates.put("edit-restconf-config", node_Templates.get("edit-restconf-config")); + node_templates.put("transaction-restconf-baseconfig", + node_Templates.get("transaction-restconf-baseconfig")); + + topology_template.setNodeTemplates(node_templates); + topology_template.setInputs(serviceTemplate.getTopologyTemplate().getInputs()); + + Map node_types = new HashMap(); + node_types.put("dg-activate-restconf", serviceTemplate.getNodeTypes().get("dg-activate-restconf")); + node_types.put("artifact-config-template", serviceTemplate.getNodeTypes().get("artifact-config-template")); + node_types.put("component-transaction-restconf", + serviceTemplate.getNodeTypes().get("component-transaction-restconf")); + node_types.put("component-restconf", serviceTemplate.getNodeTypes().get("component-restconf")); + node_types.put("vnf-restconf-device", serviceTemplate.getNodeTypes().get("vnf-restconf-device")); + + workingServiceTemplate.setNodeTypes(node_types); + workingServiceTemplate.setTopologyTemplate(topology_template); + + String workingServiceTemplateContent = TransformationUtils.getJson(workingServiceTemplate, true); + + FileUtils.writeStringToFile(new File("src/test/resources/service_templates/restconf_download_config.json"), + workingServiceTemplateContent, Charset.defaultCharset()); + + File lcmFile = new File( + "../../../adaptors/netconf-adaptor/provider/src/test/resources/service_templates/restconf_download_config.json"); + FileUtils.writeStringToFile(lcmFile, workingServiceTemplateContent, Charset.defaultCharset()); + + } + + } + + public void createResourceAssignmentNodeTemplate(ServiceTemplate serviceTemplate) throws IOException { + if (serviceTemplate != null) { + ServiceTemplate workingServiceTemplate = new ServiceTemplate(); + workingServiceTemplate.setMetadata(serviceTemplate.getMetadata()); + + Map data_types = new HashMap(); + data_types.put("datatype-property", serviceTemplate.getDataTypes().get("datatype-property")); + data_types.put("datatype-resource-assignment", + serviceTemplate.getDataTypes().get("datatype-resource-assignment")); + + workingServiceTemplate.setDataTypes(data_types); + + TopologyTemplate topology_template = new TopologyTemplate(); + Map node_templates = new HashMap(); + + Map node_Templates = serviceTemplate.getTopologyTemplate().getNodeTemplates(); + + node_templates.put("base-config-template", node_Templates.get("base-config-template")); + node_templates.put("licence-template", node_Templates.get("licence-template")); + + node_templates.put("resource-assignment-action", node_Templates.get("resource-assignment-action")); + node_templates.put("resource-assignment", node_Templates.get("resource-assignment")); + + topology_template.setNodeTemplates(node_templates); + topology_template.setInputs(serviceTemplate.getTopologyTemplate().getInputs()); + + Map node_types = new HashMap(); + node_types.put("artifact-config-template", serviceTemplate.getNodeTypes().get("artifact-config-template")); + node_types.put("dg-resource-assignment", serviceTemplate.getNodeTypes().get("dg-resource-assignment")); + node_types.put("component-resource-assignment", + serviceTemplate.getNodeTypes().get("component-resource-assignment")); + + workingServiceTemplate.setNodeTypes(node_types); + workingServiceTemplate.setTopologyTemplate(topology_template); + + String workingServiceTemplateConmtent = TransformationUtils.getJson(workingServiceTemplate, true); + + FileUtils.writeStringToFile(new File("src/test/resources/service_templates/resource_assignment.json"), + workingServiceTemplateConmtent, Charset.defaultCharset()); + + File lcmFile = new File( + "../../../northbound/selfservice-api/provider/src/test/resources/service_templates/resource_assignment.json"); + FileUtils.writeStringToFile(lcmFile, workingServiceTemplateConmtent, Charset.defaultCharset()); + + File resourceAssignmetFile = new File( + "../../../plugin/assignment/provider/src/test/resources/service_templates/resource_assignment.json"); + FileUtils.writeStringToFile(resourceAssignmetFile, workingServiceTemplateConmtent, + Charset.defaultCharset()); + + System.out.println("NodeTypeCreateUtils.createNodeTemplate() :" + workingServiceTemplateConmtent); + } + + } + + public void createVrrNodeTemplate(ServiceTemplate serviceTemplate) throws IOException { + if (serviceTemplate != null) { + ServiceTemplate workingServiceTemplate = new ServiceTemplate(); + workingServiceTemplate.setMetadata(serviceTemplate.getMetadata()); + + TopologyTemplate topology_template = new TopologyTemplate(); + Map node_templates = new HashMap(); + + Map node_Templates = serviceTemplate.getTopologyTemplate().getNodeTemplates(); + + node_templates.put("resource-assignment-action", node_Templates.get("resource-assignment-action")); + node_templates.put("resource-assignment", node_Templates.get("resource-assignment")); + + node_templates.put("activate-action", node_Templates.get("activate-action")); + node_templates.put("base-config-template", node_Templates.get("base-config-template")); + node_templates.put("licence-template", node_Templates.get("licence-template")); + node_templates.put("vrr-netconf-device", node_Templates.get("vrr-netconf-device")); + node_templates.put("get-netconf-config", node_Templates.get("get-netconf-config")); + node_templates.put("edit-netconf-config", node_Templates.get("edit-netconf-config")); + node_templates.put("transaction-netconf-baseconfig", node_Templates.get("transaction-netconf-baseconfig")); + + topology_template.setNodeTemplates(node_templates); + topology_template.setInputs(serviceTemplate.getTopologyTemplate().getInputs()); + + workingServiceTemplate.setTopologyTemplate(topology_template); + + String workingServiceTemplateContent = TransformationUtils.getJson(workingServiceTemplate, true); + + FileUtils.writeStringToFile(new File("src/test/resources/service_templates/vrr_config.json"), + workingServiceTemplateContent, Charset.defaultCharset()); + + } + } + + public void createDictionarySchema() throws IOException { + String schema = TransformationUtils.getJsonSchema(ResourceDefinition.class); + FileUtils.writeStringToFile(new File("src/test/resources/dictionary/dictionary_schema.json"), schema, + Charset.defaultCharset()); + } + + public static void main(String[] args) { + try { + ServiceTemplateCreateUtils utils = new ServiceTemplateCreateUtils(); + utils.createNodeTypes("src/test/resources/service_templates/default.json"); + } catch (Exception e) { + // TODO: handle exception + } + } + +} -- cgit 1.2.3-korg