From 1f50c72eb501af42c61c4ddbb011302a6290afdb Mon Sep 17 00:00:00 2001 From: shiria Date: Wed, 10 Oct 2018 15:16:15 +0300 Subject: Fix Policy type and Policy definition Fix policy according to TOSCA spec Change-Id: I4e3da732666dd52895c4458f0cbd16c6ca47c1cd Issue-ID: SDC-1782 Signed-off-by: shiria --- .../sdc/tosca/datatypes/model/TriggerTest.java | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/TriggerTest.java (limited to 'common/onap-tosca-datatype/src/test/java') diff --git a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/TriggerTest.java b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/TriggerTest.java new file mode 100644 index 0000000000..60886b9b42 --- /dev/null +++ b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/TriggerTest.java @@ -0,0 +1,93 @@ +/* + * 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 TriggerTest { + + public static final String TRIGGER_WF_NAME_ACTION = "/mock/trigger/wfNameAction.yaml"; + public static final String TARGET_REQ = "reqA"; + public static final String ACTION_WORKFLOW_VAL = "deployment_workflow"; + public static final String POLICY_DEF_A = "policyA"; + public static final String TRIGGER_A = "triggerA"; + public static final String NODE_A = "nodeA"; + public static final String TRIGGER_OPERATION_ACTION = "/mock/trigger/operationAction.yaml"; + public static final String TARGET_CAP = "capA"; + public static final String OPERATION_ACTION_KEY = "operationAction"; + public static final String IMPLEMENTATION = "implementation"; + ToscaExtensionYamlUtil toscaExtYamlUtil = new ToscaExtensionYamlUtil(); + + @Test + public void getPolicyTriggerActionWf() throws IOException { + String inputFile = TRIGGER_WF_NAME_ACTION; + ServiceTemplate serviceTemplate = getServiceTemplate(inputFile); + + Map policies = serviceTemplate.getTopology_template().getPolicies(); + Trigger trigger = policyCheck(policies); + Assert.assertEquals(TARGET_REQ, trigger.getTarget_filter().getRequirement()); + Object action = trigger.getAction(); + Assert.assertNotNull(action); + Assert.assertEquals(true, action instanceof String); + Assert.assertEquals(ACTION_WORKFLOW_VAL, action); + } + + private ServiceTemplate getServiceTemplate(String inputPath) throws IOException { + try (InputStream yamlFile = toscaExtYamlUtil.loadYamlFileIs(inputPath)) { + return toscaExtYamlUtil.yamlToObject(yamlFile, ServiceTemplate.class); + } + } + + private Trigger policyCheck(Map policies) { + Assert.assertNotNull(policies); + PolicyDefinition policyDefinition = policies.get(POLICY_DEF_A); + Assert.assertNotNull(policyDefinition); + Map triggers = policyDefinition.getTriggers(); + Assert.assertNotNull(triggers); + Trigger trigger = triggers.get(TRIGGER_A); + Assert.assertNotNull(trigger); + EventFilter targetFilter = trigger.getTarget_filter(); + Assert.assertNotNull(targetFilter); + Assert.assertEquals(NODE_A, targetFilter.getNode()); + return trigger; + } + + @Test + public void getPolicyTriggerActionOperation() throws IOException { + String inputFile = TRIGGER_OPERATION_ACTION; + ServiceTemplate serviceTemplate = getServiceTemplate(inputFile); + + Map policies = serviceTemplate.getTopology_template().getPolicies(); + Trigger trigger = policyCheck(policies); + Assert.assertEquals(TARGET_CAP, trigger.getTarget_filter().getCapability()); + Object action = trigger.getAction(); + Assert.assertNotNull(action); + Assert.assertEquals(true, action instanceof Map); + Object operationAction = ((Map) action).get(OPERATION_ACTION_KEY); + Assert.assertNotNull(operationAction); + Assert.assertEquals(true, operationAction instanceof Map); + Assert.assertNotNull( ((Map)operationAction).get(IMPLEMENTATION)); + + } + +} \ No newline at end of file -- cgit 1.2.3-korg