From 926646d8e5e86e680a119360f93d7bdb46c89435 Mon Sep 17 00:00:00 2001 From: "a.sreekumar" Date: Tue, 22 Jun 2021 15:55:46 +0100 Subject: 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()" 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 --- .../model/policymodel/concepts/AxPolicyModel.java | 9 +- .../model/policymodel/concepts/AxStateOutput.java | 80 +++------ .../apex/model/policymodel/concepts/AxTask.java | 180 +++++---------------- .../model/policymodel/handling/PolicyAnalyser.java | 3 +- .../policymodel/concepts/PolicyModelTest.java | 3 +- .../policymodel/concepts/StateOutputTest.java | 9 +- .../apex/model/policymodel/concepts/TasksTest.java | 46 +----- .../handling/SupportApexPolicyModelCreator.java | 20 ++- 8 files changed, 92 insertions(+), 258 deletions(-) (limited to 'model/policy-model/src') diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java index d55fbd329..4ee176d97 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicyModel.java @@ -3,6 +3,7 @@ * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -502,9 +503,9 @@ public class AxPolicyModel extends AxModel { } for (final AxStateOutput stateOutput : state.getStateOutputs().values()) { - if (events.getEventMap().get(stateOutput.getOutgingEvent()) == null) { + if (events.getEventMap().get(stateOutput.getOutgoingEvent()) == null) { result.addValidationMessage(new AxValidationMessage(stateOutput.getKey(), this.getClass(), - ValidationResult.INVALID, "output event " + stateOutput.getOutgingEvent().getId() + ValidationResult.INVALID, "output event " + stateOutput.getOutgoingEvent().getId() + " for state output " + stateOutput.getId() + DOES_NOT_EXIST)); } } @@ -555,10 +556,10 @@ public class AxPolicyModel extends AxModel { ValidationResult.INVALID, "state output on task reference for task " + task.getId() + " is null")); } else { - final AxEvent usedEvent = events.getEventMap().get(stateOutput.getOutgingEvent()); + final AxEvent usedEvent = events.getEventMap().get(stateOutput.getOutgoingEvent()); if (usedEvent == null) { result.addValidationMessage(new AxValidationMessage(stateOutput.getKey(), this.getClass(), - ValidationResult.INVALID, "output event " + stateOutput.getOutgingEvent().getId() + ValidationResult.INVALID, "output event " + stateOutput.getOutgoingEvent().getId() + " for state output " + stateOutput.getId() + DOES_NOT_EXIST)); } diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateOutput.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateOutput.java index 27c187356..1337e2417 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateOutput.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxStateOutput.java @@ -3,6 +3,7 @@ * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -23,17 +24,24 @@ package org.onap.policy.apex.model.policymodel.concepts; import java.util.List; +import java.util.Set; import javax.persistence.AttributeOverride; +import javax.persistence.CollectionTable; import javax.persistence.Column; +import javax.persistence.ElementCollection; import javax.persistence.Embedded; import javax.persistence.EmbeddedId; import javax.persistence.Entity; +import javax.persistence.JoinColumn; import javax.persistence.Table; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; import org.onap.policy.apex.model.basicmodel.concepts.AxKey; @@ -68,13 +76,15 @@ import org.onap.policy.common.utils.validation.Assertions; @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "apexStateOutput", namespace = "http://www.onap.org/policy/apex-pdp") @XmlType(name = "AxStateOutput", namespace = "http://www.onap.org/policy/apex-pdp", - propOrder = {"key", "outgoingEvent", "nextState"}) - + propOrder = {"key", "outgoingEvent", "outgoingEventSet", "nextState"}) +@Getter +@Setter public class AxStateOutput extends AxConcept { private static final long serialVersionUID = 8041771382337655535L; @EmbeddedId @XmlElement(name = "key", required = true) + @NonNull private AxReferenceKey key; // @formatter:off @@ -83,8 +93,17 @@ public class AxStateOutput extends AxConcept { @AttributeOverride(name = "version", column = @Column(name = "outgoingEventVersion")) @Column(name = "outgoingEvent") @XmlElement(required = true) + @NonNull private AxArtifactKey outgoingEvent; + @ElementCollection + @CollectionTable(joinColumns = {@JoinColumn(name = "stateParentKeyName", referencedColumnName = "parentKeyName"), + @JoinColumn(name = "stateParentKeyVersion", referencedColumnName = "parentKeyVersion"), + @JoinColumn(name = "stateParentLocalName", referencedColumnName = "parentLocalName"), + @JoinColumn(name = "stateLocalName", referencedColumnName = "localName")}) + @XmlElement(name = "outgoingEventReference", required = false) + private Set outgoingEventSet; + @Embedded @AttributeOverride(name = "parentKeyName", column = @Column(name = "nextStateParentKeyName")) @AttributeOverride(name = "parentKeyVersion", column = @Column(name = "nextStateParentKeyVersion")) @@ -92,6 +111,7 @@ public class AxStateOutput extends AxConcept { @AttributeOverride(name = "localName", column = @Column(name = "nextStateLocalName")) @Column(name = "nextState") @XmlElement(required = true) + @NonNull private AxReferenceKey nextState; // @formatter:on @@ -160,14 +180,6 @@ public class AxStateOutput extends AxConcept { this.nextState = nextState; } - /** - * {@inheritDoc}. - */ - @Override - public AxReferenceKey getKey() { - return key; - } - /** * {@inheritDoc}. */ @@ -183,54 +195,6 @@ public class AxStateOutput extends AxConcept { return keyList; } - /** - * Sets the reference key for the state output. - * - * @param key the reference key for the state output - */ - public void setKey(final AxReferenceKey key) { - Assertions.argumentNotNull(key, "key may not be null"); - this.key = key; - } - - /** - * Gets the outgoing event emitted on use of this state output. - * - * @return the outgoing event emitted on use of this state output - */ - public AxArtifactKey getOutgingEvent() { - return outgoingEvent; - } - - /** - * Sets the outgoing event emitted on use of this state output. - * - * @param outgoingEvent the outgoing event emitted on use of this state output - */ - public void setOutgoingEvent(final AxArtifactKey outgoingEvent) { - Assertions.argumentNotNull(outgoingEvent, "outgoingEvent may not be null"); - this.outgoingEvent = outgoingEvent; - } - - /** - * Gets the next state to which execution will pass on use of this state output. - * - * @return the next state to which execution will pass on use of this state output - */ - public AxReferenceKey getNextState() { - return nextState; - } - - /** - * Sets the next state to which execution will pass on use of this state output. - * - * @param nextState the next state to which execution will pass on use of this state output - */ - public void setNextState(final AxReferenceKey nextState) { - Assertions.argumentNotNull(nextState, "nextState may not be null"); - this.nextState = nextState; - } - /** * {@inheritDoc}. */ diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java index 04b40e44b..a30a80acc 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxTask.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2021 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. @@ -33,6 +34,7 @@ import javax.persistence.ElementCollection; import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; @@ -42,6 +44,9 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; import org.onap.policy.apex.model.basicmodel.concepts.AxKey; @@ -50,6 +55,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage; 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; @@ -90,9 +96,13 @@ import org.onap.policy.common.utils.validation.Assertions; @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "apexTask", namespace = "http://www.onap.org/policy/apex-pdp") -@XmlType(name = "AxTask", namespace = "http://www.onap.org/policy/apex-pdp", - propOrder = {"key", "inputFields", "outputFields", "taskParameters", "contextAlbumReferenceSet", "taskLogic"}) - +@XmlType( + name = "AxTask", + namespace = "http://www.onap.org/policy/apex-pdp", + propOrder = {"key", "inputEvent", "outputEvents", "inputFields", "outputFields", "taskParameters", + "contextAlbumReferenceSet", "taskLogic"}) +@Getter +@Setter public class AxTask extends AxConcept { private static final String DOES_NOT_EQUAL_TASK_KEY = " does not equal task key"; @@ -100,8 +110,25 @@ public class AxTask extends AxConcept { @EmbeddedId @XmlElement(name = "key", required = true) + @NonNull private AxArtifactKey key; + @OneToOne(cascade = CascadeType.ALL) + @JoinTable( + name = "INPUT_EVENT_JT", + joinColumns = {@JoinColumn(name = "inEventTaskName", referencedColumnName = "name", updatable = false), + @JoinColumn(name = "inEventTaskVersion", referencedColumnName = "version", updatable = false)}) + @XmlElement(name = "inputEvent", required = false) + private AxEvent inputEvent; + + @OneToMany(cascade = CascadeType.ALL) + @JoinTable( + name = "OUTPUT_EVENT_JT", + joinColumns = {@JoinColumn(name = "outEventTaskName", referencedColumnName = "name", updatable = false), + @JoinColumn(name = "outEventTaskVersion", referencedColumnName = "version", updatable = false)}) + @XmlElement(name = "outputEvents", required = false) + private Map outputEvents; + @OneToMany(cascade = CascadeType.ALL) @XmlElement(name = "inputFields", required = true) private Map inputFields; @@ -119,11 +146,13 @@ public class AxTask extends AxConcept { @CollectionTable(joinColumns = {@JoinColumn(name = "contextAlbumName", referencedColumnName = "name"), @JoinColumn(name = "contextAlbumVersion", referencedColumnName = "version")}) @XmlElement(name = "contextAlbumReference") + @NonNull private Set contextAlbumReferenceSet; // @formatter:on @OneToOne(cascade = CascadeType.ALL) @XmlElement(required = true) + @NonNull private AxTaskLogic taskLogic; /** @@ -215,14 +244,6 @@ public class AxTask extends AxConcept { } } - /** - * {@inheritDoc}. - */ - @Override - public AxArtifactKey getKey() { - return key; - } - /** * {@inheritDoc}. */ @@ -245,25 +266,6 @@ public class AxTask extends AxConcept { return keyList; } - /** - * Sets the key of the task. - * - * @param key the key of the task - */ - public void setKey(final AxArtifactKey key) { - Assertions.argumentNotNull(key, "key may not be null"); - this.key = key; - } - - /** - * Gets the input fields that the task expects. - * - * @return the input fields that the task expects - */ - public Map getInputFields() { - return inputFields; - } - /** * Gets the raw input fields that the task expects as a tree map. * @@ -286,16 +288,6 @@ public class AxTask extends AxConcept { return inputFieldSet; } - /** - * Sets the input fields that the task expects. - * - * @param inputFields the input fields that the task expects - */ - public void setInputFields(final Map inputFields) { - Assertions.argumentNotNull(inputFields, "inputFields may not be null"); - this.inputFields = inputFields; - } - /** * Copy the input fields from the given map into the task. This method is used to get a copy of * the input fields, which can be useful for unit testing of policies and tasks. @@ -313,15 +305,6 @@ public class AxTask extends AxConcept { } } - /** - * Gets the output fields that the task emits. - * - * @return the output fields that the task emits - */ - public Map getOutputFields() { - return outputFields; - } - /** * Gets the raw output fields that the task emits as a tree map. * @@ -344,16 +327,6 @@ public class AxTask extends AxConcept { return outputFieldSet; } - /** - * Sets the output fields that the task emits. - * - * @param outputFields the output fields that the task emits - */ - public void setOutputFields(final Map outputFields) { - Assertions.argumentNotNull(outputFields, "outputFields may not be null"); - this.outputFields = outputFields; - } - /** * Copy the output fields from the given map into the task. This method is used to get a copy of * the output fields, which can be useful for unit testing of policies and tasks. @@ -371,24 +344,6 @@ public class AxTask extends AxConcept { } } - /** - * Gets the task parameters that are used to initialize tasks of this type. - * - * @return the task parameters that are used to initialize tasks of this type - */ - public Map getTaskParameters() { - return taskParameters; - } - - /** - * Sets the task parameters that are used to initialize tasks of this type. - * - * @param taskParameters the task parameters that are used to initialize tasks of this type - */ - public void setTaskParameters(final Map taskParameters) { - Assertions.argumentNotNull(taskParameters, "taskParameters may not be null"); - this.taskParameters = taskParameters; - } /** * Gets the context album reference set defines the context that may be used by Task Logic in @@ -413,25 +368,6 @@ public class AxTask extends AxConcept { this.contextAlbumReferenceSet = contextAlbumReferences; } - /** - * Gets the task logic that performs the domain specific work of the task. - * - * @return the task logic that performs the domain specific work of the task - */ - public AxTaskLogic getTaskLogic() { - return taskLogic; - } - - /** - * Sets the task logic that performs the domain specific work of the task. - * - * @param taskLogic the task logic that performs the domain specific work of the task - */ - public void setTaskLogic(final AxTaskLogic taskLogic) { - Assertions.argumentNotNull(taskLogic, "taskLogic may not be null"); - this.taskLogic = taskLogic; - } - /** * {@inheritDoc}. */ @@ -446,30 +382,12 @@ public class AxTask extends AxConcept { result = key.validate(result); - if (inputFields.size() == 0) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "inputFields may not be empty")); - } else { - for (final Entry inputFieldEntry : inputFields.entrySet()) { - result = validateField(inputFieldEntry.getKey(), inputFieldEntry.getValue(), "input", result); - } - } - - if (outputFields.size() == 0) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "outputFields may not be empty")); - } else { - for (final Entry outputFieldEntry : outputFields.entrySet()) { - result = validateField(outputFieldEntry.getKey(), outputFieldEntry.getValue(), "input", result); - } - } - for (final Entry taskParameterEntry : taskParameters.entrySet()) { - result = vaildateTaskParameterEntry(taskParameterEntry, result); + result = validateTaskParameterEntry(taskParameterEntry, result); } for (final AxArtifactKey contextAlbumReference : contextAlbumReferenceSet) { - result = vaildateContextAlbumReference(contextAlbumReference, result); + result = validateContextAlbumReference(contextAlbumReference, result); } if (!taskLogic.getKey().getParentArtifactKey().equals(key)) { @@ -480,32 +398,6 @@ public class AxTask extends AxConcept { return taskLogic.validate(result); } - /** - * Validate a field. - * - * @param fieldKey the key of the field to validate - * @param field the field to validate - * @param direction The direction of the field - * @param result The validation result to append to - * @return The result of the validation - */ - private AxValidationResult validateField(final String fieldKey, final AxField field, final String direction, - AxValidationResult result) { - if (field == null) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "null " + direction + " field value found on " + direction + " field " + fieldKey)); - } else { - if (!field.getKey().getParentArtifactKey().equals(key)) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "parent key on " + direction + " field " + fieldKey + DOES_NOT_EQUAL_TASK_KEY)); - } - - result = field.validate(result); - } - - return result; - } - /** * Validate a task parameter entry. * @@ -513,7 +405,7 @@ public class AxTask extends AxConcept { * @param result The validation result to append to * @return The result of the validation */ - private AxValidationResult vaildateTaskParameterEntry(final Entry taskParameterEntry, + private AxValidationResult validateTaskParameterEntry(final Entry taskParameterEntry, AxValidationResult result) { if (taskParameterEntry.getValue() == null) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, @@ -537,7 +429,7 @@ public class AxTask extends AxConcept { * @param result The validation result to append to * @return The result of the validation */ - private AxValidationResult vaildateContextAlbumReference(final AxArtifactKey contextAlbumReference, + private AxValidationResult validateContextAlbumReference(final AxArtifactKey contextAlbumReference, AxValidationResult result) { if (contextAlbumReference.equals(AxArtifactKey.getNullKey())) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java index 4d076cfda..3a4c36bc5 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyser.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019 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. @@ -137,7 +138,7 @@ public class PolicyAnalyser { // Event usage by state result.getEventUsage().get(state.getTrigger()).add(state.getKey()); for (final AxStateOutput stateOutput : state.getStateOutputs().values()) { - result.getEventUsage().get(stateOutput.getOutgingEvent()).add(state.getKey()); + result.getEventUsage().get(stateOutput.getOutgoingEvent()).add(state.getKey()); } // State Context Usage 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 ifDupMap = new TreeMap<>(); final TreeMap 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 { @@ -136,6 +138,9 @@ public class SupportApexPolicyModelCreator implements TestApexModelCreator