diff options
author | a.sreekumar <ajith.sreekumar@bell.ca> | 2021-06-22 15:55:46 +0100 |
---|---|---|
committer | a.sreekumar <ajith.sreekumar@bell.ca> | 2021-06-28 10:36:48 +0100 |
commit | 926646d8e5e86e680a119360f93d7bdb46c89435 (patch) | |
tree | 7ff431e59672b19f658faed87c80b4d147253c9c /model/policy-model/src/test/java | |
parent | 63637d939697451d3ac63216d938780a157ff895 (diff) |
Changes to support multiple outputs from a state
This review addresses two main changes:
1) inputFields and outputFields are not tied to task definition anymore.
Instead inputEvent and outputEvents associated to a task is populated
as part of the policy state definition, as the state definition have
the information anyway.
- Clean up of the usage of inputFields and outputFields in task
definition will happen in a future review
- inputFields and outputFields defined in task definition in
policies until honolulu will not make the policy invalid as the
changes are done in backward compatible way.
2) Multiple output events can come out of a final state now.
- Define another policy state output with the relevant eventName in
the command file
- In the task logic, create a map to store the fields of the relevant
outputEvent, and then just call
"executor.addFieldsToOutput(<the_map_of_fields>)"
These 2 steps are enough to send multiple events to relevant
components as per the apex configuration.
Change-Id: Id88ca402704106404f529e595e1a76f6bf167876
Issue-ID: POLICY-3336
Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'model/policy-model/src/test/java')
4 files changed, 27 insertions, 51 deletions
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PolicyModelTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PolicyModelTest.java index 86bbf3e93..48022e878 100644 --- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PolicyModelTest.java +++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PolicyModelTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -335,7 +336,7 @@ public class PolicyModelTest { final AxStateOutput so = model.getPolicies().get("policy").getStateMap().get("state").getStateOutputs() .get(savedStateOutputName); - final AxArtifactKey savedOutEvent = so.getOutgingEvent(); + final AxArtifactKey savedOutEvent = so.getOutgoingEvent(); so.setOutgoingEvent(new AxArtifactKey("NonExistantEvent", "0.0.1")); result = new AxValidationResult(); result = model.validate(result); diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java index 8bd29fc55..049783a7f 100644 --- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java +++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,20 +54,20 @@ public class StateOutputTest { final AxArtifactKey eKey = new AxArtifactKey("EventName", "0.0.1"); assertThatThrownBy(() -> so.setKey(null)) - .hasMessage("key may not be null"); + .hasMessage("key is marked non-null but is null"); so.setKey(soKey); assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKey().getId()); assertEquals("SOStateParent:0.0.1:SOState:SOName", so.getKeys().get(0).getId()); assertThatThrownBy(() -> so.setNextState(null)) - .hasMessage("nextState may not be null"); + .hasMessage("nextState is marked non-null but is null"); so.setNextState(nsKey); assertEquals(nsKey, so.getNextState()); assertThatThrownBy(() -> so.setOutgoingEvent(null)) - .hasMessage("outgoingEvent may not be null"); + .hasMessage("outgoingEvent is marked non-null but is null"); so.setOutgoingEvent(eKey); - assertEquals(eKey, so.getOutgingEvent()); + assertEquals(eKey, so.getOutgoingEvent()); AxValidationResult result = new AxValidationResult(); result = so.validate(result); diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.java index 100adb9fd..95266acc8 100644 --- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.java +++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +27,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.util.Map; import java.util.TreeMap; import java.util.TreeSet; import org.junit.Test; @@ -33,6 +35,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; +import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; import org.onap.policy.apex.model.eventmodel.concepts.AxField; import org.onap.policy.apex.model.eventmodel.concepts.AxInputField; import org.onap.policy.apex.model.eventmodel.concepts.AxOutputField; @@ -91,7 +94,8 @@ public class TasksTest { assertEquals(ofMap, task.getOutputFields()); assertTrue(task.getOutputFieldSet().contains(of0)); assertTrue(task.getRawOutputFields().keySet().contains(of0.getKey().getLocalName())); - + task.setInputEvent(new AxEvent()); + task.setOutputEvents(Map.of("Event", new AxEvent())); final TreeMap<String, AxField> ifDupMap = new TreeMap<>(); final TreeMap<String, AxField> ofDupMap = new TreeMap<>(); ifDupMap.put(if1.getKey().getLocalName(), if1); @@ -131,46 +135,6 @@ public class TasksTest { result = task.validate(result); assertEquals(ValidationResult.VALID, result.getValidationResult()); - task.setInputFields(ifEmptyMap); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - task.setInputFields(ifMap); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - ifMap.put("NullField", null); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - ifMap.remove("NullField"); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - task.setOutputFields(ofEmptyMap); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - task.setOutputFields(ofMap); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - ofMap.put("NullField", null); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - ofMap.remove("NullField"); - result = new AxValidationResult(); - result = task.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - // Empty task parameter map is OK task.setTaskParameters(tpEmptyMap); result = new AxValidationResult(); diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/SupportApexPolicyModelCreator.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/SupportApexPolicyModelCreator.java index 3fca39739..ea2de8603 100644 --- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/SupportApexPolicyModelCreator.java +++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/SupportApexPolicyModelCreator.java @@ -1,25 +1,27 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * 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. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ package org.onap.policy.apex.model.policymodel.handling; +import java.util.Map; import java.util.UUID; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; @@ -52,7 +54,7 @@ import org.onap.policy.apex.model.policymodel.concepts.AxTasks; /** * Model creator for model tests. - * + * * @author Liam Fallon (liam.fallon@ericsson.com) */ public class SupportApexPolicyModelCreator implements TestApexModelCreator<AxPolicyModel> { @@ -136,6 +138,9 @@ public class SupportApexPolicyModelCreator implements TestApexModelCreator<AxPol task.getOutputFields().put(outputField.getKey().getLocalName(), outputField); } + task.setInputEvent(inEvent); + task.setOutputEvents(Map.of(outEvent0.getId(), outEvent0, outEvent1.getId(), outEvent1)); + final AxTaskParameter taskPar0 = new AxTaskParameter(new AxReferenceKey(task.getKey(), "taskParameter0"), "Task parameter 0 value"); final AxTaskParameter taskPar1 = new AxTaskParameter(new AxReferenceKey(task.getKey(), "taskParameter1"), @@ -206,7 +211,7 @@ public class SupportApexPolicyModelCreator implements TestApexModelCreator<AxPol /** * Gets another policy model. - * + * * @return the model */ public AxPolicyModel getAnotherModel() { @@ -287,6 +292,9 @@ public class SupportApexPolicyModelCreator implements TestApexModelCreator<AxPol task.getOutputFields().put(outputField.getKey().getLocalName(), outputField); } + task.setInputEvent(inEvent); + task.setOutputEvents(Map.of(outEvent0.getId(), outEvent0, outEvent1.getId(), outEvent1)); + final AxTaskParameter taskPar0 = new AxTaskParameter(new AxReferenceKey(task.getKey(), "taskParameterA0"), "Task parameter 0 value"); final AxTaskParameter taskPar1 = new AxTaskParameter(new AxReferenceKey(task.getKey(), "taskParameterA1"), @@ -406,6 +414,8 @@ public class SupportApexPolicyModelCreator implements TestApexModelCreator<AxPol anotherTask.getOutputFields().put(outputField.getKey().getLocalName(), outputField); } + anotherTask.setInputEvent(inEvent); + anotherTask.setOutputEvents(Map.of(outEvent0.getId(), outEvent0)); final AxTaskParameter taskPar0 = new AxTaskParameter(new AxReferenceKey(anotherTask.getKey(), "taskParameter0"), "Task parameter 0 value"); final AxTaskParameter taskPar1 = new AxTaskParameter(new AxReferenceKey(anotherTask.getKey(), "taskParameter1"), |