diff options
author | 2018-10-10 15:16:15 +0300 | |
---|---|---|
committer | 2018-10-15 09:43:40 +0000 | |
commit | 1f50c72eb501af42c61c4ddbb011302a6290afdb (patch) | |
tree | bea97a3203f3560ab5bbd2a38fcb7316ec3e259d /common/onap-tosca-datatype/src/test/java/org | |
parent | b54343dc3868300178017e60e4cd2c26dc08ff24 (diff) |
Fix Policy type and Policy definition
Fix policy according to TOSCA spec
Change-Id: I4e3da732666dd52895c4458f0cbd16c6ca47c1cd
Issue-ID: SDC-1782
Signed-off-by: shiria <shiri.amichai@amdocs.com>
Diffstat (limited to 'common/onap-tosca-datatype/src/test/java/org')
-rw-r--r-- | common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/TriggerTest.java | 93 |
1 files changed, 93 insertions, 0 deletions
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<String, PolicyDefinition> 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<String, PolicyDefinition> policies) { + Assert.assertNotNull(policies); + PolicyDefinition policyDefinition = policies.get(POLICY_DEF_A); + Assert.assertNotNull(policyDefinition); + Map<String, Trigger> 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<String, PolicyDefinition> 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 |