From 48528e9da9e241c59f1628ffda9020a981f939f6 Mon Sep 17 00:00:00 2001 From: shiria Date: Thu, 20 Sep 2018 12:51:32 +0300 Subject: Add support of interface in TOSCA datatypes Move all interface functionality from DataModelUtil class to TOSCA datatype relevant class Change-Id: Ifea22b60e9a71fe024e87f9987a749e9d56aad82 Issue-ID: SDC-1781 Signed-off-by: shiria --- .../tosca/datatypes/model/NodeTemplateTest.java | 112 +++++++++++ .../sdc/tosca/datatypes/model/NodeTypeTest.java | 57 ++++++ .../datatypes/model/PropertyDefinitionTest.java | 44 +++++ .../tosca/datatypes/model/ServiceTemplateTest.java | 64 +++++++ .../sdc/tosca/services/DataModelCloneUtilTest.java | 206 +++++++++++++++++++++ .../nodeTemplate/interfaceDefinitionForUpd.yaml | 37 ++++ .../interfaceDefinitionForUpdResult.yaml | 43 +++++ .../nodeTemplate/normalizeInterfaceDefinition.yaml | 37 ++++ .../nodeType/normalizeInterfaceDefinition.yaml | 19 ++ .../serviceTemplate/normalizeInterfaceType.yaml | 11 ++ 10 files changed, 630 insertions(+) create mode 100644 common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/NodeTemplateTest.java create mode 100644 common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/NodeTypeTest.java create mode 100644 common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/PropertyDefinitionTest.java create mode 100644 common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplateTest.java create mode 100644 common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/services/DataModelCloneUtilTest.java create mode 100644 common/onap-tosca-datatype/src/test/resources/mock/nodeTemplate/interfaceDefinitionForUpd.yaml create mode 100644 common/onap-tosca-datatype/src/test/resources/mock/nodeTemplate/interfaceDefinitionForUpdResult.yaml create mode 100644 common/onap-tosca-datatype/src/test/resources/mock/nodeTemplate/normalizeInterfaceDefinition.yaml create mode 100644 common/onap-tosca-datatype/src/test/resources/mock/nodeType/normalizeInterfaceDefinition.yaml create mode 100644 common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/normalizeInterfaceType.yaml (limited to 'common/onap-tosca-datatype/src/test') diff --git a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/NodeTemplateTest.java b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/NodeTemplateTest.java new file mode 100644 index 0000000000..580a8ef976 --- /dev/null +++ b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/NodeTemplateTest.java @@ -0,0 +1,112 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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.sdc.tosca.datatypes.model; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil; + + +public class NodeTemplateTest { + + private static final String NODE_WITH_INTERFACE = "nodeWithInterface"; + public static final String INTERFACE_KEY = "newInterface"; + public static final String INPUT_KEY = "newInput"; + public static final String INPUT_VAL = "myVal"; + public static final String OPER_KEY = "oper1"; + public static final String MY_WF_JSON = "myWf.json"; + public static final String STANDARD_INTERFACE_KEY = "Standard"; + public static final String CREATE_OPER = "create"; + public static final String NORMALIZE_INTERFACE_DEFINITION = "/mock/nodeTemplate/normalizeInterfaceDefinition.yaml"; + public static final String INTERFACE_DEFINITION_FOR_UPD_RESULT = + "/mock/nodeTemplate/interfaceDefinitionForUpdResult.yaml"; + public static final String INTERFACE_DEFINITION_FOR_UPD = "/mock/nodeTemplate/interfaceDefinitionForUpd.yaml"; + + @Test + public void getNormalizeInterfacesTest() throws IOException { + ServiceTemplate serviceTemplateFromYaml = + getServiceTemplate(NORMALIZE_INTERFACE_DEFINITION); + NodeTemplate nodeTemplate = + serviceTemplateFromYaml.getTopology_template().getNode_templates().get(NODE_WITH_INTERFACE); + Map normalizeInterfaces = nodeTemplate.getNormalizeInterfaces(); + chkData(normalizeInterfaces); + + } + + @Test + public void addInterfacesTest() throws IOException { + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + ServiceTemplate expectedServiceTemplateFromYaml = getServiceTemplate(INTERFACE_DEFINITION_FOR_UPD_RESULT); + ServiceTemplate serviceTemplateForUpdate = getServiceTemplate(INTERFACE_DEFINITION_FOR_UPD); + NodeTemplate nodeTemplate = + serviceTemplateForUpdate.getTopology_template().getNode_templates().get(NODE_WITH_INTERFACE); + nodeTemplate.addInterface(INTERFACE_KEY, createInterfaceDefinitionTemplate()); + + String expectedServiceTemplate = toscaExtensionYamlUtil.objectToYaml(expectedServiceTemplateFromYaml); + String actualServiceTemplate = toscaExtensionYamlUtil.objectToYaml(serviceTemplateForUpdate); + Assert.assertEquals(expectedServiceTemplate, actualServiceTemplate); + } + + + private InterfaceDefinitionTemplate createInterfaceDefinitionTemplate() { + InterfaceDefinitionTemplate interfaceDefinitionTemplate = new InterfaceDefinitionTemplate(); + interfaceDefinitionTemplate.setInputs(new HashMap<>()); + interfaceDefinitionTemplate.getInputs().put(INPUT_KEY, INPUT_VAL); + interfaceDefinitionTemplate.addOperation(OPER_KEY, createOperationDefinitionTemplate()); + return interfaceDefinitionTemplate; + } + + private OperationDefinitionTemplate createOperationDefinitionTemplate() { + OperationDefinitionTemplate operationDefinitionTemplate = new OperationDefinitionTemplate(); + operationDefinitionTemplate.setImplementation(createImpl()); + return operationDefinitionTemplate; + + } + + private Implementation createImpl() { + Implementation implementation = new Implementation(); + implementation.setPrimary(MY_WF_JSON); + return implementation; + } + + protected InterfaceDefinitionTemplate chkData(Map normalizeInterfaces) { + Assert.assertNotNull(normalizeInterfaces); + InterfaceDefinitionTemplate interfaceDefinitionTemplate = normalizeInterfaces.get(STANDARD_INTERFACE_KEY); + Assert.assertNotNull(interfaceDefinitionTemplate); + Assert.assertNotNull(interfaceDefinitionTemplate.getInputs()); + Assert.assertEquals(1, interfaceDefinitionTemplate.getInputs().size()); + Assert.assertNotNull(interfaceDefinitionTemplate.getOperations()); + Assert.assertEquals(1, interfaceDefinitionTemplate.getOperations().size()); + OperationDefinitionTemplate createOperation = interfaceDefinitionTemplate.getOperations().get(CREATE_OPER); + Assert.assertNotNull(createOperation); + Assert.assertNotNull(createOperation.getInputs()); + return interfaceDefinitionTemplate; + } + + protected ServiceTemplate getServiceTemplate(String inputPath) throws IOException { + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(inputPath)) { + return toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); + } + } + +} \ No newline at end of file diff --git a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/NodeTypeTest.java b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/NodeTypeTest.java new file mode 100644 index 0000000000..1f0732d12f --- /dev/null +++ b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/NodeTypeTest.java @@ -0,0 +1,57 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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.sdc.tosca.datatypes.model; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import org.junit.Assert; +import org.junit.Test; +import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil; + + +public class NodeTypeTest { + + private static final String NODE_WITH_INTERFACE = "amdocs.nodes.nodeWithInterface"; + public static final String NORMALIZE_INTERFACE_DEFINITION = "/mock/nodeType/normalizeInterfaceDefinition.yaml"; + public static final String STANDARD_INTERFACE_DEF = "Standard"; + + @Test + public void getNormalizeInterfacesTest() throws IOException { + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + try (InputStream yamlFile = toscaExtensionYamlUtil.loadYamlFileIs(NORMALIZE_INTERFACE_DEFINITION)) { + + ServiceTemplate serviceTemplateFromYaml = + toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); + Map normalizeInterfacesNoEvent = + serviceTemplateFromYaml.getNode_types().get(NODE_WITH_INTERFACE).getNormalizeInterfaces(); + InterfaceDefinitionType interfaceDefinitionType = chkData(normalizeInterfacesNoEvent); + } + + } + + protected InterfaceDefinitionType chkData(Map normalizeInterfacesNoEvent) { + Assert.assertNotNull(normalizeInterfacesNoEvent); + InterfaceDefinitionType interfaceDefinitionType = normalizeInterfacesNoEvent.get(STANDARD_INTERFACE_DEF); + Assert.assertNotNull(interfaceDefinitionType); + Assert.assertNotNull(interfaceDefinitionType.getInputs()); + Assert.assertEquals(1, interfaceDefinitionType.getInputs().size()); + Assert.assertNotNull(interfaceDefinitionType.getOperations()); + Assert.assertEquals(1, interfaceDefinitionType.getOperations().size()); + return interfaceDefinitionType; + } +} diff --git a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/PropertyDefinitionTest.java b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/PropertyDefinitionTest.java new file mode 100644 index 0000000000..d8645bb750 --- /dev/null +++ b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/PropertyDefinitionTest.java @@ -0,0 +1,44 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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.sdc.tosca.datatypes.model; + +import java.util.ArrayList; +import org.junit.Assert; +import org.junit.Test; + +public class PropertyDefinitionTest { + + @Test + public void cloneTest() { + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setRequired(false); + propertyDefinition.setStatus(Status.DEPRECATED); + Constraint constraint = new Constraint(); + constraint.setEqual("123"); + ArrayList constraints = new ArrayList<>(); + constraints.add(constraint); + propertyDefinition.setConstraints(constraints); + + PropertyDefinition propertyDefinitionClone = propertyDefinition.clone(); + Assert.assertEquals(propertyDefinition.getRequired(), propertyDefinitionClone.getRequired()); + Assert.assertEquals(propertyDefinition.getStatus().getDisplayName(), + propertyDefinitionClone.getStatus().getDisplayName()); + Assert.assertEquals(propertyDefinition.getConstraints().get(0).getEqual(), + propertyDefinitionClone.getConstraints().get(0).getEqual()); + } + + +} \ No newline at end of file diff --git a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplateTest.java b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplateTest.java new file mode 100644 index 0000000000..1bea8477be --- /dev/null +++ b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/ServiceTemplateTest.java @@ -0,0 +1,64 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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.sdc.tosca.datatypes.model; + + +import java.io.IOException; + +import java.io.InputStream; +import java.util.Map; +import org.junit.Assert; +import org.junit.Test; +import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil; + +public class ServiceTemplateTest { + + private static final String INTERFACE_NO_OPER = "amdocs.interfaces.interfaceNoOper"; + private static final String LIFECYCLE_STANDARD = "tosca.interfaces.node.lifecycle.Standard"; + private static final String INTERFACE_WITH_OPER = "amdocs.interfaces.interfaceWithOper"; + public static final String NORMALIZE_INTERFACE_TYPE = "/mock/serviceTemplate/normalizeInterfaceType.yaml"; + public static final String NEW_OPER_1 = "newOper1"; + public static final String NEW_OPER_2 = "newOper2"; + + @Test + public void getNormalizeInterfaceTypesTest() throws IOException { + ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil(); + try (InputStream yamlFile = toscaExtensionYamlUtil + .loadYamlFileIs(NORMALIZE_INTERFACE_TYPE)) { + + ServiceTemplate serviceTemplateFromYaml = + toscaExtensionYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); + Map normalizeInterfaceTypes = serviceTemplateFromYaml.getNormalizeInterfaceTypes(); + Assert.assertNotNull(normalizeInterfaceTypes); + + InterfaceType interfaceNoOper = normalizeInterfaceTypes.get(INTERFACE_NO_OPER); + Assert.assertNotNull(interfaceNoOper); + Assert.assertEquals(LIFECYCLE_STANDARD, interfaceNoOper.getDerived_from()); + Assert.assertNull(interfaceNoOper.getOperations()); + + InterfaceType interfaceWithOper = normalizeInterfaceTypes.get(INTERFACE_WITH_OPER); + Assert.assertNotNull(interfaceWithOper); + Assert.assertEquals(LIFECYCLE_STANDARD, interfaceWithOper.getDerived_from()); + Assert.assertNotNull(interfaceWithOper.getOperations()); + Assert.assertEquals(2, interfaceWithOper.getOperations().size()); + Assert.assertNull(interfaceWithOper.getOperations().get(NEW_OPER_1)); + Assert.assertNotNull(interfaceWithOper.getOperations().get(NEW_OPER_2)); + Assert.assertNotNull(interfaceWithOper.getOperations().get(NEW_OPER_2).getDescription()); + } + + } +} \ No newline at end of file diff --git a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/services/DataModelCloneUtilTest.java b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/services/DataModelCloneUtilTest.java new file mode 100644 index 0000000000..c0637b6c47 --- /dev/null +++ b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/services/DataModelCloneUtilTest.java @@ -0,0 +1,206 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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.sdc.tosca.services; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.Assert; +import org.junit.Test; +import org.onap.sdc.tosca.datatypes.model.Constraint; +import org.onap.sdc.tosca.datatypes.model.Implementation; +import org.onap.sdc.tosca.datatypes.model.OperationDefinition; +import org.onap.sdc.tosca.datatypes.model.OperationDefinitionTemplate; +import org.onap.sdc.tosca.datatypes.model.OperationDefinitionType; +import org.onap.sdc.tosca.datatypes.model.PropertyDefinition; +import org.onap.sdc.tosca.datatypes.model.Status; + +public class DataModelCloneUtilTest { + + private static final String KEY1 = "Key1"; + private static final String VAL1 = "Val1"; + private static final String KEY2 = "Key2"; + private static final String VAL2 = "Val2"; + private static final String KEY3 = "Key3"; + private static final String DESC1 = "Desc1"; + private static final String DESC2 = "Desc2"; + private static final String PRIMARY1 = "primary1"; + private static final String PARAM1 = "param1"; + private static final String INPUT_KEY1 = "inKey1"; + private static final String PRIMARY2 = "primary2"; + private static final String PARAM2 = "param2"; + private static final String INPUT_KEY2 = "inKey2"; + + + @Test + public void cloneStringStringMapTest() { + Map originalMap = new HashMap<>(); + originalMap.put(KEY1, VAL1); + originalMap.put(KEY2, VAL2); + + Map cloneMap = DataModelCloneUtil.cloneStringStringMap(originalMap); + Assert.assertEquals(originalMap.size(), cloneMap.size()); + Assert.assertEquals(originalMap.get(KEY1), cloneMap.get(KEY1)); + Assert.assertEquals(originalMap.get(KEY2), cloneMap.get(KEY2)); + } + + + @Test + public void cloneStringObjectMapTest() { + Map originalMap = new HashMap<>(); + originalMap.put(KEY1, VAL1); + ArrayList list = new ArrayList<>(); + list.add(VAL1); + list.add(VAL2); + originalMap.put(KEY2, list); + HashMap map = new HashMap<>(); + map.put(KEY1, VAL1); + map.put(KEY2, VAL2); + originalMap.put(KEY3, map); + + Map cloneMap = DataModelCloneUtil.cloneStringObjectMap(originalMap); + Assert.assertEquals(originalMap.size(), cloneMap.size()); + Assert.assertEquals(originalMap.get(KEY1), cloneMap.get(KEY1)); + List originalListObj = (List) originalMap.get(KEY2); + List cloneListObj = (List) cloneMap.get(KEY2); + Assert.assertEquals(originalListObj.size(), cloneListObj.size()); + Assert.assertEquals(originalListObj.get(0), cloneListObj.get(0)); + Assert.assertEquals(originalListObj.get(1), cloneListObj.get(1)); + Map originalMapObj = (Map) originalMap.get(KEY3); + Map cloneMapObj = (Map) cloneMap.get(KEY3); + Assert.assertEquals(originalMapObj.size(), cloneMapObj.size()); + Assert.assertEquals(originalMapObj.get(KEY1), cloneMapObj.get(KEY1)); + Assert.assertEquals(originalMapObj.get(KEY2), cloneMapObj.get(KEY2)); + } + + + @Test + public void cloneStringOperationDefinitionMapsTest() { + OperationDefinition operationDefinition1 = createOperationDefinition(DESC1); + OperationDefinition operationDefinition2 = createOperationDefinition(DESC2); + + Map originalMap = new HashMap<>(); + originalMap.put(KEY1, operationDefinition1); + originalMap.put(KEY2, operationDefinition2); + + + Map cloneMap = DataModelCloneUtil.cloneStringOperationDefinitionMap(originalMap); + + Assert.assertEquals(originalMap.size(), cloneMap.size()); + Assert.assertEquals(originalMap.get(KEY1).getDescription(), cloneMap.get(KEY1).getDescription()); + Assert.assertEquals(originalMap.get(KEY2).getDescription(), cloneMap.get(KEY2).getDescription()); + + } + + private OperationDefinition createOperationDefinition(String desc) { + OperationDefinition operationDefinition = new OperationDefinition(); + operationDefinition.setDescription(desc); + return operationDefinition; + } + + @Test + public void cloneStringOperationDefinitionTemplateMapsTest() { + OperationDefinitionTemplate operationDefinitionTemp1 = + createOperationDefinitionTemplate(DESC1, PRIMARY1, PARAM1, INPUT_KEY1); + + OperationDefinitionTemplate operationDefinitionTemp2 = + createOperationDefinitionTemplate(DESC2, PRIMARY2, PARAM2, INPUT_KEY2); + + + Map originalMap = new HashMap<>(); + originalMap.put(KEY1, operationDefinitionTemp1); + originalMap.put(KEY2, operationDefinitionTemp2); + + + Map cloneMap = + DataModelCloneUtil.cloneStringOperationDefinitionMap(originalMap); + + Assert.assertEquals(originalMap.size(), cloneMap.size()); + Assert.assertEquals(originalMap.get(KEY1).getDescription(), cloneMap.get(KEY1).getDescription()); + Assert.assertEquals(originalMap.get(KEY2).getDescription(), cloneMap.get(KEY2).getDescription()); + Assert.assertEquals(originalMap.get(KEY1).getImplementation().getPrimary(), + cloneMap.get(KEY1).getImplementation().getPrimary()); + Assert.assertEquals(originalMap.get(KEY2).getInputs().get(INPUT_KEY2).toString(), + cloneMap.get(KEY2).getInputs().get(INPUT_KEY2).toString()); + + + } + + @Test + public void cloneStringOperationDefinitionTypeMapsTest() { + Map inputs = new HashMap<>(); + inputs.put(INPUT_KEY1, createPropertyDefinition()); + + OperationDefinitionType operationDefinitionType1 = createOperationDefinitionType(DESC1, PRIMARY1, inputs); + OperationDefinitionType operationDefinitionType2 = + createOperationDefinitionType(DESC2, PRIMARY2, DataModelCloneUtil.clonePropertyDefinitions(inputs)); + + Map originalMap = new HashMap<>(); + originalMap.put(KEY1, operationDefinitionType1); + originalMap.put(KEY2, operationDefinitionType2); + + Map cloneMap = + DataModelCloneUtil.cloneStringOperationDefinitionMap(originalMap); + + Assert.assertEquals(originalMap.size(), cloneMap.size()); + Assert.assertEquals(originalMap.get(KEY1).getDescription(), cloneMap.get(KEY1).getDescription()); + Assert.assertEquals(originalMap.get(KEY2).getDescription(), cloneMap.get(KEY2).getDescription()); + Assert.assertEquals(originalMap.get(KEY1).getImplementation(), cloneMap.get(KEY1).getImplementation()); + Assert.assertEquals(originalMap.get(KEY2).getInputs().get(INPUT_KEY1).getStatus().getDisplayName(), + cloneMap.get(DataModelCloneUtilTest.KEY2).getInputs().get(INPUT_KEY1).getStatus().getDisplayName()); + Assert.assertEquals(originalMap.get(KEY2).getInputs().get(INPUT_KEY1).getConstraints().get(0).getEqual(), + cloneMap.get(KEY2).getInputs().get(INPUT_KEY1).getConstraints().get(0).getEqual()); + } + + private PropertyDefinition createPropertyDefinition() { + PropertyDefinition propertyDefinition = new PropertyDefinition(); + propertyDefinition.setRequired(false); + propertyDefinition.setStatus(Status.UNSUPPORTED); + Constraint constraint = new Constraint(); + constraint.setEqual("1234"); + ArrayList constraints = new ArrayList<>(); + constraints.add(constraint); + propertyDefinition.setConstraints(constraints); + return propertyDefinition; + } + + private OperationDefinitionTemplate createOperationDefinitionTemplate(String desc, String primary, + String inputParameterName, String inputKey) { + OperationDefinitionTemplate operationDefinitionTemp = new OperationDefinitionTemplate(); + operationDefinitionTemp.setDescription(desc); + Implementation implementation = new Implementation(); + implementation.setPrimary(primary); + operationDefinitionTemp.setImplementation(implementation); + HashMap valueAssignment = new HashMap<>(); + valueAssignment.put("get_input", inputParameterName); + HashMap inputs = new HashMap<>(); + inputs.put(inputKey, valueAssignment); + operationDefinitionTemp.setInputs(inputs); + return operationDefinitionTemp; + } + + private OperationDefinitionType createOperationDefinitionType(String desc, String implementationValue, + Map inputs) { + OperationDefinitionType operationDefinitionType = new OperationDefinitionType(); + operationDefinitionType.setDescription(desc); + operationDefinitionType.setImplementation(implementationValue); + operationDefinitionType.setInputs(inputs); + return operationDefinitionType; + } + +} \ No newline at end of file diff --git a/common/onap-tosca-datatype/src/test/resources/mock/nodeTemplate/interfaceDefinitionForUpd.yaml b/common/onap-tosca-datatype/src/test/resources/mock/nodeTemplate/interfaceDefinitionForUpd.yaml new file mode 100644 index 0000000000..95b01e7d16 --- /dev/null +++ b/common/onap-tosca-datatype/src/test/resources/mock/nodeTemplate/interfaceDefinitionForUpd.yaml @@ -0,0 +1,37 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 + +node_types: + amdocs.nodes.nodeInterface: + derived_from: tosca.nodes.Root + properties: + prop1: + type: string + required: true + interfaces: + Standard: + type: tosca.interfaces.node.lifecycle.Standard + inputs: + url_path: + type: string + create: + inputs: + name: + type: string + +topology_template: + description: topology template descroption + node_templates: + nodeWithInterface: + type: amdocs.nodes.nodeInterface + properties: + prop1: abcd + interfaces: + Standard: + inputs: + url_path: { get_property: [ SELF, prop1 ] } + create: + implementation: + primary: Artifacts/Deployment/WORKFLOW/nodeCreateWorkFlow.json + inputs: + name: myName + last: ["a","b"] diff --git a/common/onap-tosca-datatype/src/test/resources/mock/nodeTemplate/interfaceDefinitionForUpdResult.yaml b/common/onap-tosca-datatype/src/test/resources/mock/nodeTemplate/interfaceDefinitionForUpdResult.yaml new file mode 100644 index 0000000000..2782a44a0b --- /dev/null +++ b/common/onap-tosca-datatype/src/test/resources/mock/nodeTemplate/interfaceDefinitionForUpdResult.yaml @@ -0,0 +1,43 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 + +node_types: + amdocs.nodes.nodeInterface: + derived_from: tosca.nodes.Root + properties: + prop1: + type: string + required: true + interfaces: + Standard: + type: tosca.interfaces.node.lifecycle.Standard + inputs: + url_path: + type: string + create: + inputs: + name: + type: string + +topology_template: + description: topology template descroption + node_templates: + nodeWithInterface: + type: amdocs.nodes.nodeInterface + properties: + prop1: abcd + interfaces: + Standard: + inputs: + url_path: { get_property: [ SELF, prop1 ] } + create: + implementation: + primary: Artifacts/Deployment/WORKFLOW/nodeCreateWorkFlow.json + inputs: + name: myName + last: ["a","b"] + newInterface: + inputs: + newInput: myVal + oper1: + implementation: + primary: myWf.json diff --git a/common/onap-tosca-datatype/src/test/resources/mock/nodeTemplate/normalizeInterfaceDefinition.yaml b/common/onap-tosca-datatype/src/test/resources/mock/nodeTemplate/normalizeInterfaceDefinition.yaml new file mode 100644 index 0000000000..5f91e1e39f --- /dev/null +++ b/common/onap-tosca-datatype/src/test/resources/mock/nodeTemplate/normalizeInterfaceDefinition.yaml @@ -0,0 +1,37 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 + +node_types: + amdocs.nodes.nodeInterface: + derived_from: tosca.nodes.Root + properties: + prop1: + type: string + required: true + interfaces: + Standard: + type: tosca.interfaces.node.lifecycle.Standard + inputs: + url_path: + type: string + create: + inputs: + name: + type: string + +topology_template: + description: topology template descroption + node_templates: + nodeWithInterface: + type: amdocs.nodes.nodeInterface + properties: + prop1: abcd + interfaces: + Standard: + inputs: + url_path: { get_property: [ SELF, prop1 ] } + create: + implementation: + primary: Artifacts/Deployment/WORKFLOW/nodeCreateWorkFlow.json + inputs: + name: myName + last: ["a","b"] \ No newline at end of file diff --git a/common/onap-tosca-datatype/src/test/resources/mock/nodeType/normalizeInterfaceDefinition.yaml b/common/onap-tosca-datatype/src/test/resources/mock/nodeType/normalizeInterfaceDefinition.yaml new file mode 100644 index 0000000000..c5997c8762 --- /dev/null +++ b/common/onap-tosca-datatype/src/test/resources/mock/nodeType/normalizeInterfaceDefinition.yaml @@ -0,0 +1,19 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 + +node_types: + amdocs.nodes.nodeWithInterface: + derived_from: tosca.nodes.Root + properties: + prop1: + type: string + required: true + interfaces: + Standard: + type: tosca.interfaces.node.lifecycle.Standard + inputs: + url_path: + type: string + create: + inputs: + name: + type: string \ No newline at end of file diff --git a/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/normalizeInterfaceType.yaml b/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/normalizeInterfaceType.yaml new file mode 100644 index 0000000000..360f52cb6e --- /dev/null +++ b/common/onap-tosca-datatype/src/test/resources/mock/serviceTemplate/normalizeInterfaceType.yaml @@ -0,0 +1,11 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 + +interface_types: + amdocs.interfaces.interfaceNoOper: + derived_from: tosca.interfaces.node.lifecycle.Standard + + amdocs.interfaces.interfaceWithOper: + derived_from: tosca.interfaces.node.lifecycle.Standard + newOper1: + newOper2: + description: new operation2 \ No newline at end of file -- cgit 1.2.3-korg