diff options
author | shiria <shiri.amichai@amdocs.com> | 2018-10-10 15:16:15 +0300 |
---|---|---|
committer | Oren Kleks <orenkle@amdocs.com> | 2018-10-15 09:43:40 +0000 |
commit | 1f50c72eb501af42c61c4ddbb011302a6290afdb (patch) | |
tree | bea97a3203f3560ab5bbd2a38fcb7316ec3e259d /common/onap-tosca-datatype/src/test | |
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')
3 files changed, 154 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 diff --git a/common/onap-tosca-datatype/src/test/resources/mock/trigger/operationAction.yaml b/common/onap-tosca-datatype/src/test/resources/mock/trigger/operationAction.yaml new file mode 100644 index 0000000000..64e2b7ab5d --- /dev/null +++ b/common/onap-tosca-datatype/src/test/resources/mock/trigger/operationAction.yaml @@ -0,0 +1,34 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 + +topology_template: + description: topology template descroption + + policies: + policyA: + type: tosca.policies.threshold + description: my description + targets: [ nodeA ] + triggers: + triggerA: + description: triggering event based on CPU + event_type: eventTypeA + schedule: + start_time: 2016-04-08T21:59:43.10-06:00 + end_time: 2002-12-14 + target_filter: + node: nodeA + capability: capA + condition: + constraint: + attName: { greater_than: 80 } + period: 1200 s + evaluations: 6 + method: avg + action: + operationAction: + description: my operation + implementation: + primary: a/s/d.xml + inputs: + inputA: 3 + inputB: {get_property: [ nodeA, propertyA ]}
\ No newline at end of file diff --git a/common/onap-tosca-datatype/src/test/resources/mock/trigger/wfNameAction.yaml b/common/onap-tosca-datatype/src/test/resources/mock/trigger/wfNameAction.yaml new file mode 100644 index 0000000000..2c2ceb9511 --- /dev/null +++ b/common/onap-tosca-datatype/src/test/resources/mock/trigger/wfNameAction.yaml @@ -0,0 +1,27 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 + +topology_template: + description: topology template descroption + + policies: + policyA: + type: tosca.policies.threshold + description: my description + targets: [ nodeA ] + triggers: + triggerA: + description: triggering event based on CPU + event_type: eventTypeA + schedule: + start_time: 2016-04-08T21:59:43.10-06:00 + end_time: 2002-12-14 + target_filter: + node: nodeA + requirement: reqA + condition: + constraint: + attName: { greater_than: 80 } + period: 1200 s + evaluations: 6 + method: avg + action: deployment_workflow
\ No newline at end of file |