aboutsummaryrefslogtreecommitdiffstats
path: root/model/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'model/src/test')
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImplTest.java84
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java108
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyTest.java189
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyUseTest.java78
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKeyTest.java177
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java164
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ExceptionsTest.java66
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ValidationTest.java90
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelExceptionTest.java39
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java94
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java105
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java52
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java63
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java67
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyApexBasicModelCreator.java123
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyAxModelWithReferences.java71
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTest.java294
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java116
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator0.java64
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator1.java68
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator2.java64
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java111
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java217
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/basicmodel/service/ModelServiceTest.java65
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java248
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextModelTest.java95
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java229
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java124
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ContextComparisonTest.java189
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestApexContextModelCreator.java122
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestContextComparisonFactory.java148
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineModelTest.java176
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java267
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java81
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/DummyTestApexEngineModelCreator.java129
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventModelTest.java87
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventsTest.java323
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/FieldTest.java134
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/ApexEventModelTest.java279
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/DummyTestApexEventModelCreator.java309
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/modelapi/ApexApiResultTest.java80
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiContextAlbumTest.java176
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiContextSchemaTest.java153
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiEventTest.java202
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiKeyInfoTest.java137
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiPolicyTest.java1023
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiTaskTest.java376
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java208
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/modelapi/ModelFacadeTest.java99
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java128
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/modelapi/RealModelTest.java46
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/DummyLogicReader.java65
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/ExceptionsTest.java51
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/LogicTest.java161
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PoliciesTest.java391
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PolicyModelTest.java312
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java124
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTaskReferenceTest.java144
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTest.java461
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TaskParameterTest.java110
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.java259
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/handling/ApexPolicyModelTest.java138
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyserTest.java60
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReaderTest.java84
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelComparerTest.java118
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMergerTest.java92
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitterTest.java76
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/handling/SupportApexPolicyModelCreator.java406
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/policymodel/utils/SupportPolicyModelValidator.java48
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/utilities/CollectionUtilitiesTest.java87
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/utilities/DirectoryUtilsTest.java55
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/utilities/KeyComparerTest.java53
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/utilities/KeyedMapComparerTest.java76
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/utilities/TextFileUtilsTest.java56
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/utilities/TreeMapUtilsTest.java157
-rw-r--r--model/src/test/java/org/onap/policy/apex/model/utilities/json/JsonHandlerTest.java59
-rw-r--r--model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseKeys.txt12
-rw-r--r--model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseValues.txt12
-rw-r--r--model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseKeys.txt70
-rw-r--r--model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseValues.txt70
-rw-r--r--model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt8
-rw-r--r--model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseKeys.txt69
-rw-r--r--model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseValues.txt68
-rw-r--r--model/src/test/resources/logback-test.xml78
-rw-r--r--model/src/test/resources/models/PolicyModel.json775
-rw-r--r--model/src/test/resources/models/PolicyModel.junk9
-rw-r--r--model/src/test/resources/models/RealPolicyModel.json3076
-rw-r--r--model/src/test/resources/path/to/apex/logic/funkylogic/LogicParentLogicParentLocalNameLogicInstanceName.funkylogic21
-rw-r--r--model/src/test/resources/testdir/testfile.xml20
89 files changed, 16068 insertions, 0 deletions
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImplTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImplTest.java
new file mode 100644
index 000000000..44a9de49e
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxConceptGetterImplTest.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.basicmodel.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.NavigableMap;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import org.junit.Test;
+
+/**
+ * Test the AxConceptGetterImpl class.
+ */
+public class AxConceptGetterImplTest {
+
+ @Test
+ public void testAxConceptGetterImpl() {
+ NavigableMap<AxArtifactKey, AxArtifactKey> keyMap = new TreeMap<>();
+
+ AxConceptGetterImpl<AxArtifactKey> getter = new AxConceptGetterImpl<>(keyMap);
+ assertNotNull(getter);
+
+ AxArtifactKey keyA = new AxArtifactKey("A", "0.0.1");
+ assertNull(getter.get(keyA));
+
+ assertThatThrownBy(() -> getter.get((String) null))
+ .hasMessage("conceptKeyName may not be null");
+ assertNull(getter.get("W"));
+
+ AxArtifactKey keyZ = new AxArtifactKey("Z", "0.0.1");
+ keyMap.put(keyZ, keyZ);
+ assertNull(getter.get("W"));
+
+ AxArtifactKey keyW001 = new AxArtifactKey("W", "0.0.1");
+ keyMap.put(keyW001, keyW001);
+ assertEquals(keyW001, getter.get("W"));
+
+ AxArtifactKey keyW002 = new AxArtifactKey("W", "0.0.2");
+ keyMap.put(keyW002, keyW002);
+ assertEquals(keyW002, getter.get("W"));
+
+ keyMap.remove(keyZ);
+ assertEquals(keyW002, getter.get("W"));
+
+ assertThatThrownBy(() -> getter.get((String) null, "0.0.1"))
+ .hasMessage("conceptKeyName may not be null");
+ assertEquals(keyW002, getter.get("W", "0.0.2"));
+ assertEquals(keyW002, getter.get("W", (String) null));
+
+ assertEquals(new TreeSet<AxArtifactKey>(keyMap.values()), getter.getAll(null));
+ assertEquals(new TreeSet<AxArtifactKey>(keyMap.values()), getter.getAll(null, null));
+
+ assertEquals(keyW001, getter.getAll("W", null).iterator().next());
+ assertEquals(keyW002, getter.getAll("W", "0.0.2").iterator().next());
+ assertEquals(0, getter.getAll("A", null).size());
+ assertEquals(0, getter.getAll("Z", null).size());
+
+ keyMap.put(keyZ, keyZ);
+ assertEquals(keyW002, getter.getAll("W", "0.0.2").iterator().next());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java
new file mode 100644
index 000000000..0c7edee28
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java
@@ -0,0 +1,108 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2022 Nordix Foundation.
+ * ================================================================================
+ * 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.basicmodel.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.UUID;
+import org.junit.Test;
+
+
+public class AxKeyInfoTest {
+
+ @Test
+ public void testNullAxKeyInfo() {
+ assertNotNull(new AxKeyInfo());
+ assertNotNull(new AxKeyInfo(new AxArtifactKey()));
+ assertNotNull(new AxKeyInfo(new AxArtifactKey(), UUID.randomUUID(), "Key description"));
+ }
+
+ @Test
+ public void testAxKeyInfo() {
+ AxKeyInfo testKeyInfo = new AxKeyInfo();
+ testKeyInfo.setKey((new AxArtifactKey("PN", "0.0.1")));
+ assertEquals("PN:0.0.1", testKeyInfo.getKey().getId());
+ assertTrue(testKeyInfo.matchesId("PN:0.0.1"));
+
+ AxArtifactKey key = new AxArtifactKey("key", "0.0.1");
+ testKeyInfo.setKey(key);
+ assertEquals(key, testKeyInfo.getKey());
+
+ UUID uuid = UUID.randomUUID();
+ testKeyInfo.setUuid(uuid);
+ assertEquals(uuid, testKeyInfo.getUuid());
+ testKeyInfo.setDescription("Key Description");
+ assertEquals("Key Description", testKeyInfo.getDescription());
+
+ AxKeyInfo clonedReferenceKey = new AxKeyInfo(testKeyInfo);
+ assertTrue(clonedReferenceKey.toString()
+ .startsWith("AxKeyInfo:(artifactId=AxArtifactKey:(name=key,version=0.0.1),uuid="));
+
+ assertNotEquals(0, testKeyInfo.hashCode());
+ // disabling sonar because this code tests the equals() method
+ assertEquals(testKeyInfo, testKeyInfo); // NOSONAR
+ assertEquals(testKeyInfo, clonedReferenceKey);
+ assertNotNull(testKeyInfo);
+ Object differentKeyType = new AxArtifactKey();
+ assertNotEquals(testKeyInfo, differentKeyType);
+ assertNotEquals(testKeyInfo, new AxKeyInfo(new AxArtifactKey()));
+ assertNotEquals(testKeyInfo, new AxKeyInfo(key, UUID.randomUUID(), "Some Description"));
+ assertEquals(testKeyInfo, new AxKeyInfo(key, uuid, "Some Other Description"));
+ assertEquals(testKeyInfo, new AxKeyInfo(key, uuid, "Key Description"));
+
+ assertEquals(0, testKeyInfo.compareTo(testKeyInfo));
+ assertEquals(0, testKeyInfo.compareTo(clonedReferenceKey));
+
+
+ }
+
+ @Test
+ public void testAxKeyValidation() {
+ AxKeyInfo testKeyInfo = new AxKeyInfo();
+ testKeyInfo.setKey((new AxArtifactKey("PN", "0.0.1")));
+
+ AxValidationResult result = new AxValidationResult();
+ result = testKeyInfo.validate(result);
+ assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
+
+ testKeyInfo.setDescription("");
+ result = testKeyInfo.validate(result);
+ assertEquals(AxValidationResult.ValidationResult.OBSERVATION, result.getValidationResult());
+
+ testKeyInfo.setUuid(new UUID(0, 0));
+ result = testKeyInfo.validate(result);
+ assertEquals(AxValidationResult.ValidationResult.WARNING, result.getValidationResult());
+
+ testKeyInfo.setKey(AxArtifactKey.getNullKey());
+ result = testKeyInfo.validate(result);
+ assertEquals(AxValidationResult.ValidationResult.INVALID, result.getValidationResult());
+
+ assertNotNull(AxKeyInfo.generateReproducibleUuid(null));
+ assertNotNull(AxKeyInfo.generateReproducibleUuid("SeedString"));
+
+ testKeyInfo.clean();
+ assertNotNull(testKeyInfo);
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyTest.java
new file mode 100644
index 000000000..010f4b8a3
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyTest.java
@@ -0,0 +1,189 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * ================================================================================
+ * 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.basicmodel.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Field;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey.Compatibility;
+
+public class AxKeyTest {
+
+ private static AxArtifactKey someKey0;
+ private static AxArtifactKey someKey1;
+ private static AxArtifactKey someKey2;
+ private static AxArtifactKey someKey3;
+ private static AxArtifactKey someKey4;
+ private static AxArtifactKey someKey5;
+ private static AxArtifactKey someKey6;
+
+ /**
+ * Sets data in Keys for the tests.
+ */
+ @Before
+ public void setKeys() {
+ someKey0 = new AxArtifactKey();
+ someKey1 = new AxArtifactKey("name", "0.0.1");
+ someKey2 = new AxArtifactKey(someKey1);
+ someKey3 = new AxArtifactKey(someKey1.getId());
+ someKey4 = new AxArtifactKey(someKey1);
+ someKey5 = new AxArtifactKey(someKey1);
+ someKey6 = new AxArtifactKey(someKey1);
+ }
+
+ private void setKeyValues() {
+ someKey0.setName("zero");
+ someKey0.setVersion("0.0.2");
+ someKey3.setVersion("0.0.2");
+ someKey4.setVersion("0.1.2");
+ someKey5.setVersion("1.2.2");
+ someKey6.setVersion("3");
+ }
+
+ @Test
+ public void testArtifactKey() {
+ assertThatThrownBy(() -> new AxArtifactKey("some bad key id"))
+ .hasMessage("parameter \"id\": value \"some bad key id\", "
+ + "does not match regular expression \"[A-Za-z0-9\\-_\\.]+:[0-9].[0-9].[0-9]\"");
+
+ assertEquals(AxArtifactKey.getNullKey(), someKey0);
+
+ assertEquals(someKey1, someKey2);
+ assertEquals(someKey1, someKey3);
+
+ assertEquals(someKey2, someKey1.getKey());
+ assertEquals(1, someKey1.getKeys().size());
+
+ setKeyValues();
+
+ someKey0.clean();
+ assertNotNull(someKey0.toString());
+
+ AxArtifactKey someKey7 = new AxArtifactKey(someKey1);
+ assertEquals(150332875, someKey7.hashCode());
+ assertEquals(0, someKey7.compareTo(someKey1));
+ assertEquals(-12, someKey7.compareTo(someKey0));
+
+ assertThatThrownBy(() -> someKey0.compareTo(null))
+ .hasMessage("comparison object may not be null");
+ assertEquals(0, someKey0.compareTo(someKey0));
+ assertEquals(353602977, someKey0.compareTo(new AxReferenceKey()));
+
+ assertNotNull(someKey0);
+ // disabling sonar because this code tests the equals() method
+ assertEquals(someKey0, someKey0); // NOSONAR
+ assertNotEquals(someKey0, (Object) new AxReferenceKey());
+ }
+
+ @Test
+ public void testAxCompatibility() {
+ setKeyValues();
+
+ assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(new AxReferenceKey()));
+ assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(someKey1));
+ assertEquals(Compatibility.IDENTICAL, someKey2.getCompatibility(someKey1));
+ assertEquals(Compatibility.PATCH, someKey3.getCompatibility(someKey1));
+ assertEquals(Compatibility.MINOR, someKey4.getCompatibility(someKey1));
+ assertEquals(Compatibility.MAJOR, someKey5.getCompatibility(someKey1));
+ assertEquals(Compatibility.MAJOR, someKey6.getCompatibility(someKey1));
+
+ assertTrue(someKey1.isCompatible(someKey2));
+ assertTrue(someKey1.isCompatible(someKey3));
+ assertTrue(someKey1.isCompatible(someKey4));
+ assertFalse(someKey1.isCompatible(someKey0));
+ assertFalse(someKey1.isCompatible(someKey5));
+ assertFalse(someKey1.isCompatible(new AxReferenceKey()));
+ }
+
+ @Test
+ public void testAxValidation() {
+ setKeyValues();
+
+ assertEquals(AxValidationResult.ValidationResult.VALID,
+ someKey0.validate(new AxValidationResult()).getValidationResult());
+ assertEquals(AxValidationResult.ValidationResult.VALID,
+ someKey1.validate(new AxValidationResult()).getValidationResult());
+ assertEquals(AxValidationResult.ValidationResult.VALID,
+ someKey2.validate(new AxValidationResult()).getValidationResult());
+ assertEquals(AxValidationResult.ValidationResult.VALID,
+ someKey3.validate(new AxValidationResult()).getValidationResult());
+ assertEquals(AxValidationResult.ValidationResult.VALID,
+ someKey4.validate(new AxValidationResult()).getValidationResult());
+ assertEquals(AxValidationResult.ValidationResult.VALID,
+ someKey5.validate(new AxValidationResult()).getValidationResult());
+ assertEquals(AxValidationResult.ValidationResult.VALID,
+ someKey6.validate(new AxValidationResult()).getValidationResult());
+ }
+
+ @Test
+ public void testNullKey() {
+ setKeyValues();
+
+ AxArtifactKey nullKey0 = AxArtifactKey.getNullKey();
+ assertTrue(nullKey0.isNullKey());
+ AxArtifactKey nullKey1 = new AxArtifactKey();
+ assertTrue(nullKey1.isNullKey());
+ AxArtifactKey nullKey2 = new AxArtifactKey(AxKey.NULL_KEY_NAME, AxKey.NULL_KEY_VERSION);
+ assertTrue(nullKey2.isNullKey());
+ AxArtifactKey notnullKey = new AxArtifactKey("Blah", AxKey.NULL_KEY_VERSION);
+ assertFalse(notnullKey.isNullKey());
+ }
+
+
+ @Test
+ public void testValidation() throws IllegalArgumentException, IllegalAccessException,
+ NoSuchFieldException, SecurityException {
+ AxArtifactKey testKey = new AxArtifactKey("TheKey", "0.0.1");
+ assertEquals("TheKey:0.0.1", testKey.getId());
+
+ Field nameField = testKey.getClass().getDeclaredField("name");
+ nameField.setAccessible(true);
+ nameField.set(testKey, "Key Name");
+ AxValidationResult validationResult = new AxValidationResult();
+ testKey.validate(validationResult);
+ nameField.set(testKey, "TheKey");
+ nameField.setAccessible(false);
+ assertEquals(
+ "name invalid-parameter name with value Key Name "
+ + "does not match regular expression [A-Za-z0-9\\-_\\.]+",
+ validationResult.getMessageList().get(0).getMessage());
+
+ Field versionField = testKey.getClass().getDeclaredField("version");
+ versionField.setAccessible(true);
+ versionField.set(testKey, "Key Version");
+ AxValidationResult validationResultV = new AxValidationResult();
+ testKey.validate(validationResultV);
+ versionField.set(testKey, "0.0.1");
+ versionField.setAccessible(false);
+ assertEquals(
+ "version invalid-parameter version with value Key Version "
+ + "does not match regular expression [A-Za-z0-9.]+",
+ validationResultV.getMessageList().get(0).getMessage());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyUseTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyUseTest.java
new file mode 100644
index 000000000..5346b6b21
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyUseTest.java
@@ -0,0 +1,78 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * ================================================================================
+ * 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.basicmodel.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey.Compatibility;
+
+public class AxKeyUseTest {
+
+ @Test
+ public void test() {
+ assertNotNull(new AxKeyUse());
+ assertNotNull(new AxKeyUse(new AxArtifactKey()));
+ assertNotNull(new AxKeyUse(new AxReferenceKey()));
+
+ AxArtifactKey key = new AxArtifactKey("Key", "0.0.1");
+ AxKeyUse keyUse = new AxKeyUse();
+ keyUse.setKey(key);
+ assertEquals(key, keyUse.getKey());
+ assertEquals("Key:0.0.1", keyUse.getId());
+ assertEquals(key, keyUse.getKeys().get(0));
+
+ assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key));
+ assertTrue(keyUse.isCompatible(key));
+
+ keyUse.clean();
+ assertNotNull(keyUse);
+
+ AxValidationResult result = new AxValidationResult();
+ result = keyUse.validate(result);
+ assertNotNull(result);
+
+ assertNotEquals(0, keyUse.hashCode());
+
+ AxKeyUse clonedKeyUse = new AxKeyUse(keyUse);
+ assertEquals("AxKeyUse:(usedKey=AxArtifactKey:(name=Key,version=0.0.1))", clonedKeyUse.toString());
+
+ assertNotEquals(0, keyUse.hashCode());
+ // disabling sonar because this code tests the equals() method
+ assertEquals(keyUse, keyUse); // NOSONAR
+ assertEquals(keyUse, clonedKeyUse);
+ assertNotEquals(keyUse, (Object) "Hello");
+ assertEquals(keyUse, new AxKeyUse(key));
+
+ assertEquals(0, keyUse.compareTo(keyUse));
+ assertEquals(0, keyUse.compareTo(clonedKeyUse));
+ assertNotEquals(0, keyUse.compareTo(new AxArtifactKey()));
+ assertEquals(0, keyUse.compareTo(new AxKeyUse(key)));
+
+ AxKeyUse keyUseNull = new AxKeyUse(AxArtifactKey.getNullKey());
+ AxValidationResult resultNull = new AxValidationResult();
+ assertEquals(false, keyUseNull.validate(resultNull).isValid());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKeyTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKeyTest.java
new file mode 100644
index 000000000..515587558
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKeyTest.java
@@ -0,0 +1,177 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * ================================================================================
+ * 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.basicmodel.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Field;
+import org.junit.Test;
+
+
+public class AxReferenceKeyTest {
+
+ @Test
+ public void testAxReferenceKey() {
+ assertNotNull(new AxReferenceKey());
+ assertNotNull(new AxReferenceKey(new AxArtifactKey()));
+ assertNotNull(new AxReferenceKey(new AxArtifactKey(), "LocalName"));
+ assertNotNull(new AxReferenceKey(new AxReferenceKey()));
+ assertNotNull(new AxReferenceKey(new AxReferenceKey(), "LocalName"));
+ assertNotNull(new AxReferenceKey(new AxArtifactKey(), "ParentLocalName", "LocalName"));
+ assertNotNull(new AxReferenceKey("ParentKeyName", "0.0.1", "LocalName"));
+ assertNotNull(new AxReferenceKey("ParentKeyName", "0.0.1", "ParentLocalName", "LocalName"));
+ assertNotNull(new AxReferenceKey("ParentKeyName:0.0.1:ParentLocalName:LocalName"));
+ assertEquals(AxReferenceKey.getNullKey().getKey(), AxReferenceKey.getNullKey());
+ assertEquals("NULL:0.0.0:NULL:NULL", AxReferenceKey.getNullKey().getId());
+
+ AxReferenceKey testReferenceKey = new AxReferenceKey();
+ testReferenceKey.setParentArtifactKey(new AxArtifactKey("PN", "0.0.1"));
+ assertEquals("PN:0.0.1", testReferenceKey.getParentArtifactKey().getId());
+
+ testReferenceKey.setParentReferenceKey(new AxReferenceKey("PN", "0.0.1", "LN"));
+ assertEquals("PN:0.0.1:NULL:LN", testReferenceKey.getParentReferenceKey().getId());
+
+ testReferenceKey.setParentKeyName("NPKN");
+ assertEquals("NPKN", testReferenceKey.getParentKeyName());
+
+ testReferenceKey.setParentKeyVersion("0.0.1");
+ assertEquals("0.0.1", testReferenceKey.getParentKeyVersion());
+
+ testReferenceKey.setParentLocalName("NPKLN");
+ assertEquals("NPKLN", testReferenceKey.getParentLocalName());
+
+ testReferenceKey.setLocalName("NLN");
+ assertEquals("NLN", testReferenceKey.getLocalName());
+
+ assertFalse(testReferenceKey.isCompatible(AxArtifactKey.getNullKey()));
+ assertFalse(testReferenceKey.isCompatible(AxReferenceKey.getNullKey()));
+ assertTrue(testReferenceKey.isCompatible(testReferenceKey));
+
+ assertEquals(AxKey.Compatibility.DIFFERENT, testReferenceKey.getCompatibility(AxArtifactKey.getNullKey()));
+ assertEquals(AxKey.Compatibility.DIFFERENT, testReferenceKey.getCompatibility(AxReferenceKey.getNullKey()));
+ assertEquals(AxKey.Compatibility.IDENTICAL, testReferenceKey.getCompatibility(testReferenceKey));
+
+ AxValidationResult result = new AxValidationResult();
+ result = testReferenceKey.validate(result);
+ assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
+
+ testReferenceKey.clean();
+
+ AxReferenceKey clonedReferenceKey = new AxReferenceKey(testReferenceKey);
+ assertEquals("AxReferenceKey:(parentKeyName=NPKN,parentKeyVersion=0.0.1,parentLocalName=NPKLN,localName=NLN)",
+ clonedReferenceKey.toString());
+
+ assertNotEquals(0, testReferenceKey.hashCode());
+ // disabling sonar because this code tests the equals() method
+ assertEquals(testReferenceKey, testReferenceKey); // NOSONAR
+ assertEquals(testReferenceKey, clonedReferenceKey);
+ assertNotEquals(testReferenceKey, (Object) "Hello");
+ assertNotEquals(testReferenceKey, new AxReferenceKey("PKN", "0.0.2", "PLN", "LN"));
+ assertNotEquals(testReferenceKey, new AxReferenceKey("NPKN", "0.0.2", "PLN", "LN"));
+ assertNotEquals(testReferenceKey, new AxReferenceKey("NPKN", "0.0.1", "PLN", "LN"));
+ assertNotEquals(testReferenceKey, new AxReferenceKey("NPKN", "0.0.1", "NPLN", "LN"));
+ assertEquals(testReferenceKey, new AxReferenceKey("NPKN", "0.0.1", "NPKLN", "NLN"));
+
+ assertEquals(0, testReferenceKey.compareTo(testReferenceKey));
+ assertEquals(0, testReferenceKey.compareTo(clonedReferenceKey));
+ assertNotEquals(0, testReferenceKey.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("PKN", "0.0.2", "PLN", "LN")));
+ assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.2", "PLN", "LN")));
+ assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "PLN", "LN")));
+ assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "NPLN", "LN")));
+ assertEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "NPKLN", "NLN")));
+
+ assertNotNull(testReferenceKey.getKeys());
+
+ assertThatThrownBy(() -> testReferenceKey.equals(null))
+ .hasMessage("comparison object may not be null");
+ assertThatThrownBy(() -> testReferenceKey.copyTo(null))
+ .hasMessage("target may not be null");
+ assertThatThrownBy(() -> testReferenceKey.copyTo(new AxArtifactKey("Key", "0.0.1")))
+ .hasMessage("org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey is not an instance of "
+ + "org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey");
+ AxReferenceKey targetRefKey = new AxReferenceKey();
+ assertEquals(testReferenceKey, testReferenceKey.copyTo(targetRefKey));
+ }
+
+ @Test
+ public void testValidation() throws IllegalArgumentException, IllegalAccessException,
+ NoSuchFieldException, SecurityException {
+ AxReferenceKey testReferenceKey = new AxReferenceKey();
+ testReferenceKey.setParentArtifactKey(new AxArtifactKey("PN", "0.0.1"));
+ assertEquals("PN:0.0.1", testReferenceKey.getParentArtifactKey().getId());
+
+ Field parentNameField = testReferenceKey.getClass().getDeclaredField("parentKeyName");
+ parentNameField.setAccessible(true);
+ parentNameField.set(testReferenceKey, "Parent Name");
+ AxValidationResult validationResult = new AxValidationResult();
+ testReferenceKey.validate(validationResult);
+ parentNameField.set(testReferenceKey, "ParentName");
+ parentNameField.setAccessible(false);
+ assertEquals(
+ "parentKeyName invalid-parameter parentKeyName with value Parent Name "
+ + "does not match regular expression [A-Za-z0-9\\-_\\.]+",
+ validationResult.getMessageList().get(0).getMessage());
+
+ Field parentVersionField = testReferenceKey.getClass().getDeclaredField("parentKeyVersion");
+ parentVersionField.setAccessible(true);
+ parentVersionField.set(testReferenceKey, "Parent Version");
+ AxValidationResult validationResultPV = new AxValidationResult();
+ testReferenceKey.validate(validationResultPV);
+ parentVersionField.set(testReferenceKey, "0.0.1");
+ parentVersionField.setAccessible(false);
+ assertEquals(
+ "parentKeyVersion invalid-parameter parentKeyVersion with value Parent Version "
+ + "does not match regular expression [A-Za-z0-9.]+",
+ validationResultPV.getMessageList().get(0).getMessage());
+
+ Field parentLocalNameField = testReferenceKey.getClass().getDeclaredField("parentLocalName");
+ parentLocalNameField.setAccessible(true);
+ parentLocalNameField.set(testReferenceKey, "Parent Local Name");
+ AxValidationResult validationResultPL = new AxValidationResult();
+ testReferenceKey.validate(validationResultPL);
+ parentLocalNameField.set(testReferenceKey, "ParentLocalName");
+ parentLocalNameField.setAccessible(false);
+ assertEquals(
+ "parentLocalName invalid-parameter parentLocalName with value "
+ + "Parent Local Name does not match regular expression [A-Za-z0-9\\-_\\.]+|^$",
+ validationResultPL.getMessageList().get(0).getMessage());
+
+ Field localNameField = testReferenceKey.getClass().getDeclaredField("localName");
+ localNameField.setAccessible(true);
+ localNameField.set(testReferenceKey, "Local Name");
+ AxValidationResult validationResultLN = new AxValidationResult();
+ testReferenceKey.validate(validationResultLN);
+ localNameField.set(testReferenceKey, "LocalName");
+ localNameField.setAccessible(false);
+ assertEquals(
+ "localName invalid-parameter localName with value Local Name "
+ + "does not match regular expression [A-Za-z0-9\\-_\\.]+|^$",
+ validationResultLN.getMessageList().get(0).getMessage());
+
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java
new file mode 100644
index 000000000..2b16e89ed
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java
@@ -0,0 +1,164 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ * ================================================================================
+ * 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.basicmodel.concepts;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class DummyEntity extends AxConcept {
+ private static final long serialVersionUID = -2962570563281067894L;
+
+ protected AxReferenceKey key;
+ private double doubleValue;
+
+ public DummyEntity() {
+ this.key = new AxReferenceKey();
+ this.doubleValue = 0;
+ }
+
+ public DummyEntity(Double doubleValue) {
+ this.key = new AxReferenceKey();
+ this.doubleValue = doubleValue;
+ }
+
+ public DummyEntity(AxReferenceKey key, Double doubleValue) {
+ this.key = key;
+ this.doubleValue = doubleValue;
+ }
+
+ @Override
+ public AxReferenceKey getKey() {
+ return key;
+ }
+
+ @Override
+ public List<AxKey> getKeys() {
+ return Arrays.asList((AxKey) getKey());
+ }
+
+ public void setKey(AxReferenceKey key) {
+ this.key = key;
+ }
+
+ public boolean checkSetKey() {
+ return (this.key != null);
+ }
+
+ public double getDoubleValue() {
+ return doubleValue;
+ }
+
+ public void setDoubleValue(double doubleValue) {
+ this.doubleValue = doubleValue;
+ }
+
+ @Override
+ public AxValidationResult validate(AxValidationResult result) {
+ return key.validate(result);
+ }
+
+ @Override
+ public void clean() {
+ key.clean();
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("doubleValue=");
+ builder.append(doubleValue);
+ return builder.toString();
+ }
+
+ @Override
+ public AxConcept copyTo(AxConcept target) {
+ final Object copyObject = ((target == null) ? new DummyEntity() : target);
+ if (copyObject instanceof DummyEntity) {
+ final DummyEntity copy = ((DummyEntity) copyObject);
+ if (this.checkSetKey()) {
+ copy.setKey(new AxReferenceKey(key));
+ } else {
+ copy.key = null;
+ }
+ copy.doubleValue = doubleValue;
+ return copy;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((key == null) ? 0 : key.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (this == obj) {
+ return true;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ DummyEntity other = (DummyEntity) obj;
+ if (key == null) {
+ if (other.key != null) {
+ return false;
+ }
+ } else if (!key.equals(other.key)) {
+ return false;
+ }
+ if (doubleValue != other.doubleValue) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int compareTo(AxConcept otherObj) {
+ if (otherObj == null) {
+ return -1;
+ }
+ if (this == otherObj) {
+ return 0;
+ }
+ DummyEntity other = (DummyEntity) otherObj;
+ if (key == null) {
+ if (other.key != null) {
+ return 1;
+ }
+ } else if (!key.equals(other.key)) {
+ return key.compareTo(other.key);
+ }
+ if (doubleValue != other.doubleValue) {
+ return Double.valueOf(doubleValue).compareTo(other.doubleValue);
+ }
+
+ return 0;
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ExceptionsTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ExceptionsTest.java
new file mode 100644
index 000000000..ff87bc2d0
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ExceptionsTest.java
@@ -0,0 +1,66 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.basicmodel.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import org.junit.Test;
+
+
+public class ExceptionsTest {
+
+ @Test
+ public void test() {
+ assertNotNull(new ApexException("Message"));
+ assertNotNull(new ApexException("Message", new AxArtifactKey()));
+ assertNotNull(new ApexException("Message", new IOException()));
+ assertNotNull(new ApexException("Message", new IOException(), new AxArtifactKey()));
+
+ AxArtifactKey key = new AxArtifactKey();
+ ApexException ae = new ApexException("Message", new IOException("IO exception message"), key);
+ assertEquals("Message\ncaused by: Message\ncaused by: IO exception message", ae.getCascadedMessage());
+ assertEquals(key, ae.getObject());
+
+ assertNotNull(new ApexRuntimeException("Message"));
+ assertNotNull(new ApexRuntimeException("Message", new AxArtifactKey()));
+ assertNotNull(new ApexRuntimeException("Message", new IOException()));
+ assertNotNull(new ApexRuntimeException("Message", new IOException(), new AxArtifactKey()));
+
+ AxArtifactKey rkey = new AxArtifactKey();
+ ApexRuntimeException re = new ApexRuntimeException("Runtime Message",
+ new IOException("IO runtime exception message"), rkey);
+ assertEquals("Runtime Message\ncaused by: Runtime Message\ncaused by: IO runtime exception message",
+ re.getCascadedMessage());
+ assertEquals(key, re.getObject());
+
+ assertNotNull(new ApexConceptException("Message"));
+ assertNotNull(new ApexConceptException("Message", new IOException()));
+
+ AxArtifactKey ckey = new AxArtifactKey();
+ ApexException ace = new ApexException("Concept Message", new IOException("IO concept exception message"), ckey);
+ assertEquals("Concept Message\ncaused by: Concept Message\ncaused by: IO concept exception message",
+ ace.getCascadedMessage());
+ assertEquals(ckey, ace.getObject());
+ }
+
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ValidationTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ValidationTest.java
new file mode 100644
index 000000000..21ae9b65c
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ValidationTest.java
@@ -0,0 +1,90 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.basicmodel.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
+
+public class ValidationTest {
+
+ @Test
+ public void test() {
+ AxValidationResult result = new AxValidationResult();
+ AxReferenceKey refKey = new AxReferenceKey("PK", "0.0.1", "PLN", "LN");
+ result = refKey.validate(result);
+
+ assertNotNull(result);
+ assertTrue(result.isOk());
+ assertTrue(result.isValid());
+ assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
+ assertNotNull(result.getMessageList());
+
+ AxValidationMessage vmess0 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
+ ValidationResult.VALID, "Some message");
+ result.addValidationMessage(vmess0);
+
+ assertTrue(result.isOk());
+ assertTrue(result.isValid());
+ assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
+ assertNotNull(result.getMessageList());
+ assertNotNull("hello", result.toString());
+
+ AxValidationMessage vmess1 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
+ ValidationResult.OBSERVATION, "Some message");
+ result.addValidationMessage(vmess1);
+
+ assertTrue(result.isOk());
+ assertTrue(result.isValid());
+ assertEquals(AxValidationResult.ValidationResult.OBSERVATION, result.getValidationResult());
+ assertNotNull(result.getMessageList());
+ assertNotNull("hello", result.toString());
+
+ AxValidationMessage vmess2 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
+ ValidationResult.WARNING, "Some message");
+ result.addValidationMessage(vmess2);
+
+ assertFalse(result.isOk());
+ assertTrue(result.isValid());
+ assertEquals(AxValidationResult.ValidationResult.WARNING, result.getValidationResult());
+ assertNotNull(result.getMessageList());
+ assertNotNull("hello", result.toString());
+
+ AxValidationMessage vmess3 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class,
+ ValidationResult.INVALID, "Some message");
+ result.addValidationMessage(vmess3);
+
+ assertFalse(result.isOk());
+ assertFalse(result.isValid());
+ assertEquals(AxValidationResult.ValidationResult.INVALID, result.getValidationResult());
+ assertNotNull(result.getMessageList());
+ assertNotNull("hello", result.toString());
+
+ assertEquals(AxValidationResult.ValidationResult.INVALID, result.getMessageList().get(3).getValidationResult());
+ assertEquals("Some message", result.getMessageList().get(3).getMessage());
+ assertEquals(AxArtifactKey.class.getName(), result.getMessageList().get(3).getObservedClass());
+ assertEquals(AxArtifactKey.getNullKey(), result.getMessageList().get(3).getObservedKey());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelExceptionTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelExceptionTest.java
new file mode 100644
index 000000000..2571ea65b
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelExceptionTest.java
@@ -0,0 +1,39 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.basicmodel.handling;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import org.junit.Test;
+
+public class ApexModelExceptionTest {
+
+ @Test
+ public void test() {
+ assertNotNull(new ApexModelException("Message"));
+ assertNotNull(new ApexModelException("Message", new IOException()));
+
+ ApexModelException ame = new ApexModelException("Message", new IOException("IO exception message"));
+ assertEquals("Message\ncaused by: Message\ncaused by: IO exception message", ame.getCascadedMessage());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java
new file mode 100644
index 000000000..0f8f956ab
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java
@@ -0,0 +1,94 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
+ * ================================================================================
+ * 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.basicmodel.handling;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
+
+public class ApexModelFileWriterTest {
+
+ @Test
+ public void testModelFileWriter() throws IOException, ApexException {
+ ApexModelFileWriter<AxModel> modelFileWriter = new ApexModelFileWriter<>(true);
+
+ modelFileWriter.setValidate(true);
+ assertTrue(modelFileWriter.isValidate());
+
+ File tempFile = File.createTempFile("ApexFileWriterTest", "test");
+ File tempDir = tempFile.getParentFile();
+
+ File jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/ApexFileWriterTest.json");
+
+ AxModel model = new DummyApexBasicModelCreator().getModel();
+
+ modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath());
+
+ jsonTempFile.delete();
+ new File(tempDir.getAbsolutePath() + "/aaa").delete();
+ new File(tempDir.getAbsolutePath() + "/ccc").delete();
+
+ jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json");
+
+ modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath());
+
+ jsonTempFile.delete();
+
+ new File(tempDir.getAbsolutePath() + "/aaa/bbb").delete();
+ new File(tempDir.getAbsolutePath() + "/aaa").delete();
+ new File(tempDir.getAbsolutePath() + "/ccc/ddd").delete();
+ new File(tempDir.getAbsolutePath() + "/ccc").delete();
+
+ File dirA = new File(tempDir.getAbsolutePath() + "/aaa");
+ // File dirB = new File(tempDir.getAbsolutePath() + "/aaa/bbb");
+ dirA.createNewFile();
+ // dirB.createNewFile();
+
+ jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json");
+ final File jsonTempFile01 = jsonTempFile;
+ assertThatThrownBy(
+ () -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile01.getAbsolutePath()))
+ .hasMessageContaining("could not create directory");
+
+ dirA.delete();
+
+ dirA = new File(tempDir.getAbsolutePath() + "/aaa");
+ File fileB = new File(tempDir.getAbsolutePath() + "/aaa/bbb");
+ dirA.mkdir();
+ fileB.createNewFile();
+
+ jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json");
+
+ File jsonTempFile02 = jsonTempFile;
+ assertThatThrownBy(
+ () -> modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile02.getAbsolutePath()))
+ .hasMessageContaining("error processing file");
+
+ fileB.delete();
+ dirA.delete();
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java
new file mode 100644
index 000000000..1152771ea
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java
@@ -0,0 +1,105 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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.basicmodel.handling;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ApexModelReaderTest {
+ @Test
+ public void testModelReader() throws IOException, ApexException {
+ AxModel model = new DummyApexBasicModelCreator().getModel();
+ AxModel invalidModel = new DummyApexBasicModelCreator().getInvalidModel();
+
+ ApexModelWriter<AxModel> modelWriter = new ApexModelWriter<AxModel>(AxModel.class);
+ modelWriter.setValidate(true);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ modelWriter.write(model, baos);
+
+ ByteArrayOutputStream baosInvalid = new ByteArrayOutputStream();
+ modelWriter.setValidate(false);
+ modelWriter.write(invalidModel, baosInvalid);
+
+ ApexModelReader<AxModel> modelReader = new ApexModelReader<AxModel>(AxModel.class, true);
+
+ modelReader.setValidate(true);
+ assertTrue(modelReader.isValidate());
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ AxModel readModel = modelReader.read(bais);
+ assertEquals(model, readModel);
+
+ ByteArrayInputStream baisInvalid = new ByteArrayInputStream(baosInvalid.toByteArray());
+ assertThatThrownBy(() -> modelReader.read(baisInvalid))
+ .hasMessageStartingWith("Apex concept validation failed");
+ modelReader.setValidate(false);
+ assertFalse(modelReader.isValidate());
+
+ ByteArrayInputStream bais2 = new ByteArrayInputStream(baos.toByteArray());
+ AxModel readModel2 = modelReader.read(bais2);
+ assertEquals(model, readModel2);
+
+ ByteArrayOutputStream baosJson = new ByteArrayOutputStream();
+ modelWriter.write(model, baosJson);
+
+ ByteArrayInputStream baisJson = new ByteArrayInputStream(baosJson.toByteArray());
+ AxModel readModelJson = modelReader.read(baisJson);
+ assertEquals(model, readModelJson);
+
+ String dummyString = "SomeDummyText";
+ ByteArrayInputStream baisDummy = new ByteArrayInputStream(dummyString.getBytes());
+ assertThatThrownBy(() -> modelReader.read(baisDummy))
+ .hasMessageContaining("Unable to unmarshal Apex concept");
+ ByteArrayInputStream nullBais = null;
+ assertThatThrownBy(() -> modelReader.read(nullBais))
+ .hasMessage("concept stream may not be null");
+
+ assertThatThrownBy(() -> {
+ FileInputStream fis = new FileInputStream(new File("somewhere/over/the/rainbow"));
+ modelReader.read(fis);
+ }).hasMessageContaining("rainbow");
+ final File tempFile = File.createTempFile("Apex", "Dummy");
+ BufferedReader br = new BufferedReader(new FileReader(tempFile));
+ br.close();
+ assertThatThrownBy(() -> modelReader.read(br))
+ .hasMessage("Unable to read Apex concept ");
+ tempFile.delete();
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java
new file mode 100644
index 000000000..c95106aa8
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java
@@ -0,0 +1,52 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
+ * ================================================================================
+ * 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.basicmodel.handling;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
+
+public class ApexModelSaverTest {
+
+ @Test
+ public void testModelSaver() throws IOException, ApexException {
+ AxModel model = new DummyApexBasicModelCreator().getModel();
+ assertNotNull(model);
+
+ Path tempPath = Files.createTempDirectory("ApexTest");
+ assertNotNull(tempPath);
+
+ ApexModelSaver<AxModel> modelSaver =
+ new ApexModelSaver<AxModel>(AxModel.class, model, tempPath.toAbsolutePath().toString());
+ assertNotNull(modelSaver);
+ modelSaver.apexModelWriteJson();
+
+ Files.deleteIfExists(new File(tempPath.toAbsolutePath() + "/BasicModel.json").toPath());
+ Files.deleteIfExists(tempPath);
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java
new file mode 100644
index 000000000..13e72d3e2
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java
@@ -0,0 +1,63 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
+ * ================================================================================
+ * 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.basicmodel.handling;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
+
+public class ApexModelStringWriterTest {
+
+ @Test
+ public void testModelStringWriter() throws IOException, ApexException {
+ AxModel basicModel = new DummyApexBasicModelCreator().getModel();
+ assertNotNull(basicModel);
+
+ AxKeyInfo intKeyInfo = basicModel.getKeyInformation().get("IntegerKIKey");
+ AxKeyInfo floatKeyInfo = basicModel.getKeyInformation().get("FloatKIKey");
+
+ // Ensure marshalling is OK
+ ApexModelStringWriter<AxKeyInfo> stringWriter = new ApexModelStringWriter<AxKeyInfo>(true);
+
+ assertNotNull(stringWriter.writeJsonString(intKeyInfo, AxKeyInfo.class));
+ assertNotNull(stringWriter.writeJsonString(floatKeyInfo, AxKeyInfo.class));
+
+ assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class));
+ assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class));
+
+ assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class));
+ assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class));
+
+ assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class)).hasMessage("concept may not be null");
+ assertThatThrownBy(() -> stringWriter.writeString(null, AxKeyInfo.class)).hasMessage("concept may not be null");
+ assertThatThrownBy(() -> stringWriter.writeJsonString(null, AxKeyInfo.class))
+ .hasMessage("error writing JSON string");
+ stringWriter.setValidate(true);
+ assertTrue(stringWriter.isValidate());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java
new file mode 100644
index 000000000..063855976
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java
@@ -0,0 +1,67 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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.basicmodel.handling;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ApexModelWriterTest {
+ @Test
+ public void testModelWriter() throws IOException, ApexException {
+ ApexModelWriter<AxModel> modelWriter = new ApexModelWriter<AxModel>(AxModel.class);
+
+ modelWriter.setValidate(true);
+ assertTrue(modelWriter.isValidate());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ AxModel model = new DummyApexBasicModelCreator().getModel();
+
+ modelWriter.write(model, baos);
+
+ modelWriter.setValidate(false);
+ modelWriter.write(model, baos);
+
+ modelWriter.setValidate(true);
+ model.getKeyInformation().getKeyInfoMap().clear();
+ assertThatThrownBy(() -> modelWriter.write(model, baos))
+ .hasMessageContaining("Apex concept (BasicModel:0.0.1) validation failed");
+ model.getKeyInformation().generateKeyInfo(model);
+
+ assertThatThrownBy(() -> modelWriter.write(null, baos))
+ .hasMessage("concept may not be null");
+
+ ByteArrayOutputStream nullBaos = null;
+ assertThatThrownBy(() -> modelWriter.write(model, nullBaos))
+ .hasMessage("concept stream may not be null");
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyApexBasicModelCreator.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyApexBasicModelCreator.java
new file mode 100644
index 000000000..353722b2d
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyApexBasicModelCreator.java
@@ -0,0 +1,123 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.basicmodel.handling;
+
+import java.util.UUID;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator;
+
+public class DummyApexBasicModelCreator implements TestApexModelCreator<AxModel> {
+
+ @Override
+ public AxModel getModel() {
+ AxModel basicModel = new AxModel();
+
+ basicModel.setKey(new AxArtifactKey("BasicModel", "0.0.1"));
+ basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1")));
+
+ basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey()));
+ basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(),
+ new AxKeyInfo(basicModel.getKeyInformation().getKey()));
+
+ AxKeyInfo intKeyInfo = new AxKeyInfo(new AxArtifactKey("IntegerKIKey", "0.0.1"), UUID.randomUUID(),
+ "IntegerKIKey description");
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKeyInfo.getKey(), new AxKeyInfo(intKeyInfo.getKey()));
+
+ AxKeyInfo floatKeyInfo = new AxKeyInfo(new AxArtifactKey("FloatKIKey", "0.0.1"), UUID.randomUUID(),
+ "FloatKIKey description");
+ basicModel.getKeyInformation().getKeyInfoMap().put(floatKeyInfo.getKey(), new AxKeyInfo(floatKeyInfo.getKey()));
+
+ return basicModel;
+ }
+
+ @Override
+ public final AxModel getMalstructuredModel() {
+ AxModel basicModel = new AxModel();
+
+ // Note: No Data types
+ basicModel.setKey(new AxArtifactKey("BasicModelKey", "0.0.1"));
+ basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1")));
+
+ basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey(),
+ UUID.fromString("00000000-0000-0000-0000-000000000000"),
+ "\nbasic model description\nThis is a multi line description\nwith another line of text."));
+
+ return basicModel;
+ }
+
+ @Override
+ public final AxModel getObservationModel() {
+ AxModel basicModel = getModel();
+
+ // Set key information as blank
+ basicModel.getKeyInformation().getKeyInfoMap().get(basicModel.getKey()).setDescription("");
+
+ return basicModel;
+ }
+
+ @Override
+ public final AxModel getWarningModel() {
+ AxModel basicModel = getModel();
+
+ // Add unreferenced key information
+ AxKeyInfo unreferencedKeyInfo0 = new AxKeyInfo(new AxArtifactKey("Unref0", "0.0.1"));
+ AxKeyInfo unreferencedKeyInfo1 = new AxKeyInfo(new AxArtifactKey("Unref1", "0.0.1"));
+
+ basicModel.getKeyInformation().getKeyInfoMap().put(unreferencedKeyInfo0.getKey(), unreferencedKeyInfo0);
+ basicModel.getKeyInformation().getKeyInfoMap().put(unreferencedKeyInfo1.getKey(), unreferencedKeyInfo1);
+
+ return basicModel;
+ }
+
+ @Override
+ public final AxModel getInvalidModel() {
+ AxModel basicModel = new AxModel();
+
+ basicModel.setKey(new AxArtifactKey("BasicModelKey", "0.0.1"));
+ basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1")));
+
+ basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey(),
+ UUID.fromString("00000000-0000-0000-0000-000000000000"),
+ "nbasic model description\nThis is a multi line description\nwith another line of text."));
+ basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(),
+ new AxKeyInfo(basicModel.getKeyInformation().getKey(),
+ UUID.fromString("00000000-0000-0000-0000-000000000000"), ""));
+
+ return basicModel;
+ }
+
+ /**
+ * Get the model with its references.
+ * @return the model with its references
+ */
+ public final DummyAxModelWithReferences getModelWithReferences() {
+ AxModel model = getModel();
+
+ DummyAxModelWithReferences modelWithReferences = new DummyAxModelWithReferences(model.getKey());
+ modelWithReferences.setKeyInformation(model.getKeyInformation());
+ modelWithReferences.setReferenceKeyList();
+
+ return modelWithReferences;
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyAxModelWithReferences.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyAxModelWithReferences.java
new file mode 100644
index 000000000..887755d03
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyAxModelWithReferences.java
@@ -0,0 +1,71 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.basicmodel.handling;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+
+public class DummyAxModelWithReferences extends AxModel {
+ private static final long serialVersionUID = -8194956638511120008L;
+
+ private List<AxKey> extrakeyList = new ArrayList<>();
+
+ public DummyAxModelWithReferences(final AxArtifactKey key) {
+ super(key);
+ }
+
+ @Override
+ public List<AxKey> getKeys() {
+ List<AxKey> keys = super.getKeys();
+ keys.addAll(extrakeyList);
+
+ return keys;
+ }
+
+ public List<AxKey> getExtrakeyList() {
+ return extrakeyList;
+ }
+
+ /**
+ * Set the reference key list.
+ */
+ public void setReferenceKeyList() {
+ List<AxKey> keys = super.getKeys();
+
+ for (AxKey key: keys) {
+ AxArtifactKey akey = (AxArtifactKey) key;
+ AxReferenceKey keyRef = new AxReferenceKey(akey, akey.getName());
+ extrakeyList.add(keyRef);
+ }
+ }
+
+ public void addKey(final AxKey akey) {
+ extrakeyList.add(akey);
+ }
+
+ public void removeKey(final AxKey akey) {
+ extrakeyList.remove(akey);
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTest.java
new file mode 100644
index 000000000..905a27f38
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTest.java
@@ -0,0 +1,294 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * ================================================================================
+ * 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.basicmodel.handling;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyUse;
+import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
+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.basicmodel.service.ModelService;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
+
+public class SupportApexBasicModelConceptsTest {
+ TestApexModel<AxModel> testApexModel;
+
+ @Before
+ public void setup() throws Exception {
+ testApexModel = new TestApexModel<AxModel>(AxModel.class, new DummyApexBasicModelCreator());
+ }
+
+ @Test
+ public void testModelConcepts() {
+ final AxModel model = testApexModel.getModel();
+ assertNotNull(model);
+ model.clean();
+ assertNotNull(model);
+
+ AxValidationResult result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.WARNING, result.getValidationResult());
+
+ model.register();
+ assertEquals(model.getKeyInformation(), ModelService.getModel(AxKeyInformation.class));
+
+ final AxModel clonedModel = new AxModel(model);
+ assertTrue(clonedModel.toString().startsWith("AxModel:(key=AxArtifactKey:(name=BasicModel"));
+
+ assertNotEquals(0, model.hashCode());
+
+ // disabling sonar because this code tests the equals() method
+ assertEquals(model, model); // NOSONAR
+ assertEquals(model, clonedModel);
+ assertNotNull(model);
+ assertNotEquals(model, (Object) "Hello");
+ clonedModel.getKey().setVersion("0.0.2");
+ assertNotEquals(model, clonedModel);
+ clonedModel.getKey().setVersion("0.0.1");
+
+ assertEquals(0, model.compareTo(model));
+ assertNotEquals(0, model.compareTo(null));
+ assertNotEquals(0, model.compareTo(new AxReferenceKey()));
+ assertEquals(0, model.compareTo(clonedModel));
+ clonedModel.getKey().setVersion("0.0.2");
+ assertNotEquals(0, model.compareTo(clonedModel));
+ clonedModel.getKey().setVersion("0.0.1");
+
+ assertNotNull(model.getKeys());
+
+ model.getKeyInformation().generateKeyInfo(model);
+ assertNotNull(model.getKeyInformation());
+
+ }
+
+ @Test
+ public void testKeyInformation() {
+
+ final AxModel model = testApexModel.getModel();
+ final AxKeyInformation keyI = model.getKeyInformation();
+ final AxKeyInformation clonedKeyI = new AxKeyInformation(keyI);
+
+ assertNotNull(keyI);
+ assertNotEquals(keyI, (Object) new AxArtifactKey());
+ assertEquals(keyI, clonedKeyI);
+
+ clonedKeyI.setKey(new AxArtifactKey());
+ assertNotEquals(keyI, clonedKeyI);
+ clonedKeyI.setKey(keyI.getKey());
+
+ assertEquals(0, keyI.compareTo(keyI));
+ assertEquals(0, keyI.compareTo(clonedKeyI));
+ assertNotEquals(0, keyI.compareTo(null));
+ assertNotEquals(0, keyI.compareTo(new AxArtifactKey()));
+
+ clonedKeyI.setKey(new AxArtifactKey());
+ assertNotEquals(0, keyI.compareTo(clonedKeyI));
+ clonedKeyI.setKey(keyI.getKey());
+ assertEquals(0, keyI.compareTo(clonedKeyI));
+
+ clonedKeyI.getKeyInfoMap().clear();
+ assertNotEquals(0, keyI.compareTo(clonedKeyI));
+
+ AxKeyInfo keyInfo = keyI.get("BasicModel");
+ assertNotNull(keyInfo);
+
+ keyInfo = keyI.get(new AxArtifactKey("BasicModel", "0.0.1"));
+ assertNotNull(keyInfo);
+
+ Set<AxKeyInfo> keyInfoSet = keyI.getAll("BasicModel");
+ assertNotNull(keyInfoSet);
+
+ keyInfoSet = keyI.getAll("BasicModel", "0..0.1");
+ assertNotNull(keyInfoSet);
+
+ List<AxKey> keys = model.getKeys();
+ assertNotEquals(0, keys.size());
+
+ keys = keyI.getKeys();
+ assertNotEquals(0, keys.size());
+
+ model.getKeyInformation().generateKeyInfo(model);
+ assertNotNull(model.getKeyInformation());
+ model.getKeyInformation().getKeyInfoMap().clear();
+ model.getKeyInformation().generateKeyInfo(model);
+ assertNotNull(model.getKeyInformation());
+ }
+
+ @Test
+ public void testClonedKey() {
+ final AxModel model = testApexModel.getModel();
+ final AxKeyInformation keyI = model.getKeyInformation();
+ final AxKeyInformation clonedKeyI = new AxKeyInformation(keyI);
+ AxValidationResult result = new AxValidationResult();
+
+ clonedKeyI.setKey(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = clonedKeyI.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+ clonedKeyI.setKey(keyI.getKey());
+
+ clonedKeyI.getKeyInfoMap().clear();
+ result = new AxValidationResult();
+ result = clonedKeyI.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+ clonedKeyI.generateKeyInfo(model);
+
+ result = new AxValidationResult();
+ result = clonedKeyI.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ clonedKeyI.getKeyInfoMap().put(AxArtifactKey.getNullKey(), null);
+ result = new AxValidationResult();
+ result = clonedKeyI.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+ clonedKeyI.getKeyInfoMap().clear();
+ clonedKeyI.generateKeyInfo(model);
+
+ result = new AxValidationResult();
+ result = clonedKeyI.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ clonedKeyI.getKeyInfoMap().put(new AxArtifactKey("SomeKey", "0.0.1"), null);
+ result = new AxValidationResult();
+ result = clonedKeyI.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+ clonedKeyI.getKeyInfoMap().clear();
+ clonedKeyI.generateKeyInfo(model);
+
+ result = new AxValidationResult();
+ result = clonedKeyI.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxKeyInfo mk = clonedKeyI.get(new AxArtifactKey("BasicModel", "0.0.1"));
+ assertNotNull(mk);
+ mk.setKey(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = clonedKeyI.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+ clonedKeyI.getKeyInfoMap().clear();
+ clonedKeyI.generateKeyInfo(model);
+
+ result = new AxValidationResult();
+ result = clonedKeyI.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxModel clonedModel = new AxModel(model);
+ clonedModel.setKey(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = clonedModel.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ clonedModel.setKey(model.getKey());
+ result = new AxValidationResult();
+ result = clonedKeyI.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+ }
+
+ @Test
+ public void testModelConceptsWithReferences() {
+ final DummyAxModelWithReferences mwr = new DummyApexBasicModelCreator().getModelWithReferences();
+ assertNotNull(mwr);
+ mwr.getKeyInformation().getKeyInfoMap().clear();
+ mwr.getKeyInformation().generateKeyInfo(mwr);
+
+ AxValidationResult result = new AxValidationResult();
+ result = mwr.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ // Duplicate key error
+ mwr.addKey(mwr.getKey());
+ result = new AxValidationResult();
+ result = mwr.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+ mwr.removeKey(mwr.getKey());
+
+ result = new AxValidationResult();
+ result = mwr.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ // Null Reference Key
+ mwr.addKey(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = mwr.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+ mwr.removeKey(AxReferenceKey.getNullKey());
+
+ result = new AxValidationResult();
+ result = mwr.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ // Duplicate Reference Key
+ final AxReferenceKey rKey = new AxReferenceKey(mwr.getKey(), "LocalName");
+ mwr.addKey(rKey);
+ mwr.addKey(rKey);
+ result = new AxValidationResult();
+ result = mwr.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+ mwr.removeKey(rKey);
+ mwr.removeKey(rKey);
+
+ result = new AxValidationResult();
+ result = mwr.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ // Key Use is legal
+ final AxKeyUse keyU = new AxKeyUse(mwr.getKey());
+ mwr.addKey(keyU);
+ result = new AxValidationResult();
+ result = mwr.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+ mwr.removeKey(keyU);
+
+ // Key Use on bad artifact key
+ final AxKeyUse keyBadUsage = new AxKeyUse(new AxArtifactKey("SomeKey", "0.0.1"));
+ mwr.addKey(keyBadUsage);
+ result = new AxValidationResult();
+ result = mwr.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+ mwr.removeKey(keyBadUsage);
+
+ // Key Use on bad reference key
+ final AxKeyUse keyBadReferenceUsage = new AxKeyUse(new AxReferenceKey("SomeKey", "0.0.1", "Local"));
+ mwr.addKey(keyBadReferenceUsage);
+ result = new AxValidationResult();
+ result = mwr.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+ mwr.removeKey(keyBadReferenceUsage);
+
+ result = new AxValidationResult();
+ result = mwr.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java
new file mode 100644
index 000000000..68f755886
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java
@@ -0,0 +1,116 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020-2022 Nordix Foundation.
+ * ================================================================================
+ * 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.basicmodel.handling;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
+
+public class SupportApexBasicModelTest {
+ // As there are no real concepts in a basic model, this is as near to a valid model as we can get
+ private static final String VALID_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
+ + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n"
+ + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
+
+ private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
+ + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n"
+ + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n"
+ + "AxArtifactKey:(name=Unref0,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n"
+ + "AxArtifactKey:(name=Unref1,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts"
+ + ".AxModel:WARNING:key not found for key information entry\n" + "********************************";
+
+ private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
+ + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxKeyInfo:OBSERVATION:description is blank\n"
+ + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
+ + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxKeyInformation:INVALID:duplicate UUID found on keyInfoMap entry AxArtifactKey:"
+ + "(name=KeyInfoMapKey,version=0.0.1):00000000-0000-0000-0000-000000000000\n"
+ + "********************************";
+
+ private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
+ + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts."
+ + "AxModel:INVALID:key information not found for key "
+ + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" + "********************************";
+
+ TestApexModel<AxModel> testApexModel;
+
+ /**
+ * Set up the test.
+ *
+ * @throws Exception any exception thrown by the test
+ */
+ @Before
+ public void setup() throws Exception {
+ testApexModel = new TestApexModel<AxModel>(AxModel.class, new DummyApexBasicModelCreator());
+ }
+
+ @Test
+ public void testModelValid() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelValid();
+ assertEquals(VALID_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testApexModelVaidateObservation() throws Exception {
+ assertThatThrownBy(testApexModel::testApexModelVaidateObservation)
+ .hasMessage("model should have observations");
+ }
+
+ @Test
+ public void testApexModelVaidateWarning() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
+ assertEquals(WARNING_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelVaidateInvalidModel() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
+ assertEquals(INVALID_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelVaidateMalstructured() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
+ assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelWriteReadJson() throws Exception {
+ testApexModel.testApexModelWriteReadJson();
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator0.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator0.java
new file mode 100644
index 000000000..e835bc0fc
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator0.java
@@ -0,0 +1,64 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.basicmodel.handling;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator;
+
+public class SupportApexModelCreator0 implements TestApexModelCreator<AxModel> {
+
+ @Override
+ public AxModel getModel() {
+ AxModel basicModel = new AxModel();
+
+ basicModel.setKey(new AxArtifactKey("BasicModel", "0.0.1"));
+ basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1")));
+
+ basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey()));
+ basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(),
+ new AxKeyInfo(basicModel.getKeyInformation().getKey()));
+
+ return basicModel;
+ }
+
+ @Override
+ public final AxModel getMalstructuredModel() {
+ return getModel();
+ }
+
+ @Override
+ public final AxModel getObservationModel() {
+ return getModel();
+ }
+
+ @Override
+ public final AxModel getWarningModel() {
+ return getModel();
+ }
+
+ @Override
+ public final AxModel getInvalidModel() {
+ return getModel();
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator1.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator1.java
new file mode 100644
index 000000000..9ad34a38c
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator1.java
@@ -0,0 +1,68 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.basicmodel.handling;
+
+import java.util.UUID;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator;
+
+public class SupportApexModelCreator1 implements TestApexModelCreator<AxModel> {
+
+ @Override
+ public AxModel getModel() {
+ return getInvalidModel();
+ }
+
+ @Override
+ public final AxModel getMalstructuredModel() {
+ return getInvalidModel();
+ }
+
+ @Override
+ public final AxModel getObservationModel() {
+ return getInvalidModel();
+ }
+
+ @Override
+ public final AxModel getWarningModel() {
+ return getInvalidModel();
+ }
+
+ @Override
+ public final AxModel getInvalidModel() {
+ AxModel basicModel = new AxModel();
+
+ basicModel.setKey(new AxArtifactKey("BasicModelKey", "0.0.1"));
+ basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1")));
+
+ basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey(),
+ UUID.fromString("00000000-0000-0000-0000-000000000000"),
+ "nbasic model description\nThis is a multi line description\nwith another line of text."));
+ basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(),
+ new AxKeyInfo(basicModel.getKeyInformation().getKey(),
+ UUID.fromString("00000000-0000-0000-0000-000000000000"), ""));
+
+ return basicModel;
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator2.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator2.java
new file mode 100644
index 000000000..0ab7aab7f
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexModelCreator2.java
@@ -0,0 +1,64 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.basicmodel.handling;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator;
+
+public class SupportApexModelCreator2 implements TestApexModelCreator<AxModel> {
+
+ @Override
+ public AxModel getModel() {
+ AxModel basicModel = new AxModel();
+
+ basicModel.setKey(new AxArtifactKey("BasicModel", "0.0.1"));
+ basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1")));
+
+ basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey()));
+ basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(),
+ new AxKeyInfo(basicModel.getKeyInformation().getKey()));
+ basicModel.getKeyInformation().get("BasicModel").setDescription("");
+ return basicModel;
+ }
+
+ @Override
+ public final AxModel getMalstructuredModel() {
+ return getModel();
+ }
+
+ @Override
+ public final AxModel getObservationModel() {
+ return getModel();
+ }
+
+ @Override
+ public final AxModel getWarningModel() {
+ return getModel();
+ }
+
+ @Override
+ public final AxModel getInvalidModel() {
+ return getModel();
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java
new file mode 100644
index 000000000..d55a9da29
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java
@@ -0,0 +1,111 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020-2022 Nordix Foundation
+ * ================================================================================
+ * 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.basicmodel.handling;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
+
+public class SupportBasicModelTest {
+
+ @Test
+ public void testNormalModelCreator() throws ApexException {
+ final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
+ new DummyApexBasicModelCreator());
+
+ testApexModel.testApexModelValid();
+ assertThatThrownBy(testApexModel::testApexModelVaidateObservation)
+ .hasMessage("model should have observations");
+ testApexModel.testApexModelVaidateWarning();
+ testApexModel.testApexModelVaidateInvalidModel();
+ testApexModel.testApexModelVaidateMalstructured();
+
+ testApexModel.testApexModelWriteReadJson();
+ }
+
+ @Test
+ public void testModelsUnequal() throws ApexException {
+ final TestApexModel<AxModel> testApexModel0 = new TestApexModel<AxModel>(AxModel.class,
+ new DummyApexBasicModelCreator());
+ final TestApexModel<AxModel> testApexModel1 = new TestApexModel<AxModel>(AxModel.class,
+ new DummyApexBasicModelCreator());
+
+ testApexModel1.getModel().getKey().setVersion("0.0.2");
+
+ assertThatThrownBy(() -> testApexModel0.checkModelEquality(testApexModel0.getModel(), testApexModel1.getModel(),
+ "Models are not equal")).hasMessage("Models are not equal");
+ }
+
+ @Test
+ public void testModelCreator0() throws ApexException {
+ final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
+ new SupportApexModelCreator0());
+
+ testApexModel.testApexModelValid();
+ assertThatThrownBy(() -> testApexModel.testApexModelVaidateObservation())
+ .hasMessage("model should have observations");
+ assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning())
+ .hasMessage("model should have warnings");
+ assertThatThrownBy(() -> testApexModel.testApexModelVaidateInvalidModel())
+ .hasMessage("model should not be valid ***validation of model successful***");
+ assertThatThrownBy(() -> testApexModel.testApexModelVaidateMalstructured())
+ .hasMessage("model should not be valid ***validation of model successful***");
+ }
+
+ @Test
+ public void testModelCreator1() throws ApexException {
+ final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
+ new SupportApexModelCreator1());
+
+ assertThatThrownBy(() -> testApexModel.testApexModelValid())
+ .hasMessageStartingWith("model is invalid");
+ assertThatThrownBy(() -> testApexModel.testApexModelVaidateObservation())
+ .hasMessageStartingWith("model is invalid");
+ assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning())
+ .hasMessageStartingWith("model is invalid");
+ testApexModel.testApexModelVaidateInvalidModel();
+ testApexModel.testApexModelVaidateMalstructured();
+ }
+
+ @Test
+ public void testModelCreator2() throws ApexException {
+ final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
+ new SupportApexModelCreator2());
+
+ testApexModel.testApexModelValid();
+ testApexModel.testApexModelVaidateObservation();
+ assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning())
+ .hasMessage("model should have warnings");
+ }
+
+ @Test
+ public void testModelCreator1Json() throws ApexException {
+ final TestApexModel<AxModel> testApexModel = new TestApexModel<AxModel>(AxModel.class,
+ new SupportApexModelCreator1());
+
+ assertThatThrownBy(() -> testApexModel.testApexModelWriteReadJson())
+ .hasMessageStartingWith("error processing file");
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java
new file mode 100644
index 000000000..1783fc00f
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java
@@ -0,0 +1,217 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020-2022 Nordix Foundation.
+ * ================================================================================
+ * 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.basicmodel.handling;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.UUID;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
+
+public class SupportConceptGetterTest {
+
+ private static final AxKeyInfo intKI01 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey01", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey01 description");
+ private static final AxKeyInfo intKI11 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey11", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey11 description");
+ private static final AxKeyInfo intKI21 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey21", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey21 description");
+ private static final AxKeyInfo intKI22 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey22", "0.0.2"),
+ UUID.randomUUID(), "IntegerKIKey22 description");
+ private static final AxKeyInfo intKI23 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey23", "0.0.3"),
+ UUID.randomUUID(), "IntegerKIKey23 description");
+ private static final AxKeyInfo intKI24 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey24", "0.0.4"),
+ UUID.randomUUID(), "IntegerKIKey24 description");
+ private static final AxKeyInfo intKI25 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey25", "0.0.5"),
+ UUID.randomUUID(), "IntegerKIKey25 description");
+ private static final AxKeyInfo intKI26 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey26", "0.0.6"),
+ UUID.randomUUID(), "IntegerKIKey26 description");
+ private static final AxKeyInfo intKI31 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey31", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey31 description");
+ private static final AxKeyInfo intKI41 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey41", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey41 description");
+ private static final AxKeyInfo intKI51 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey51", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey51 description");
+ private static final AxKeyInfo intKI52 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey52", "0.0.2"),
+ UUID.randomUUID(), "IntegerKIKey52 description");
+ private static final AxKeyInfo intKI53 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey53", "0.0.3"),
+ UUID.randomUUID(), "IntegerKIKey53 description");
+ private static final AxKeyInfo intKI54 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey54", "0.0.4"),
+ UUID.randomUUID(), "IntegerKIKey54 description");
+ private static final AxKeyInfo intKI61 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey61", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey61 description");
+ private static final AxKeyInfo intKI62 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey62", "0.0.2"),
+ UUID.randomUUID(), "IntegerKIKey62 description");
+ private static final AxKeyInfo intKI63 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey63", "0.0.3"),
+ UUID.randomUUID(), "IntegerKIKey63 description");
+ private static final AxKeyInfo intKI64 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey64", "0.0.4"),
+ UUID.randomUUID(), "IntegerKIKey64 description");
+ private static final AxKeyInfo intKI71 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey71", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey71 description");
+ private static final AxKeyInfo intKI81 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey81", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey81 description");
+ private static final AxKeyInfo intKI91 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey91", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey91 description");
+ private static final AxKeyInfo floatKI01 = new AxKeyInfo(new AxArtifactKey("FloatKIKey01", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey01 description");
+ private static final AxKeyInfo floatKI11 = new AxKeyInfo(new AxArtifactKey("FloatKIKey11", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey11 description");
+ private static final AxKeyInfo floatKI21 = new AxKeyInfo(new AxArtifactKey("FloatKIKey21", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey21 description");
+ private static final AxKeyInfo floatKI31 = new AxKeyInfo(new AxArtifactKey("FloatKIKey31", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey31 description");
+ private static final AxKeyInfo floatKI41 = new AxKeyInfo(new AxArtifactKey("FloatKIKey41", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey41 description");
+ private static final AxKeyInfo floatKI51 = new AxKeyInfo(new AxArtifactKey("FloatKIKey51", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey51 description");
+ private static final AxKeyInfo floatKI61 = new AxKeyInfo(new AxArtifactKey("FloatKIKey61", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey61 description");
+ private static final AxKeyInfo floatKI71 = new AxKeyInfo(new AxArtifactKey("FloatKIKey71", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey71 description");
+ private static final AxKeyInfo floatKI81 = new AxKeyInfo(new AxArtifactKey("FloatKIKey81", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey81 description");
+ private static final AxKeyInfo floatKI82 = new AxKeyInfo(new AxArtifactKey("FloatKIKey82", "0.0.2"),
+ UUID.randomUUID(), "IntegerKIKey82 description");
+ private static final AxKeyInfo floatKI83 = new AxKeyInfo(new AxArtifactKey("FloatKIKey83", "0.0.3"),
+ UUID.randomUUID(), "IntegerKIKey83 description");
+ private static final AxKeyInfo floatKI91 = new AxKeyInfo(new AxArtifactKey("FloatKIKey91", "0.0.1"),
+ UUID.randomUUID(), "IntegerKIKey91 description");
+ private static final AxKeyInfo floatKI92 = new AxKeyInfo(new AxArtifactKey("FloatKIKey92", "0.0.2"),
+ UUID.randomUUID(), "IntegerKIKey92 description");
+ private static final AxKeyInfo floatKI93 = new AxKeyInfo(new AxArtifactKey("FloatKIKey93", "0.0.3"),
+ UUID.randomUUID(), "IntegerKIKey93 description");
+
+ @Test
+ public void testConceptGetterInteger() {
+ AxModel basicModel = setTestBasicModel();
+
+ assertNull(basicModel.getKeyInformation().get("NonExistantKey", "0.0.6"));
+ assertEquals(intKI26, basicModel.getKeyInformation().get("IntegerKIKey26", "0.0.6"));
+ assertEquals(intKI62, basicModel.getKeyInformation().get("IntegerKIKey62", "0.0.2"));
+ assertEquals(intKI21, basicModel.getKeyInformation().get("IntegerKIKey21", "0.0.1"));
+ assertEquals(intKI61, basicModel.getKeyInformation().get("IntegerKIKey61", "0.0.1"));
+
+ assertNull(basicModel.getKeyInformation().get("NonExistantKey"));
+
+ assertEquals(intKI01, basicModel.getKeyInformation().get("IntegerKIKey01"));
+ assertEquals(intKI11, basicModel.getKeyInformation().get("IntegerKIKey11"));
+ assertEquals(intKI26, basicModel.getKeyInformation().get("IntegerKIKey26"));
+ assertEquals(intKI31, basicModel.getKeyInformation().get("IntegerKIKey31"));
+ assertEquals(intKI41, basicModel.getKeyInformation().get("IntegerKIKey41"));
+ assertEquals(intKI54, basicModel.getKeyInformation().get("IntegerKIKey54"));
+ assertEquals(intKI64, basicModel.getKeyInformation().get("IntegerKIKey64"));
+ assertEquals(intKI71, basicModel.getKeyInformation().get("IntegerKIKey71"));
+ assertEquals(intKI81, basicModel.getKeyInformation().get("IntegerKIKey81"));
+ assertEquals(intKI91, basicModel.getKeyInformation().get("IntegerKIKey91"));
+ }
+
+ @Test
+ public void testConceptGetterFloat() {
+ AxModel basicModel = setTestBasicModel();
+
+ assertEquals(floatKI01, basicModel.getKeyInformation().get("FloatKIKey01"));
+ assertEquals(floatKI11, basicModel.getKeyInformation().get("FloatKIKey11"));
+ assertEquals(floatKI21, basicModel.getKeyInformation().get("FloatKIKey21"));
+ assertEquals(floatKI31, basicModel.getKeyInformation().get("FloatKIKey31"));
+ assertEquals(floatKI41, basicModel.getKeyInformation().get("FloatKIKey41"));
+ assertEquals(floatKI51, basicModel.getKeyInformation().get("FloatKIKey51"));
+ assertEquals(floatKI61, basicModel.getKeyInformation().get("FloatKIKey61"));
+ assertEquals(floatKI71, basicModel.getKeyInformation().get("FloatKIKey71"));
+ assertEquals(floatKI83, basicModel.getKeyInformation().get("FloatKIKey83"));
+ assertEquals(floatKI93, basicModel.getKeyInformation().get("FloatKIKey93"));
+ }
+
+ @Test
+ public void testMarshalling() throws IOException, ApexException {
+ AxModel basicModel = setTestBasicModel();
+
+ // Ensure marshalling and unmarshalling is OK
+ ApexModelReader<AxModel> modelReader = new ApexModelReader<AxModel>(AxModel.class);
+ ApexModelFileWriter<AxModel> modelWriter = new ApexModelFileWriter<AxModel>(true);
+
+ modelReader.setValidate(false);
+ modelWriter.setValidate(false);
+
+ File tempJsonFile = File.createTempFile("ApexModel", "json");
+ modelWriter.apexModelWriteJsonFile(basicModel, AxModel.class, tempJsonFile.getCanonicalPath());
+
+ FileInputStream jsonFileInputStream = new FileInputStream(tempJsonFile);
+ AxModel readJsonModel = modelReader.read(jsonFileInputStream);
+ jsonFileInputStream.close();
+ assertEquals(basicModel, readJsonModel);
+ assertEquals(intKI91, readJsonModel.getKeyInformation().get("IntegerKIKey91"));
+ assertNotNull(readJsonModel.getKeyInformation().get("FloatKIKey"));
+ tempJsonFile.delete();
+ }
+
+ private AxModel setTestBasicModel() {
+ AxModel basicModel = new DummyApexBasicModelCreator().getModel();
+ assertNotNull(basicModel);
+
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI31.getKey(), intKI31);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI24.getKey(), intKI24);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI11.getKey(), intKI11);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI64.getKey(), intKI64);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI41.getKey(), intKI41);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI51.getKey(), intKI51);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI23.getKey(), intKI23);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI81.getKey(), intKI81);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI71.getKey(), intKI71);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI01.getKey(), intKI01);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI91.getKey(), intKI91);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI52.getKey(), intKI52);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI53.getKey(), intKI53);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI62.getKey(), intKI62);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI54.getKey(), intKI54);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI26.getKey(), intKI26);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI22.getKey(), intKI22);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI25.getKey(), intKI25);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI21.getKey(), intKI21);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI61.getKey(), intKI61);
+ basicModel.getKeyInformation().getKeyInfoMap().put(intKI63.getKey(), intKI63);
+
+ basicModel.getKeyInformation().getKeyInfoMap().put(floatKI11.getKey(), floatKI11);
+ basicModel.getKeyInformation().getKeyInfoMap().put(floatKI83.getKey(), floatKI83);
+ basicModel.getKeyInformation().getKeyInfoMap().put(floatKI51.getKey(), floatKI51);
+ basicModel.getKeyInformation().getKeyInfoMap().put(floatKI71.getKey(), floatKI71);
+ basicModel.getKeyInformation().getKeyInfoMap().put(floatKI21.getKey(), floatKI21);
+ basicModel.getKeyInformation().getKeyInfoMap().put(floatKI81.getKey(), floatKI81);
+ basicModel.getKeyInformation().getKeyInfoMap().put(floatKI92.getKey(), floatKI92);
+ basicModel.getKeyInformation().getKeyInfoMap().put(floatKI91.getKey(), floatKI91);
+ basicModel.getKeyInformation().getKeyInfoMap().put(floatKI01.getKey(), floatKI01);
+ basicModel.getKeyInformation().getKeyInfoMap().put(floatKI82.getKey(), floatKI82);
+ basicModel.getKeyInformation().getKeyInfoMap().put(floatKI61.getKey(), floatKI61);
+ basicModel.getKeyInformation().getKeyInfoMap().put(floatKI41.getKey(), floatKI41);
+ basicModel.getKeyInformation().getKeyInfoMap().put(floatKI31.getKey(), floatKI31);
+ basicModel.getKeyInformation().getKeyInfoMap().put(floatKI93.getKey(), floatKI93);
+
+ return basicModel;
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/basicmodel/service/ModelServiceTest.java b/model/src/test/java/org/onap/policy/apex/model/basicmodel/service/ModelServiceTest.java
new file mode 100644
index 000000000..746e10607
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/basicmodel/service/ModelServiceTest.java
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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.basicmodel.service;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+import org.onap.policy.apex.model.basicmodel.handling.DummyApexBasicModelCreator;
+
+public class ModelServiceTest {
+
+ @Test
+ public void testModelService() {
+ ModelService.clear();
+
+ assertFalse(ModelService.existsModel(AxKeyInformation.class));
+ assertThatThrownBy(() -> ModelService.getModel(AxKeyInformation.class))
+ .hasMessage("Model for org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation "
+ + "not found in model service");
+ ModelService.registerModel(AxKeyInformation.class,
+ new DummyApexBasicModelCreator().getModel().getKeyInformation());
+ assertTrue(ModelService.existsModel(AxKeyInformation.class));
+ assertNotNull(ModelService.getModel(AxKeyInformation.class));
+
+ ModelService.deregisterModel(AxKeyInformation.class);
+
+ assertFalse(ModelService.existsModel(AxKeyInformation.class));
+ assertThatThrownBy(() -> ModelService.getModel(AxKeyInformation.class))
+ .hasMessage("Model for org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation "
+ + "not found in model service");
+ ModelService.registerModel(AxKeyInformation.class,
+ new DummyApexBasicModelCreator().getModel().getKeyInformation());
+ assertTrue(ModelService.existsModel(AxKeyInformation.class));
+ assertNotNull(ModelService.getModel(AxKeyInformation.class));
+
+ ModelService.clear();
+ assertFalse(ModelService.existsModel(AxKeyInformation.class));
+ assertThatThrownBy(() -> ModelService.getModel(AxKeyInformation.class))
+ .hasMessage("Model for org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation "
+ + "not found in model service");
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java b/model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java
new file mode 100644
index 000000000..44161b329
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java
@@ -0,0 +1,248 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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.contextmodel.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
+
+/**
+ * Context album tests.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ContextAlbumsTest {
+
+ @Test
+ public void testNewAxContectAlbum() {
+ assertNotNull(new AxContextAlbum());
+ assertNotNull(new AxContextAlbum(new AxArtifactKey()));
+ assertNotNull(new AxContextAlbum(new AxArtifactKey(), "AlbumScope", false, new AxArtifactKey()));
+ }
+
+ @Test
+ public void testContextAlbums() {
+ final AxArtifactKey albumKey = new AxArtifactKey("AlbumName", "0.0.1");
+ final AxArtifactKey albumSchemaKey = new AxArtifactKey("AlbumSchemaName", "0.0.1");
+
+ final AxContextAlbum album = new AxContextAlbum(albumKey, "AlbumScope", false, albumSchemaKey);
+ assertNotNull(album);
+
+ final AxArtifactKey newKey = new AxArtifactKey("NewAlbumName", "0.0.1");
+ album.setKey(newKey);
+ assertEquals("NewAlbumName:0.0.1", album.getKey().getId());
+ assertEquals("NewAlbumName:0.0.1", album.getKeys().get(0).getId());
+ album.setKey(albumKey);
+
+ assertThatThrownBy(() -> album.setScope(""))
+ .hasMessage("parameter \"scope\": value \"\", does not match regular expression "
+ + "\"[A-Za-z0-9\\-_]+\"");
+
+ album.setScope("NewAlbumScope");
+ assertEquals("NewAlbumScope", album.getScope());
+
+ assertEquals(false, album.isWritable());
+ album.setWritable(true);
+ assertEquals(true, album.isWritable());
+
+ final AxArtifactKey newSchemaKey = new AxArtifactKey("NewAlbumSchemaName", "0.0.1");
+ album.setItemSchema(newSchemaKey);
+ assertEquals("NewAlbumSchemaName:0.0.1", album.getItemSchema().getId());
+ album.setItemSchema(albumSchemaKey);
+ }
+
+ private AxContextAlbum setTestAlbum() {
+ final AxArtifactKey newKey = new AxArtifactKey("NewAlbumName", "0.0.1");
+ final AxArtifactKey newSchemaKey = new AxArtifactKey("NewAlbumSchemaName", "0.0.1");
+
+ final AxContextAlbum album = new AxContextAlbum(newKey, "AlbumScope", false, newSchemaKey);
+
+ album.setScope("NewAlbumScope");
+ album.setWritable(true);
+
+ return album;
+ }
+
+ @Test
+ public void testAxvalidationAlbum() {
+ final AxContextAlbum album = setTestAlbum();
+ AxValidationResult result = new AxValidationResult();
+ result = album.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ album.setKey(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = album.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ final AxArtifactKey newKey = new AxArtifactKey("NewAlbumName", "0.0.1");
+ album.setKey(newKey);
+ result = new AxValidationResult();
+ result = album.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ album.setScope("UNDEFINED");
+ result = new AxValidationResult();
+ result = album.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ album.setScope("NewAlbumScope");
+ result = new AxValidationResult();
+ result = album.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ album.setItemSchema(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = album.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ final AxArtifactKey albumSchemaKey = new AxArtifactKey("AlbumSchemaName", "0.0.1");
+ album.setItemSchema(albumSchemaKey);
+ result = new AxValidationResult();
+ result = album.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ }
+
+ @Test
+ public void testEqualsAlbum() {
+ final AxContextAlbum album = setTestAlbum();
+ final AxArtifactKey newKey = new AxArtifactKey("NewAlbumName", "0.0.1");
+ final AxArtifactKey albumSchemaKey = new AxArtifactKey("AlbumSchemaName", "0.0.1");
+ album.setItemSchema(albumSchemaKey);
+
+ final AxContextAlbum clonedAlbum = new AxContextAlbum(album);
+ assertEquals("AxContextAlbum(key=AxArtifactKey:(name=NewAlbumName,version=0.0.1), "
+ + "scope=NewAlbumScope, isWritable=true, itemSchema="
+ + "AxArtifactKey:(name=AlbumSchemaName,version=0.0.1))", clonedAlbum.toString());
+
+ assertNotEquals(0, album.hashCode());
+ // disabling sonar because this code tests the equals() method
+ assertEquals(album, album); // NOSONAR
+ assertEquals(album, clonedAlbum);
+ assertNotNull(album);
+ assertNotEquals(album, (Object) "Hello");
+ assertNotEquals(album, new AxContextAlbum(new AxArtifactKey(), "Scope", false, AxArtifactKey.getNullKey()));
+ assertNotEquals(album, new AxContextAlbum(newKey, "Scope", false, AxArtifactKey.getNullKey()));
+ assertNotEquals(album, new AxContextAlbum(newKey, "NewAlbumScope", false, AxArtifactKey.getNullKey()));
+ assertNotEquals(album, new AxContextAlbum(newKey, "NewAlbumScope", true, AxArtifactKey.getNullKey()));
+ assertEquals(album, new AxContextAlbum(newKey, "NewAlbumScope", true, albumSchemaKey));
+
+ assertEquals(0, album.compareTo(album));
+ assertEquals(0, album.compareTo(clonedAlbum));
+ assertNotEquals(0, album.compareTo(null));
+ assertNotEquals(0, album.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, album.compareTo(
+ new AxContextAlbum(new AxArtifactKey(), "Scope", false, AxArtifactKey.getNullKey())));
+ assertNotEquals(0, album.compareTo(new AxContextAlbum(newKey, "Scope", false, AxArtifactKey.getNullKey())));
+ assertNotEquals(0, album
+ .compareTo(new AxContextAlbum(newKey, "NewAlbumScope", false, AxArtifactKey.getNullKey())));
+ assertNotEquals(0,
+ album.compareTo(new AxContextAlbum(newKey, "NewAlbumScope", true, AxArtifactKey.getNullKey())));
+ assertEquals(0, album.compareTo(new AxContextAlbum(newKey, "NewAlbumScope", true, albumSchemaKey)));
+ }
+
+ @Test
+ public void testMultipleAlbums() {
+ final AxContextAlbums albums = new AxContextAlbums();
+ final AxContextAlbum album = setTestAlbum();
+ final AxArtifactKey newKey = new AxArtifactKey("NewAlbumName", "0.0.1");
+ AxValidationResult result = new AxValidationResult();
+ result = albums.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ // Observation, no albums in album map
+ albums.setKey(new AxArtifactKey("AlbumsKey", "0.0.1"));
+ result = new AxValidationResult();
+ result = albums.validate(result);
+ assertEquals(ValidationResult.OBSERVATION, result.getValidationResult());
+
+ albums.getAlbumsMap().put(newKey, album);
+ result = new AxValidationResult();
+ result = albums.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ albums.getAlbumsMap().put(AxArtifactKey.getNullKey(), null);
+ result = new AxValidationResult();
+ result = albums.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ albums.getAlbumsMap().remove(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = albums.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ albums.getAlbumsMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null);
+ result = new AxValidationResult();
+ result = albums.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ albums.getAlbumsMap().remove(new AxArtifactKey("NullValueKey", "0.0.1"));
+ result = new AxValidationResult();
+ result = albums.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ }
+
+ @Test
+ public void testClonedAlbums() {
+ final AxContextAlbums albums = new AxContextAlbums();
+ final AxContextAlbum album = setTestAlbum();
+ final AxArtifactKey newKey = new AxArtifactKey("NewAlbumName", "0.0.1");
+ albums.setKey(new AxArtifactKey("AlbumsKey", "0.0.1"));
+ albums.getAlbumsMap().put(newKey, album);
+ albums.clean();
+
+ final AxContextAlbums clonedAlbums = new AxContextAlbums(albums);
+ assertThat(clonedAlbums.toString()).startsWith(
+ "AxContextAlbums(key=AxArtifactKey:(name=AlbumsKey,version=0.0.1)");
+
+ assertNotEquals(0, albums.hashCode());
+
+ assertEquals(albums, clonedAlbums);
+ assertNotNull(albums);
+ assertNotEquals(albums, (Object) "Hello");
+ assertNotEquals(albums, new AxContextAlbums(new AxArtifactKey()));
+
+ assertEquals(0, albums.compareTo(albums));
+ assertEquals(0, albums.compareTo(clonedAlbums));
+ assertNotEquals(0, albums.compareTo(null));
+ assertNotEquals(0, albums.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, albums.compareTo(new AxContextAlbums(new AxArtifactKey())));
+
+ clonedAlbums.get(newKey).setScope("YetAnotherScope");
+ assertNotEquals(0, albums.compareTo(clonedAlbums));
+
+ assertEquals("NewAlbumName", albums.get("NewAlbumName").getKey().getName());
+ assertEquals("NewAlbumName", albums.get("NewAlbumName", "0.0.1").getKey().getName());
+ assertEquals(1, albums.getAll("NewAlbumName", "0.0.1").size());
+ assertEquals(0, albums.getAll("NonExistantAlbumName").size());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextModelTest.java b/model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextModelTest.java
new file mode 100644
index 000000000..b148ef6be
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextModelTest.java
@@ -0,0 +1,95 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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.contextmodel.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+
+/**
+ * Context model tests.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ContextModelTest {
+
+ @Test
+ public void test() {
+ assertNotNull(new AxContextModel());
+ assertNotNull(new AxContextModel(new AxArtifactKey()));
+ assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation()));
+ assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(),
+ new AxKeyInformation()));
+
+ final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1");
+ final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1");
+ final AxArtifactKey albumsKey = new AxArtifactKey("SchemasKey", "0.0.1");
+ final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1");
+ final AxContextModel model = new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey));
+ model.register();
+
+ model.clean();
+ assertNotNull(model);
+ assertThat(model.toString()).startsWith("AxContextModel(super=AxContextModel:(key=AxArtifactKey:");
+
+ final AxContextModel clonedModel = new AxContextModel(model);
+
+ assertNotEquals(0, model.hashCode());
+
+ // disabling sonar because this code tests the equals() method
+ assertEquals(model, model); // NOSONAR
+ assertEquals(model, clonedModel);
+ assertNotEquals(model, (Object) "Hello");
+ assertNotEquals(model, new AxContextModel(new AxArtifactKey()));
+ assertNotEquals(model, new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(),
+ new AxKeyInformation()));
+ assertNotEquals(model, new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
+ new AxKeyInformation()));
+ assertNotEquals(model, new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
+ new AxKeyInformation(keyInfoKey)));
+ assertNotEquals(model, new AxContextModel(modelKey, new AxContextSchemas(schemasKey), new AxContextAlbums(),
+ new AxKeyInformation(keyInfoKey)));
+ assertEquals(model, new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)));
+
+ assertEquals(0, model.compareTo(model));
+ assertEquals(0, model.compareTo(clonedModel));
+ assertNotEquals(0, model.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, model.compareTo(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(),
+ new AxContextAlbums(), new AxKeyInformation())));
+ assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
+ new AxKeyInformation())));
+ assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
+ new AxKeyInformation(keyInfoKey))));
+ assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxContextAlbums(), new AxKeyInformation(keyInfoKey))));
+ assertEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey))));
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java b/model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java
new file mode 100644
index 000000000..52cca14bf
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java
@@ -0,0 +1,229 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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.contextmodel.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
+
+/**
+ * Context schema tests.
+ */
+public class ContextSchemasTest {
+
+ @Test
+ public void testNewAxContextSchema() {
+ assertNotNull(new AxContextSchema());
+ assertNotNull(new AxContextSchema(new AxArtifactKey(), "SchemaFlavour", "SchemaDefinition"));
+
+ }
+
+ @Test
+ public void testContextSchemas() {
+ final AxContextSchema schema = new AxContextSchema(new AxArtifactKey("SchemaName", "0.0.1"), "SchemaFlavour",
+ "SchemaDefinition");
+ assertNotNull(schema);
+
+ final AxArtifactKey newKey = new AxArtifactKey("NewSchemaName", "0.0.1");
+ schema.setKey(newKey);
+ assertEquals("NewSchemaName:0.0.1", schema.getKey().getId());
+ assertEquals("NewSchemaName:0.0.1", schema.getKeys().get(0).getId());
+
+ assertThatThrownBy(() -> schema.setSchemaFlavour(""))
+ .hasMessage("parameter \"schemaFlavour\": value \"\", "
+ + "does not match regular expression \"[A-Za-z0-9\\-_]+\"");
+ schema.setSchemaFlavour("NewSchemaFlavour");
+ assertEquals("NewSchemaFlavour", schema.getSchemaFlavour());
+
+ schema.setSchema("NewSchemaDefinition");
+ assertEquals("NewSchemaDefinition", schema.getSchema());
+ }
+
+ private AxContextSchema setTestSchema() {
+ final AxContextSchema schema = new AxContextSchema(new AxArtifactKey("SchemaName", "0.0.1"), "SchemaFlavour",
+ "SchemaDefinition");
+ final AxArtifactKey newKey = new AxArtifactKey("NewSchemaName", "0.0.1");
+ schema.setKey(newKey);
+ schema.setSchemaFlavour("NewSchemaFlavour");
+ schema.setSchema("NewSchemaDefinition");
+
+ return schema;
+ }
+
+ @Test
+ public void testAxvalidationSchema() {
+ AxContextSchema schema = setTestSchema();
+ AxValidationResult result = new AxValidationResult();
+ result = schema.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ schema.setKey(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = schema.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ final AxArtifactKey newKey = new AxArtifactKey("NewSchemaName", "0.0.1");
+ schema.setKey(newKey);
+ result = new AxValidationResult();
+ result = schema.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ schema.setSchemaFlavour("UNDEFINED");
+ result = new AxValidationResult();
+ result = schema.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ schema.setSchemaFlavour("NewSchemaFlavour");
+ result = new AxValidationResult();
+ result = schema.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ schema.setSchema("");
+ result = new AxValidationResult();
+ result = schema.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ schema.setSchema("NewSchemaDefinition");
+ result = new AxValidationResult();
+ result = schema.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+ }
+
+ @Test
+ public void testEqualsSchema() {
+ AxContextSchema schema = setTestSchema();
+ schema.clean();
+
+ final AxContextSchema clonedSchema = new AxContextSchema(schema);
+ assertEquals("AxContextSchema(key=AxArtifactKey:(name=NewSchemaName,version=0.0.1), "
+ + "schemaFlavour=NewSchemaFlavour, schemaDefinition=NewSchemaDefinition)",
+ clonedSchema.toString());
+
+ assertNotEquals(0, schema.hashCode());
+
+ // disabling sonar because this code tests the equals() method
+ assertEquals(schema, schema); // NOSONAR
+ assertEquals(schema, clonedSchema);
+ assertNotNull(schema);
+ assertNotEquals(schema, (Object) "Hello");
+ assertNotEquals(schema, new AxContextSchema(new AxArtifactKey(), "Flavour", "Def"));
+
+ final AxArtifactKey newKey = new AxArtifactKey("NewSchemaName", "0.0.1");
+ assertNotEquals(schema, new AxContextSchema(newKey, "Flavour", "Def"));
+ assertNotEquals(schema, new AxContextSchema(newKey, "NewSchemaFlavour", "Def"));
+ assertEquals(schema, new AxContextSchema(newKey, "NewSchemaFlavour", "NewSchemaDefinition"));
+
+ assertEquals(0, schema.compareTo(schema));
+ assertEquals(0, schema.compareTo(clonedSchema));
+ assertNotEquals(0, schema.compareTo(null));
+ assertNotEquals(0, schema.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, schema.compareTo(new AxContextSchema(new AxArtifactKey(), "Flavour", "Def")));
+ assertNotEquals(0, schema.compareTo(new AxContextSchema(newKey, "Flavour", "Def")));
+ assertNotEquals(0, schema.compareTo(new AxContextSchema(newKey, "NewSchemaFlavour", "Def")));
+ assertEquals(0, schema.compareTo(new AxContextSchema(newKey, "NewSchemaFlavour", "NewSchemaDefinition")));
+ }
+
+ @Test
+ public void testMultipleSchemas() {
+ final AxContextSchemas schemas = new AxContextSchemas();
+ AxValidationResult result = new AxValidationResult();
+ result = schemas.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ // Still invalid, no schemas in schema map
+ schemas.setKey(new AxArtifactKey("SchemasKey", "0.0.1"));
+ result = new AxValidationResult();
+ result = schemas.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ AxContextSchema schema = setTestSchema();
+ final AxArtifactKey newKey = new AxArtifactKey("NewSchemaName", "0.0.1");
+ schemas.getSchemasMap().put(newKey, schema);
+ result = new AxValidationResult();
+ result = schemas.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ schemas.getSchemasMap().put(AxArtifactKey.getNullKey(), null);
+ result = new AxValidationResult();
+ result = schemas.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ schemas.getSchemasMap().remove(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = schemas.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ schemas.getSchemasMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null);
+ result = new AxValidationResult();
+ result = schemas.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ schemas.getSchemasMap().remove(new AxArtifactKey("NullValueKey", "0.0.1"));
+ result = new AxValidationResult();
+ result = schemas.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ }
+
+ @Test
+ public void testClonedSchemas() {
+ final AxContextSchemas schemas = new AxContextSchemas();
+ AxContextSchema schema = setTestSchema();
+ final AxArtifactKey newKey = new AxArtifactKey("NewSchemaName", "0.0.1");
+ schemas.setKey(new AxArtifactKey("SchemasKey", "0.0.1"));
+ schemas.getSchemasMap().put(newKey, schema);
+ schemas.clean();
+
+ final AxContextSchemas clonedSchemas = new AxContextSchemas(schemas);
+ assertThat(clonedSchemas.toString())
+ .startsWith("AxContextSchemas(key=AxArtifactKey:(name=SchemasKey,version=0.0.1),");
+
+ assertNotEquals(0, schemas.hashCode());
+
+ assertEquals(schemas, clonedSchemas);
+ assertNotNull(schemas);
+ assertNotEquals(schemas, (Object) "Hello");
+ assertNotEquals(schemas, new AxContextSchemas(new AxArtifactKey()));
+
+ assertEquals(0, schemas.compareTo(schemas));
+ assertEquals(0, schemas.compareTo(clonedSchemas));
+ assertNotEquals(0, schemas.compareTo(null));
+ assertNotEquals(0, schemas.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, schemas.compareTo(new AxContextSchemas(new AxArtifactKey())));
+
+ clonedSchemas.get(newKey).setSchemaFlavour("YetAnotherFlavour");
+ assertNotEquals(0, schemas.compareTo(clonedSchemas));
+
+ assertEquals("NewSchemaName", schemas.get("NewSchemaName").getKey().getName());
+ assertEquals("NewSchemaName", schemas.get("NewSchemaName", "0.0.1").getKey().getName());
+ assertEquals(1, schemas.getAll("NewSchemaName", "0.0.1").size());
+ assertEquals(0, schemas.getAll("NonExistantSchemaName").size());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java b/model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java
new file mode 100644
index 000000000..998469bac
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java
@@ -0,0 +1,124 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ * ================================================================================
+ * 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.contextmodel.handling;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
+
+/**
+ * Apex context model tests.
+ *
+ * @author liam
+ *
+ */
+public class ApexContextModelTest {
+
+ private static final String VALID_MODEL_STRING = "***validation of model successful***";
+
+ private static final String OBSERVATION_MODEL_STRING = "\n"
+ + "***observations noted during validation of model***\n"
+ + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
+ + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:OBSERVATION:description is blank\n"
+ + "********************************";
+
+ private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
+ + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
+ + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:WARNING:"
+ + "UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n"
+ + "********************************";
+
+ private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=StringType,version=0.0.1):"
+ + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema:INVALID:"
+ + "no schemaDefinition specified, schemaDefinition may not be blank\n"
+ + "AxArtifactKey:(name=contextAlbum0,version=0.0.1):"
+ + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:"
+ + "scope is not defined\n" + "********************************";
+
+ private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=ContextModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n"
+ + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
+ + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:WARNING:"
+ + "key not found for key information entry\n" + "AxArtifactKey:(name=ContextSchemas,version=0.0.1):"
+ + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas:INVALID:"
+ + "key on schemas entry AxArtifactKey:(name=MapType,version=0.0.1) "
+ + "does not equal entry key AxArtifactKey:(name=MapType,version=0.0.2)\n"
+ + "AxArtifactKey:(name=contextAlbums,version=0.0.1):"
+ + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums:INVALID:"
+ + "key on context album entry key AxArtifactKey:(name=contextAlbum1,version=0.0.1) "
+ + "does not equal context album value key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n"
+ + "********************************";
+
+ TestApexModel<AxContextModel> testApexModel;
+
+ /**
+ * Set up tests.
+ *
+ * @throws Exception a testing exception
+ */
+ @Before
+ public void setup() throws Exception {
+ testApexModel = new TestApexModel<AxContextModel>(AxContextModel.class, new TestApexContextModelCreator());
+ }
+
+ @Test
+ public void testModelValid() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelValid();
+ assertEquals(VALID_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testApexModelVaidateObservation() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateObservation();
+ assertEquals(OBSERVATION_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testApexModelVaidateWarning() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
+ assertEquals(WARNING_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelVaidateInvalidModel() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
+ assertEquals(INVALID_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelVaidateMalstructured() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
+ assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelWriteReadJson() throws Exception {
+ testApexModel.testApexModelWriteReadJson();
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ContextComparisonTest.java b/model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ContextComparisonTest.java
new file mode 100644
index 000000000..483bc3661
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ContextComparisonTest.java
@@ -0,0 +1,189 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.contextmodel.handling;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
+import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference;
+
+/**
+ * Test context comparisons.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ContextComparisonTest {
+ private AxContextModel emptyModel;
+ private AxContextModel fullModel;
+ private AxContextModel noGlobalContextModel;
+ private AxContextModel shellModel;
+ private AxContextModel singleEntryModel;
+
+ /**
+ * Set up tests.
+ */
+ @Before
+ public void getContext() {
+ final TestContextComparisonFactory factory = new TestContextComparisonFactory();
+ emptyModel = factory.getEmptyModel();
+ fullModel = factory.getFullModel();
+ noGlobalContextModel = factory.getNoGlobalContextModel();
+ shellModel = factory.getShellModel();
+ singleEntryModel = factory.getSingleEntryModel();
+ }
+
+ @Test
+ public void testEmptyEmpty() {
+ final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
+ .compare(emptyModel.getSchemas(), emptyModel.getSchemas());
+ assertNotNull(schemaResult);
+ assertEquals(emptyModel.getSchemas().getSchemasMap(), schemaResult.getIdenticalValues());
+
+ final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
+ .compare(emptyModel.getAlbums(), emptyModel.getAlbums());
+ assertNotNull(albumResult);
+ assertEquals(emptyModel.getAlbums().getAlbumsMap(), albumResult.getIdenticalValues());
+ }
+
+ @Test
+ public void testEmptyFull() {
+ final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
+ .compare(emptyModel.getSchemas(), fullModel.getSchemas());
+ assertNotNull(schemaResult);
+ assertEquals(fullModel.getSchemas().getSchemasMap(), schemaResult.getRightOnly());
+
+ final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
+ .compare(emptyModel.getAlbums(), fullModel.getAlbums());
+ assertNotNull(albumResult);
+ assertEquals(fullModel.getAlbums().getAlbumsMap(), albumResult.getRightOnly());
+ }
+
+ @Test
+ public void testFullEmpty() {
+ final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
+ .compare(fullModel.getSchemas(), emptyModel.getSchemas());
+ assertNotNull(schemaResult);
+ assertEquals(fullModel.getSchemas().getSchemasMap(), schemaResult.getLeftOnly());
+
+ final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
+ .compare(fullModel.getAlbums(), emptyModel.getAlbums());
+ assertNotNull(albumResult);
+ assertEquals(fullModel.getAlbums().getAlbumsMap(), albumResult.getLeftOnly());
+ }
+
+ @Test
+ public void testEmptyNoGlobalContext() {
+ final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
+ .compare(emptyModel.getSchemas(), noGlobalContextModel.getSchemas());
+ assertNotNull(schemaResult);
+ assertEquals(noGlobalContextModel.getSchemas().getSchemasMap(), schemaResult.getRightOnly());
+
+ final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
+ .compare(emptyModel.getAlbums(), noGlobalContextModel.getAlbums());
+ assertNotNull(albumResult);
+ assertEquals(noGlobalContextModel.getAlbums().getAlbumsMap(), albumResult.getRightOnly());
+ }
+
+ @Test
+ public void testNoGlobalContextEmpty() {
+ final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
+ .compare(noGlobalContextModel.getSchemas(), emptyModel.getSchemas());
+ assertNotNull(schemaResult);
+ assertEquals(noGlobalContextModel.getSchemas().getSchemasMap(), schemaResult.getLeftOnly());
+
+ final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
+ .compare(noGlobalContextModel.getAlbums(), emptyModel.getAlbums());
+ assertNotNull(albumResult);
+ assertEquals(noGlobalContextModel.getAlbums().getAlbumsMap(), albumResult.getLeftOnly());
+ }
+
+ @Test
+ public void testEmptyShell() {
+ final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
+ .compare(emptyModel.getSchemas(), shellModel.getSchemas());
+ assertNotNull(schemaResult);
+ assertEquals(shellModel.getSchemas().getSchemasMap(), schemaResult.getRightOnly());
+
+ final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
+ .compare(emptyModel.getAlbums(), shellModel.getAlbums());
+ assertNotNull(albumResult);
+ assertEquals(shellModel.getAlbums().getAlbumsMap(), albumResult.getRightOnly());
+ }
+
+ @Test
+ public void testShellEmpty() {
+ final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
+ .compare(shellModel.getSchemas(), emptyModel.getSchemas());
+ assertNotNull(schemaResult);
+ assertEquals(shellModel.getSchemas().getSchemasMap(), schemaResult.getLeftOnly());
+
+ final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
+ .compare(shellModel.getAlbums(), emptyModel.getAlbums());
+ assertNotNull(albumResult);
+ assertEquals(shellModel.getAlbums().getAlbumsMap(), albumResult.getLeftOnly());
+ }
+
+ @Test
+ public void testEmptySingleEntry() {
+ final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
+ .compare(emptyModel.getSchemas(), singleEntryModel.getSchemas());
+ assertNotNull(schemaResult);
+ assertEquals(singleEntryModel.getSchemas().getSchemasMap(), schemaResult.getRightOnly());
+
+ final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
+ .compare(emptyModel.getAlbums(), singleEntryModel.getAlbums());
+ assertNotNull(albumResult);
+ assertEquals(singleEntryModel.getAlbums().getAlbumsMap(), albumResult.getRightOnly());
+ }
+
+ @Test
+ public void testSingleEntryEmpty() {
+ final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
+ .compare(singleEntryModel.getSchemas(), emptyModel.getSchemas());
+ assertNotNull(schemaResult);
+ assertEquals(singleEntryModel.getSchemas().getSchemasMap(), schemaResult.getLeftOnly());
+
+ final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
+ .compare(singleEntryModel.getAlbums(), emptyModel.getAlbums());
+ assertNotNull(albumResult);
+ assertEquals(singleEntryModel.getAlbums().getAlbumsMap(), albumResult.getLeftOnly());
+ }
+
+ @Test
+ public void testFullFull() {
+ final KeyedMapDifference<AxArtifactKey, AxContextSchema> schemaResult = new ContextComparer()
+ .compare(fullModel.getSchemas(), fullModel.getSchemas());
+ assertNotNull(schemaResult);
+ assertEquals(fullModel.getSchemas().getSchemasMap(), schemaResult.getIdenticalValues());
+
+ final KeyedMapDifference<AxArtifactKey, AxContextAlbum> albumResult = new ContextComparer()
+ .compare(fullModel.getAlbums(), fullModel.getAlbums());
+ assertNotNull(albumResult);
+ assertEquals(fullModel.getAlbums().getAlbumsMap(), albumResult.getIdenticalValues());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestApexContextModelCreator.java b/model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestApexContextModelCreator.java
new file mode 100644
index 000000000..3fe7e3aa2
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestApexContextModelCreator.java
@@ -0,0 +1,122 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.contextmodel.handling;
+
+import java.util.UUID;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
+
+public class TestApexContextModelCreator implements TestApexModelCreator<AxContextModel> {
+
+ @Override
+ public AxContextModel getModel() {
+ final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
+ "org.onap.policy.apex.concept.TestContextItem000");
+ final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
+ "org.onap.policy.apex.concept.TestContextItem00A");
+
+ final AxContextSchemas contextSchemas = new AxContextSchemas(new AxArtifactKey("ContextSchemas", "0.0.1"));
+ contextSchemas.getSchemasMap().put(schema0.getKey(), schema0);
+ contextSchemas.getSchemasMap().put(schema1.getKey(), schema1);
+
+ final AxContextAlbum contextAlbum0 =
+ new AxContextAlbum(new AxArtifactKey("contextAlbum0", "0.0.1"), "APPLICATION", true, schema0.getKey());
+ final AxContextAlbum contextAlbum1 =
+ new AxContextAlbum(new AxArtifactKey("contextAlbum1", "0.0.1"), "GLOBAL", false, schema1.getKey());
+
+ final AxContextAlbums axContext = new AxContextAlbums(new AxArtifactKey("contextAlbums", "0.0.1"));
+ axContext.getAlbumsMap().put(contextAlbum0.getKey(), contextAlbum0);
+ axContext.getAlbumsMap().put(contextAlbum1.getKey(), contextAlbum1);
+
+ final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"));
+ final AxContextModel contextModel = new AxContextModel(new AxArtifactKey("ContextModel", "0.0.1"),
+ contextSchemas, axContext, keyInformation);
+
+ contextModel.setKeyInformation(keyInformation);
+ contextModel.getKeyInformation().getKeyInfoMap().put(schema0.getKey(), new AxKeyInfo(schema0.getKey(),
+ UUID.fromString("00000000-0000-0000-0000-000000000001"), "axContextSchema0"));
+ contextModel.getKeyInformation().getKeyInfoMap().put(schema1.getKey(), new AxKeyInfo(schema1.getKey(),
+ UUID.fromString("00000000-0000-0000-0000-000000000002"), "axContextSchema1"));
+ contextModel.getKeyInformation().getKeyInfoMap().put(contextSchemas.getKey(), new AxKeyInfo(
+ contextSchemas.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000003"), "ContextSchemas"));
+ contextModel.getKeyInformation().getKeyInfoMap().put(contextAlbum0.getKey(), new AxKeyInfo(
+ contextAlbum0.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000004"), "contextAlbum0"));
+ contextModel.getKeyInformation().getKeyInfoMap().put(contextAlbum1.getKey(), new AxKeyInfo(
+ contextAlbum1.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000005"), "contextAlbum1"));
+ contextModel.getKeyInformation().getKeyInfoMap().put(axContext.getKey(), new AxKeyInfo(axContext.getKey(),
+ UUID.fromString("00000000-0000-0000-0000-000000000006"), "axContext"));
+ contextModel.getKeyInformation().getKeyInfoMap().put(contextModel.getKey(), new AxKeyInfo(contextModel.getKey(),
+ UUID.fromString("00000000-0000-0000-0000-000000000007"), "contextModel"));
+ contextModel.getKeyInformation().getKeyInfoMap().put(keyInformation.getKey(), new AxKeyInfo(
+ keyInformation.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000008"), "keyInformation"));
+
+ return contextModel;
+ }
+
+ @Override
+ public AxContextModel getInvalidModel() {
+ final AxContextModel contextModel = getModel();
+
+ contextModel.getAlbums().get(new AxArtifactKey("contextAlbum0", "0.0.1")).setScope("UNDEFINED");
+
+ contextModel.getSchemas().get(new AxArtifactKey("StringType", "0.0.1")).setSchema("");
+
+ return contextModel;
+ }
+
+ @Override
+ public AxContextModel getMalstructuredModel() {
+ final AxContextModel contextModel = getModel();
+
+ contextModel.getAlbums().get(new AxArtifactKey("contextAlbum1", "0.0.1"))
+ .setKey(new AxArtifactKey("contextAlbum1", "0.0.2"));;
+ contextModel.getSchemas().get(new AxArtifactKey("MapType", "0.0.1"))
+ .setKey(new AxArtifactKey("MapType", "0.0.2"));;
+
+ return contextModel;
+ }
+
+ @Override
+ public AxContextModel getObservationModel() {
+ final AxContextModel contextModel = getModel();
+
+ contextModel.getKeyInformation().get("contextAlbum1", "0.0.1").setDescription("");
+
+ return contextModel;
+ }
+
+ @Override
+ public AxContextModel getWarningModel() {
+ final AxContextModel contextModel = getModel();
+
+ contextModel.getKeyInformation().get("contextAlbum1", "0.0.1")
+ .setUuid(UUID.fromString("00000000-0000-0000-0000-000000000000"));
+
+ return contextModel;
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestContextComparisonFactory.java b/model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestContextComparisonFactory.java
new file mode 100644
index 000000000..f7c7a1345
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestContextComparisonFactory.java
@@ -0,0 +1,148 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.contextmodel.handling;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
+
+/**
+ * This class creates sample Policy Models.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestContextComparisonFactory {
+
+ /**
+ * Get a full context model.
+ * @return the model
+ */
+ public AxContextModel getFullModel() {
+ final AxContextSchema testContextSchema000 =
+ new AxContextSchema(new AxArtifactKey("TestContextSchema000", "0.0.1"), "JAVA",
+ "org.onap.policy.apex.concept.TestContextSchema000");
+ final AxContextSchema testContextSchema00A =
+ new AxContextSchema(new AxArtifactKey("TestContextSchema00A", "0.0.1"), "JAVA",
+ "org.onap.policy.apex.concept.TestContextSchema00A");
+ final AxContextSchema testContextSchema00C =
+ new AxContextSchema(new AxArtifactKey("TestContextSchema00C", "0.0.1"), "JAVA",
+ "org.onap.policy.apex.concept.TestContextSchema00C");
+
+ final AxContextAlbum externalContextAlbum = new AxContextAlbum(
+ new AxArtifactKey("ExternalContextAlbum", "0.0.1"), "EXTERNAL", false, testContextSchema000.getKey());
+ final AxContextAlbum globalContextAlbum = new AxContextAlbum(new AxArtifactKey("GlobalContextAlbum", "0.0.1"),
+ "GLOBAL", true, testContextSchema00A.getKey());
+ final AxContextAlbum policy0ContextAlbum = new AxContextAlbum(new AxArtifactKey("Policy0ContextAlbum", "0.0.1"),
+ "APPLICATION", true, testContextSchema00C.getKey());
+ final AxContextAlbum policy1ContextAlbum = new AxContextAlbum(
+ new AxArtifactKey("Policy1ContextAlbum ", "0.0.1"), "APPLICATION", true, testContextSchema00C.getKey());
+
+ final AxContextModel contextModel = new AxContextModel(new AxArtifactKey("ContextModel", "0.0.1"));
+ contextModel.getSchemas().getSchemasMap().put(testContextSchema000.getKey(), testContextSchema000);
+ contextModel.getSchemas().getSchemasMap().put(testContextSchema00A.getKey(), testContextSchema00A);
+ contextModel.getSchemas().getSchemasMap().put(testContextSchema00C.getKey(), testContextSchema00C);
+
+ contextModel.getAlbums().getAlbumsMap().put(externalContextAlbum.getKey(), externalContextAlbum);
+ contextModel.getAlbums().getAlbumsMap().put(globalContextAlbum.getKey(), globalContextAlbum);
+ contextModel.getAlbums().getAlbumsMap().put(policy0ContextAlbum.getKey(), policy0ContextAlbum);
+ contextModel.getAlbums().getAlbumsMap().put(policy1ContextAlbum.getKey(), policy1ContextAlbum);
+
+ return contextModel;
+ }
+
+ public AxContextModel getEmptyModel() {
+ return new AxContextModel(new AxArtifactKey("Context", "0.0.1"));
+ }
+
+ /**
+ * Get a skeleton model.
+ * @return The model
+ */
+ public AxContextModel getShellModel() {
+ final AxContextSchema testContextSchema000 =
+ new AxContextSchema(new AxArtifactKey("TestContextSchema000", "0.0.1"), "JAVA",
+ "org.onap.policy.apex.concept.TestContextSchema000");
+ final AxContextSchema testContextSchema00A =
+ new AxContextSchema(new AxArtifactKey("TestContextSchema00A", "0.0.1"), "JAVA",
+ "org.onap.policy.apex.concept.TestContextSchema00A");
+ final AxContextSchema testContextSchema00C =
+ new AxContextSchema(new AxArtifactKey("TestContextSchema00C", "0.0.1"), "JAVA",
+ "org.onap.policy.apex.concept.TestContextSchema00C");
+
+ final AxContextModel contextModel = new AxContextModel(new AxArtifactKey("ContextModel", "0.0.1"));
+ contextModel.getSchemas().getSchemasMap().put(testContextSchema000.getKey(), testContextSchema000);
+ contextModel.getSchemas().getSchemasMap().put(testContextSchema00A.getKey(), testContextSchema00A);
+ contextModel.getSchemas().getSchemasMap().put(testContextSchema00C.getKey(), testContextSchema00C);
+
+ return contextModel;
+ }
+
+ /**
+ * Get a single entry model.
+ * @return The single entry model
+ */
+ public AxContextModel getSingleEntryModel() {
+ final AxContextSchema testContextSchema000 =
+ new AxContextSchema(new AxArtifactKey("TestContextSchema000", "0.0.1"), "JAVA",
+ "org.onap.policy.apex.concept.TestContextSchema000");
+
+ final AxContextAlbum policy1ContextAlbum = new AxContextAlbum(
+ new AxArtifactKey("Policy1ContextAlbum ", "0.0.1"), "APPLICATION", true, testContextSchema000.getKey());
+
+ final AxContextModel contextModel = new AxContextModel(new AxArtifactKey("ContextModel", "0.0.1"));
+ contextModel.getSchemas().getSchemasMap().put(testContextSchema000.getKey(), testContextSchema000);
+
+ contextModel.getAlbums().getAlbumsMap().put(policy1ContextAlbum.getKey(), policy1ContextAlbum);
+
+ return contextModel;
+ }
+
+ /**
+ * Get a model with no global entries.
+ * @return the model
+ */
+ public AxContextModel getNoGlobalContextModel() {
+ final AxContextSchema testContextSchema000 =
+ new AxContextSchema(new AxArtifactKey("TestContextSchema000", "0.0.1"), "JAVA",
+ "org.onap.policy.apex.concept.TestContextSchema000");
+ final AxContextSchema testContextSchema00C =
+ new AxContextSchema(new AxArtifactKey("TestContextSchema00C", "0.0.1"), "JAVA",
+ "org.onap.policy.apex.concept.TestContextSchema00C");
+
+ final AxContextAlbum externalContextAlbum = new AxContextAlbum(
+ new AxArtifactKey("ExternalContextAlbum", "0.0.1"), "EXTERNAL", false, testContextSchema000.getKey());
+ final AxContextAlbum policy0ContextAlbum = new AxContextAlbum(new AxArtifactKey("Policy0ContextAlbum", "0.0.1"),
+ "APPLICATION", true, testContextSchema00C.getKey());
+ final AxContextAlbum policy1ContextAlbum = new AxContextAlbum(
+ new AxArtifactKey("Policy1ContextAlbum ", "0.0.1"), "APPLICATION", true, testContextSchema00C.getKey());
+
+ final AxContextModel contextModel = new AxContextModel(new AxArtifactKey("ContextModel", "0.0.1"));
+ contextModel.getSchemas().getSchemasMap().put(testContextSchema000.getKey(), testContextSchema000);
+ contextModel.getSchemas().getSchemasMap().put(testContextSchema00C.getKey(), testContextSchema00C);
+
+ contextModel.getAlbums().getAlbumsMap().put(externalContextAlbum.getKey(), externalContextAlbum);
+ contextModel.getAlbums().getAlbumsMap().put(policy0ContextAlbum.getKey(), policy0ContextAlbum);
+ contextModel.getAlbums().getAlbumsMap().put(policy1ContextAlbum.getKey(), policy1ContextAlbum);
+
+ return contextModel;
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineModelTest.java b/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineModelTest.java
new file mode 100644
index 000000000..c23687bb1
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineModelTest.java
@@ -0,0 +1,176 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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.enginemodel.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+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.contextmodel.concepts.AxContextAlbums;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
+
+/**
+ * Test engine models.
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class EngineModelTest {
+
+ @Test
+ public void testEnginetModel() {
+ assertNotNull(new AxEngineModel());
+ assertNotNull(new AxEngineModel(new AxArtifactKey()));
+ assertNotNull(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(),
+ new AxContextAlbums()));
+ assertNotNull(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(),
+ new AxContextAlbums(), AxEngineState.UNDEFINED, new AxEngineStats()));
+
+ final AxArtifactKey modelKey = new AxArtifactKey("ModelName", "0.0.1");
+ final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1");
+ final AxArtifactKey albumKey = new AxArtifactKey("AlbumKey", "0.0.1");
+ final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1");
+ final AxEngineStats stats = new AxEngineStats(new AxReferenceKey(modelKey, "EngineStats"));
+ final AxEngineStats otherStats = new AxEngineStats();
+ otherStats.setAverageExecutionTime(100);
+
+ final AxEngineModel model = new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats);
+ model.register();
+
+ assertThatThrownBy(() -> model.setKey(null))
+ .hasMessage("key may not be null");
+ model.setKey(modelKey);
+ assertEquals("ModelName:0.0.1", model.getKey().getId());
+ assertEquals("ModelName:0.0.1", model.getKeys().get(0).getId());
+
+ final long timestamp = System.currentTimeMillis();
+ model.setTimestamp(timestamp);
+ assertEquals(timestamp, model.getTimestamp());
+ model.setTimestamp(-1);
+ assertTrue(model.getTimeStampString().matches("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3}"));
+
+ assertThatThrownBy(() -> model.setState(null))
+ .hasMessage("state may not be null");
+ for (final AxEngineState state : AxEngineState.values()) {
+ model.setState(state);
+ assertEquals(state, model.getState());
+ }
+
+ model.setState(AxEngineState.READY);
+ assertEquals(AxEngineState.READY, model.getState());
+
+ assertThatThrownBy(() -> model.setStats(null))
+ .hasMessage("stats may not be null");
+ model.setStats(stats);
+ assertEquals(stats, model.getStats());
+
+ model.clean();
+ assertNotNull(model);
+ assertThat(model.toString()).startsWith("AxEngineModel:(AxContextModel(super=AxEngineModel:(key=A");
+
+ final AxEngineModel clonedModel = new AxEngineModel(model);
+
+ assertNotEquals(0, model.hashCode());
+
+ // disabling sonar because this code tests the equals() method
+ assertEquals(model, model); // NOSONAR
+ assertEquals(model, clonedModel);
+ assertNotEquals(model, (Object) "Hello");
+ assertNotEquals(model, new AxEngineModel(new AxArtifactKey()));
+ assertNotEquals(model, new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats));
+ assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(), new AxKeyInformation(keyInfoKey),
+ new AxContextAlbums(albumKey), AxEngineState.READY, stats));
+ assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), new AxKeyInformation(),
+ new AxContextAlbums(albumKey), AxEngineState.READY, stats));
+ assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(), AxEngineState.READY, stats));
+ assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.STOPPED, stats));
+ assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, otherStats));
+ model.setTimestamp(timestamp);
+ assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats));
+ model.setTimestamp(0);
+ assertEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats));
+
+ model.setTimestamp(-1);
+ assertEquals(0, model.compareTo(model));
+ assertEquals(0, model.compareTo(clonedModel));
+ assertNotEquals(0, model.compareTo(new AxArtifactKey()));
+ assertNotEquals(model, new AxEngineModel(new AxArtifactKey()));
+ assertNotEquals(0, model.compareTo(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
+ assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
+ assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
+ assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(), AxEngineState.READY, stats)));
+ assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.STOPPED, stats)));
+ assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, otherStats)));
+ model.setTimestamp(timestamp);
+ assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
+ model.setTimestamp(0);
+ assertEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)));
+
+ model.setTimestamp(timestamp);
+ AxValidationResult result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ model.setTimestamp(-1);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.setTimestamp(timestamp);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ model.setState(AxEngineState.UNDEFINED);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.setState(AxEngineState.READY);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java b/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java
new file mode 100644
index 000000000..3eca27c08
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java
@@ -0,0 +1,267 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2022 Bell Canada.
+ * ================================================================================
+ * 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.enginemodel.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import io.prometheus.client.CollectorRegistry;
+import org.junit.Test;
+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;
+
+/**
+ * Test the engine statistics.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class EngineStatsTest {
+ private static final Object WAIT_LOCK = new Object();
+ private static final String ENGINE_KEY = "EngineKey";
+ private static final String ENGINE_VERSION = "0.0.1";
+
+ @Test
+ public void testEngineStats() {
+ assertNotNull(new AxEngineStats());
+ assertNotNull(new AxEngineStats(new AxReferenceKey()));
+
+ final AxReferenceKey statsKey = new AxReferenceKey(ENGINE_KEY, ENGINE_VERSION, "EngineStats");
+ final AxEngineStats stats = new AxEngineStats(statsKey);
+
+ assertThatThrownBy(() -> stats.setKey(null))
+ .hasMessage("key may not be null");
+ stats.setKey(statsKey);
+ assertEquals("EngineKey:0.0.1:NULL:EngineStats", stats.getKey().getId());
+ assertEquals("EngineKey:0.0.1:NULL:EngineStats", stats.getKeys().get(0).getId());
+
+ stats.setAverageExecutionTime(123.45);
+ assertEquals(Double.valueOf(123.45), Double.valueOf(stats.getAverageExecutionTime()));
+ checkAvgExecTimeMetric(stats);
+
+ stats.setEventCount(987);
+ assertEquals(987, stats.getEventCount());
+ checkEventsCountMetric(stats);
+
+ final long lastExecutionTime = System.currentTimeMillis();
+ stats.setLastExecutionTime(lastExecutionTime);
+ assertEquals(lastExecutionTime, stats.getLastExecutionTime());
+ checkLastExecTimeMetric(stats);
+
+ final long timestamp = System.currentTimeMillis();
+ stats.setTimeStamp(timestamp);
+ assertEquals(timestamp, stats.getTimeStamp());
+ assertNotNull(stats.getTimeStampString());
+
+ final long upTime = System.currentTimeMillis() - timestamp;
+ stats.setUpTime(upTime);
+ assertEquals(upTime, stats.getUpTime());
+ checkUpTimeMetric(stats);
+
+ stats.engineStart();
+ assertTrue(stats.getUpTime() > -1);
+ checkEngineStartTimestampMetric(stats);
+ checkLastExecTimeMetric(stats);
+ stats.engineStop();
+ assertTrue(stats.getUpTime() >= 0);
+
+ stats.engineStop();
+ checkUpTimeMetric(stats);
+ checkEngineStartTimestampMetric(stats);
+
+ stats.reset();
+
+ stats.setEventCount(-2);
+ stats.executionEnter(new AxArtifactKey());
+ assertEquals(2, stats.getEventCount());
+ checkEventsCountMetric(stats);
+
+ stats.setEventCount(10);
+ stats.executionEnter(new AxArtifactKey());
+ assertEquals(11, stats.getEventCount());
+ checkEventsCountMetric(stats);
+
+ stats.reset();
+ stats.engineStart();
+ stats.setEventCount(4);
+ checkUpTimeMetric(stats);
+ stats.executionEnter(new AxArtifactKey());
+ checkEventsCountMetric(stats);
+ checkAvgExecTimeMetric(stats);
+ checkEngineStartTimestampMetric(stats);
+
+ synchronized (WAIT_LOCK) {
+ try {
+ WAIT_LOCK.wait(10);
+ } catch (InterruptedException e) {
+ fail("test should not throw an exception");
+ }
+ }
+
+ stats.executionExit();
+ final double avExecutionTime = stats.getAverageExecutionTime();
+ assertTrue(avExecutionTime >= 2.0 && avExecutionTime < 10.0);
+ stats.engineStop();
+ checkUpTimeMetric(stats);
+
+ AxValidationResult result = new AxValidationResult();
+ result = stats.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ stats.setKey(new AxReferenceKey());
+ result = new AxValidationResult();
+ result = stats.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ stats.setKey(statsKey);
+ result = new AxValidationResult();
+ result = stats.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ stats.clean();
+ stats.reset();
+ checkAllPrometheusMetrics(stats);
+
+ final AxEngineStats clonedStats = new AxEngineStats(stats);
+ assertEquals("AxEngineStats:(engineKey=AxReferenceKey:(parentKey", clonedStats.toString().substring(0, 50));
+
+ assertNotNull(stats.getKeys());
+
+ assertNotEquals(0, stats.hashCode());
+
+ // disabling sonar because this code tests the equals() method
+ assertEquals(stats, stats); // NOSONAR
+ assertEquals(stats, clonedStats);
+ assertNotNull(stats);
+ checkAllPrometheusMetrics(clonedStats);
+
+ Object helloObject = "Hello";
+ assertNotEquals(stats, helloObject);
+ assertNotEquals(stats, new AxEngineStats(new AxReferenceKey()));
+
+ assertEquals(0, stats.compareTo(stats));
+ assertEquals(0, stats.compareTo(clonedStats));
+ assertNotEquals(0, stats.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, stats.compareTo(null));
+ assertNotEquals(0, stats.compareTo(new AxEngineStats(new AxReferenceKey())));
+
+ stats.setTimeStamp(1);
+ assertNotEquals(stats, new AxEngineStats(statsKey));
+ assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+ stats.setTimeStamp(0);
+ assertEquals(stats, new AxEngineStats(statsKey));
+ assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+ checkAllPrometheusMetrics(clonedStats);
+
+ stats.setEventCount(1);
+ assertNotEquals(stats, new AxEngineStats(statsKey));
+ assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+ stats.setEventCount(0);
+ assertEquals(stats, new AxEngineStats(statsKey));
+ assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+
+ stats.setLastExecutionTime(1);
+ assertNotEquals(stats, new AxEngineStats(statsKey));
+ assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+ stats.setLastExecutionTime(0);
+ assertEquals(stats, new AxEngineStats(statsKey));
+ assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+
+ stats.setAverageExecutionTime(1);
+ assertNotEquals(stats, new AxEngineStats(statsKey));
+ assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+ stats.setAverageExecutionTime(0);
+ assertEquals(stats, new AxEngineStats(statsKey));
+ assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+
+ stats.setUpTime(1);
+ assertNotEquals(stats, new AxEngineStats(statsKey));
+ assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+ stats.setUpTime(0);
+ assertEquals(stats, new AxEngineStats(statsKey));
+ assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+
+ assertEquals(-1, stats.compareTo(new AxEngineStats(statsKey, 0, 0, 0, 0.0, 0, 1)));
+
+ stats.engineStart();
+ assertNotEquals(stats, new AxEngineStats(statsKey));
+ final AxEngineStats newStats = new AxEngineStats(statsKey);
+ newStats.setTimeStamp(stats.getTimeStamp());
+ assertNotEquals(stats, newStats);
+ assertNotEquals(0, stats.compareTo(newStats));
+ stats.engineStop();
+ checkUpTimeMetric(stats);
+ checkEngineStartTimestampMetric(stats);
+ stats.reset();
+ assertEquals(stats, new AxEngineStats(statsKey));
+ assertEquals(0, stats.compareTo(new AxEngineStats(statsKey)));
+ checkAllPrometheusMetrics(stats);
+ }
+
+ private void checkUpTimeMetric(AxEngineStats stats) {
+ Double upTimeMetric = CollectorRegistry.defaultRegistry.getSampleValue("pdpa_engine_uptime",
+ new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d;
+ assertEquals(upTimeMetric.longValue(), stats.getUpTime());
+ }
+
+ private void checkEventsCountMetric(AxEngineStats stats) {
+ Double eventsCountMetric = CollectorRegistry.defaultRegistry.getSampleValue("pdpa_engine_event_executions",
+ new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION});
+ assertEquals(eventsCountMetric.longValue(), stats.getEventCount());
+ }
+
+ private void checkLastExecTimeMetric(AxEngineStats stats) {
+ Double lastExecTimeMetric = CollectorRegistry.defaultRegistry
+ .getSampleValue("pdpa_engine_last_execution_time_sum", new String[]{AxEngineStats.ENGINE_INSTANCE_ID},
+ new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d;
+ assertEquals(lastExecTimeMetric.longValue(), stats.getLastExecutionTime());
+ }
+
+ private void checkEngineStartTimestampMetric(AxEngineStats stats) {
+ Double engineStartTimestampMetric = CollectorRegistry.defaultRegistry
+ .getSampleValue("pdpa_engine_last_start_timestamp_epoch",
+ new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION});
+ assertEquals(engineStartTimestampMetric.longValue(), stats.getLastStart());
+ }
+
+ private void checkAvgExecTimeMetric(AxEngineStats stats) {
+ Double avgExecTimeMetric = CollectorRegistry.defaultRegistry
+ .getSampleValue("pdpa_engine_average_execution_time_seconds",
+ new String[]{AxEngineStats.ENGINE_INSTANCE_ID},
+ new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d;
+ assertEquals(avgExecTimeMetric, Double.valueOf(stats.getAverageExecutionTime()));
+ }
+
+ private void checkAllPrometheusMetrics(AxEngineStats stats) {
+ checkEventsCountMetric(stats);
+ checkUpTimeMetric(stats);
+ checkAvgExecTimeMetric(stats);
+ checkEngineStartTimestampMetric(stats);
+ checkEngineStartTimestampMetric(stats);
+ }
+} \ No newline at end of file
diff --git a/model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java b/model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java
new file mode 100644
index 000000000..e7fdd2d93
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ * ================================================================================
+ * 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.enginemodel.handling;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
+import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel;
+
+public class ApexEngineModelTest {
+ private static final String VALID_MODEL_STRING = "***validation of model successful***";
+
+ private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=AnEngine,version=0.0.1):"
+ + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:"
+ + "AxEngineModel - state is UNDEFINED\n" + "********************************";
+
+ private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=AnEngine,version=0.0.1):"
+ + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:"
+ + "AxEngineModel - timestamp is not set\n" + "AxArtifactKey:(name=AnEngine,version=0.0.1):"
+ + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:"
+ + "AxEngineModel - state is UNDEFINED\n" + "********************************";
+
+ TestApexModel<AxEngineModel> testApexModel;
+
+ /**
+ * Set up the test.
+ *
+ * @throws Exception errors from test setup
+ */
+ @Before
+ public void setup() throws Exception {
+ testApexModel = new TestApexModel<AxEngineModel>(AxEngineModel.class, new DummyTestApexEngineModelCreator());
+ }
+
+ @Test
+ public void testModelValid() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelValid();
+ assertEquals(VALID_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelVaidateInvalidModel() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
+ assertEquals(INVALID_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelVaidateMalstructured() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
+ assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelWriteReadJson() throws Exception {
+ testApexModel.testApexModelWriteReadJson();
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/DummyTestApexEngineModelCreator.java b/model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/DummyTestApexEngineModelCreator.java
new file mode 100644
index 000000000..9e7d99b72
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/DummyTestApexEngineModelCreator.java
@@ -0,0 +1,129 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.enginemodel.handling;
+
+import java.util.UUID;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+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.test.TestApexModelCreator;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
+import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel;
+import org.onap.policy.apex.model.enginemodel.concepts.AxEngineState;
+import org.onap.policy.apex.model.enginemodel.concepts.AxEngineStats;
+
+public class DummyTestApexEngineModelCreator implements TestApexModelCreator<AxEngineModel> {
+
+ @Override
+ public AxEngineModel getModel() {
+ final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000");
+ final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A");
+
+ final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("ContextSchemas", "0.0.1"));
+ schemas.getSchemasMap().put(schema0.getKey(), schema0);
+ schemas.getSchemasMap().put(schema1.getKey(), schema1);
+
+ final AxContextAlbum album0 =
+ new AxContextAlbum(new AxArtifactKey("contextAlbum0", "0.0.1"), "APPLICATION", true, schema1.getKey());
+
+ final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey("context", "0.0.1"));
+ albums.getAlbumsMap().put(album0.getKey(), album0);
+
+ final AxEngineModel engineModel = new AxEngineModel(new AxArtifactKey("AnEngine", "0.0.1"));
+ engineModel.setSchemas(schemas);
+ engineModel.setAlbums(albums);
+ engineModel.setTimestamp(System.currentTimeMillis());
+ engineModel.setState(AxEngineState.EXECUTING);
+ engineModel.setStats(new AxEngineStats(new AxReferenceKey(engineModel.getKey(), "EngineStats"),
+ System.currentTimeMillis(), 100, 205, 200, 12345, 9876));
+ engineModel.getKeyInformation().generateKeyInfo(engineModel);
+
+ final AxValidationResult result = new AxValidationResult();
+ engineModel.validate(result);
+
+ return engineModel;
+ }
+
+ @Override
+ public AxEngineModel getInvalidModel() {
+ final AxEngineModel engineModel = getModel();
+
+ engineModel.setTimestamp(System.currentTimeMillis());
+ engineModel.setState(AxEngineState.UNDEFINED);
+ engineModel.setStats(new AxEngineStats(new AxReferenceKey(engineModel.getKey(), "EngineStats"),
+ System.currentTimeMillis(), 100, 205, 200, 12345, 9876));
+ engineModel.getKeyInformation().generateKeyInfo(engineModel);
+
+ return engineModel;
+ }
+
+ /**
+ * Get a malstructured model.
+ */
+ public AxEngineModel getMalstructuredModel() {
+ final AxEngineModel engineModel = getModel();
+
+ engineModel.setTimestamp(-1);
+ engineModel.setState(AxEngineState.UNDEFINED);
+
+ return engineModel;
+ }
+
+ @Override
+ public AxEngineModel getObservationModel() {
+ final AxEngineModel engineModel = getModel();
+
+ final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000");
+ final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A");
+
+ engineModel.getKeyInformation().getKeyInfoMap().put(schema0.getKey(),
+ new AxKeyInfo(schema0.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000001"), ""));
+ engineModel.getKeyInformation().getKeyInfoMap().put(schema1.getKey(),
+ new AxKeyInfo(schema1.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000002"), ""));
+
+ return engineModel;
+ }
+
+ @Override
+ public AxEngineModel getWarningModel() {
+ final AxEngineModel engineModel = getModel();
+
+ final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000");
+ final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A");
+
+ engineModel.getKeyInformation().getKeyInfoMap().put(schema0.getKey(),
+ new AxKeyInfo(schema0.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000000"), ""));
+ engineModel.getKeyInformation().getKeyInfoMap().put(schema1.getKey(),
+ new AxKeyInfo(schema1.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000001"), ""));
+
+ return engineModel;
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventModelTest.java b/model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventModelTest.java
new file mode 100644
index 000000000..cdc5fecf6
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventModelTest.java
@@ -0,0 +1,87 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * ================================================================================
+ * 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.eventmodel.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
+
+/**
+ * Test event models.
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class EventModelTest {
+
+ @Test
+ public void testEventModel() {
+ assertNotNull(new AxEventModel());
+ assertNotNull(new AxEventModel(new AxArtifactKey()));
+ assertNotNull(
+ new AxEventModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(), new AxEvents()));
+
+ final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1");
+ final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1");
+ final AxArtifactKey eventsKey = new AxArtifactKey("EventsKey", "0.0.1");
+ final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1");
+ final AxEventModel model = new AxEventModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey));
+ model.register();
+
+ model.clean();
+ assertNotNull(model);
+ assertEquals("AxEventModel:(AxEventModel:(key=AxArtifactKey:(nam", model.toString().substring(0, 50));
+
+ final AxEventModel clonedModel = new AxEventModel(model);
+
+ assertNotEquals(0, model.hashCode());
+ // disabling sonar because this code tests the equals() method
+ assertEquals(model, model); // NOSONAR
+ assertEquals(model, clonedModel);
+ assertNotEquals(model, (Object) "Hello");
+ assertNotEquals(model, new AxEventModel(new AxArtifactKey()));
+ assertNotEquals(model, new AxEventModel(modelKey, new AxContextSchemas(), new AxKeyInformation(keyInfoKey),
+ new AxEvents(eventsKey)));
+ assertNotEquals(model, new AxEventModel(modelKey, new AxContextSchemas(schemasKey), new AxKeyInformation(),
+ new AxEvents(eventsKey)));
+ assertNotEquals(model, new AxEventModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents()));
+ assertEquals(model, new AxEventModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey)));
+
+ assertEquals(0, model.compareTo(model));
+ assertEquals(0, model.compareTo(clonedModel));
+ assertNotEquals(0, model.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, model.compareTo(new AxEventModel(modelKey, new AxContextSchemas(),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey))));
+ assertNotEquals(0, model.compareTo(new AxEventModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(), new AxEvents(eventsKey))));
+ assertNotEquals(0, model.compareTo(new AxEventModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents())));
+ assertEquals(0, model.compareTo(new AxEventModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey))));
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventsTest.java b/model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventsTest.java
new file mode 100644
index 000000000..7062fcb3c
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventsTest.java
@@ -0,0 +1,323 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2020,2022 Nordix Foundation.
+ * Modifications Copyright (C) 2022 Bell Canada.
+ * ================================================================================
+ * 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.eventmodel.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.TreeMap;
+import java.util.TreeSet;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxToscaPolicyProcessingStatus;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
+
+/**
+ * Test events.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class EventsTest {
+
+ @Test
+ public void testEvents() {
+ final TreeMap<String, AxField> parameterMap = new TreeMap<>();
+ final TreeMap<String, AxField> parameterMapEmpty = new TreeMap<>();
+
+ assertNotNull(new AxEvent());
+ assertNotNull(new AxEvent(new AxArtifactKey()));
+ assertNotNull(new AxEvent(new AxArtifactKey(), "namespace"));
+ assertNotNull(new AxEvent(new AxArtifactKey(), "namespace", "source", "target"));
+ assertNotNull(new AxEvent(new AxArtifactKey(), "namespace", "source", "target"));
+ assertNotNull(new AxEvent(new AxArtifactKey(), "namespace", "source", "target", parameterMap, ""));
+
+ final AxEvent event = new AxEvent();
+
+ final AxArtifactKey eventKey = new AxArtifactKey("EventName", "0.0.1");
+ event.setKey(eventKey);
+ assertEquals("EventName:0.0.1", event.getKey().getId());
+ assertEquals("EventName:0.0.1", event.getKeys().get(0).getId());
+
+ event.setNameSpace("namespace");
+ assertEquals("namespace", event.getNameSpace());
+
+ event.setSource("source");
+ assertEquals("source", event.getSource());
+
+ event.setTarget("target");
+ assertEquals("target", event.getTarget());
+
+ event.setParameterMap(parameterMap);
+ assertEquals(0, event.getParameterMap().size());
+
+ event.setToscaPolicyState(AxToscaPolicyProcessingStatus.ENTRY.name());
+ assertEquals(AxToscaPolicyProcessingStatus.ENTRY.name(), event.getToscaPolicyState());
+
+ final AxField eventField =
+ new AxField(new AxReferenceKey(eventKey, "Field0"), new AxArtifactKey("Field0Schema", "0.0.1"));
+ event.getParameterMap().put(eventField.getKey().getLocalName(), eventField);
+ assertEquals(1, event.getParameterMap().size());
+
+ final AxField eventFieldBadParent =
+ new AxField(new AxReferenceKey(new AxArtifactKey("OtherEvent", "0.0.01"), "Field0"),
+ new AxArtifactKey("Field0Schema", "0.0.1"));
+
+ final AxArtifactKey newEventKey = new AxArtifactKey("NewEventName", "0.0.1");
+ event.setKey(newEventKey);
+ assertEquals("NewEventName:0.0.1", event.getKey().getId());
+ assertEquals("NewEventName:0.0.1", event.getKeys().get(0).getId());
+ assertEquals("NewEventName:0.0.1",
+ event.getParameterMap().get("Field0").getKey().getParentArtifactKey().getId());
+ event.setKey(eventKey);
+ assertEquals("EventName:0.0.1", event.getKey().getId());
+ assertEquals("EventName:0.0.1", event.getKeys().get(0).getId());
+
+ assertTrue("Field0", event.getFields().contains(eventField));
+ assertTrue(event.hasFields(new TreeSet<AxField>(parameterMap.values())));
+
+ AxValidationResult result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
+
+ event.setKey(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ event.setKey(eventKey);
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ event.setNameSpace("");
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.WARNING, result.getValidationResult());
+
+ event.setNameSpace("namespace");
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ event.setSource("");
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.OBSERVATION, result.getValidationResult());
+
+ event.setSource("source");
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ event.setTarget("");
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.OBSERVATION, result.getValidationResult());
+
+ event.setTarget("target");
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ event.getParameterMap().put(AxKey.NULL_KEY_NAME, null);
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ event.getParameterMap().remove(AxKey.NULL_KEY_NAME);
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ event.getParameterMap().put("NullField", null);
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ event.getParameterMap().remove("NullField");
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ event.getParameterMap().put("NullField", eventField);
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ event.getParameterMap().remove("NullField");
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ event.getParameterMap().put("BadParent", eventFieldBadParent);
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ event.getParameterMap().remove("BadParent");
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ event.setToscaPolicyState("invalid_enum");
+ result = new AxValidationResult();
+ result = event.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+ event.setToscaPolicyState(AxToscaPolicyProcessingStatus.ENTRY.name());
+
+ event.clean();
+ event.buildReferences();
+ assertNotEquals(AxKey.NULL_KEY_NAME,
+ event.getParameterMap().values().iterator().next().getKey().getParentKeyName());
+
+ final AxEvent clonedEvent = new AxEvent(event);
+ assertEquals("AxEvent:(key=AxArtifactKey:(name=EventName,version=0.0.1),nameSpace=namespace",
+ clonedEvent.toString().substring(0, 77));
+
+ assertNotEquals(0, event.hashCode());
+
+ // disabling sonar because this code tests the equals() method
+ assertEquals(event, event); // NOSONAR
+ assertEquals(event, clonedEvent);
+ assertNotNull(event);
+
+ Object helloObj = "Hello";
+ assertNotEquals(event, helloObj);
+ assertNotEquals(event, new AxEvent(AxArtifactKey.getNullKey(), "namespace", "source", "target", parameterMap,
+ AxToscaPolicyProcessingStatus.ENTRY.name()));
+ assertNotEquals(event, new AxEvent(eventKey, "namespace1", "source", "target", parameterMap,
+ AxToscaPolicyProcessingStatus.ENTRY.name()));
+ assertNotEquals(event, new AxEvent(eventKey, "namespace", "source2", "target", parameterMap,
+ AxToscaPolicyProcessingStatus.ENTRY.name()));
+ assertNotEquals(event, new AxEvent(eventKey, "namespace", "source", "target3", parameterMap,
+ AxToscaPolicyProcessingStatus.ENTRY.name()));
+ assertNotEquals(event, new AxEvent(eventKey, "namespace", "source", "target", parameterMapEmpty,
+ AxToscaPolicyProcessingStatus.ENTRY.name()));
+ assertEquals(event, new AxEvent(eventKey, "namespace", "source", "target", parameterMap,
+ AxToscaPolicyProcessingStatus.ENTRY.name()));
+
+ assertEquals(0, event.compareTo(event));
+ assertEquals(0, event.compareTo(clonedEvent));
+ assertNotEquals(0, event.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, event.compareTo(null));
+ assertNotEquals(0, event.compareTo(new AxEvent(AxArtifactKey.getNullKey(), "namespace", "source", "target",
+ parameterMap, AxToscaPolicyProcessingStatus.ENTRY.name())));
+ assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace1", "source", "target", parameterMap,
+ AxToscaPolicyProcessingStatus.ENTRY.name())));
+ assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source2", "target", parameterMap,
+ AxToscaPolicyProcessingStatus.ENTRY.name())));
+ assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source", "target3", parameterMap,
+ AxToscaPolicyProcessingStatus.ENTRY.name())));
+ assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source", "target", parameterMapEmpty,
+ AxToscaPolicyProcessingStatus.ENTRY.name())));
+ assertEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source", "target", parameterMap,
+ AxToscaPolicyProcessingStatus.ENTRY.name())));
+
+ assertNotNull(event.getKeys());
+
+ final AxEvents events = new AxEvents();
+ result = new AxValidationResult();
+ result = events.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ // Invalid, no events in event map
+ events.setKey(new AxArtifactKey("EventsKey", "0.0.1"));
+ assertEquals("EventsKey:0.0.1", events.getKey().getId());
+
+ result = new AxValidationResult();
+ result = events.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ events.getEventMap().put(eventKey, event);
+ result = new AxValidationResult();
+ result = events.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ events.getEventMap().put(AxArtifactKey.getNullKey(), null);
+ result = new AxValidationResult();
+ result = events.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ events.getEventMap().remove(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = events.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ events.getEventMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null);
+ result = new AxValidationResult();
+ result = events.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ events.getEventMap().remove(new AxArtifactKey("NullValueKey", "0.0.1"));
+ result = new AxValidationResult();
+ result = events.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ events.getEventMap().put(new AxArtifactKey("BadEventKey", "0.0.1"), event);
+ result = new AxValidationResult();
+ result = events.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ events.getEventMap().remove(new AxArtifactKey("BadEventKey", "0.0.1"));
+ result = new AxValidationResult();
+ result = events.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ events.clean();
+ event.buildReferences();
+ assertNotEquals(AxKey.NULL_KEY_NAME,
+ event.getParameterMap().values().iterator().next().getKey().getParentKeyName());
+
+ final AxEvents clonedEvents = new AxEvents(events);
+ assertEquals("AxEvents:(key=AxArtifactKey:(name=EventsKey,version=0.0.1),e",
+ clonedEvents.toString().substring(0, 60));
+
+ assertNotEquals(0, events.hashCode());
+
+ assertEquals(events, clonedEvents);
+ assertNotNull(events);
+ assertNotEquals(event, helloObj);
+ assertNotEquals(events, new AxEvents(new AxArtifactKey()));
+
+ assertEquals(0, events.compareTo(events));
+ assertEquals(0, events.compareTo(clonedEvents));
+ assertNotEquals(0, events.compareTo(null));
+ assertNotEquals(0, events.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, events.compareTo(new AxEvents(new AxArtifactKey())));
+
+ clonedEvents.get(eventKey).setSource("AnotherSource");
+ assertNotEquals(0, events.compareTo(clonedEvents));
+
+ assertEquals(events.getKey(), events.getKeys().get(0));
+
+ assertEquals("EventName", events.get("EventName").getKey().getName());
+ assertEquals("EventName", events.get("EventName", "0.0.1").getKey().getName());
+ assertEquals(1, events.getAll("EventName", "0.0.1").size());
+ assertEquals(0, events.getAll("NonExistantEventsName").size());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/FieldTest.java b/model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/FieldTest.java
new file mode 100644
index 000000000..6ec46dbd5
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/FieldTest.java
@@ -0,0 +1,134 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * ================================================================================
+ * 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.eventmodel.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+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;
+
+/**
+ * Test fields.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class FieldTest {
+
+ @Test
+ public void testField() {
+ assertNotNull(new AxField());
+ assertNotNull(new AxField(new AxReferenceKey()));
+ assertNotNull(new AxField(new AxReferenceKey(), new AxArtifactKey()));
+ assertNotNull(new AxField(new AxReferenceKey(), new AxArtifactKey(), false));
+ assertNotNull(new AxField("LocalName", new AxArtifactKey(), false));
+ assertNotNull(new AxField("LocalName", new AxArtifactKey()));
+ assertNotNull(new AxField("LocalName", new AxArtifactKey(), false));
+
+ assertNotNull(new AxInputField());
+ assertNotNull(new AxInputField(new AxReferenceKey()));
+ assertNotNull(new AxInputField(new AxReferenceKey(), new AxArtifactKey()));
+ assertNotNull(new AxInputField(new AxReferenceKey(), new AxArtifactKey(), true));
+ assertNotNull(new AxInputField("LocalName", new AxArtifactKey()));
+ assertNotNull(new AxInputField(new AxInputField()));
+
+ assertNotNull(new AxOutputField());
+ assertNotNull(new AxOutputField(new AxReferenceKey()));
+ assertNotNull(new AxOutputField(new AxReferenceKey(), new AxArtifactKey()));
+ assertNotNull(new AxOutputField(new AxReferenceKey(), new AxArtifactKey(), false));
+ assertNotNull(new AxOutputField("LocalName", new AxArtifactKey()));
+ assertNotNull(new AxOutputField(new AxOutputField()));
+
+ final AxField field = new AxField();
+
+ final AxReferenceKey fieldKey = new AxReferenceKey("FieldName", "0.0.1", "PLN", "LN");
+ field.setKey(fieldKey);
+ assertEquals("FieldName:0.0.1:PLN:LN", field.getKey().getId());
+ assertEquals("FieldName:0.0.1:PLN:LN", field.getKeys().get(0).getId());
+
+ final AxArtifactKey schemaKey = new AxArtifactKey("SchemaName", "0.0.1");
+ field.setSchema(schemaKey);
+ assertEquals("SchemaName:0.0.1", field.getSchema().getId());
+
+ assertEquals(false, field.getOptional());
+ field.setOptional(true);
+ assertEquals(true, field.getOptional());
+
+ AxValidationResult result = new AxValidationResult();
+ result = field.validate(result);
+ assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
+
+ field.setKey(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = field.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ field.setKey(fieldKey);
+ result = new AxValidationResult();
+ result = field.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ field.setSchema(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = field.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ field.setSchema(schemaKey);
+ result = new AxValidationResult();
+ result = field.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ field.clean();
+
+ final AxField clonedField = new AxField(field);
+ assertEquals("AxField:(key=AxReferenceKey:(parentKeyName=FieldName,parentKeyVersion=0.0.1,"
+ + "parentLocalName=PLN,localName=LN),fieldSchemaKey="
+ + "AxArtifactKey:(name=SchemaName,version=0.0.1),optional=true)", clonedField.toString());
+
+ assertNotEquals(0, field.hashCode());
+ // disabling sonar because this code tests the equals() method
+ assertEquals(field, field); // NOSONAR
+ assertEquals(field, clonedField);
+ assertNotNull(field);
+ assertNotEquals(field, (Object) "Hello");
+ assertNotEquals(field, new AxField(AxReferenceKey.getNullKey(), AxArtifactKey.getNullKey(), false));
+ assertNotEquals(field, new AxField(fieldKey, AxArtifactKey.getNullKey(), false));
+ assertNotEquals(field, new AxField(fieldKey, schemaKey, false));
+ assertEquals(field, new AxField(fieldKey, schemaKey, true));
+
+ assertEquals(0, field.compareTo(field));
+ assertEquals(0, field.compareTo(clonedField));
+ assertNotEquals(0, field.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, field.compareTo(null));
+ assertNotEquals(0,
+ field.compareTo(new AxField(AxReferenceKey.getNullKey(), AxArtifactKey.getNullKey(), false)));
+ assertNotEquals(0, field.compareTo(new AxField(fieldKey, AxArtifactKey.getNullKey(), false)));
+ assertNotEquals(0, field.compareTo(new AxField(fieldKey, schemaKey, false)));
+ assertEquals(0, field.compareTo(new AxField(fieldKey, schemaKey, true)));
+
+ assertNotNull(field.getKeys());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/ApexEventModelTest.java b/model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/ApexEventModelTest.java
new file mode 100644
index 000000000..21b97c454
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/ApexEventModelTest.java
@@ -0,0 +1,279 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ * ================================================================================
+ * 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.eventmodel.handling;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEventModel;
+
+public class ApexEventModelTest {
+ private static final String VALID_MODEL_STRING = "***validation of model successful***";
+
+ private static final String OBSERVATION_MODEL_STRING = "\n"
+ + "***observations noted during validation of model***\n"
+ + "AxArtifactKey:(name=event0,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n"
+ + "AxArtifactKey:(name=event0,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n"
+ + "AxArtifactKey:(name=event1,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n"
+ + "AxArtifactKey:(name=event1,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n"
+ + "AxArtifactKey:(name=event2,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n"
+ + "AxArtifactKey:(name=event2,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n"
+ + "********************************";
+
+ private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
+ + "AxArtifactKey:(name=event0,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:WARNING:nameSpace on event is blank\n"
+ + "AxArtifactKey:(name=event0,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n"
+ + "AxArtifactKey:(name=event0,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n"
+ + "AxArtifactKey:(name=event1,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:WARNING:nameSpace on event is blank\n"
+ + "AxArtifactKey:(name=event1,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n"
+ + "AxArtifactKey:(name=event1,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n"
+ + "AxArtifactKey:(name=event2,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:WARNING:nameSpace on event is blank\n"
+ + "AxArtifactKey:(name=event2,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n"
+ + "AxArtifactKey:(name=event2,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n"
+ + "********************************";
+
+ private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):"
+ + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation:INVALID:"
+ + "keyInfoMap may not be empty\n" + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=smallEventModel,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=Schemas,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=BigIntType,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=BooleanType,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=IntType,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=MapType,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=SetType,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=StringType,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=smallEventMap,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=event0,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for parent key of key AxReferenceKey:"
+ + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par0)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for parent key of key AxReferenceKey:"
+ + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for parent key of key AxReferenceKey:"
+ + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par2)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for parent key of key AxReferenceKey:"
+ + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par3)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for parent key of key AxReferenceKey:"
+ + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par4)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for parent key of key AxReferenceKey:"
+ + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par5)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for parent key of key AxReferenceKey:"
+ + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par6)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=event1,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for parent key of key AxReferenceKey:"
+ + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=theOnlyPar)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "duplicate key AxArtifactKey:(name=event1,version=0.0.1) found\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=event1,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "duplicate key AxReferenceKey:(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,"
+ + "localName=theOnlyPar) found\n" + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for parent key of key AxReferenceKey:"
+ + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=theOnlyPar)\n"
+ + "AxArtifactKey:(name=event0,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n"
+ + "AxArtifactKey:(name=event0,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n"
+ + "AxArtifactKey:(name=event1,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n"
+ + "AxArtifactKey:(name=event1,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n"
+ + "AxArtifactKey:(name=event1,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:INVALID:"
+ + "parent key on parameter field AxReferenceKey:(parentKeyName=event0,parentKeyVersion=0.0.1,"
+ + "parentLocalName=NULL,localName=theOnlyPar) does not equal event key\n"
+ + "AxArtifactKey:(name=smallEventMap,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvents:INVALID:"
+ + "key on event entry key AxArtifactKey:(name=event2,version=0.0.1) does not equal event value key "
+ + "AxArtifactKey:(name=event1,version=0.0.1)\n" + "AxArtifactKey:(name=event1,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n"
+ + "AxArtifactKey:(name=event1,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n"
+ + "AxArtifactKey:(name=event1,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:INVALID:"
+ + "parent key on parameter field AxReferenceKey:(parentKeyName=event0,parentKeyVersion=0.0.1,"
+ + "parentLocalName=NULL,localName=theOnlyPar) does not equal event key\n"
+ + "********************************";
+
+ private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):"
+ + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation:INVALID:"
+ + "keyInfoMap may not be empty\n" + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=smallEventModel,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=Schemas,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=SetType,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=smallEventMap,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=event1,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for parent key of key AxReferenceKey:"
+ + "(parentKeyName=event1,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=theOnlyPar)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "duplicate key AxArtifactKey:(name=event1,version=0.0.1) found\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=event1,version=0.0.1)\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "duplicate key AxReferenceKey:(parentKeyName=event1,parentKeyVersion=0.0.1,"
+ + "parentLocalName=NULL,localName=theOnlyPar) found\n"
+ + "AxArtifactKey:(name=smallEventModel,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:"
+ + "key information not found for parent key of key AxReferenceKey:"
+ + "(parentKeyName=event1,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=theOnlyPar)\n"
+ + "AxArtifactKey:(name=event1,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n"
+ + "AxArtifactKey:(name=event1,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n"
+ + "AxArtifactKey:(name=smallEventMap,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvents:INVALID:"
+ + "key on event entry key AxArtifactKey:(name=event2,version=0.0.1) does not equal event value key "
+ + "AxArtifactKey:(name=event1,version=0.0.1)\n" + "AxArtifactKey:(name=event1,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n"
+ + "AxArtifactKey:(name=event1,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n"
+ + "********************************";
+
+ TestApexModel<AxEventModel> testApexModel;
+
+ /**
+ * Set up the test.
+ *
+ * @throws Exception exceptions from the test
+ */
+ @Before
+ public void setup() throws Exception {
+ testApexModel = new TestApexModel<AxEventModel>(AxEventModel.class, new DummyTestApexEventModelCreator());
+ }
+
+ @Test
+ public void testModelValid() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelValid();
+ assertEquals(VALID_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testApexModelVaidateObservation() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateObservation();
+ assertEquals(OBSERVATION_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testApexModelVaidateWarning() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
+ assertEquals(WARNING_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelVaidateInvalidModel() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
+ assertEquals(INVALID_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelVaidateMalstructured() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
+ assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelWriteReadJson() throws Exception {
+ testApexModel.testApexModelWriteReadJson();
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/DummyTestApexEventModelCreator.java b/model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/DummyTestApexEventModelCreator.java
new file mode 100644
index 000000000..11685a6b4
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/DummyTestApexEventModelCreator.java
@@ -0,0 +1,309 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.eventmodel.handling;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+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.test.TestApexModelCreator;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEventModel;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEvents;
+import org.onap.policy.apex.model.eventmodel.concepts.AxField;
+
+public class DummyTestApexEventModelCreator implements TestApexModelCreator<AxEventModel> {
+
+ @Override
+ public AxEventModel getModel() {
+ final AxContextSchema axSchema0 =
+ new AxContextSchema(new AxArtifactKey("BooleanType", "0.0.1"), "Java", "java.lang.Boolean");
+ final AxContextSchema axSchema1 =
+ new AxContextSchema(new AxArtifactKey("IntType", "0.0.1"), "Java", "java.lang.Integer");
+ final AxContextSchema axSchema2 =
+ new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java", "java.lang.String");
+ final AxContextSchema axSchema3 = new AxContextSchema(new AxArtifactKey("KeyType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey");
+ final AxContextSchema axSchema4 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation");
+ final AxContextSchema axSchema5 =
+ new AxContextSchema(new AxArtifactKey("BigIntType", "0.0.1"), "Java", "java.math.BigInteger");
+ final AxContextSchema axSchema6 = new AxContextSchema(new AxArtifactKey("ModelType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.basicmodel.concepts.AxModel");
+
+ final AxContextSchemas dataTypes = new AxContextSchemas(new AxArtifactKey("Schemas", "0.0.1"));
+ dataTypes.getSchemasMap().put(axSchema0.getKey(), axSchema0);
+ dataTypes.getSchemasMap().put(axSchema1.getKey(), axSchema1);
+ dataTypes.getSchemasMap().put(axSchema2.getKey(), axSchema2);
+ dataTypes.getSchemasMap().put(axSchema3.getKey(), axSchema3);
+ dataTypes.getSchemasMap().put(axSchema4.getKey(), axSchema4);
+ dataTypes.getSchemasMap().put(axSchema5.getKey(), axSchema5);
+ dataTypes.getSchemasMap().put(axSchema6.getKey(), axSchema6);
+
+ final AxEvents eventMap = new AxEvents(new AxArtifactKey("smallEventMap", "0.0.1"));
+
+ final AxEvent event0 = new AxEvent(new AxArtifactKey("event0", "0.0.1"),
+ "org.onap.policy.apex.model.eventmodel.events", "Source", "Target");
+ event0.getParameterMap().put("par0",
+ new AxField(new AxReferenceKey(event0.getKey(), "par0"), axSchema0.getKey()));
+ event0.getParameterMap().put("par1",
+ new AxField(new AxReferenceKey(event0.getKey(), "par1"), axSchema1.getKey()));
+ event0.getParameterMap().put("par2",
+ new AxField(new AxReferenceKey(event0.getKey(), "par2"), axSchema2.getKey()));
+ event0.getParameterMap().put("par3",
+ new AxField(new AxReferenceKey(event0.getKey(), "par3"), axSchema6.getKey()));
+ event0.getParameterMap().put("par4",
+ new AxField(new AxReferenceKey(event0.getKey(), "par4"), axSchema4.getKey()));
+ event0.getParameterMap().put("par5",
+ new AxField(new AxReferenceKey(event0.getKey(), "par5"), axSchema5.getKey()));
+ event0.getParameterMap().put("par6",
+ new AxField(new AxReferenceKey(event0.getKey(), "par6"), axSchema5.getKey()));
+ eventMap.getEventMap().put(event0.getKey(), event0);
+
+ final AxEvent event1 = new AxEvent(new AxArtifactKey("event1", "0.0.1"),
+ "org.onap.policy.apex.model.eventmodel.events", "Source", "Target");
+ event1.getParameterMap().put("theOnlyPar",
+ new AxField(new AxReferenceKey(event1.getKey(), "theOnlyPar"), axSchema3.getKey()));
+ eventMap.getEventMap().put(event1.getKey(), event1);
+
+ final AxEvent event2 = new AxEvent(new AxArtifactKey("event2", "0.0.1"),
+ "org.onap.policy.apex.model.eventmodel.events", "Source", "Target");
+ eventMap.getEventMap().put(event2.getKey(), event2);
+
+ final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"));
+
+ final AxEventModel eventModel =
+ new AxEventModel(new AxArtifactKey("EventModel", "0.0.1"), dataTypes, keyInformation, eventMap);
+ keyInformation.generateKeyInfo(eventModel);
+
+ eventModel.validate(new AxValidationResult());
+ return eventModel;
+ }
+
+ @Override
+ public AxEventModel getInvalidModel() {
+ final AxContextSchema axSchema0 =
+ new AxContextSchema(new AxArtifactKey("BooleanType", "0.0.1"), "Java", "java.lang.Zoolean");
+ final AxContextSchema axSchema1 =
+ new AxContextSchema(new AxArtifactKey("IntType", "0.0.1"), "Java", "java.lang.Integer");
+ final AxContextSchema axSchema2 =
+ new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java", "java.lang.String");
+ final AxContextSchema axSchema3 =
+ new AxContextSchema(new AxArtifactKey("SetType", "0.0.1"), "Java", "java.util.Set");
+ final AxContextSchema axSchema4 =
+ new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java", "java.util.Map");
+ final AxContextSchema axSchema5 =
+ new AxContextSchema(new AxArtifactKey("BigIntType", "0.0.1"), "Java", "java.math.BigInteger");
+
+ final AxContextSchemas dataTypes = new AxContextSchemas(new AxArtifactKey("Schemas", "0.0.1"));
+ dataTypes.getSchemasMap().put(axSchema0.getKey(), axSchema0);
+ dataTypes.getSchemasMap().put(axSchema1.getKey(), axSchema1);
+ dataTypes.getSchemasMap().put(axSchema2.getKey(), axSchema2);
+ dataTypes.getSchemasMap().put(axSchema3.getKey(), axSchema3);
+ dataTypes.getSchemasMap().put(axSchema4.getKey(), axSchema4);
+ dataTypes.getSchemasMap().put(axSchema5.getKey(), axSchema5);
+
+ final AxEvents eventMap = new AxEvents(new AxArtifactKey("smallEventMap", "0.0.1"));
+
+ final AxEvent event0 =
+ new AxEvent(new AxArtifactKey("event0", "0.0.1"), "org.onap.policy.apex.model.eventmodel.events");
+ event0.getParameterMap().put("par0",
+ new AxField(new AxReferenceKey(event0.getKey(), "par0"), axSchema0.getKey()));
+ event0.getParameterMap().put("par1",
+ new AxField(new AxReferenceKey(event0.getKey(), "par1"), axSchema1.getKey()));
+ event0.getParameterMap().put("par2",
+ new AxField(new AxReferenceKey(event0.getKey(), "par2"), axSchema2.getKey()));
+ event0.getParameterMap().put("par3",
+ new AxField(new AxReferenceKey(event0.getKey(), "par3"), axSchema3.getKey()));
+ event0.getParameterMap().put("par4",
+ new AxField(new AxReferenceKey(event0.getKey(), "par4"), axSchema4.getKey()));
+ event0.getParameterMap().put("par5",
+ new AxField(new AxReferenceKey(event0.getKey(), "par5"), axSchema5.getKey()));
+ event0.getParameterMap().put("par6",
+ new AxField(new AxReferenceKey(event0.getKey(), "par6"), axSchema5.getKey()));
+ eventMap.getEventMap().put(event0.getKey(), event0);
+
+ final AxEvent event1 =
+ new AxEvent(new AxArtifactKey("event1", "0.0.1"), "org.onap.policy.apex.model.eventmodel.events");
+ event1.getParameterMap().put("theOnlyPar",
+ new AxField(new AxReferenceKey(event0.getKey(), "theOnlyPar"), axSchema3.getKey()));
+ eventMap.getEventMap().put(event1.getKey(), event1);
+
+ final AxEvent event2 =
+ new AxEvent(new AxArtifactKey("event2", "0.0.1"), "org.onap.policy.apex.model.eventmodel.events");
+ eventMap.getEventMap().put(event2.getKey(), event1);
+
+ final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"));
+
+ final AxEventModel eventModel =
+ new AxEventModel(new AxArtifactKey("smallEventModel", "0.0.1"), dataTypes, keyInformation, eventMap);
+
+ return eventModel;
+ }
+
+ @Override
+ public AxEventModel getMalstructuredModel() {
+ final AxContextSchema axSchema3 =
+ new AxContextSchema(new AxArtifactKey("SetType", "0.0.1"), "Java", "java.util.Set");
+ final AxContextSchemas dataTypes = new AxContextSchemas(new AxArtifactKey("Schemas", "0.0.1"));
+ dataTypes.getSchemasMap().put(axSchema3.getKey(), axSchema3);
+
+ final AxEvents eventMap = new AxEvents(new AxArtifactKey("smallEventMap", "0.0.1"));
+
+ final AxEvent event1 =
+ new AxEvent(new AxArtifactKey("event1", "0.0.1"), "org.onap.policy.apex.model.eventmodel.events");
+ event1.getParameterMap().put("theOnlyPar",
+ new AxField(new AxReferenceKey(event1.getKey(), "theOnlyPar"), axSchema3.getKey()));
+ eventMap.getEventMap().put(event1.getKey(), event1);
+
+ final AxEvent event2 =
+ new AxEvent(new AxArtifactKey("event2", "0.0.1"), "org.onap.policy.apex.model.eventmodel.events");
+ eventMap.getEventMap().put(event2.getKey(), event1);
+
+ final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"));
+
+ final AxEventModel eventModel =
+ new AxEventModel(new AxArtifactKey("smallEventModel", "0.0.1"), dataTypes, keyInformation, eventMap);
+
+ eventModel.validate(new AxValidationResult());
+
+ return eventModel;
+ }
+
+ @Override
+ public AxEventModel getWarningModel() {
+ final AxContextSchema axSchema0 =
+ new AxContextSchema(new AxArtifactKey("BooleanType", "0.0.1"), "Java", "java.lang.Boolean");
+ final AxContextSchema axSchema1 =
+ new AxContextSchema(new AxArtifactKey("IntType", "0.0.1"), "Java", "java.lang.Integer");
+ final AxContextSchema axSchema2 =
+ new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java", "java.lang.String");
+ final AxContextSchema axSchema3 =
+ new AxContextSchema(new AxArtifactKey("SetType", "0.0.1"), "Java", "java.util.Set");
+ final AxContextSchema axSchema4 =
+ new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java", "java.util.Map");
+ final AxContextSchema axSchema5 =
+ new AxContextSchema(new AxArtifactKey("BigIntType", "0.0.1"), "Java", "java.math.BigInteger");
+ final AxContextSchemas dataTypes = new AxContextSchemas(new AxArtifactKey("Schemas", "0.0.1"));
+ dataTypes.getSchemasMap().put(axSchema0.getKey(), axSchema0);
+ dataTypes.getSchemasMap().put(axSchema1.getKey(), axSchema1);
+ dataTypes.getSchemasMap().put(axSchema2.getKey(), axSchema2);
+ dataTypes.getSchemasMap().put(axSchema3.getKey(), axSchema3);
+ dataTypes.getSchemasMap().put(axSchema4.getKey(), axSchema4);
+ dataTypes.getSchemasMap().put(axSchema5.getKey(), axSchema5);
+
+ final AxEvents eventMap = new AxEvents(new AxArtifactKey("smallEventMap", "0.0.1"));
+
+ final AxEvent event0 = new AxEvent(new AxArtifactKey("event0", "0.0.1"), "");
+ event0.getParameterMap().put("par0",
+ new AxField(new AxReferenceKey(event0.getKey(), "par0"), axSchema0.getKey()));
+ event0.getParameterMap().put("par1",
+ new AxField(new AxReferenceKey(event0.getKey(), "par1"), axSchema1.getKey()));
+ event0.getParameterMap().put("par2",
+ new AxField(new AxReferenceKey(event0.getKey(), "par2"), axSchema2.getKey()));
+ event0.getParameterMap().put("par3",
+ new AxField(new AxReferenceKey(event0.getKey(), "par3"), axSchema3.getKey()));
+ event0.getParameterMap().put("par4",
+ new AxField(new AxReferenceKey(event0.getKey(), "par4"), axSchema4.getKey()));
+ event0.getParameterMap().put("par5",
+ new AxField(new AxReferenceKey(event0.getKey(), "par5"), axSchema5.getKey()));
+ eventMap.getEventMap().put(event0.getKey(), event0);
+
+ final AxEvent event1 = new AxEvent(new AxArtifactKey("event1", "0.0.1"), "");
+ event1.getParameterMap().put("theOnlyPar",
+ new AxField(new AxReferenceKey(event1.getKey(), "theOnlyPar"), axSchema3.getKey()));
+ eventMap.getEventMap().put(event1.getKey(), event1);
+
+ final AxEvent event2 = new AxEvent(new AxArtifactKey("event2", "0.0.1"), "");
+ eventMap.getEventMap().put(event2.getKey(), event2);
+
+ final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"));
+
+ final AxEventModel eventModel =
+ new AxEventModel(new AxArtifactKey("smallEventModel", "0.0.1"), dataTypes, keyInformation, eventMap);
+ eventModel.getKeyInformation().generateKeyInfo(eventModel);
+ eventModel.validate(new AxValidationResult());
+
+ return eventModel;
+ }
+
+ @Override
+ public AxEventModel getObservationModel() {
+ final AxContextSchema axSchema0 =
+ new AxContextSchema(new AxArtifactKey("BooleanType", "0.0.1"), "Java", "java.lang.Boolean");
+ final AxContextSchema axSchema1 =
+ new AxContextSchema(new AxArtifactKey("IntType", "0.0.1"), "Java", "java.lang.Integer");
+ final AxContextSchema axSchema2 =
+ new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java", "java.lang.String");
+ final AxContextSchema axSchema3 =
+ new AxContextSchema(new AxArtifactKey("SetType", "0.0.1"), "Java", "java.util.Set");
+ final AxContextSchema axSchema4 =
+ new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java", "java.util.Map");
+ final AxContextSchema axSchema5 =
+ new AxContextSchema(new AxArtifactKey("BigIntType", "0.0.1"), "Java", "java.math.BigInteger");
+ final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("Schemas", "0.0.1"));
+ schemas.getSchemasMap().put(axSchema0.getKey(), axSchema0);
+ schemas.getSchemasMap().put(axSchema1.getKey(), axSchema1);
+ schemas.getSchemasMap().put(axSchema2.getKey(), axSchema2);
+ schemas.getSchemasMap().put(axSchema3.getKey(), axSchema3);
+ schemas.getSchemasMap().put(axSchema4.getKey(), axSchema4);
+ schemas.getSchemasMap().put(axSchema5.getKey(), axSchema5);
+
+ final AxEvents eventMap = new AxEvents(new AxArtifactKey("smallEventMap", "0.0.1"));
+
+ final AxEvent event0 =
+ new AxEvent(new AxArtifactKey("event0", "0.0.1"), "org.onap.policy.apex.model.eventmodel.events");
+ event0.getParameterMap().put("par0",
+ new AxField(new AxReferenceKey(event0.getKey(), "par0"), axSchema0.getKey()));
+ event0.getParameterMap().put("par1",
+ new AxField(new AxReferenceKey(event0.getKey(), "par1"), axSchema1.getKey()));
+ event0.getParameterMap().put("par2",
+ new AxField(new AxReferenceKey(event0.getKey(), "par2"), axSchema2.getKey()));
+ event0.getParameterMap().put("par3",
+ new AxField(new AxReferenceKey(event0.getKey(), "par3"), axSchema3.getKey()));
+ event0.getParameterMap().put("par4",
+ new AxField(new AxReferenceKey(event0.getKey(), "par4"), axSchema4.getKey()));
+ event0.getParameterMap().put("par5",
+ new AxField(new AxReferenceKey(event0.getKey(), "par5"), axSchema5.getKey()));
+ eventMap.getEventMap().put(event0.getKey(), event0);
+
+ final AxEvent event1 =
+ new AxEvent(new AxArtifactKey("event1", "0.0.1"), "org.onap.policy.apex.model.eventmodel.events");
+ event1.getParameterMap().put("theOnlyPar",
+ new AxField(new AxReferenceKey(event1.getKey(), "theOnlyPar"), axSchema3.getKey()));
+ eventMap.getEventMap().put(event1.getKey(), event1);
+
+ final AxEvent event2 =
+ new AxEvent(new AxArtifactKey("event2", "0.0.1"), "org.onap.policy.apex.model.eventmodel.events");
+ eventMap.getEventMap().put(event2.getKey(), event2);
+
+ final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"));
+
+ final AxEventModel eventModel =
+ new AxEventModel(new AxArtifactKey("smallEventModel", "0.0.1"), schemas, keyInformation, eventMap);
+ eventModel.getKeyInformation().generateKeyInfo(eventModel);
+ eventModel.validate(new AxValidationResult());
+
+ return eventModel;
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexApiResultTest.java b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexApiResultTest.java
new file mode 100644
index 000000000..3c2af18ea
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexApiResultTest.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.Arrays;
+import org.junit.Test;
+import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
+
+/**
+ * Test API results.
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ApexApiResultTest {
+
+ @Test
+ public void testApiResult() {
+ assertNotNull(new ApexApiResult());
+
+ for (final Result result : Result.values()) {
+ assertNotNull(new ApexApiResult(result));
+ }
+
+ assertNotNull(new ApexApiResult(Result.SUCCESS, "Result Message"));
+ assertNotNull(new ApexApiResult(Result.FAILED, new IOException("IO Exception message")));
+ assertNotNull(new ApexApiResult(Result.FAILED, "Result Message", new IOException("IO Exception message")));
+
+ final ApexApiResult result =
+ new ApexApiResult(Result.FAILED, "Result Message", new IOException("IO Exception message"));
+
+ assertFalse(result.isOk());
+ assertTrue(result.isNok());
+ assertEquals(Result.FAILED, result.getResult());
+ assertEquals("Result Message\nIO Exception message\njava.io.IOExce", result.getMessage().substring(0, 50));
+
+ final ApexApiResult result2 = new ApexApiResult(Result.SUCCESS);
+ result2.addMessage(null);
+ assertEquals("", result2.getMessage());
+ result2.addMessage("");
+ assertEquals("", result2.getMessage());
+ result2.addMessage("funky message");
+ assertEquals("funky message\n", result2.getMessage());
+
+ result2.setResult(Result.OTHER_ERROR);
+ assertEquals(Result.OTHER_ERROR, result2.getResult());
+
+ final String[] messages = {"First Message", "Second Message", "Third Message"};
+ result2.setMessages(Arrays.asList(messages));
+ assertEquals("First Message", result2.getMessages().get(0));
+ assertEquals("Second Message", result2.getMessages().get(1));
+ assertEquals("Third Message", result2.getMessages().get(2));
+
+ assertEquals("result: OTHER_ERROR\nFirst Message\nSecond Message\nThird Message\n", result2.toString());
+ assertEquals("{\n" + "\"result\": \"OTHER_ERROR\",\n" + "\"messages\": [\n" + "\"First Message\",\n"
+ + "\"Second Message\",\n" + "\"Third Message\"]\n" + "}\n", result2.toJson());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiContextAlbumTest.java b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiContextAlbumTest.java
new file mode 100644
index 000000000..5ce6b6760
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiContextAlbumTest.java
@@ -0,0 +1,176 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ * ================================================================================
+ * 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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Context album for API tests.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ApexEditorApiContextAlbumTest {
+ @Test
+ public void testContextAlbumCrud() {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null);
+
+ ApexApiResult result = apexModel.validateContextAlbum(null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.validateContextAlbum("%%%$£", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.createContextAlbum("MyMap002", "0.0.2", "APPLICATION", "true", "MapType", "0.0.1",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createContextAlbum("MyMap012", "0.1.2", "ZOOBY", "false", "MapType", "0.0.1",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 012");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createContextAlbum("MyMap012", "0.1.4", "UNDEFINED", null, "MapType", "0.0.1",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 014");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createContextAlbum("MyMap012", null, null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "+++", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "MapZooby", null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "MapType", "--++", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "MapType", "0.0.2", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "MapType", "0.0.1", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createContextAlbum("MyMap012", null, "EPHEMERAL", "false", "MapType", null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createContextAlbum("MyMap002", "0.0.2", "APPLICATION", "true", "MapType", null,
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createContextAlbum("MyMap011", "0.1.2", "APPLICATION", "true", "MapType", "0.0.1",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.deleteContextAlbum("MyMap012", "0.1.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createContextAlbum("MyMap012", "0.1.2", "ZOOBY", "false", "MapType", "0.0.1",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 012");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.validateContextAlbum(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.updateContextAlbum(null, null, null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.updateContextAlbum("MyMap002", "0.0.2", null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateContextAlbum("MyMap002", "0.0.2", "ZOOBY", "true", null, null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateContextAlbum("MyMap002", "0.0.2", null, null, null, null,
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateContextAlbum("MyMap012", null, null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateContextAlbum("MyMap012", null, null, "true", null, null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateContextAlbum("MyMap015", null, null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updateContextAlbum("MyMap014", "0.1.5", null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "false", null, null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "false", "StringType", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "false", "String", null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "false", "StringType", "0.0.2", null,
+ null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "false", "StringType", "0.0.1", null,
+ null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateContextAlbum("MyMap012", null, "APPLICATION", "Hello", "StringType", "0.0.1", null,
+ null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.listContextAlbum("@£%%$", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.listContextAlbum(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listContextAlbum("MyMap012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listContextAlbum("MyMap012", "0.0.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listContextAlbum("MyMap012", "0.2.5");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listContextAlbum("MyMap014", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deleteContextAlbum("@£%%$", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.deleteContextAlbum("MyMap012", "0.1.1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deleteContextAlbum("MyMap012oooo", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.listContextAlbum("MyMap012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(3, result.getMessages().size());
+
+ result = apexModel.deleteContextAlbum("MyMap012", "0.1.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.listContextAlbum("MyMap012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+
+ result = apexModel.deleteContextAlbum("MyMap012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+
+ result = apexModel.listContextAlbum("MyMap012", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deleteContextAlbum(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(4, result.getMessages().size());
+
+ result = apexModel.listContextAlbum(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(0, result.getMessages().size());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiContextSchemaTest.java b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiContextSchemaTest.java
new file mode 100644
index 000000000..20310a29e
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiContextSchemaTest.java
@@ -0,0 +1,153 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ * ================================================================================
+ * 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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Context schema for API tests.
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ApexEditorApiContextSchemaTest {
+ @Test
+ public void testContextSchemaCrud() {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null);
+
+ ApexApiResult result = apexModel.validateContextSchemas(null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.validateContextSchemas("%%%$£", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listContextSchemas(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.createContextSchema("Hello", "0.0.2", "Java", "java.lang.String",
+ "1fa2e430-f2b2-11e6-bc64-92361f002671", "A description of hello");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createContextSchema("Hello", "0.1.2", "Java", "java.lang.String",
+ "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of hola");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createContextSchema("Hello", "0.1.4", "Java", "java.lang.String",
+ "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of connichi wa");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createContextSchema("Hello", null, "Java", "java.lang.String", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createContextSchema("Hello", null, "Java", "java.lang.String", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.deleteContextSchema("Hello", "0.1.4");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createContextSchema("Hello", "0.1.4", "Java", "java.lang.String",
+ "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of connichi wa");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.createContextSchema("Hello2", null, null, "java.lang.String", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createContextSchema("Hello2", null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createContextSchema("Hello2", null, "Java", "java.lang.String", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.createContextSchema("Hello", "0.1.2", "Java", "java.lang.Float",
+ "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of hola");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+
+ result = apexModel.deleteContextSchema("Hello", "0.1.4");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createContextSchema("Hello", "0.1.4", "Java", "java.lang.String",
+ "1fa2e430-f2b2-11e6-bc64-92361f002672", "A description of connichi wa");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.validateContextSchemas(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.updateContextSchema(null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.updateContextSchema("Hello", "0.0.2", null, null, null, "An updated description of hello");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateContextSchema("Hello", "0.0.2", null, null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateContextSchema("Hello", "0.1.2", "Java", "java.lang.Integer",
+ "1fa2e430-f2b2-11e6-bc64-92361f002673", "A further updated description of hola");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.updateContextSchema("Hello2", "0.0.2", null, null, null, "An updated description of hello");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.listContextSchemas("@£%%$", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.listContextSchemas("Hello", "0.1.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+
+ result = apexModel.listContextSchemas("Hello", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(4, result.getMessages().size());
+
+ result = apexModel.listContextSchemas(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(9, result.getMessages().size());
+
+ result = apexModel.deleteContextSchema("@£%%$", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.deleteContextSchema("Hello", "0.1.1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deleteContextSchema("Hellooooo", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.listContextSchemas("Hello", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(4, result.getMessages().size());
+
+ result = apexModel.deleteContextSchema("Hello", "0.1.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.listContextSchemas("Hello", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(3, result.getMessages().size());
+
+ result = apexModel.deleteContextSchema("Hello", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.listContextSchemas("Hello", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.listContextSchemas(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.deleteContextSchema(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(5, result.getMessages().size());
+
+ result = apexModel.listContextSchemas(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(0, result.getMessages().size());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiEventTest.java b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiEventTest.java
new file mode 100644
index 000000000..ac9265e84
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiEventTest.java
@@ -0,0 +1,202 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ * Modifications Copyright (C) 2022 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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Test events for API tests.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ApexEditorApiEventTest {
+ @Test
+ public void testEventCrud() {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null);
+
+ ApexApiResult result = apexModel.validateEvent(null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.validateEvent("%%%$£", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.createEvent("MyEvent002", "0.0.2", "My Namespace", "My Source", "my target",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createEvent("MyEvent012", "0.1.2", "My Namespace", "My Source", "my target",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createEvent("MyEvent012", "0.1.4", "My Namespace", "My Source", "my target",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 014", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createEvent("MyEvent012", null, null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createEvent("MyEvent012", null, null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createEvent("MyEvent002", "0.0.2", "My Namespace", "My Source", "my target",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createEvent("@£$%^", "0.2.5", "My Namespace", "My Source", "my target",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.deleteEvent("MyEvent012", "0.1.4");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createEvent("MyEvent012", "0.1.4", "My Namespace", "My Source", "my target",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 014", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.validateEvent(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.updateEvent(null, null, null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result =
+ apexModel.updateEvent("MyEvent012", "0.1.2", "Another Namespace", null, "Another target", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateEvent("MyEvent002", "0.0.2", "My Namespace", "My Source", "my target",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateEvent("MyEvent012", null, null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateEvent("MyEvent015", null, null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updateEvent("MyEvent014", "0.1.5", null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updateEvent("@£$%^^", "0.6.9", null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.listEvent("@£$%", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listEvent(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listEvent("MyEvent012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listEvent("MyEvent012", "0.0.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listEvent("MyEvent012", "0.2.5");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listEvent("MyEvent123", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deleteEvent("@£$%^", "0.1.1");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deleteEvent("MyEvent012", "0.1.1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deleteEvent("MyEvent012oooo", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.listEvent("MyEvent012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(3, result.getMessages().size());
+
+ result = apexModel.deleteEvent("MyEvent012", "0.1.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.listEvent("MyEvent012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+
+ result = apexModel.deleteEvent("MyEvent012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.listEvent("MyEvent012", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createEventPar("MyEvent123", null, "NewPar00", null, null, false);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createEventPar("MyEvent002", "4.5.6", "NewPar00", null, null, true);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createEventPar("MyEvent002", "0.1.4", "NewPar00", null, null, false);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createEventPar("MyEvent002", "0.0.2", "NewPar00", null, null, true);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.createContextSchema("eventContextItem0", "0.0.1", "Java", "java.lang.Integer",
+ "1fa2e430-f2b2-11e6-bc64-92361f002673", "A further updated description of hola");
+ result = apexModel.createEventPar("MyEvent002", "0.0.2", "NewPar00", "eventContextItem0", null, false);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createEventPar("MyEvent002", "0.0.2", "NewPar00", "eventContextItem0", null, true);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createEventPar("MyEvent002", "0.0.2", "NewPar01", "eventContextItem0", "0.0.1", false);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createEventPar("MyEvent002", "0.0.2", "NewPar02", "eventContextItem0", "0.0.2", true);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createEventPar("MyEvent002", null, "NewPar02", "eventContextItem0", null, false);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createEventPar("MyEvent002", null, "NewPar03", "eventContextItem0", null, true);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.listEventPar("@£%%$", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listEventPar("MyEvent002", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listEventPar("MyEvent002", "0.0.1", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listEventPar("MyEvent002", "0.0.2", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listEventPar("MyEvent002", "0.0.2", "NewPar01");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listEventPar("MyEvent002", "0.0.2", "NewPar02");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listEventPar("MyEvent002", "0.0.2", "NewPar04");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deleteEventPar("@££%%%", "0.0.2", "NewPar04");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deleteEventPar("NonExistantEvent", "0.0.2", "NewPar04");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ assertEquals(4, apexModel.listEventPar("MyEvent002", null, null).getMessages().size());
+ result = apexModel.deleteEventPar("MyEvent002", "0.0.2", "NewPar04");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ assertEquals(4, apexModel.listEventPar("MyEvent002", null, null).getMessages().size());
+ result = apexModel.deleteEventPar("MyEvent002", null, "NewPar02");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(3, apexModel.listEventPar("MyEvent002", null, null).getMessages().size());
+ result = apexModel.deleteEventPar("MyEvent002", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listEventPar("MyEvent002", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deleteEventPar("MyEvent002", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listEventPar("MyEvent002", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deleteEvent(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(4, result.getMessages().size());
+
+ result = apexModel.listEvent(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(0, result.getMessages().size());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiKeyInfoTest.java b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiKeyInfoTest.java
new file mode 100644
index 000000000..2519b8cb2
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiKeyInfoTest.java
@@ -0,0 +1,137 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ * ================================================================================
+ * 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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Key information for API tests.
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ApexEditorApiKeyInfoTest {
+
+ @Test
+ public void testKeyInfoCrud() {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null);
+
+ ApexApiResult result = apexModel.validateKeyInformation(null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.validateKeyInformation("%%%$£", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.createKeyInformation(null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.createKeyInformation("Hello", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002671",
+ "A description of hello");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createKeyInformation("Hello", "0.1.2", "1fa2e430-f2b2-11e6-bc64-92361f002672",
+ "A description of hola");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createKeyInformation("Hello", "0.1.4", "1fa2e430-f2b2-11e6-bc64-92361f002672",
+ "A description of connichi wa");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createKeyInformation("Hello", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createKeyInformation("Hello", null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+
+ result = apexModel.createKeyInformation("Hello", "0.1.2", "1fa2e430-f2b2-11e6-bc64-92361f002672",
+ "A description of hola");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+
+ result = apexModel.validateKeyInformation(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.updateKeyInformation(null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.updateKeyInformation("Hello", "0.0.2", null, "An updated description of hello");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateKeyInformation("Hello", "0.0.2", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateKeyInformation("Hello", "0.1.2", "1fa2e430-f2b2-11e6-bc64-92361f002673",
+ "A further updated description of hola");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.updateKeyInformation("Hello2", "0.0.2", null, "An updated description of hello");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.listKeyInformation(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.listKeyInformation("%%%$$", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.listKeyInformation("Hello", "0.1.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+
+ result = apexModel.listKeyInformation("Hello", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(4, result.getMessages().size());
+
+ result = apexModel.deleteKeyInformation("Hello", "0.1.1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deleteKeyInformation("Hellooooo", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.listKeyInformation("Hello", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(4, result.getMessages().size());
+
+ result = apexModel.listKeyInformation(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(22, result.getMessages().size());
+
+ result = apexModel.deleteKeyInformation("%%%$$", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.deleteKeyInformation("Hello", "0.1.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.listKeyInformation("Hello", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(3, result.getMessages().size());
+
+ result = apexModel.deleteKeyInformation("Hello", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.listKeyInformation("Hello", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deleteKeyInformation(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(18, result.getMessages().size());
+
+ result = apexModel.listKeyInformation(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(0, result.getMessages().size());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiPolicyTest.java b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiPolicyTest.java
new file mode 100644
index 000000000..0a4d72214
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiPolicyTest.java
@@ -0,0 +1,1023 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ * ================================================================================
+ * 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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Test policies for API.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ApexEditorApiPolicyTest {
+ @Test
+ public void testMyTestPolicyCrud() {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null);
+
+ ApexApiResult result = apexModel.validatePolicy(null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.validatePolicy("%%%$£", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.createPolicy("MyPolicy002", "0.0.2", "SomeTemplate", "AState",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicy("MyPolicy002", "0.0.2", "SomeTemplate", "AState",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createPolicy("MyPolicy012", null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicy("MyPolicy012", null, "SomeTemplate", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicy("MyPolicy013", null, null, "AState", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicy("MyPolicy012", null, "SomeTemplate", "AState", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicy("MyPolicy002", "0.0.2", "SomeTemplate", "AState",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createPolicy("MyPolicy012", "0.1.2", "SomeTemplate", "AState",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicy("MyTestPolicy", "0.0.1", "SomeTemplate", "TestState",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.deletePolicy("MyPolicy002", "0.0.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicy("MyPolicy002", "0.0.2", "SomeTemplate", "AState",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.validatePolicy(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.updatePolicy("@£$$", "0.0.2", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.updatePolicy("MyPolicy002", "0.0.2", null, null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicy("MyPolicy002", "0.0.1", null, null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicy("MyPolicy002", "0.0.2", "SomeOtherTemplate", "BState",
+ "1fa2e430-f2b2-11e6-bc64-92361f002700", "A description of 002");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicy("MyPolicy012", null, "SomeOtherTemplate", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicy("MyPolicy012", null, null, "CState", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicy("MyPolicy012", null, "SomeOtherTemplate", "BState", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicy("MyPolicy015", null, "SomeOtherTemplate", "DState", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicy("MyPolicy014", "0.1.5", "SomeOtherTemplate", "EState", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.listPolicy("@£$%%", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicy(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(6, result.getMessages().size());
+ result = apexModel.listPolicy("MyPolicy012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listPolicy("MyPolicy012", "0.0.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicy("MyPolicy012", "0.2.5");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicy("MyPolicy014", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deletePolicy("@£$%", "0.1.1");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.deletePolicy("MyPolicy012", "0.1.1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deletePolicy("MyPolicy012oooo", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.listPolicy("MyPolicy012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+
+ result = apexModel.deletePolicy("MyPolicy002", "0.0.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+
+ result = apexModel.listPolicy("MyPolicy012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+
+ result = apexModel.deletePolicy("MyPolicy012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.createPolicyState(null, null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyState("MyPolicy123", null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyState("MyPolicy123", null, "AState", null, null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.2", "AState", null, null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "ATrigger", null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", "0.0.2", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", "0.0.1", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", null, "ATask", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", "0.0.2");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "AState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "BState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "CState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "DState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.updatePolicyState(null, null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.updatePolicyState("MyPolicy123", null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.updatePolicyState("MyPolicy123", null, "AState", null, null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyState("MyTestPolicy", "0.0.2", "AState", null, null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", null, null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "ZState", null, null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "ATrigger", null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", "0.0.2", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", "0.0.2", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", null, "ATask", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", "0.0.2");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyState("MyTestPolicy", null, "AState", "inEvent", null, "task", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyState("MyTestPolicy", "0.0.1", "AState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyState("MyTestPolicy", "0.0.1", "BState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyState("MyTestPolicy", "0.0.1", "CState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyState("MyTestPolicy", "0.0.1", "DState", "inEvent", "0.0.1", "task", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.listPolicyState("MyTestPolicy", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(4, result.getMessages().size());
+ result = apexModel.listPolicyState(null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyState("SomeOtherPolicy", "0.0.1", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyState("SomeOtherPolicy", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyState("MyTestPolicy", "0.0.2", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyState("MyTestPolicy", "0.0.1", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(4, result.getMessages().size());
+ result = apexModel.listPolicyState("MyTestPolicy", "0.0.1", "CState");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyState("MyTestPolicy", null, "CState");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyState("MyTestPolicy", "0.0.1", "AState");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyState("MyTestPolicy", "0.0.1", "EState");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deletePolicyState("@£$$", "0.0.2", "Trigger04");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ assertEquals(4, apexModel.listPolicyState("MyTestPolicy", null, null).getMessages().size());
+ result = apexModel.deletePolicyState("MyTestPolicy", "0.0.2", "Trigger04");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ assertEquals(4, apexModel.listPolicyState("MyTestPolicy", null, null).getMessages().size());
+ result = apexModel.deletePolicyState("MyTestPolicy", null, "CState");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.deletePolicyState("MyTestPolicy", null, "ZState");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ assertEquals(3, apexModel.listPolicyState("MyTestPolicy", null, null).getMessages().size());
+ result = apexModel.deletePolicyState("MyTestPolicy", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listPolicyState("MyTestPolicy", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyState("MyTestPolicy", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "TestState1", "inEvent", "0.0.1", "task",
+ "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "TestState2", "outEvent0", "0.0.1", "task",
+ "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.createPolicyState("MyTestPolicy", "0.0.1", "TestState3", "outEvent1", "0.0.1", "task",
+ "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.createPolicyStateTaskSelectionLogic(null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", null, "SomeState", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "1.2.3", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "NewTSL00", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "UNDEFINED",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "MVEL",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "JAVA",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "JYTHON",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", "JAVASCRIPT",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", "JRUBY",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.updatePolicyStateTaskSelectionLogic(null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState99", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy2", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy1", "0.0.2", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "NonExistantState", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "",
+ "Some Other Policy Logic");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1", "MVEL",
+ "Some Other Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyPolicy012", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", null,
+ "Some Other Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyPolicy015", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyPolicy014", "0.1.5", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.listPolicyStateTaskSelectionLogic(null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateTaskSelectionLogic("zooby", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateTaskSelectionLogic("zooby", null, "looby");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateTaskSelectionLogic("zooby", null, "TestState1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", null, "looby");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.2", "TestState1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+
+ result = apexModel.deletePolicyStateTaskSelectionLogic(null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateTaskSelectionLogic("zooby", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateTaskSelectionLogic("zooby", null, "looby");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateTaskSelectionLogic("zooby", null, "TestState1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", null, "looby");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.2", "TestState1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", null,
+ "Some Other Policy Logic");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.createPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1", "JRUBY",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listPolicyStateTaskSelectionLogic("MyTestPolicy", null, "TestState1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.deletePolicyStateTaskSelectionLogic("MyTestPolicy", "0.0.1", "TestState1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createPolicyStateOutput(null, null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", null, "SomeState", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", null, "SomeState", "SomeOutput", null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "1.2.3", "TestState1", "SomeOutput", null, null,
+ null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", null, null,
+ null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput",
+ "SomeDummyEvent", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", "inEvent",
+ "1.2.3", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", "inEvent",
+ "0.0.1", "SomeDummyNextState");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", "inEvent",
+ "0.0.1", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOtherOutput", "inEvent",
+ "0.0.1", "TestState1");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOtherOutput", "inEvent",
+ "0.0.1", "TestState2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOtherOutput", "inEvent",
+ "0.0.1", "TestState2");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", "AnotherOtherOutput",
+ "outEvent0", "0.0.1", "TestState3");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", "YetAnotherOtherOutput",
+ "outEvent0", "0.0.1", "TestState3");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.listPolicyStateOutput(null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.2", "TestState1", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "SomeState", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "YetAnotherOtherOutput");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", "YetAnotherOtherOutput");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState3", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deletePolicyStateOutput(null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", "0.0.1", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", "0.0.2", "TestState1", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", null, "SomeState", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", "0.0.1", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", "0.0.1", "TestState3", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", "0.0.1", "TestState3", "DummyOutput");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "TestState1", null);
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", null, "TestState1", "SomeOutput");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "TestState1", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", null, "TestState1", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "TestState1", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "TestState2", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.deletePolicyStateOutput("MyTestPolicy", null, "TestState2", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listPolicyStateOutput("MyTestPolicy", null, "TestState2", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOutput", "inEvent",
+ "0.0.1", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOtherOutput", "inEvent",
+ "0.0.1", "TestState1");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState1", "SomeOtherOutput", "inEvent",
+ "0.0.1", "TestState2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", "AnotherOtherOutput",
+ "outEvent0", "0.0.1", "TestState3");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateOutput("MyTestPolicy", "0.0.1", "TestState2", "YetAnotherOtherOutput",
+ "outEvent0", "0.0.1", "TestState3");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.createPolicyStateFinalizerLogic(null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "SomeState", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "SomeState", "SFLName01", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "1.2.3", "TestState1", "SFLName01", null,
+ null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName01", null,
+ null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName01",
+ "NewTSL00", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName02",
+ "UNDEFINED", "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName03", "MVEL",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName03", "MVEL",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName04", "JAVA",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName05", "JYTHON",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06",
+ "JAVASCRIPT", "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName07", "JRUBY",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.updatePolicyStateFinalizerLogic(null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", null, "TestState99", "SomeSFLName", null,
+ null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy2", null, "TestState1", "SomeSFLName", null,
+ null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy1", "0.0.2", "TestState1", "SomeSFLName", null,
+ null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "NonEistantSFL", null,
+ null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName06", null,
+ null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName06", "",
+ "Some Other Policy Logic");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName06", "MVEL",
+ "Some Other Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyStateFinalizerLogic("MyPolicy012", null, "TestState1", "SFLName06", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06", null,
+ "Some Other Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updatePolicyStateFinalizerLogic("MyPolicy015", null, "TestState1", "SFLName06", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updatePolicyStateFinalizerLogic("MyPolicy014", "0.1.5", "TestState1", "SFLName06", null,
+ null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.listPolicyStateFinalizerLogic(null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", "0.0.2", "TestState1", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "SomeState", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateFinalizerLogic("zooby", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateFinalizerLogic("zooby", null, "looby", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateFinalizerLogic("zooby", null, "TestState1", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "looby", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", "0.0.2", "TestState1", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(6, result.getMessages().size());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+
+ result = apexModel.deletePolicyStateFinalizerLogic(null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.2", "TestState1", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", null, "SomeState", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateFinalizerLogic("zooby", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateFinalizerLogic("zooby", null, "looby", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateFinalizerLogic("zooby", null, "TestState1", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", null, "looby", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.2", "TestState1", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName06");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName06");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(5, result.getMessages().size());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName02");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName02");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName02");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(4, result.getMessages().size());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(4, result.getMessages().size());
+ result = apexModel.deletePolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName02",
+ "UNDEFINED", "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName03", "MVEL",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName04", "JAVA",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", "0.0.1", "TestState1", "SFLName05", "JYTHON",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName06",
+ "JAVASCRIPT", "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateFinalizerLogic("MyTestPolicy", null, "TestState1", "SFLName07", "JRUBY",
+ "Some Policy Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.createTask("TestTask0", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTask("TestTask1", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTask("TestTask2", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTask("TestTask3", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTask("TestTask4", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.createPolicyStateTaskRef(null, null, null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, null, null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "SomeState", null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "SomeState", null, null, null, null,
+ "DummyOutput");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "1.2.3", "SomeState", null, null, null, null,
+ "DummyOutput");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("AnyOldPolicy", "1.2.3", "SomeState", null, null, null, null,
+ "DummyOutput");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", null,
+ null, null, "DummyOutput");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName",
+ "SomeTask", "Zooby|", null, "DummyOutput");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName",
+ "SomeTask", "0.0.1", null, "DummyOutput");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", null, "DummyOutput");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", "Some Policy Logic", "DummyOutput");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", "DIRECT", "DummyOutput");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", "LOGIC", "DummyOutput");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", "DIRECT", "SFLName07");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", "LOGIC", "SomeOutput");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", "DIRECT", "SomeOutput");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "NonExistantTask", "0.0.1", "DIRECT", "SomeOutput");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName", "task",
+ "0.0.1", "LOGIC", "SFLName07");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "TestTask0", "0.0.1", "LOGIC", "SFLName07");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "TestTask1", "0.0.1", "DIRECT", "SomeOtherOutput");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "TestTask2", "0.0.1", "LOGIC", "SFLName07");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "TestTask3", "0.0.1", "DIRECT", "SomeOtherOutput");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, "TestTask4", "0.0.1",
+ "LOGIC", "SFLName07");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, "TestTask4", "0.0.1",
+ "LOGIC", "SFLName07");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "TestState1", "TestTask4", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "TestTask4", "0.0.1", "FUNKY", "SFLName07");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "TestTask4", "0.0.1", "UNDEFINED", "SFLName07");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeTaskLocalName",
+ "TestTask4", "0.0.1", "LOGIC", "SFLName07");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, "TestTask0", "0.0.1",
+ "LOGIC", "SFLName07");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+
+ result = apexModel.listPolicyStateTaskRef(null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "SomeState", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateTaskRef("zooby", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateTaskRef("zooby", null, "looby", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateTaskRef("zooby", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "looby", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(12, result.getMessages().size());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "SomeOldTask", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "task", "1.0.1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "task", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", "task", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+
+ result = apexModel.deletePolicyStateTaskRef(null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "SomeState", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateTaskRef("zooby", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateTaskRef("zooby", null, "looby", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateTaskRef("zooby", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "looby", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "ADummyTask", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", "0.0.1", "TestState1", "task", "0.0.2");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(12, result.getMessages().size());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "TestState1", "TestTask0", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(10, result.getMessages().size());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "TestState1", "TestTask2", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(8, result.getMessages().size());
+ result = apexModel.deletePolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(4, result.getMessages().size());
+ result = apexModel.listPolicyStateTaskRef("MyTestPolicy", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createPolicyStateContextRef(null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", null, "SomeState", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", null, "SomeState", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "1.2.3", "SomeState", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateContextRef("AnyOldPolicy", "1.2.3", "SomeState", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTask", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTask", "Zooby|");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "SomeTask", "0.0.1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "task", "0.0.1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyPolicy123", null, null, "AContextMap00", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyPolicy123", null, "TestState1", "AContextMap00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "4.5.6", "TestState1", "AContextMap00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.1.4", "TestState1", "AContextMap00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "AContextMap00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.2");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum1", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.1");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", null, "TestState1", "contextAlbum0", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+
+ result = apexModel.listPolicyStateContextRef(null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, "SomeState", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateContextRef("zooby", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateContextRef("zooby", null, "looby", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateContextRef("zooby", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, "looby", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.2");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "AContextMap04", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "1.0.1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deletePolicyStateContextRef(null, null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "SomeState", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.1", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("zooby", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("zooby", null, "looby", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("zooby", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "looby", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.2", "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "ADummyContextMap", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.2");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "AContextMap04", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "TestState1", "contextAlbum0", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "TestState1", "contextAlbum0", "0.1.5");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "TestState1", "contextAlbum1", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.createPolicyStateContextRef("MyTestPolicy", "0.0.1", "TestState1", "contextAlbum0", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.deletePolicyStateContextRef("MyTestPolicy", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listPolicyStateContextRef("MyTestPolicy", null, "TestState1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deletePolicy(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(3, result.getMessages().size());
+
+ result = apexModel.listPolicy(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(0, result.getMessages().size());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiTaskTest.java b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiTaskTest.java
new file mode 100644
index 000000000..15e53f925
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexEditorApiTaskTest.java
@@ -0,0 +1,376 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 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.
+ * 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.modelapi;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.modelapi.impl.ApexModelImpl;
+
+/**
+ * Test tasks for API tests.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ApexEditorApiTaskTest {
+ @Test
+ public void testTaskCrud() {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null);
+
+ ApexApiResult result = apexModel.validateTask(null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.validateTask("%%%$£", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.createTask("@^^$^^$", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700",
+ "A description of 002");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createTask("MyTask002", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700",
+ "A description of 002");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTask("MyTask002", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700",
+ "A description of 002");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createTask("MyTask012", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTask("MyTask012", null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.listTask(null, null);
+ result = apexModel.createTask("MyTask002", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700",
+ "A description of 002");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createTask("MyTask012", "0.1.2", "1fa2e430-f2b2-11e6-bc64-92361f002700",
+ "A description of 002");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.deleteTask("MyTask002", "0.0.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTask("MyTask002", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700",
+ "A description of 002");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.validateTask(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.updateTask("@$$$£", "0.0.2", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.updateTask("MyTask002", "0.0.2", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateTask("MyTask002", "0.0.1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updateTask("MyTask002", "0.0.2", "1fa2e430-f2b2-11e6-bc64-92361f002700",
+ "A description of 002");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateTask("MyTask012", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateTask("MyTask012", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateTask("MyTask012", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateTask("MyTask015", null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updateTask("MyTask014", "0.1.5", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.listTask("£@£@@£@£", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listTask(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listTask("MyTask012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listTask("MyTask012", "0.0.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listTask("MyTask012", "0.2.5");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listTask("MyTask014", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deleteTask("@£££@", "0.1.1");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deleteTask("MyTask012", "0.1.1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deleteTask("MyTask012oooo", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.listTask("MyTask012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+
+ result = apexModel.deleteTask("MyTask012", "0.1.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.listTask("MyTask012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+
+ result = apexModel.deleteTask("MyTask012", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.listTask("MyTask012", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.updateTaskLogic("MyTask002", null, "NewLogic00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createTaskLogic("MyTask123", null, "NewLogic00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createTaskLogic("MyTask002", "4.5.6", "NewLogic00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createTaskLogic("MyTask002", "0.1.4", "NewLogic00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createTaskLogic("MyTask002", "0.0.2", "NewLogic00", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createTaskLogic("MyTask002", "0.0.2", "UNDEFINED", "Some Task Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTaskLogic("MyTask002", "0.0.2", "MVEL", "Some Task Logic");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.deleteTaskLogic("MyTask002", "0.0.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTaskLogic("MyTask002", "0.0.2", "JAVA", "Some Task Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTaskLogic("MyTask002", "0.0.2", "JYTHON", "Some Task Logic");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.deleteTaskLogic("MyTask002", "0.0.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTaskLogic("MyTask002", null, "JAVASCRIPT", "Some Task Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.deleteTaskLogic("MyTask002", "0.0.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTaskLogic("MyTask002", null, "JRUBY", "Some Task Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.updateTaskLogic("MyTask002", "0.0.2", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateTaskLogic("MyTask002", "0.0.1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updateTaskLogic("MyTask002", "0.0.2", "", "Some Other Task Logic");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.updateTaskLogic("MyTask002", "0.0.2", "MVEL", "Some Other Task Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateTaskLogic("MyTask012", null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updateTaskLogic("MyTask002", null, null, "Some Other Task Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateTaskLogic("MyTask002", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.updateTaskLogic("MyTask015", null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.updateTaskLogic("MyTask014", "0.1.5", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.listTaskLogic("MyTask002", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listTaskLogic("MyTask002", "0.0.1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listTaskLogic("MyTask002", "0.0.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listTaskLogic("MyTask002", "0.0.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listTaskLogic("MyTask002", "0.0.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listTaskLogic(null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.deleteTaskLogic("@£@£@£", "0.0.2");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deleteTaskLogic("NonExistantTask", "0.0.2");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ assertEquals(1, apexModel.listTaskLogic("MyTask002", null).getMessages().size());
+ result = apexModel.deleteTaskLogic("MyTask002", "0.0.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listTaskLogic("MyTask002", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.deleteTaskLogic("MyTask002", "0.0.2");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ assertEquals(1, apexModel.listTaskLogic("MyTask002", null).getMessages().size());
+ result = apexModel.createTaskLogic("MyTask002", null, "JRUBY", "Some Task Logic");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listTaskLogic("MyTask002", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.deleteTaskLogic("MyTask002", "0.0.2");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.deleteTaskLogic("MyTask002", "0.0.2");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createTaskField("MyTask002", "0.0.2", "NewField00", "eventContextItem0", null, false);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(ApexModelImpl.FIELDS_DEPRECATED_WARN_MSG, result.getMessage().trim());
+ result = apexModel.handleTaskField("MyTask002", "0.0.2", "NewField01");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(ApexModelImpl.FIELDS_DEPRECATED_WARN_MSG, result.getMessage().trim());
+
+ result = apexModel.createTaskParameter("MyTask123", null, "NewPar00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createTaskParameter("MyTask002", "4.5.6", "NewPar00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createTaskParameter("MyTask002", "0.1.4", "NewPar00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar00", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar00", "eventContextItem0");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar00", "eventContextItem0");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar01", "eventContextItem0");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar02", "eventContextItem0");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar02", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createTaskParameter("MyTask002", "0.0.2", "NewPar03", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createTaskParameter("MyTask002", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createTaskParameter("MyTask002", null, null, "Default value");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.listTaskParameter("@£$%", null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listTaskParameter("MyTask002", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listTaskParameter("MyTask002", "0.0.3", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listTaskParameter("MyTask002", "0.0.2", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listTaskParameter("MyTask002", "0.0.2", "NewPar01");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listTaskParameter("MyTask002", "0.0.2", "NewPar02");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listTaskParameter("MyTask002", "0.0.2", "NewPar04");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deleteTaskParameter("@£$%", "0.0.2", "NewPar04");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deleteTaskParameter("NonExistantTask", "0.0.2", "NewPar04");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ assertEquals(3, apexModel.listTaskParameter("MyTask002", null, null).getMessages().size());
+ result = apexModel.deleteTaskParameter("MyTask002", "0.0.2", "NewPar04");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ assertEquals(3, apexModel.listTaskParameter("MyTask002", null, null).getMessages().size());
+ result = apexModel.deleteTaskParameter("MyTask002", null, "NewPar02");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, apexModel.listTaskParameter("MyTask002", null, null).getMessages().size());
+ result = apexModel.deleteTaskParameter("MyTask002", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.listTaskParameter("MyTask002", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deleteTaskParameter("MyTask002", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createTaskContextRef("@£$$", null, "AContextMap00", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.createTaskContextRef("MyTask123", null, "AContextMap00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createTaskContextRef("MyTask123", null, "AContextMap00", "0.0.1");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createTaskContextRef("MyTask123", null, "AContextMap00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createTaskContextRef("MyTask002", "4.5.6", "AContextMap00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createTaskContextRef("MyTask002", "0.1.4", "AContextMap00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "AContextMap00", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum2", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.2");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum1", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = apexModel.createTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.1");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = apexModel.createTaskContextRef("MyTask002", null, "contextAlbum0", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+
+ result = apexModel.listTaskContextRef("@£$%", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.listTaskContextRef("MyTask002", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.1", null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.2");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "AContextMap04", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum0", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum1", "0.0.1");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listTaskContextRef("MyTask002", "0.0.2", "contextAlbum1", "0.0.2");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deleteTaskContextRef("@£$%", "0.0.2", "AContextMap04", null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ result = apexModel.deleteTaskContextRef("NonExistantTask", "0.0.2", "AContextMap04", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ assertEquals(2, apexModel.listTaskContextRef("MyTask002", null, null, null).getMessages().size());
+ result = apexModel.deleteTaskContextRef("MyTask002", "0.0.2", "AContextMap04", null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deleteTaskContextRef("MyTask002", null, "contextAlbum0", "0.0.3");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deleteTaskContextRef("MyTask002", null, "contextAlbum0", "0.1.5");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+ result = apexModel.deleteTaskContextRef("MyTask002", null, "contextAlbum0", null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.deleteTaskContextRef("MyTask002", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(1, result.getMessages().size());
+ result = apexModel.listTaskContextRef("MyTask002", null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = apexModel.deleteTask(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(2, result.getMessages().size());
+
+ result = apexModel.listTask(null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertEquals(0, result.getMessages().size());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java
new file mode 100644
index 000000000..f28d0e634
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java
@@ -0,0 +1,208 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ * ================================================================================
+ * 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.modelapi;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.UUID;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.model.modelapi.impl.ApexModelImpl;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+
+/**
+ * Test the apex model API.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ApexModelApiTest {
+ private Connection connection;
+
+ @Before
+ public void setup() throws Exception {
+ // Hold the h2 database up for entire tests
+ connection = DriverManager.getConnection("jdbc:h2:mem:testdb");
+ }
+
+ @After
+ public void teardown() throws Exception {
+ // Close the h2 database after tests
+ connection.close();
+ }
+
+ @Test
+ public void testApexModelLoadFromFile() {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null);
+
+ ApexApiResult result = apexModel.loadFromFile("src/main/resources/models/PolicyModel.json");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.deleteModel();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.deleteModel();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.junk");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ assertEquals("Unable to unmarshal Apex concept", result.getMessages().get(0).trim());
+ }
+
+ @Test
+ public void testApexModelSaveToFile() throws IOException {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null);
+
+ ApexApiResult result = apexModel.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ final File tempJsonModelFile = File.createTempFile("ApexModelTest", ".json");
+ result = apexModel.saveToFile(tempJsonModelFile.getPath());
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ final ApexModel jsonApexModel = new ApexModelFactory().createApexModel(null);
+ result = jsonApexModel.loadFromFile(tempJsonModelFile.getPath());
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ tempJsonModelFile.delete();
+
+ final File tempModelFile = File.createTempFile("ApexModelTest", ".json");
+ result = apexModel.saveToFile(tempModelFile.getPath());
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ final ApexModel testApexModel = new ApexModelFactory().createApexModel(null);
+ result = testApexModel.loadFromFile(tempModelFile.getPath());
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ tempModelFile.delete();
+ }
+
+ @Test
+ public void testApexModelUrl() throws IOException {
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null);
+
+ assertThatThrownBy(() -> apexModel.readFromUrl(null)).isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> apexModel.writeToUrl(null)).isInstanceOf(IllegalArgumentException.class);
+ ApexApiResult result = null;
+ result = apexModel.readFromUrl("zooby/looby");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.writeToUrl("zooby/looby");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.readFromUrl("zooby://zooby/looby");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.writeToUrl("zooby://zooby/looby");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ final File tempJsonModelFile = File.createTempFile("ApexModelTest", "json");
+
+ result = apexModel.saveToFile(tempJsonModelFile.getPath());
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ final String tempFileUrlString = tempJsonModelFile.toURI().toString();
+ result = apexModel.readFromUrl(tempFileUrlString);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.writeToUrl(tempFileUrlString);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ assertEquals("protocol doesn't support output", result.getMessages().get(0));
+
+ tempJsonModelFile.delete();
+ }
+
+ @Test
+ public void testApexModelMisc() throws IOException {
+ final ApexModelImpl apexModelImpl = (ApexModelImpl) new ApexModelFactory().createApexModel(null);
+
+ ApexApiResult result = null;
+
+ result = apexModelImpl.getModelKey();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModelImpl.listModel();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModelImpl.createModel("ModelName", "0.0.1", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModelImpl.updateModel("ModelName", "0.0.1", UUID.randomUUID().toString(), "Model Description");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ apexModelImpl.deleteModel();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+ result = apexModelImpl.loadFromString(modelString);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ final File tempFile = File.createTempFile("ApexModel", "json");
+ tempFile.deleteOnExit();
+ TextFileUtils.putStringAsFile(modelString, tempFile);
+
+ apexModelImpl.deleteModel();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModelImpl.loadFromFile(tempFile.getPath());
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModelImpl.analyse();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModelImpl.validate();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModelImpl.compare(tempFile.getPath(), true, true);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModelImpl.compareWithString(modelString, true, true);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModelImpl.split("policy");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModelImpl.split(tempFile.getPath(), "policy");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModelImpl.merge(tempFile.getPath(), true);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModelImpl.mergeWithString(modelString, true);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ assertNotEquals(0, apexModelImpl.hashCode());
+ assertNotNull(apexModelImpl.getCopy());
+ assertNotNull(apexModelImpl.build());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/modelapi/ModelFacadeTest.java b/model/src/test/java/org/onap/policy/apex/model/modelapi/ModelFacadeTest.java
new file mode 100644
index 000000000..d3b32b923
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/modelapi/ModelFacadeTest.java
@@ -0,0 +1,99 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
+ * ================================================================================
+ * 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.modelapi;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Properties;
+import java.util.UUID;
+import org.junit.Test;
+import org.onap.policy.apex.model.modelapi.impl.ModelFacade;
+
+public class ModelFacadeTest {
+
+ @Test
+ public void testModelFacade() {
+ assertThatThrownBy(() -> new ModelFacade(null, null))
+ .hasMessage("apexModel may not be null");
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null);
+
+ assertThatThrownBy(() -> new ModelFacade(apexModel, null))
+ .hasMessage("apexProperties may not be null");
+ final Properties modelProperties = new Properties();
+ final ModelFacade mf = new ModelFacade(apexModel, modelProperties);
+
+ ApexApiResult result = mf.createModel(null, null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = mf.createModel("ModelName", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = mf.createModel("ModelName", "0.0.1", null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "");
+ result = mf.createModel("ModelName", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "£$£$£$");
+ result = mf.createModel("ModelName", null, null, null);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ modelProperties.setProperty("DEFAULT_CONCEPT_VERSION", "0.0.1");
+ result = mf.createModel("ModelName", null, null, null);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+ result = mf.deleteModel();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = mf.createModel("ModelName", null, null, null);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = mf.updateModel("ModelName", null, UUID.randomUUID().toString(), "New Description");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = mf.updateModel("ModelName", "0.0.1", UUID.randomUUID().toString(), "New Description");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ modelProperties.remove("DEFAULT_CONCEPT_VERSION");
+ result = mf.updateModel("ModelName", null, UUID.randomUUID().toString(), "New Description");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = mf.updateModel(null, null, UUID.randomUUID().toString(), "New Description");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = mf.deleteModel();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = mf.updateModel("name", "0.0.1", UUID.randomUUID().toString(), "New Description");
+ assertEquals(ApexApiResult.Result.CONCEPT_DOES_NOT_EXIST, result.getResult());
+
+ result = mf.getModelKey();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = mf.listModel();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = mf.deleteModel();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ assertNotNull(mf);
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java b/model/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java
new file mode 100644
index 000000000..5bbc95992
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/modelapi/ModelHandlerFacadeTest.java
@@ -0,0 +1,128 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ * ================================================================================
+ * 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.modelapi;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+import org.junit.Test;
+import org.onap.policy.apex.model.modelapi.impl.ModelHandlerFacade;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+
+/**
+ * Test the model handler facade.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ModelHandlerFacadeTest {
+
+ @Test
+ public void testModelHandlerFacade() throws IOException {
+ assertThatThrownBy(() -> new ModelHandlerFacade(null, null))
+ .hasMessage("apexModel may not be null");
+ final ApexModel apexModel = new ApexModelFactory().createApexModel(null);
+
+ assertThatThrownBy(() -> new ModelHandlerFacade(apexModel, null))
+ .hasMessage("apexProperties may not be null");
+ final Properties modelProperties = new Properties();
+ final ModelHandlerFacade mhf = new ModelHandlerFacade(apexModel, modelProperties);
+ assertNotNull(mhf);
+
+ ApexApiResult result = mhf.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = mhf.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+
+ final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+
+ result = apexModel.deleteModel();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = mhf.loadFromString(modelString);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = mhf.loadFromString(modelString);
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+
+ result = apexModel.deleteModel();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = mhf.readFromUrl("blah://somewhere/over/the/rainbow");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = mhf.loadFromString(modelString);
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = mhf.readFromUrl("http://somewhere/over/the/rainbow");
+ assertEquals(ApexApiResult.Result.CONCEPT_EXISTS, result.getResult());
+
+ final File tempFile = File.createTempFile("ApexModel", "json");
+ tempFile.deleteOnExit();
+
+ result = mhf.writeToUrl("File:///" + tempFile.getCanonicalPath());
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = mhf.validate();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = apexModel.deleteModel();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = mhf.validate();
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = mhf.compare("src/test/resources/models/NonExistant.json", true, true);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = mhf.compareWithString("zooby", true, true);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = mhf.split("FailSplit", "NonExistantPolicy");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = mhf.split("NonExistantPolicy");
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = mhf.merge("src/test/resources/models/NonExistant.json", false);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.deleteModel();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = mhf.merge("src/test/resources/models/PolicyModel.json", false);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = mhf.loadFromFile("src/test/resources/models/PolicyModel.json");
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+
+ result = mhf.mergeWithString("@£@$@£", true);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+
+ result = apexModel.deleteModel();
+ assertEquals(ApexApiResult.Result.SUCCESS, result.getResult());
+ result = mhf.mergeWithString(modelString, false);
+ assertEquals(ApexApiResult.Result.FAILED, result.getResult());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/modelapi/RealModelTest.java b/model/src/test/java/org/onap/policy/apex/model/modelapi/RealModelTest.java
new file mode 100644
index 000000000..2a29f5297
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/modelapi/RealModelTest.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * 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.modelapi;
+
+import static org.junit.Assert.assertTrue;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import java.util.Map;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelCustomGsonMapAdapter;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+
+public class RealModelTest {
+ @Test
+ public void testRealModel() throws Exception {
+
+ final String modelString = TextFileUtils.getTextFileAsString("src/test/resources/models/PolicyModel.json");
+
+ AxPolicyModel policyModel = new ApexModelReader<AxPolicyModel>(AxPolicyModel.class).read(modelString);
+
+ AxValidationResult result = new AxValidationResult();
+ assertTrue(policyModel.validate(result).isValid());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/DummyLogicReader.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/DummyLogicReader.java
new file mode 100644
index 000000000..007288343
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/DummyLogicReader.java
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.concepts;
+
+public class DummyLogicReader implements AxLogicReader {
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String getLogicPackage() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public AxLogicReader setLogicPackage(final String logicPackage) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String getDefaultLogic() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public AxLogicReader setDefaultLogic(final String defaultLogic) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public String readLogic(final AxLogic axLogic) {
+ return "Dummy Logic";
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/ExceptionsTest.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/ExceptionsTest.java
new file mode 100644
index 000000000..0afb48b3c
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/ExceptionsTest.java
@@ -0,0 +1,51 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import org.junit.Test;
+
+/**
+ * Test model exceptions.
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class ExceptionsTest {
+
+ @Test
+ public void test() {
+ assertNotNull(new PolicyException("Message"));
+ assertNotNull(new PolicyException("Message", new IOException()));
+
+ final PolicyException ae = new PolicyException("Message", new IOException("IO exception message"));
+ assertEquals("Message\ncaused by: Message\ncaused by: IO exception message", ae.getCascadedMessage());
+
+ assertNotNull(new PolicyRuntimeException("Message"));
+ assertNotNull(new PolicyRuntimeException("Message", new IOException()));
+
+ final PolicyRuntimeException re =
+ new PolicyRuntimeException("Runtime Message", new IOException("IO runtime exception message"));
+ assertEquals("Runtime Message\ncaused by: Runtime Message\ncaused by: IO runtime exception message",
+ re.getCascadedMessage());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/LogicTest.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/LogicTest.java
new file mode 100644
index 000000000..fbfc7c4a0
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/LogicTest.java
@@ -0,0 +1,161 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * ================================================================================
+ * 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.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+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;
+
+/**
+ * Test apex logic.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class LogicTest {
+
+ @Test
+ public void testLogic() {
+ final DummyLogicReader logicReader = new DummyLogicReader();
+
+ assertNotNull(new AxLogic());
+ assertNotNull(new AxLogic(new AxReferenceKey()));
+ assertNotNull(new AxLogic(new AxReferenceKey(), "LogicFlavour", "Logic"));
+ assertNotNull(new AxLogic(new AxReferenceKey(), "LogicName", "LogicFlavour", "Logic"));
+ assertNotNull(new AxLogic(new AxReferenceKey(), "LogicFlavour", logicReader));
+
+ assertNotNull(new AxTaskLogic());
+ assertNotNull(new AxTaskLogic(new AxReferenceKey()));
+ assertNotNull(new AxTaskLogic(new AxReferenceKey(), "LogicFlavour", "Logic"));
+ assertNotNull(new AxTaskLogic(new AxReferenceKey(), "LogicFlavour", logicReader));
+ assertNotNull(new AxTaskLogic(new AxLogic()));
+ assertNotNull(new AxTaskLogic(new AxArtifactKey(), "LogicName", "LogicFlavour", logicReader));
+ assertNotNull(new AxTaskLogic(new AxArtifactKey(), "LogicName", "LogicFlavour", "Logic"));
+ assertNotNull(new AxTaskLogic(new AxReferenceKey(), "LogicFlavour", logicReader));
+
+ assertNotNull(new AxTaskSelectionLogic());
+ assertNotNull(new AxTaskSelectionLogic(new AxReferenceKey()));
+ assertNotNull(new AxTaskSelectionLogic(new AxReferenceKey(), "LogicFlavour", "Logic"));
+ assertNotNull(new AxTaskSelectionLogic(new AxReferenceKey(), "LogicName", "LogicFlavour", "Logic"));
+ assertNotNull(new AxTaskSelectionLogic(new AxReferenceKey(), "LogicFlavour", logicReader));
+ assertNotNull(new AxTaskSelectionLogic(new AxLogic()));
+ assertNotNull(new AxTaskSelectionLogic(new AxReferenceKey(), "LogicFlavour", logicReader));
+ assertNotNull(new AxTaskSelectionLogic(new AxReferenceKey(), "LogicName", "LogicFlavour", logicReader));
+
+ assertNotNull(new AxStateFinalizerLogic());
+ assertNotNull(new AxStateFinalizerLogic(new AxReferenceKey()));
+ assertNotNull(new AxStateFinalizerLogic(new AxReferenceKey(), "LogicFlavour", "Logic"));
+ assertNotNull(new AxStateFinalizerLogic(new AxReferenceKey(), "LogicName", "LogicFlavour", "Logic"));
+ assertNotNull(new AxStateFinalizerLogic(new AxReferenceKey(), "LogicFlavour", logicReader));
+ assertNotNull(new AxStateFinalizerLogic(new AxLogic()));
+ assertNotNull(new AxStateFinalizerLogic(new AxReferenceKey(), "LogicFlavour", logicReader));
+ assertNotNull(new AxStateFinalizerLogic(new AxReferenceKey(), "LogicName", "LogicFlavour", logicReader));
+
+ final AxLogic logic = new AxLogic();
+
+ final AxReferenceKey logicKey = new AxReferenceKey("LogicParentName", "0.0.1", "PLN", "LN");
+ logic.setKey(logicKey);
+ assertEquals("LogicParentName:0.0.1:PLN:LN", logic.getKey().getId());
+ assertEquals("LogicParentName:0.0.1:PLN:LN", logic.getKeys().get(0).getId());
+
+ logic.setLogicFlavour("LogicFlavour");
+ assertEquals("LogicFlavour", logic.getLogicFlavour());
+
+ logic.setLogic("Logic");
+ assertEquals("Logic", logic.getLogic());
+
+ AxValidationResult result = new AxValidationResult();
+ result = logic.validate(result);
+ assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
+
+ logic.setKey(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = logic.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ logic.setKey(logicKey);
+ result = new AxValidationResult();
+ result = logic.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ assertThatThrownBy(() -> logic.setLogicFlavour(null))
+ .hasMessageContaining("parameter \"logicFlavour\" is null");
+ assertThatThrownBy(() -> logic.setLogicFlavour(""))
+ .hasMessage("parameter \"logicFlavour\": value \"\", "
+ + "does not match regular expression \"[A-Za-z0-9\\-_]+\"");
+ logic.setLogicFlavour(AxLogic.LOGIC_FLAVOUR_UNDEFINED);
+ result = new AxValidationResult();
+ result = logic.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ logic.setLogicFlavour("LogicFlavour");
+ result = new AxValidationResult();
+ result = logic.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ assertThatThrownBy(() -> logic.setLogic(null)).hasMessage("logic may not be null");
+ logic.setLogic("");
+ result = new AxValidationResult();
+ result = logic.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ logic.setLogic("Logic");
+ result = new AxValidationResult();
+ result = logic.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ logic.clean();
+
+ final AxLogic clonedLogic = new AxLogic(logic);
+ assertEquals("AxLogic:(key=AxReferenceKey:(parentKeyName=LogicParentName,parentKeyVersion=0.0.1,"
+ + "parentLocalName=PLN,localName=LN),logicFlavour=LogicFlavour,logic=Logic)",
+ clonedLogic.toString());
+
+ assertNotEquals(0, logic.hashCode());
+ // disabling sonar because this code tests the equals() method
+ assertEquals(logic, logic); // NOSONAR
+ assertEquals(logic, clonedLogic);
+ assertNotNull(logic);
+ assertNotEquals(logic, (Object) "Hello");
+ assertNotEquals(logic, new AxLogic(AxReferenceKey.getNullKey(), "LogicFlavour", "Logic"));
+ assertNotEquals(logic, new AxLogic(logicKey, "AnotherLogicFlavour", "Logic"));
+ assertNotEquals(logic, new AxLogic(logicKey, "LogicFlavour", "AnotherLogic"));
+ assertEquals(logic, new AxLogic(logicKey, "LogicFlavour", "Logic"));
+
+ assertEquals(0, logic.compareTo(logic));
+ assertEquals(0, logic.compareTo(clonedLogic));
+ assertNotEquals(0, logic.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, logic.compareTo(null));
+ assertNotEquals(0, logic.compareTo(new AxLogic(AxReferenceKey.getNullKey(), "LogicFlavour", "Logic")));
+ assertNotEquals(0, logic.compareTo(new AxLogic(logicKey, "AnotherLogicFlavour", "Logic")));
+ assertNotEquals(0, logic.compareTo(new AxLogic(logicKey, "LogicFlavour", "AnotherLogic")));
+ assertEquals(0, logic.compareTo(new AxLogic(logicKey, "LogicFlavour", "Logic")));
+
+ assertNotNull(logic.getKeys());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PoliciesTest.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PoliciesTest.java
new file mode 100644
index 000000000..526f5a628
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PoliciesTest.java
@@ -0,0 +1,391 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2020,2022 Nordix Foundation.
+ * ================================================================================
+ * 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.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Map;
+import java.util.TreeMap;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+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.policymodel.handling.SupportApexPolicyModelCreator;
+
+/**
+ * Test apex policies.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class PoliciesTest {
+
+ @Test
+ public void testPolicies() {
+ final TreeMap<String, AxState> stateMap = new TreeMap<>();
+ final TreeMap<String, AxState> stateMapEmpty = new TreeMap<>();
+
+ assertNotNull(new AxPolicy());
+ assertNotNull(new AxPolicy(new AxArtifactKey()));
+ assertNotNull(new AxPolicy(new AxArtifactKey(), "PolicyTemplate", stateMapEmpty, "FirstState"));
+
+ final AxPolicy policy = new AxPolicy();
+
+ final AxArtifactKey policyKey = new AxArtifactKey("PolicyName", "0.0.1");
+
+ final AxState firstState = new AxState(new AxReferenceKey(policy.getKey(), "FirstState"));
+ final AxState badState = new AxState(new AxReferenceKey(policy.getKey(), "BadState"));
+ final AxStateOutput badStateOutput = new AxStateOutput(badState.getKey(), AxArtifactKey.getNullKey(),
+ new AxReferenceKey(policyKey, "BadNextState"));
+ badState.getStateOutputs().put(badStateOutput.getKey().getLocalName(), badStateOutput);
+ stateMap.put(firstState.getKey().getLocalName(), firstState);
+
+ assertThatThrownBy(() -> policy.setKey(null))
+ .hasMessage("key may not be null");
+ policy.setKey(policyKey);
+ assertEquals("PolicyName:0.0.1", policy.getKey().getId());
+ assertEquals("PolicyName:0.0.1", policy.getKeys().get(0).getId());
+
+ assertThatThrownBy(() -> policy.setTemplate(null))
+ .hasMessage("template may not be null");
+ policy.setTemplate("PolicyTemplate");
+ assertEquals("PolicyTemplate", policy.getTemplate());
+
+ assertThatThrownBy(() -> policy.setStateMap(null))
+ .hasMessage("stateMap may not be null");
+ policy.setStateMap(stateMap);
+ assertEquals(stateMap, policy.getStateMap());
+
+ assertThatThrownBy(() -> policy.setFirstState(null))
+ .hasMessage("firstState may not be null");
+ policy.setFirstState("FirstState");
+ assertEquals("FirstState", policy.getFirstState());
+
+ assertEquals("PolicyName:0.0.1", policy.getKeys().get(0).getId());
+
+ final AxPolicy policyPN = new SupportApexPolicyModelCreator().getModel().getPolicies().get("policy");
+
+ AxValidationResult result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxArtifactKey savedPolicyKey = policyPN.getKey();
+ policyPN.setKey(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policyPN.setKey(savedPolicyKey);
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final String savedTemplate = policyPN.getTemplate();
+ policyPN.setTemplate("");
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.OBSERVATION, result.getValidationResult());
+
+ policyPN.setTemplate(savedTemplate);
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final Map<String, AxState> savedStateMap = policyPN.getStateMap();
+
+ policyPN.setStateMap(stateMapEmpty);
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policyPN.setStateMap(savedStateMap);
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ savedStateMap.put(AxKey.NULL_KEY_NAME, firstState);
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ savedStateMap.remove(AxKey.NULL_KEY_NAME);
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ savedStateMap.put("NullState", null);
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ savedStateMap.remove("NullState");
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ savedStateMap.put("BadStateKey", firstState);
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ savedStateMap.remove("BadStateKey");
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ savedStateMap.put(badState.getKey().getLocalName(), badState);
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ savedStateMap.remove(badState.getKey().getLocalName());
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final String savedFirstState = policyPN.getFirstState();
+
+ policyPN.setFirstState("");
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policyPN.setFirstState(savedFirstState);
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ policyPN.setFirstState("NonExistantFirstState");
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policyPN.setFirstState(savedFirstState);
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxState clonedState = new AxState(policyPN.getStateMap().get("state"));
+ clonedState.getKey().setLocalName("ClonedState");
+
+ savedStateMap.put(clonedState.getKey().getLocalName(), clonedState);
+ policyPN.buildReferences();
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.WARNING, result.getValidationResult());
+
+ savedStateMap.remove(clonedState.getKey().getLocalName());
+ result = new AxValidationResult();
+ result = policyPN.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ policyPN.clean();
+
+ final AxPolicy clonedPolicy = new AxPolicy(policyPN);
+ assertEquals("AxPolicy:(key=AxArtifactKey:(name=policy,version=0.0.1),template=FREEFORM,sta",
+ clonedPolicy.toString().substring(0, 77));
+
+ assertNotEquals(0, policyPN.hashCode());
+ // disabling sonar because this code tests the equals() method
+ assertEquals(policyPN, policyPN); // NOSONAR
+ assertEquals(policyPN, clonedPolicy);
+ assertNotNull(policyPN);
+
+ Object helloObj = "Hello";
+ assertNotEquals(policyPN, helloObj);
+ assertNotEquals(policyPN,
+ new AxPolicy(AxArtifactKey.getNullKey(), savedTemplate, savedStateMap, savedFirstState));
+ assertNotEquals(policyPN, new AxPolicy(savedPolicyKey, "SomeTemplate", savedStateMap, savedFirstState));
+ assertNotEquals(policyPN, new AxPolicy(savedPolicyKey, savedTemplate, stateMapEmpty, savedFirstState));
+ assertNotEquals(policyPN, new AxPolicy(savedPolicyKey, savedTemplate, savedStateMap, "SomeFirstState"));
+ assertEquals(policyPN, new AxPolicy(savedPolicyKey, savedTemplate, savedStateMap, savedFirstState));
+
+ assertEquals(0, policyPN.compareTo(policyPN));
+ assertEquals(0, policyPN.compareTo(clonedPolicy));
+ assertNotEquals(0, policyPN.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, policyPN.compareTo(null));
+ assertNotEquals(0, policyPN.compareTo(
+ new AxPolicy(AxArtifactKey.getNullKey(), savedTemplate, savedStateMap, savedFirstState)));
+ assertNotEquals(0, policyPN.compareTo(new AxPolicy(savedPolicyKey,
+ "SomeTemplate", savedStateMap, savedFirstState)));
+ assertNotEquals(0, policyPN.compareTo(new AxPolicy(savedPolicyKey, savedTemplate,
+ stateMapEmpty, savedFirstState)));
+ assertNotEquals(0, policyPN.compareTo(new AxPolicy(savedPolicyKey, savedTemplate,
+ savedStateMap, "SomeFirstState")));
+ assertEquals(0, policyPN.compareTo(new AxPolicy(savedPolicyKey, savedTemplate,
+ savedStateMap, savedFirstState)));
+
+ assertNotNull(policyPN.getKeys());
+
+ final AxPolicies policies = new AxPolicies();
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ // Invalid, no events in event map
+ policies.setKey(new AxArtifactKey("PoliciesKey", "0.0.1"));
+ assertEquals("PoliciesKey:0.0.1", policies.getKey().getId());
+
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policies.getPolicyMap().put(savedPolicyKey, policyPN);
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ policies.getPolicyMap().put(AxArtifactKey.getNullKey(), null);
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policies.getPolicyMap().remove(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ policies.getPolicyMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null);
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policies.getPolicyMap().remove(new AxArtifactKey("NullValueKey", "0.0.1"));
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ policies.getPolicyMap().put(new AxArtifactKey("BadEventKey", "0.0.1"), policyPN);
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ policies.getPolicyMap().remove(new AxArtifactKey("BadEventKey", "0.0.1"));
+ result = new AxValidationResult();
+ result = policies.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ policies.clean();
+
+ final AxPolicies clonedPolicies = new AxPolicies(policies);
+ assertEquals("AxPolicies:(key=AxArtifactKey:(name=PoliciesKey,version=0.0.",
+ clonedPolicies.toString().substring(0, 60));
+
+ assertNotEquals(0, policies.hashCode());
+ // disabling sonar because this code tests the equals() method
+ assertEquals(policies, policies); // NOSONAR
+ assertEquals(policies, clonedPolicies);
+ assertNotNull(policies);
+ assertNotEquals(policyPN, helloObj);
+ assertNotEquals(policies, new AxPolicies(new AxArtifactKey()));
+
+ assertEquals(0, policies.compareTo(policies));
+ assertEquals(0, policies.compareTo(clonedPolicies));
+ assertNotEquals(0, policies.compareTo(null));
+ assertNotEquals(0, policies.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, policies.compareTo(new AxPolicies(new AxArtifactKey())));
+
+ clonedPolicies.get(savedPolicyKey).setTemplate("AnotherTemplate");
+ assertNotEquals(0, policies.compareTo(clonedPolicies));
+
+ assertEquals(policies.getKey(), policies.getKeys().get(0));
+
+ assertEquals("policy", policies.get("policy").getKey().getName());
+ assertEquals("policy", policies.get("policy", "0.0.1").getKey().getName());
+ assertEquals(1, policies.getAll("policy", "0.0.1").size());
+ assertEquals(0, policies.getAll("NonExistantPolicy").size());
+
+ AxStateTree stateTree = policy.getStateTree();
+ assertNotNull(stateTree);
+ assertNotNull(stateTree.getReferencedStateList());
+ assertNotNull(stateTree.getReferencedStateSet());
+
+ final AxState secondState = new AxState(policyPN.getStateMap().get("state"));
+ secondState.getKey().setLocalName("SecondState");
+ policyPN.getStateMap().put("SecondState", secondState);
+ policyPN.getStateMap().get("state").getStateOutputs().get("stateOutput0").setNextState(secondState.getKey());
+
+ stateTree = policyPN.getStateTree();
+ assertNotNull(stateTree);
+ assertNotNull(stateTree.getReferencedStateList());
+ assertNotNull(stateTree.getReferencedStateSet());
+ assertNotNull(stateTree.getNextStates());
+
+ policyPN.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0")
+ .setNextState(policyPN.getStateMap().get("state").getKey());
+ assertThatThrownBy(() -> policyPN.getStateTree())
+ .hasMessageContaining("loop detected in state tree for policy policy:0.0.1 state SecondState, "
+ + "next state state referenced more than once");
+ policyPN.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0")
+ .setNextState(AxReferenceKey.getNullKey());
+
+ final AxState thirdState = new AxState(policyPN.getStateMap().get("state"));
+ thirdState.getKey().setLocalName("ThirdState");
+ policyPN.getStateMap().put("ThirdState", thirdState);
+ policyPN.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0")
+ .setNextState(thirdState.getKey());
+ policyPN.getStateMap().get("ThirdState").getStateOutputs().get("stateOutput0")
+ .setNextState(AxReferenceKey.getNullKey());
+
+ stateTree = policyPN.getStateTree();
+
+ final AxStateOutput ssS0Clone = new AxStateOutput(
+ policyPN.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0"));
+ ssS0Clone.getKey().setLocalName("ssS0Clone");
+ policyPN.getStateMap().get("SecondState").getStateOutputs().put("ssS0Clone", ssS0Clone);
+
+ assertThatThrownBy(() -> policyPN.getStateTree())
+ .hasMessageContaining("loop detected in state tree for policy policy:0.0.1 state SecondState, "
+ + "next state ThirdState referenced more than once");
+ policyPN.getStateMap().get("SecondState").getStateOutputs().remove("ssS0Clone");
+
+ policyPN.getStateMap().get("state").getStateOutputs().get("stateOutput0").setNextState(secondState.getKey());
+ secondState.getStateOutputs().get("stateOutput0").setNextState(thirdState.getKey());
+ thirdState.getStateOutputs().get("stateOutput0").setNextState(AxReferenceKey.getNullKey());
+
+ stateTree = policyPN.getStateTree();
+ assertNotNull(stateTree.getState());
+
+ thirdState.getStateOutputs().get("stateOutput0").setNextState(secondState.getKey());
+
+ assertThatThrownBy(() -> policyPN.getStateTree())
+ .hasMessageContaining("loop detected in state tree for policy policy:0.0.1 state ThirdState, "
+ + "next state SecondState referenced more than once");
+ thirdState.getStateOutputs().get("stateOutput0").setNextState(AxReferenceKey.getNullKey());
+
+ stateTree = policyPN.getStateTree();
+
+ final AxStateTree otherStateTree = policyPN.getStateTree();
+ assertEquals(0, stateTree.compareTo(otherStateTree));
+
+ for (final AxStateTree childStateTree : stateTree.getNextStates()) {
+ assertNotEquals(0, stateTree.compareTo(childStateTree));
+ }
+
+ otherStateTree.getNextStates().clear();
+ assertNotEquals(0, stateTree.compareTo(otherStateTree));
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PolicyModelTest.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PolicyModelTest.java
new file mode 100644
index 000000000..b699b5d48
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PolicyModelTest.java
@@ -0,0 +1,312 @@
+/*-
+ * ============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.
+ * 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.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+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.contextmodel.concepts.AxContextAlbum;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEvents;
+import org.onap.policy.apex.model.eventmodel.concepts.AxField;
+import org.onap.policy.apex.model.policymodel.handling.SupportApexPolicyModelCreator;
+
+/**
+ * Test policy models.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class PolicyModelTest {
+
+ @Test
+ public void testPolicyModel() {
+ assertNotNull(new AxPolicyModel());
+ assertNotNull(new AxPolicyModel(new AxArtifactKey()));
+ assertNotNull(new AxPolicyModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(),
+ new AxEvents(), new AxContextAlbums(), new AxTasks(), new AxPolicies()));
+
+ final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1");
+ final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1");
+ final AxArtifactKey eventsKey = new AxArtifactKey("EventsKey", "0.0.1");
+ final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1");
+ final AxArtifactKey albumsKey = new AxArtifactKey("AlbumsKey", "0.0.1");
+ final AxArtifactKey tasksKey = new AxArtifactKey("TasksKey", "0.0.1");
+ final AxArtifactKey policiesKey = new AxArtifactKey("PoliciesKey", "0.0.1");
+
+ AxPolicyModel model = new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey));
+
+ model.register();
+
+ assertNotNull(model.getContextModel());
+ assertEquals("ModelKey:0.0.1", model.getKeys().get(0).getId());
+
+ model.clean();
+ assertNotNull(model);
+ assertEquals("AxPolicyModel:(AxPolicyModel:(key=AxArtifactKey:(n", model.toString().substring(0, 50));
+
+ final AxPolicyModel clonedModel = new AxPolicyModel(model);
+
+ assertNotEquals(0, model.hashCode());
+
+ // disabling sonar because this code tests the equals() method
+ assertEquals(model, model); // NOSONAR
+ assertEquals(model, clonedModel);
+ assertNotEquals(model, (Object) "Hello");
+ assertNotEquals(model, new AxPolicyModel(new AxArtifactKey()));
+ assertNotEquals(model, new AxPolicyModel(AxArtifactKey.getNullKey(), new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey)));
+ assertNotEquals(model, new AxPolicyModel(modelKey, new AxContextSchemas(), new AxKeyInformation(keyInfoKey),
+ new AxEvents(eventsKey), new AxContextAlbums(albumsKey), new AxTasks(tasksKey),
+ new AxPolicies(policiesKey)));
+ assertNotEquals(model, new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey), new AxKeyInformation(),
+ new AxEvents(eventsKey), new AxContextAlbums(albumsKey), new AxTasks(tasksKey),
+ new AxPolicies(policiesKey)));
+ assertNotEquals(model, new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey)));
+ assertNotEquals(model, new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey)));
+ assertNotEquals(model, new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(), new AxPolicies(policiesKey)));
+ assertNotEquals(model, new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies()));
+ assertEquals(model, new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey)));
+
+ assertEquals(0, model.compareTo(model));
+ assertEquals(0, model.compareTo(clonedModel));
+ assertNotEquals(0, model.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, model.compareTo(new AxPolicyModel(AxArtifactKey.getNullKey(),
+ new AxContextSchemas(schemasKey), new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey),
+ new AxContextAlbums(albumsKey), new AxTasks(tasksKey), new AxPolicies(policiesKey))));
+ assertNotEquals(0, model.compareTo(new AxPolicyModel(modelKey, new AxContextSchemas(),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey))));
+ assertNotEquals(0,
+ model.compareTo(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey))));
+ assertNotEquals(0, model.compareTo(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey))));
+ assertNotEquals(0,
+ model.compareTo(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey),
+ new AxContextAlbums(), new AxTasks(tasksKey), new AxPolicies(policiesKey))));
+ assertNotEquals(0,
+ model.compareTo(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey),
+ new AxContextAlbums(albumsKey), new AxTasks(), new AxPolicies(policiesKey))));
+ assertNotEquals(0,
+ model.compareTo(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey),
+ new AxContextAlbums(albumsKey), new AxTasks(tasksKey), new AxPolicies())));
+ assertEquals(0, model.compareTo(new AxPolicyModel(modelKey, new AxContextSchemas(schemasKey),
+ new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey), new AxContextAlbums(albumsKey),
+ new AxTasks(tasksKey), new AxPolicies(policiesKey))));
+
+ model = new SupportApexPolicyModelCreator().getModel();
+
+ AxValidationResult result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxArtifactKey savedPolicyKey = model.getKey();
+ model.setKey(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.setKey(savedPolicyKey);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxField badField = new AxField(new AxReferenceKey(model.getEvents().get("inEvent").getKey(), "BadField"),
+ new AxArtifactKey("NonExistantSchema", "0.0.1"));
+ model.getEvents().get("inEvent").getParameterMap().put(badField.getKey().getLocalName(), badField);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getEvents().get("inEvent").getParameterMap().remove(badField.getKey().getLocalName());
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxContextAlbum badAlbum = new AxContextAlbum(new AxArtifactKey("BadAlbum", "0.0.1"), "SomeScope", true,
+ new AxArtifactKey("NonExistantSchema", "0.0.1"));
+ model.getAlbums().getAlbumsMap().put(badAlbum.getKey(), badAlbum);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getAlbums().getAlbumsMap().remove(badAlbum.getKey());
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ model.getTasks().get("task").getContextAlbumReferences()
+ .add(new AxArtifactKey("NonExistantContextAlbum", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getTasks().get("task").getContextAlbumReferences()
+ .remove(new AxArtifactKey("NonExistantContextAlbum", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ model.getPolicies().get("policy").getStateMap().get("state").getContextAlbumReferences()
+ .add(new AxArtifactKey("NonExistantContextAlbum", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getPolicies().get("policy").getStateMap().get("state").getContextAlbumReferences()
+ .remove(new AxArtifactKey("NonExistantContextAlbum", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxArtifactKey savedTrigger = model.getPolicies().get("policy").getStateMap().get("state").getTrigger();
+ model.getPolicies().get("policy").getStateMap().get("state")
+ .setTrigger(new AxArtifactKey("NonExistantEvent", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getPolicies().get("policy").getStateMap().get("state").setTrigger(savedTrigger);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxArtifactKey savedDefaultTask = model.getPolicies().get("policy").getStateMap().get("state")
+ .getDefaultTask();
+ model.getPolicies().get("policy").getStateMap().get("state")
+ .setDefaultTask(new AxArtifactKey("NonExistantTask", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getPolicies().get("policy").getStateMap().get("state").setDefaultTask(savedDefaultTask);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ // It is OK not to have TSL
+ final AxTaskSelectionLogic savedTaskSelectionLogic = model.getPolicies().get("policy").getStateMap()
+ .get("state").getTaskSelectionLogic();
+ model.getPolicies().get("policy").getStateMap().get("state")
+ .setTaskSelectionLogic(new AxTaskSelectionLogic(AxReferenceKey.getNullKey()));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ model.getPolicies().get("policy").getStateMap().get("state").setTaskSelectionLogic(savedTaskSelectionLogic);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxStateOutput badStateOutput = new AxStateOutput(
+ new AxReferenceKey(model.getPolicies().get("policy").getStateMap().get("state").getKey(),
+ "BadSO"),
+ new AxArtifactKey("NonExistantEvent", "0.0.1"), AxReferenceKey.getNullKey());
+ model.getPolicies().get("policy").getStateMap().get("state").getStateOutputs()
+ .put(badStateOutput.getKey().getLocalName(), badStateOutput);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getPolicies().get("policy").getStateMap().get("state").getStateOutputs()
+ .remove(badStateOutput.getKey().getLocalName());
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxStateTaskReference badTaskReference = new AxStateTaskReference(
+ new AxReferenceKey(model.getPolicies().get("policy").getStateMap().get("state").getKey(),
+ "NonExistantTask"),
+ AxStateTaskOutputType.LOGIC, badStateOutput.getKey());
+ model.getPolicies().get("policy").getStateMap().get("state").getTaskReferences()
+ .put(new AxArtifactKey("NonExistantTask", "0.0.1"), badTaskReference);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ badTaskReference.setStateTaskOutputType(AxStateTaskOutputType.DIRECT);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ model.getPolicies().get("policy").getStateMap().get("state").getTaskReferences()
+ .remove(new AxArtifactKey("NonExistantTask", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxStateTaskReference tr = model.getPolicies().get("policy").getStateMap().get("state").getTaskReferences()
+ .get(new AxArtifactKey("task", "0.0.1"));
+
+ final String savedStateOutputName = tr.getOutput().getLocalName();
+ tr.getOutput().setLocalName("NonExistantOutput");
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ tr.getOutput().setLocalName(savedStateOutputName);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ final AxStateOutput so = model.getPolicies().get("policy").getStateMap().get("state").getStateOutputs()
+ .get(savedStateOutputName);
+
+ final AxArtifactKey savedOutEvent = so.getOutgoingEvent();
+ so.setOutgoingEvent(new AxArtifactKey("NonExistantEvent", "0.0.1"));
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ so.setOutgoingEvent(savedOutEvent);
+ result = new AxValidationResult();
+ result = model.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java
new file mode 100644
index 000000000..049783a7f
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateOutputTest.java
@@ -0,0 +1,124 @@
+/*-
+ * ============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.
+ * 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.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+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;
+
+/**
+ * Test state outputs.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class StateOutputTest {
+
+ @Test
+ public void testStateOutput() {
+ assertNotNull(new AxStateOutput());
+ assertNotNull(new AxStateOutput(new AxReferenceKey()));
+ assertNotNull(new AxStateOutput(new AxReferenceKey(), new AxReferenceKey(), new AxArtifactKey()));
+ assertNotNull(new AxStateOutput(new AxReferenceKey(), new AxArtifactKey(), new AxReferenceKey()));
+
+ final AxStateOutput so = new AxStateOutput();
+
+ final AxReferenceKey soKey = new AxReferenceKey("SOStateParent", "0.0.1", "SOState", "SOName");
+ final AxReferenceKey nsKey = new AxReferenceKey("SOStateParent", "0.0.1", "NotUsed", "NextStateName");
+ final AxArtifactKey eKey = new AxArtifactKey("EventName", "0.0.1");
+
+ assertThatThrownBy(() -> so.setKey(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 is marked non-null but is null");
+ so.setNextState(nsKey);
+ assertEquals(nsKey, so.getNextState());
+
+ assertThatThrownBy(() -> so.setOutgoingEvent(null))
+ .hasMessage("outgoingEvent is marked non-null but is null");
+ so.setOutgoingEvent(eKey);
+ assertEquals(eKey, so.getOutgoingEvent());
+
+ AxValidationResult result = new AxValidationResult();
+ result = so.validate(result);
+ assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
+
+ so.setKey(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = so.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ so.setKey(soKey);
+ result = new AxValidationResult();
+ result = so.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ so.setOutgoingEvent(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = so.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ so.setOutgoingEvent(eKey);
+ result = new AxValidationResult();
+ result = so.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ so.clean();
+
+ final AxStateOutput clonedPar = new AxStateOutput(so);
+ assertEquals("AxStateOutput:(stateKey=AxReferenceKey:(parentKeyN", clonedPar.toString().substring(0, 50));
+
+ assertNotEquals(0, so.hashCode());
+
+ // disabling sonar because this code tests the equals() method
+ assertEquals(so, so); // NOSONAR
+ assertEquals(so, clonedPar);
+ assertNotNull(so);
+ assertNotEquals(so, (Object) "Hello");
+ assertNotEquals(so, new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey));
+ assertNotEquals(so, new AxStateOutput(soKey, new AxArtifactKey(), nsKey));
+ assertNotEquals(so, new AxStateOutput(soKey, eKey, new AxReferenceKey()));
+ assertEquals(so, new AxStateOutput(soKey, eKey, nsKey));
+
+ assertEquals(0, so.compareTo(so));
+ assertEquals(0, so.compareTo(clonedPar));
+ assertNotEquals(0, so.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, so.compareTo(null));
+ assertNotEquals(0, so.compareTo(new AxStateOutput(AxReferenceKey.getNullKey(), eKey, nsKey)));
+ assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, new AxArtifactKey(), nsKey)));
+ assertNotEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, new AxReferenceKey())));
+ assertEquals(0, so.compareTo(new AxStateOutput(soKey, eKey, nsKey)));
+
+ assertNotNull(so.getKeys());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTaskReferenceTest.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTaskReferenceTest.java
new file mode 100644
index 000000000..568c47f61
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTaskReferenceTest.java
@@ -0,0 +1,144 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * ================================================================================
+ * 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.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+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;
+
+/**
+ * Test state task references.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class StateTaskReferenceTest {
+
+ @Test
+ public void testStateTaskReference() {
+ assertNotNull(new AxStateTaskReference());
+ assertNotNull(new AxStateTaskReference(new AxReferenceKey()));
+ assertNotNull(new AxStateTaskReference(new AxReferenceKey(), AxStateTaskOutputType.UNDEFINED,
+ new AxReferenceKey()));
+ assertNotNull(new AxStateTaskReference(new AxReferenceKey(), new AxArtifactKey(),
+ AxStateTaskOutputType.UNDEFINED, new AxReferenceKey()));
+
+ AxStateTaskReference stRef = new AxStateTaskReference();
+
+ AxReferenceKey stRefKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "SOName");
+
+ assertThatThrownBy(() -> stRef.setKey(null))
+ .hasMessage("key may not be null");
+ stRef.setKey(stRefKey);
+ assertEquals("StateParent:0.0.1:SOState:SOName", stRef.getKey().getId());
+ assertEquals("StateParent:0.0.1:SOState:SOName", stRef.getKeys().get(0).getId());
+
+ assertThatThrownBy(() -> stRef.setStateTaskOutputType(null))
+ .hasMessage("outputType may not be null");
+ stRef.setStateTaskOutputType(AxStateTaskOutputType.UNDEFINED);
+ assertEquals(AxStateTaskOutputType.UNDEFINED, stRef.getStateTaskOutputType());
+ stRef.setStateTaskOutputType(AxStateTaskOutputType.DIRECT);
+ assertEquals(AxStateTaskOutputType.DIRECT, stRef.getStateTaskOutputType());
+ stRef.setStateTaskOutputType(AxStateTaskOutputType.LOGIC);
+ assertEquals(AxStateTaskOutputType.LOGIC, stRef.getStateTaskOutputType());
+
+ assertThatThrownBy(() -> stRef.setOutput(null))
+ .hasMessage("output may not be null");
+ AxReferenceKey soKey = new AxReferenceKey("StateParent", "0.0.1", "SOState", "STRef0");
+ stRef.setOutput(soKey);
+ assertEquals(soKey, stRef.getOutput());
+
+ AxValidationResult result = new AxValidationResult();
+ result = stRef.validate(result);
+ assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
+
+ stRef.setKey(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = stRef.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ stRef.setKey(stRefKey);
+ result = new AxValidationResult();
+ result = stRef.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ stRef.setStateTaskOutputType(AxStateTaskOutputType.UNDEFINED);
+ result = new AxValidationResult();
+ result = stRef.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ stRef.setStateTaskOutputType(AxStateTaskOutputType.LOGIC);
+ result = new AxValidationResult();
+ result = stRef.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ stRef.setOutput(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = stRef.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ stRef.setOutput(soKey);
+ result = new AxValidationResult();
+ result = stRef.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ stRef.clean();
+
+ AxStateTaskReference clonedStRef = new AxStateTaskReference(stRef);
+ assertEquals("AxStateTaskReference:(stateKey=AxReferenceKey:(par", clonedStRef.toString().substring(0, 50));
+
+ assertNotEquals(0, stRef.hashCode());
+
+ // disabling sonar because this code tests the equals() method
+ assertEquals(stRef, stRef); // NOSONAR
+ assertEquals(stRef, clonedStRef);
+ assertNotNull(stRef);
+ assertNotEquals(stRef, (Object) "Hello");
+ assertNotEquals(stRef, new AxStateTaskReference(AxReferenceKey.getNullKey(), AxStateTaskOutputType.LOGIC,
+ soKey));
+ assertNotEquals(stRef, new AxStateTaskReference(stRefKey, AxStateTaskOutputType.DIRECT, soKey));
+ assertNotEquals(stRef, new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, new AxReferenceKey()));
+ assertEquals(stRef, new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, soKey));
+
+ assertNotNull(new AxStateTaskReference(new AxReferenceKey(), new AxArtifactKey(),
+ AxStateTaskOutputType.UNDEFINED, new AxReferenceKey()));
+
+ assertEquals(0, stRef.compareTo(stRef));
+ assertEquals(0, stRef.compareTo(clonedStRef));
+ assertNotEquals(0, stRef.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, stRef.compareTo(null));
+ assertNotEquals(0, stRef.compareTo(
+ new AxStateTaskReference(AxReferenceKey.getNullKey(), AxStateTaskOutputType.LOGIC, soKey)));
+ assertNotEquals(0, stRef.compareTo(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.DIRECT, soKey)));
+ assertNotEquals(0, stRef.compareTo(
+ new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, new AxReferenceKey())));
+ assertEquals(0, stRef.compareTo(new AxStateTaskReference(stRefKey, AxStateTaskOutputType.LOGIC, soKey)));
+
+ assertNotNull(stRef.getKeys());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTest.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTest.java
new file mode 100644
index 000000000..7fbe78078
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTest.java
@@ -0,0 +1,461 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation
+ * ================================================================================
+ * 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.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+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;
+
+/**
+ * Test policy states.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class StateTest {
+
+ @Test
+ public void testState() {
+ final TreeMap<String, AxStateOutput> soEmptyMap = new TreeMap<>();
+ final TreeSet<AxArtifactKey> ctxtEmptySet = new TreeSet<>();
+ final TreeMap<String, AxStateFinalizerLogic> sflEmptyMap = new TreeMap<>();
+ final TreeMap<AxArtifactKey, AxStateTaskReference> trEmptyMap = new TreeMap<>();
+
+ final TreeMap<String, AxStateOutput> soMap = new TreeMap<>();
+ final TreeSet<AxArtifactKey> ctxtSet = new TreeSet<>();
+ final TreeMap<String, AxStateFinalizerLogic> sflMap = new TreeMap<>();
+ final TreeMap<AxArtifactKey, AxStateTaskReference> trMap = new TreeMap<>();
+
+ assertNotNull(new AxState());
+ assertNotNull(new AxState(new AxReferenceKey()));
+ assertNotNull(new AxState(new AxStateParamsBuilder().key(new AxReferenceKey()).trigger(new AxArtifactKey())
+ .stateOutputs(soEmptyMap).contextAlbumReferenceSet(ctxtEmptySet)
+ .taskSelectionLogic(new AxTaskSelectionLogic()).stateFinalizerLogicMap(sflEmptyMap)
+ .defaultTask(new AxArtifactKey()).taskReferenceMap(trEmptyMap)));
+
+ final AxState state = new AxState();
+
+ final AxReferenceKey stateKey = new AxReferenceKey("PolicyName", "0.0.1", "StateName");
+ final AxReferenceKey stateKeyNext = new AxReferenceKey("PolicyName", "0.0.1", "StateNameNext");
+ final AxReferenceKey stateKeyBad = new AxReferenceKey("PolicyName", "0.0.1", "BadStateName");
+ final AxArtifactKey triggerKey = new AxArtifactKey("TriggerName", "0.0.1");
+ final AxTaskSelectionLogic tsl = new AxTaskSelectionLogic(stateKey, "TSL", "LogicFlavour", "Some Logic");
+ final AxArtifactKey defTaskKey = new AxArtifactKey("TaskName", "0.0.1");
+ final AxArtifactKey taskKey1 = new AxArtifactKey("Task1", "0.0.1");
+ final AxArtifactKey taskKey2 = new AxArtifactKey("Task2", "0.0.1");
+ final AxArtifactKey taskKeyBad = new AxArtifactKey("TaskBad", "0.0.1");
+
+ assertThatThrownBy(() -> state.setKey(null))
+ .hasMessage("key may not be null");
+ state.setKey(stateKey);
+ assertEquals("PolicyName:0.0.1:NULL:StateName", state.getKey().getId());
+ assertEquals("PolicyName:0.0.1:NULL:StateName", state.getKeys().get(0).getId());
+
+ final AxStateOutput so0 = new AxStateOutput(new AxReferenceKey(stateKey, "SO0"), triggerKey,
+ new AxReferenceKey());
+ final AxStateOutput soU = new AxStateOutput(new AxReferenceKey(stateKey, "SOU"), triggerKey, stateKeyNext);
+ final AxStateOutput soSame = new AxStateOutput(new AxReferenceKey(stateKey, "SOU"), triggerKey, stateKey);
+ final AxArtifactKey cr0 = new AxArtifactKey("ContextReference", "0.0.1");
+ final AxStateFinalizerLogic sfl = new AxStateFinalizerLogic(stateKey, "SFLogicName", "LogicFlavour", "Logic");
+ final AxStateFinalizerLogic sflU = new AxStateFinalizerLogic(stateKey, "UnusedSFLogicName", "LogicFlavour",
+ "Logic");
+ final AxStateTaskReference str0 = new AxStateTaskReference(new AxReferenceKey(stateKey, "STR0"),
+ AxStateTaskOutputType.DIRECT, so0.getKey());
+ final AxStateTaskReference str1 = new AxStateTaskReference(new AxReferenceKey(stateKey, "STR1"),
+ AxStateTaskOutputType.DIRECT, so0.getKey());
+ final AxStateTaskReference str2 = new AxStateTaskReference(new AxReferenceKey(stateKey, "STR2"),
+ AxStateTaskOutputType.LOGIC, sfl.getKey());
+
+ final AxStateTaskReference strBadState = new AxStateTaskReference(new AxReferenceKey(stateKeyBad, "STR2"),
+ AxStateTaskOutputType.LOGIC, sfl.getKey());
+ final AxStateTaskReference strBadStateOutput = new AxStateTaskReference(new AxReferenceKey(stateKey, "STR2"),
+ AxStateTaskOutputType.UNDEFINED, sfl.getKey());
+ final AxStateTaskReference strBadStateFinalizerLogic = new AxStateTaskReference(
+ new AxReferenceKey(stateKeyBad, "STR2"), AxStateTaskOutputType.LOGIC,
+ new AxReferenceKey(stateKey, "SomeSFL"));
+
+ soMap.put(so0.getKey().getLocalName(), so0);
+ ctxtSet.add(cr0);
+ sflMap.put(sfl.getKey().getLocalName(), sfl);
+ trMap.put(defTaskKey.getKey(), str0);
+ trMap.put(taskKey1.getKey(), str1);
+ trMap.put(taskKey2.getKey(), str2);
+
+ assertThatThrownBy(() -> state.setTrigger(null))
+ .hasMessage("trigger may not be null");
+ state.setTrigger(triggerKey);
+ assertEquals(triggerKey, state.getTrigger());
+
+ assertThatThrownBy(() -> state.setStateOutputs(null))
+ .hasMessage("stateOutputs may not be null");
+ state.setStateOutputs(soMap);
+ assertEquals(soMap, state.getStateOutputs());
+
+ assertThatThrownBy(() -> state.setContextAlbumReferences(null))
+ .hasMessage("contextAlbumReferenceSet may not be null");
+ state.setContextAlbumReferences(ctxtSet);
+ assertEquals(ctxtSet, state.getContextAlbumReferences());
+
+ assertThatThrownBy(() -> state.setTaskSelectionLogic(null))
+ .hasMessage("taskSelectionLogic may not be null");
+ assertEquals(false, state.checkSetTaskSelectionLogic());
+ state.setTaskSelectionLogic(tsl);
+ assertEquals(tsl, state.getTaskSelectionLogic());
+ assertEquals(true, state.checkSetTaskSelectionLogic());
+
+ assertThatThrownBy(() -> state.setStateFinalizerLogicMap(null))
+ .hasMessage("stateFinalizerLogic may not be null");
+ state.setStateFinalizerLogicMap(sflMap);
+ assertEquals(sflMap, state.getStateFinalizerLogicMap());
+
+ assertThatThrownBy(() -> state.setDefaultTask(null))
+ .hasMessage("defaultTask may not be null");
+ state.setDefaultTask(defTaskKey);
+ assertEquals(defTaskKey, state.getDefaultTask());
+
+ assertThatThrownBy(() -> state.setTaskReferences(null))
+ .hasMessage("taskReferenceMap may not be null");
+ state.setTaskReferences(trMap);
+ assertEquals(trMap, state.getTaskReferences());
+
+ state.buildReferences();
+ assertEquals(state.getKey(), state.getKeys().get(0));
+ state.getTaskSelectionLogic().getKey().setLocalName(AxKey.NULL_KEY_NAME);
+ state.buildReferences();
+ assertEquals(state.getKey(), state.getKeys().get(0));
+
+ final Set<String> stateSet = state.getNextStateSet();
+ assertEquals(1, stateSet.size());
+
+ AxValidationResult result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.setKey(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ state.setKey(stateKey);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.setTrigger(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ state.setTrigger(triggerKey);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.setStateOutputs(soEmptyMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ state.setStateOutputs(soMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ so0.getKey().setParentLocalName("Zooby");
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ so0.getKey().setParentLocalName("StateName");
+ state.setStateOutputs(soMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ soMap.put("NullOutput", null);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ soMap.remove("NullOutput");
+ state.setStateOutputs(soMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ soMap.put("DupOutput", so0);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ soMap.remove("DupOutput");
+ state.setStateOutputs(soMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ soMap.put("UnusedOutput", soU);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.OBSERVATION, result.getValidationResult());
+
+ soMap.remove("UnusedOutput");
+ state.setStateOutputs(soMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ soMap.put("OutputToSameState", soSame);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ soMap.remove("OutputToSameState");
+ state.setStateOutputs(soMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ // Empty context reference set is OK
+ state.setContextAlbumReferences(ctxtEmptySet);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.setContextAlbumReferences(ctxtSet);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ ctxtSet.add(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ ctxtSet.remove(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ // Null TSL is OK
+ state.getTaskSelectionLogic().setKey(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.getTaskSelectionLogic().setKey(new AxReferenceKey(stateKey, "TSL"));
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.setDefaultTask(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ state.setDefaultTask(defTaskKey);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.setTaskReferences(trEmptyMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ state.setTaskReferences(trMap);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ trMap.put(AxArtifactKey.getNullKey(), null);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ trMap.remove(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ trMap.put(AxArtifactKey.getNullKey(), str0);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ trMap.remove(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ trMap.put(taskKeyBad, strBadStateOutput);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ trMap.remove(taskKeyBad);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ trMap.put(taskKeyBad, strBadState);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ trMap.remove(taskKeyBad);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ trMap.put(taskKeyBad, strBadStateFinalizerLogic);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ trMap.remove(taskKeyBad);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.setDefaultTask(new AxArtifactKey("NonExistantTask", "0.0.1"));
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ state.setDefaultTask(defTaskKey);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ sflMap.put("NullSFL", null);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ sflMap.remove("NullSFL");
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ sflMap.put(sflU.getKey().getLocalName(), sflU);
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.OBSERVATION, result.getValidationResult());
+
+ sflMap.remove(sflU.getKey().getLocalName());
+ result = new AxValidationResult();
+ result = state.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ state.clean();
+
+ final AxState clonedState = new AxState(state);
+ assertEquals("AxState:(stateKey=AxReferenceKey:(parent", clonedState.toString().substring(0, 40));
+
+ assertNotEquals(0, state.hashCode());
+ // disabling sonar because this code tests the equals() method
+ assertEquals(state, state); // NOSONAR
+ assertEquals(state, clonedState);
+ assertNotNull(state);
+
+ Object helloObj = "Hello";
+ assertNotEquals(state, helloObj);
+ assertNotEquals(state, new AxState(new AxStateParamsBuilder().key(new AxReferenceKey()).trigger(triggerKey)
+ .stateOutputs(soMap).contextAlbumReferenceSet(ctxtSet).taskSelectionLogic(tsl)
+ .stateFinalizerLogicMap(sflMap).defaultTask(defTaskKey).taskReferenceMap(trMap)));
+ assertNotEquals(state, new AxState(new AxStateParamsBuilder().key(stateKey).trigger(new AxArtifactKey())
+ .stateOutputs(soMap).contextAlbumReferenceSet(ctxtSet).taskSelectionLogic(tsl)
+ .stateFinalizerLogicMap(sflMap).defaultTask(defTaskKey).taskReferenceMap(trMap)));
+ assertNotEquals(state, new AxState(new AxStateParamsBuilder().key(stateKey).trigger(triggerKey)
+ .stateOutputs(soEmptyMap).contextAlbumReferenceSet(ctxtSet).taskSelectionLogic(tsl)
+ .stateFinalizerLogicMap(sflMap).defaultTask(defTaskKey).taskReferenceMap(trMap)));
+ assertNotEquals(state, new AxState(new AxStateParamsBuilder().key(stateKey).trigger(triggerKey)
+ .stateOutputs(soMap).contextAlbumReferenceSet(ctxtEmptySet).taskSelectionLogic(tsl)
+ .stateFinalizerLogicMap(sflMap).defaultTask(defTaskKey).taskReferenceMap(trMap)));
+ assertNotEquals(state, new AxState(new AxStateParamsBuilder().key(stateKey).trigger(triggerKey)
+ .stateOutputs(soMap).contextAlbumReferenceSet(ctxtSet)
+ .taskSelectionLogic(new AxTaskSelectionLogic()).stateFinalizerLogicMap(sflMap)
+ .defaultTask(defTaskKey).taskReferenceMap(trMap)));
+ assertNotEquals(state, new AxState(new AxStateParamsBuilder().key(stateKey).trigger(triggerKey)
+ .stateOutputs(soMap).contextAlbumReferenceSet(ctxtSet).taskSelectionLogic(tsl)
+ .stateFinalizerLogicMap(sflEmptyMap).defaultTask(defTaskKey).taskReferenceMap(trMap)));
+ assertNotEquals(state, new AxState(new AxStateParamsBuilder().key(stateKey).trigger(triggerKey)
+ .stateOutputs(soMap).contextAlbumReferenceSet(ctxtSet).taskSelectionLogic(tsl)
+ .stateFinalizerLogicMap(sflMap).defaultTask(new AxArtifactKey()).taskReferenceMap(trMap)));
+ assertNotEquals(state, new AxState(new AxStateParamsBuilder().key(stateKey).trigger(triggerKey)
+ .stateOutputs(soMap).contextAlbumReferenceSet(ctxtSet).taskSelectionLogic(tsl)
+ .stateFinalizerLogicMap(sflMap).defaultTask(defTaskKey).taskReferenceMap(trEmptyMap)));
+ assertEquals(state, new AxState(new AxStateParamsBuilder().key(stateKey).trigger(triggerKey)
+ .stateOutputs(soMap).contextAlbumReferenceSet(ctxtSet).taskSelectionLogic(tsl)
+ .stateFinalizerLogicMap(sflMap).defaultTask(defTaskKey).taskReferenceMap(trMap)));
+
+ assertEquals(0, state.compareTo(state));
+ assertEquals(0, state.compareTo(clonedState));
+ assertNotEquals(0, state.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, state.compareTo(null));
+ assertNotEquals(0,
+ state.compareTo(new AxState(new AxStateParamsBuilder().key(new AxReferenceKey())
+ .trigger(triggerKey).stateOutputs(soMap).contextAlbumReferenceSet(ctxtSet)
+ .taskSelectionLogic(tsl).stateFinalizerLogicMap(sflMap).defaultTask(defTaskKey)
+ .taskReferenceMap(trMap))));
+ assertNotEquals(0, state.compareTo(new AxState(new AxStateParamsBuilder().key(stateKey)
+ .trigger(new AxArtifactKey()).stateOutputs(soMap).contextAlbumReferenceSet(ctxtSet)
+ .taskSelectionLogic(tsl).stateFinalizerLogicMap(sflMap).defaultTask(defTaskKey)
+ .taskReferenceMap(trMap))));
+ assertNotEquals(0, state.compareTo(new AxState(new AxStateParamsBuilder().key(stateKey).trigger(triggerKey)
+ .stateOutputs(soEmptyMap).contextAlbumReferenceSet(ctxtSet).taskSelectionLogic(tsl)
+ .stateFinalizerLogicMap(sflMap).defaultTask(defTaskKey).taskReferenceMap(trMap))));
+ assertNotEquals(0, state.compareTo(new AxState(new AxStateParamsBuilder().key(stateKey).trigger(triggerKey)
+ .stateOutputs(soMap).contextAlbumReferenceSet(ctxtEmptySet).taskSelectionLogic(tsl)
+ .stateFinalizerLogicMap(sflMap).defaultTask(defTaskKey).taskReferenceMap(trMap))));
+ assertNotEquals(0,
+ state.compareTo(new AxState(new AxStateParamsBuilder().key(stateKey).trigger(triggerKey)
+ .stateOutputs(soMap).contextAlbumReferenceSet(ctxtSet)
+ .taskSelectionLogic(new AxTaskSelectionLogic()).stateFinalizerLogicMap(sflMap)
+ .defaultTask(defTaskKey).taskReferenceMap(trMap))));
+ assertNotEquals(0, state.compareTo(new AxState(new AxStateParamsBuilder().key(stateKey).trigger(triggerKey)
+ .stateOutputs(soMap).contextAlbumReferenceSet(ctxtSet).taskSelectionLogic(tsl)
+ .stateFinalizerLogicMap(sflEmptyMap).defaultTask(defTaskKey).taskReferenceMap(trMap))));
+ assertNotEquals(0, state.compareTo(new AxState(new AxStateParamsBuilder().key(stateKey).trigger(triggerKey)
+ .stateOutputs(soMap).contextAlbumReferenceSet(ctxtSet).taskSelectionLogic(tsl)
+ .stateFinalizerLogicMap(sflMap).defaultTask(new AxArtifactKey()).taskReferenceMap(trMap))));
+ assertNotEquals(0, state.compareTo(new AxState(new AxStateParamsBuilder().key(stateKey).trigger(triggerKey)
+ .stateOutputs(soMap).contextAlbumReferenceSet(ctxtSet).taskSelectionLogic(tsl)
+ .stateFinalizerLogicMap(sflMap).defaultTask(defTaskKey).taskReferenceMap(trEmptyMap))));
+ assertEquals(0, state.compareTo(new AxState(new AxStateParamsBuilder().key(stateKey).trigger(triggerKey)
+ .stateOutputs(soMap).contextAlbumReferenceSet(ctxtSet).taskSelectionLogic(tsl)
+ .stateFinalizerLogicMap(sflMap).defaultTask(defTaskKey).taskReferenceMap(trMap))));
+
+ assertNotNull(state.getKeys());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TaskParameterTest.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TaskParameterTest.java
new file mode 100644
index 000000000..4255b495d
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TaskParameterTest.java
@@ -0,0 +1,110 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * ================================================================================
+ * 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.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+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;
+
+/**
+ * Test task parameters.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TaskParameterTest {
+
+ @Test
+ public void testTaskParameter() {
+ assertNotNull(new AxTaskParameter());
+ assertNotNull(new AxTaskParameter(new AxReferenceKey()));
+ assertNotNull(new AxTaskParameter(new AxReferenceKey(), "DefaultValue"));
+
+ final AxTaskParameter par = new AxTaskParameter();
+
+ final AxReferenceKey parKey = new AxReferenceKey("ParParentName", "0.0.1", "PLN", "LN");
+ par.setKey(parKey);
+ assertEquals("ParParentName:0.0.1:PLN:LN", par.getKey().getId());
+ assertEquals("ParParentName:0.0.1:PLN:LN", par.getKeys().get(0).getId());
+
+ par.setDefaultValue("DefaultValue");
+ assertEquals("DefaultValue", par.getTaskParameterValue());
+
+ AxValidationResult result = new AxValidationResult();
+ result = par.validate(result);
+ assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
+
+ par.setKey(AxReferenceKey.getNullKey());
+ result = new AxValidationResult();
+ result = par.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ par.setKey(parKey);
+ result = new AxValidationResult();
+ result = par.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ assertThatThrownBy(() -> par.setDefaultValue(null))
+ .hasMessage("defaultValue may not be null");
+ par.setDefaultValue("");
+ result = new AxValidationResult();
+ result = par.validate(result);
+ assertEquals(ValidationResult.WARNING, result.getValidationResult());
+
+ par.setDefaultValue("DefaultValue");
+ result = new AxValidationResult();
+ result = par.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ par.clean();
+
+ final AxTaskParameter clonedPar = new AxTaskParameter(par);
+ assertEquals("AxTaskParameter:(key=AxReferenceKey:(parentKeyName=ParParentName,parentKeyVersion=0.0.1,"
+ + "parentLocalName=PLN,localName=LN),defaultValue=DefaultValue)", clonedPar.toString());
+
+ assertNotEquals(0, par.hashCode());
+ // disabling sonar because this code tests the equals() method
+ assertEquals(par, par); // NOSONAR
+ assertEquals(par, clonedPar);
+ assertNotNull(par);
+ assertNotEquals(par, (Object) "Hello");
+ assertNotEquals(par, new AxTaskParameter(AxReferenceKey.getNullKey(), "DefaultValue"));
+ assertNotEquals(par, new AxTaskParameter(parKey, "OtherDefaultValue"));
+ assertEquals(par, new AxTaskParameter(parKey, "DefaultValue"));
+
+ assertEquals(0, par.compareTo(par));
+ assertEquals(0, par.compareTo(clonedPar));
+ assertNotEquals(0, par.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, par.compareTo(null));
+ assertNotEquals(0, par.compareTo(new AxTaskParameter(AxReferenceKey.getNullKey(), "DefaultValue")));
+ assertNotEquals(0, par.compareTo(new AxTaskParameter(parKey, "OtherDefaultValue")));
+ assertEquals(0, par.compareTo(new AxTaskParameter(parKey, "DefaultValue")));
+
+ assertNotNull(par.getKeys());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.java
new file mode 100644
index 000000000..9c7866c85
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.java
@@ -0,0 +1,259 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019-2020,2022 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.
+ * 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.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import org.junit.Test;
+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;
+
+/**
+ * Test policy tasks.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TasksTest {
+
+ @Test
+ public void testTasks() {
+ final TreeMap<String, AxTaskParameter> tpEmptyMap = new TreeMap<>();
+ final TreeSet<AxArtifactKey> ctxtEmptySet = new TreeSet<>();
+
+ final TreeMap<String, AxTaskParameter> tpMap = new TreeMap<>();
+ final TreeSet<AxArtifactKey> ctxtSet = new TreeSet<>();
+
+ assertNotNull(new AxTask());
+ assertNotNull(new AxTask(new AxArtifactKey()));
+ assertNotNull(new AxTask(new AxArtifactKey(), tpMap, ctxtSet, new AxTaskLogic()));
+
+ final AxTask task = new AxTask();
+
+ final AxArtifactKey taskKey = new AxArtifactKey("TaskName", "0.0.1");
+ task.setKey(taskKey);
+ assertEquals("TaskName:0.0.1", task.getKey().getId());
+ assertEquals("TaskName:0.0.1", task.getKeys().get(0).getId());
+
+ final AxTaskParameter tp0 = new AxTaskParameter(new AxReferenceKey(taskKey, "TP0"), "DefaultValue");
+ final AxArtifactKey cr0 = new AxArtifactKey("ContextReference", "0.0.1");
+ final AxTaskLogic tl = new AxTaskLogic(taskKey, "LogicName", "LogicFlavour", "Logic");
+
+ tpMap.put(tp0.getKey().getLocalName(), tp0);
+ ctxtSet.add(cr0);
+
+ task.setInputEvent(new AxEvent());
+ task.setOutputEvents(Map.of("Event", new AxEvent()));
+
+ task.setTaskParameters(tpMap);
+ assertEquals(tpMap, task.getTaskParameters());
+
+ task.setContextAlbumReferences(ctxtSet);
+ assertEquals(ctxtSet, task.getContextAlbumReferences());
+
+ task.setTaskLogic(tl);
+ assertEquals(tl, task.getTaskLogic());
+
+ task.setKey(taskKey);
+ assertEquals("TaskName:0.0.1", task.getKey().getId());
+ assertEquals("TaskName:0.0.1", task.getKeys().get(0).getId());
+
+ task.buildReferences();
+ assertEquals(1, task.getTaskParameters().size());
+
+ AxValidationResult result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ task.setKey(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ task.setKey(taskKey);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ // Empty task parameter map is OK
+ task.setTaskParameters(tpEmptyMap);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ task.setTaskParameters(tpMap);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ tpMap.put("NullField", null);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ tpMap.remove("NullField");
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ // Empty context reference set is OK
+ task.setContextAlbumReferences(ctxtEmptySet);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ task.setContextAlbumReferences(ctxtSet);
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ ctxtSet.add(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ ctxtSet.remove(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = task.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ task.clean();
+
+ final AxTask clonedTask = new AxTask(task);
+ assertEquals("AxTask:(key=AxArtifactKey:(name=TaskName", clonedTask.toString().substring(0, 40));
+
+ assertNotEquals(0, task.hashCode());
+ // disabling sonar because this code tests the equals() method
+ assertEquals(task, task); // NOSONAR
+ assertEquals(task, clonedTask);
+ assertNotNull(task);
+
+ Object helloObj = "Hello";
+ assertNotEquals(task, helloObj);
+ assertNotEquals(task, new AxTask(new AxArtifactKey(), tpMap, ctxtSet, tl));
+ assertEquals(task, new AxTask(taskKey, tpMap, ctxtSet, tl));
+ assertNotEquals(task, new AxTask(taskKey, tpEmptyMap, ctxtSet, tl));
+ assertNotEquals(task, new AxTask(taskKey, tpMap, ctxtEmptySet, tl));
+ assertNotEquals(task, new AxTask(taskKey, tpMap, ctxtSet, new AxTaskLogic()));
+ assertEquals(task, new AxTask(taskKey, tpMap, ctxtSet, tl));
+
+ assertEquals(0, task.compareTo(task));
+ assertEquals(0, task.compareTo(clonedTask));
+ assertNotEquals(0, task.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, task.compareTo(null));
+ assertNotEquals(0, task.compareTo(new AxTask(new AxArtifactKey(), tpMap, ctxtSet, tl)));
+ assertEquals(0, task.compareTo(new AxTask(taskKey, tpMap, ctxtSet, tl)));
+ assertNotEquals(0, task.compareTo(new AxTask(taskKey, tpEmptyMap, ctxtSet, tl)));
+ assertNotEquals(0, task.compareTo(new AxTask(taskKey, tpMap, ctxtEmptySet, tl)));
+ assertNotEquals(0, task.compareTo(new AxTask(taskKey, tpMap, ctxtSet, new AxTaskLogic())));
+ assertEquals(0, task.compareTo(new AxTask(taskKey, tpMap, ctxtSet, tl)));
+
+ assertNotNull(task.getKeys());
+
+ final AxTasks tasks = new AxTasks();
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ // Invalid, no tasks in task map
+ tasks.setKey(new AxArtifactKey("TasksKey", "0.0.1"));
+ assertEquals("TasksKey:0.0.1", tasks.getKey().getId());
+
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ tasks.getTaskMap().put(taskKey, task);
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ tasks.getTaskMap().put(AxArtifactKey.getNullKey(), null);
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ tasks.getTaskMap().remove(AxArtifactKey.getNullKey());
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ tasks.getTaskMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null);
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ tasks.getTaskMap().remove(new AxArtifactKey("NullValueKey", "0.0.1"));
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ tasks.getTaskMap().put(new AxArtifactKey("BadTaskKey", "0.0.1"), task);
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.INVALID, result.getValidationResult());
+
+ tasks.getTaskMap().remove(new AxArtifactKey("BadTaskKey", "0.0.1"));
+ result = new AxValidationResult();
+ result = tasks.validate(result);
+ assertEquals(ValidationResult.VALID, result.getValidationResult());
+
+ tasks.clean();
+
+ final AxTasks clonedTasks = new AxTasks(tasks);
+ assertEquals("AxTasks:(key=AxArtifactKey:(name=TasksKey,version=0.0.1),tas",
+ clonedTasks.toString().substring(0, 60));
+
+ assertNotEquals(0, tasks.hashCode());
+
+ // disabling sonar because this code tests the equals() method
+ assertEquals(tasks, tasks); // NOSONAR
+ assertEquals(tasks, clonedTasks);
+ assertNotNull(tasks);
+ assertNotEquals(tasks, helloObj);
+ assertNotEquals(tasks, new AxTasks(new AxArtifactKey()));
+
+ assertEquals(0, tasks.compareTo(tasks));
+ assertEquals(0, tasks.compareTo(clonedTasks));
+ assertNotEquals(0, tasks.compareTo(null));
+ assertNotEquals(0, tasks.compareTo(new AxArtifactKey()));
+ assertNotEquals(0, tasks.compareTo(new AxTasks(new AxArtifactKey())));
+
+ clonedTasks.get(taskKey).getTaskLogic().setLogic("SomeChangedLogic");
+ assertNotEquals(0, tasks.compareTo(clonedTasks));
+
+ assertEquals(tasks.getKey(), tasks.getKeys().get(0));
+
+ assertEquals("TaskName", tasks.get("TaskName").getKey().getName());
+ assertEquals("TaskName", tasks.get("TaskName", "0.0.1").getKey().getName());
+ assertEquals(1, tasks.getAll("TaskName", "0.0.1").size());
+ assertEquals(0, tasks.getAll("NonExistantTaskName").size());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/ApexPolicyModelTest.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/ApexPolicyModelTest.java
new file mode 100644
index 000000000..48e4f87f9
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/ApexPolicyModelTest.java
@@ -0,0 +1,138 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 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.
+ * 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 static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+
+public class ApexPolicyModelTest {
+ private static final String VALID_MODEL_STRING = "***validation of model successful***";
+
+ private static final String OBSERVATION_MODEL_STRING = "\n"
+ + "***observations noted during validation of model***\n"
+ + "AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,"
+ + "localName=state):org.onap.policy.apex.model.policymodel.concepts.AxState:OBSERVATION:"
+ + "state output stateOutput0 is not used directly by any task\n"
+ + "********************************";
+
+ private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n"
+ + "AxArtifactKey:(name=policy,version=0.0.1)"
+ + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicy:WARNING:state AxReferenceKey:"
+ + "(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=anotherState) "
+ + "is not referenced in the policy execution tree\n" + "********************************";
+
+ private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=contextAlbum0,version=0.0.1):"
+ + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:scope is not defined\n"
+ + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):"
+ + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:scope is not defined\n"
+ + "********************************";
+
+ private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n"
+ + "AxArtifactKey:(name=policyModel_KeyInfo,version=0.0.1):"
+ + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation:INVALID:"
+ + "keyInfoMap may not be empty\n" + "AxArtifactKey:(name=policyModel,version=0.0.1)"
+ + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=policyModel,version=0.0.1)\n"
+ + "AxArtifactKey:(name=policyModel,version=0.0.1)"
+ + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=policyModel_KeyInfo,version=0.0.1)\n"
+ + "AxArtifactKey:(name=policyModel,version=0.0.1)"
+ + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=policyModel_Schemas,version=0.0.1)\n"
+ + "AxArtifactKey:(name=policyModel,version=0.0.1)"
+ + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=policyModel_Events,version=0.0.1)\n"
+ + "AxArtifactKey:(name=policyModel,version=0.0.1)"
+ + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=policyModel_Albums,version=0.0.1)\n"
+ + "AxArtifactKey:(name=policyModel,version=0.0.1)"
+ + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=policyModel_Tasks,version=0.0.1)\n"
+ + "AxArtifactKey:(name=policyModel,version=0.0.1)"
+ + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel:INVALID:"
+ + "key information not found for key AxArtifactKey:(name=policyModel_Policies,version=0.0.1)\n"
+ + "AxArtifactKey:(name=policyModel_Schemas,version=0.0.1):"
+ + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas:INVALID:"
+ + "contextSchemas may not be empty\n" + "AxArtifactKey:(name=policyModel_Events,version=0.0.1):"
+ + "org.onap.policy.apex.model.eventmodel.concepts.AxEvents:INVALID:eventMap may not be empty\n"
+ + "AxArtifactKey:(name=policyModel_Albums,version=0.0.1):"
+ + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums:OBSERVATION:albums are empty\n"
+ + "AxArtifactKey:(name=policyModel_Tasks,version=0.0.1)"
+ + ":org.onap.policy.apex.model.policymodel.concepts.AxTasks:INVALID:taskMap may not be empty\n"
+ + "AxArtifactKey:(name=policyModel_Policies,version=0.0.1)"
+ + ":org.onap.policy.apex.model.policymodel.concepts.AxPolicies:INVALID:policyMap may not be empty\n"
+ + "********************************";
+
+ TestApexModel<AxPolicyModel> testApexModel;
+
+ /**
+ * Set up the policy model tests.
+ *
+ * @throws Exception on setup errors
+ */
+ @Before
+ public void setup() throws Exception {
+ testApexModel = new TestApexModel<AxPolicyModel>(AxPolicyModel.class, new SupportApexPolicyModelCreator());
+ }
+
+ @Test
+ public void testModelValid() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelValid();
+ assertEquals(VALID_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testApexModelVaidateObservation() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateObservation();
+ assertEquals(OBSERVATION_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testApexModelVaidateWarning() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateWarning();
+ assertEquals(WARNING_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelVaidateInvalidModel() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel();
+ assertEquals(INVALID_MODEL_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelVaidateMalstructured() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured();
+ assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString());
+ }
+
+ @Test
+ public void testModelWriteReadJson() throws Exception {
+ testApexModel.testApexModelWriteReadJson();
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyserTest.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyserTest.java
new file mode 100644
index 000000000..b1e2d5cbd
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyAnalyserTest.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 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.
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+
+public class PolicyAnalyserTest {
+ @Test
+ public void test() {
+ final AxPolicyModel apexModel = new SupportApexPolicyModelCreator().getModel();
+
+ final PolicyAnalyser policyAnalyser = new PolicyAnalyser();
+ final PolicyAnalysisResult analysisResult = policyAnalyser.analyse(apexModel);
+
+ assertEquals(EXPECTED_ANALYSIS_RESULT, analysisResult.toString());
+
+ assertNotNull(analysisResult.getUsedContextAlbums());
+ assertNotNull(analysisResult.getUsedContextSchemas());
+ assertNotNull(analysisResult.getUsedEvents());
+ assertNotNull(analysisResult.getUsedTasks());
+ assertNotNull(analysisResult.getUnusedContextAlbums());
+ assertNotNull(analysisResult.getUnusedContextSchemas());
+ assertNotNull(analysisResult.getUnusedEvents());
+ assertNotNull(analysisResult.getUnusedTasks());
+ }
+
+ private static final String EXPECTED_ANALYSIS_RESULT = "" + "Context Schema usage\n" + " MapType:0.0.1\n"
+ + " contextAlbum0:0.0.1\n" + " StringType:0.0.1\n" + " contextAlbum1:0.0.1\n"
+ + " eventContextItem0:0.0.1\n" + " inEvent:0.0.1\n" + " outEvent0:0.0.1\n" + " outEvent1:0.0.1\n"
+ + " eventContextItem1:0.0.1\n" + " inEvent:0.0.1\n" + " outEvent0:0.0.1\n"
+ + " outEvent1:0.0.1\n" + "Context Album usage\n" + " contextAlbum0:0.0.1\n"
+ + " task:0.0.1\n" + " policy:0.0.1:NULL:state\n" + " contextAlbum1:0.0.1\n" + " task:0.0.1\n"
+ + " policy:0.0.1:NULL:state\n" + "Event usage\n" + " inEvent:0.0.1\n" + " policy:0.0.1:NULL:state\n"
+ + " outEvent0:0.0.1\n" + " policy:0.0.1:NULL:state\n" + " outEvent1:0.0.1 (unused)\n" + "Task usage\n"
+ + " task:0.0.1\n" + " policy:0.0.1:NULL:state\n";
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReaderTest.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReaderTest.java
new file mode 100644
index 000000000..a2cbe7415
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyLogicReaderTest.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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 static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.policymodel.concepts.AxLogic;
+
+/**
+ * Logic reader for policy tests.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class PolicyLogicReaderTest {
+
+ @Test
+ public void test() {
+ final AxReferenceKey logicKey = new AxReferenceKey("LogicParent", "0.0.1", "LogicInstanceName");
+
+ final PolicyLogicReader plReader = new PolicyLogicReader();
+
+ plReader.setLogicPackage("somewhere.over.the.rainbow");
+ assertEquals("somewhere.over.the.rainbow", plReader.getLogicPackage());
+
+ plReader.setDefaultLogic("FunkyDefaultLogic");
+ assertEquals("FunkyDefaultLogic", plReader.getDefaultLogic());
+
+ assertThatThrownBy(() -> new AxLogic(logicKey, "FunkyLogic", plReader))
+ .hasMessage("logic not found for logic "
+ + "\"somewhere/over/the/rainbow/funkylogic/FunkyDefaultLogic.funkylogic\"");
+ plReader.setDefaultLogic(null);
+ assertThatThrownBy(() -> new AxLogic(logicKey, "FunkyLogic", plReader))
+ .hasMessage("logic not found for logic "
+ + "\"somewhere/over/the/rainbow/funkylogic/LogicParentLogicInstanceName.funkylogic\"");
+ logicKey.setParentLocalName("LogicParentLocalName");
+ assertThatThrownBy(() -> new AxLogic(logicKey, "FunkyLogic", plReader))
+ .hasMessage("logic not found for logic " + "\"somewhere/over/the/rainbow/funkylogic/"
+ + "LogicParentLogicParentLocalNameLogicInstanceName.funkylogic\"");
+ plReader.setLogicPackage("path.to.apex.logic");
+
+ AxLogic logic = new AxLogic(logicKey, "FunkyLogic", plReader);
+ assertThat(logic.getLogic()).endsWith("Way out man, this is funky logic!");
+
+ plReader.setLogicPackage("somewhere.over.the.rainbow");
+ plReader.setDefaultLogic("JavaLogic");
+
+ logic = new AxLogic(logicKey, "JAVA", plReader);
+ assertEquals("somewhere.over.the.rainbow.java.JavaLogic", logic.getLogic());
+
+ plReader.setDefaultLogic(null);
+
+ logic = new AxLogic(logicKey, "JAVA", plReader);
+ assertEquals("somewhere.over.the.rainbow.java.LogicParentLogicParentLocalNameLogicInstanceName",
+ logic.getLogic());
+
+ logicKey.setParentLocalName(AxKey.NULL_KEY_NAME);
+ logic = new AxLogic(logicKey, "JAVA", plReader);
+ assertEquals("somewhere.over.the.rainbow.java.LogicParentLogicInstanceName", logic.getLogic());
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelComparerTest.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelComparerTest.java
new file mode 100644
index 000000000..691880d6b
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelComparerTest.java
@@ -0,0 +1,118 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ * ================================================================================
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.util.UUID;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+
+public class PolicyModelComparerTest {
+
+ @Test
+ public void testPolicyComparer() throws IOException {
+ final AxPolicyModel leftApexModel = new SupportApexPolicyModelCreator().getModel();
+ final AxPolicyModel rightApexModel = new AxPolicyModel(leftApexModel);
+
+ PolicyModelComparer policyModelComparer = new PolicyModelComparer(leftApexModel, rightApexModel);
+
+ String resultString = policyModelComparer.asString(false, false);
+ String checkString = TextFileUtils
+ .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseValues.txt");
+ assertEquals(resultString.trim().replaceAll("\\s+", ""), checkString.trim().replaceAll("\\s+", ""));
+
+ resultString = policyModelComparer.asString(false, true);
+ checkString = TextFileUtils
+ .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseKeys.txt");
+ assertEquals(checkString.trim().replaceAll("\\s+", ""), resultString.trim().replaceAll("\\s+", ""));
+
+ resultString = policyModelComparer.asString(true, false);
+ checkString =
+ TextFileUtils.getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt");
+ assertEquals(checkString.trim().replaceAll("\\s+", ""), resultString.trim().replaceAll("\\s+", ""));
+
+ resultString = policyModelComparer.asString(true, true);
+ checkString =
+ TextFileUtils.getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt");
+ assertEquals(checkString.trim().replaceAll("\\s+", ""), resultString.trim().replaceAll("\\s+", ""));
+
+ final AxKeyInfo leftOnlyKeyInfo = new AxKeyInfo(new AxArtifactKey("LeftOnlyKeyInfo", "0.0.1"),
+ UUID.fromString("ce9168c-e6df-414f-9646-6da464b6f000"), "Left only key info");
+ final AxKeyInfo rightOnlyKeyInfo = new AxKeyInfo(new AxArtifactKey("RightOnlyKeyInfo", "0.0.1"),
+ UUID.fromString("ce9168c-e6df-414f-9646-6da464b6f001"), "Right only key info");
+
+ leftApexModel.getKeyInformation().getKeyInfoMap().put(leftOnlyKeyInfo.getKey(), leftOnlyKeyInfo);
+ rightApexModel.getKeyInformation().getKeyInfoMap().put(rightOnlyKeyInfo.getKey(), rightOnlyKeyInfo);
+
+ leftApexModel.getKeyInformation().getKeyInfoMap().get(new AxArtifactKey("inEvent", "0.0.1"))
+ .setDescription("Left InEvent Description");
+ rightApexModel.getKeyInformation().getKeyInfoMap().get(new AxArtifactKey("inEvent", "0.0.1"))
+ .setDescription("Right InEvent Description");
+
+ policyModelComparer = new PolicyModelComparer(leftApexModel, rightApexModel);
+
+ resultString = policyModelComparer.asString(false, false);
+ checkString = TextFileUtils
+ .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseValues.txt");
+ assertEquals(resultString.trim().replaceAll("\\s+", ""), checkString.trim().replaceAll("\\s+", ""));
+
+ resultString = policyModelComparer.asString(false, true);
+ checkString = TextFileUtils
+ .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseKeys.txt");
+ assertEquals(checkString.trim().replaceAll("\\s+", ""), resultString.trim().replaceAll("\\s+", ""));
+
+ resultString = policyModelComparer.asString(true, false);
+ checkString = TextFileUtils
+ .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseValues.txt");
+ assertEquals(checkString.trim().replaceAll("\\s+", ""), resultString.trim().replaceAll("\\s+", ""));
+
+ resultString = policyModelComparer.asString(true, true);
+ checkString = TextFileUtils
+ .getTextFileAsString("src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseKeys.txt");
+ assertEquals(checkString.trim().replaceAll("\\s+", ""), resultString.trim().replaceAll("\\s+", ""));
+
+ assertNotNull(policyModelComparer.getContextAlbumComparisonResult());
+ assertNotNull(policyModelComparer.getContextAlbumKeyDifference());
+ assertNotNull(policyModelComparer.getContextSchemaComparisonResult());
+ assertNotNull(policyModelComparer.getContextSchemaKeyDifference());
+ assertNotNull(policyModelComparer.getEventComparisonResult());
+ assertNotNull(policyModelComparer.getEventKeyDifference());
+ assertNotNull(policyModelComparer.getKeyInfoComparisonResult());
+ assertNotNull(policyModelComparer.getKeyInformationKeyDifference());
+ assertNotNull(policyModelComparer.getPolicyComparisonResult());
+ assertNotNull(policyModelComparer.getPolicykeyDifference());
+ assertNotNull(policyModelComparer.getPolicyModelsKeyDifference());
+ assertNotNull(policyModelComparer.getTaskComparisonResult());
+ assertNotNull(policyModelComparer.getTaskKeyDifference());
+
+ assertNotNull(new PolicyComparer().compare(leftApexModel.getPolicies(), rightApexModel.getPolicies()));
+
+ assertEquals("****** policy map differences ******\n*** context s",
+ policyModelComparer.toString().substring(0, 50));
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMergerTest.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMergerTest.java
new file mode 100644
index 000000000..2bdf7499f
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMergerTest.java
@@ -0,0 +1,92 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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 static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskLogic;
+
+/**
+ * Test model merging.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class PolicyModelMergerTest {
+
+ @Test
+ public void testPolicyModelMerger() throws ApexModelException {
+ final AxPolicyModel leftPolicyModel = new SupportApexPolicyModelCreator().getModel();
+ final AxPolicyModel rightPolicyModel = new SupportApexPolicyModelCreator().getModel();
+
+ AxPolicyModel mergedPolicyModel =
+ PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false, false);
+ assertEquals(leftPolicyModel, mergedPolicyModel);
+ assertEquals(rightPolicyModel, mergedPolicyModel);
+
+ leftPolicyModel.setKey(new AxArtifactKey("LeftPolicyModel", "0.0.1"));
+ assertThatThrownBy(
+ () -> PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false, false))
+ .hasMessageContaining("left model is invalid: \n***validation of model failed");
+
+ leftPolicyModel.setKey(new AxArtifactKey("LeftPolicyModel", "0.0.1"));
+ assertNotNull(PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false, true, false));
+
+ leftPolicyModel.getKeyInformation().generateKeyInfo(leftPolicyModel);
+ mergedPolicyModel = PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, true, false);
+ assertNotNull(mergedPolicyModel);
+
+ rightPolicyModel.setKey(new AxArtifactKey("RightPolicyModel", "0.0.1"));
+ assertThatThrownBy(
+ () -> PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false, false))
+ .hasMessageContaining("right model is invalid: \n***validation of model failed");
+
+ rightPolicyModel.setKey(new AxArtifactKey("RightPolicyModel", "0.0.1"));
+ assertNotNull(PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false, true, false));
+
+ rightPolicyModel.getKeyInformation().generateKeyInfo(rightPolicyModel);
+ mergedPolicyModel = PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel, false, false);
+ assertNotNull(mergedPolicyModel);
+
+ final AxPolicyModel rightPolicyModel2 = new SupportApexPolicyModelCreator().getAnotherModel();
+ mergedPolicyModel = PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel2, true, false);
+ assertNotNull(mergedPolicyModel);
+
+ mergedPolicyModel = PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel2, true, true);
+ assertNotNull(mergedPolicyModel);
+
+ final AxPolicyModel rightPolicyModel3 = new SupportApexPolicyModelCreator().getModel();
+ AxArtifactKey taskArtifactKey = new AxArtifactKey("task", "0.0.1");
+ // fail when concepts in two policies have same name but different definition
+ // here make up some change so as to update the definition of the task in second policy
+ rightPolicyModel3.getTasks().getTaskMap().get(taskArtifactKey)
+ .setTaskLogic(new AxTaskLogic(taskArtifactKey, "logicName", "logicFlavour", "logicImpl"));
+ assertThatThrownBy(() -> PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel3, true, true))
+ .hasMessage("\n Same task - task:0.0.1 with different definitions used in different policies");
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitterTest.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitterTest.java
new file mode 100644
index 000000000..902206d51
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelSplitterTest.java
@@ -0,0 +1,76 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation
+ * ================================================================================
+ * 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 static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Set;
+import java.util.TreeSet;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+
+public class PolicyModelSplitterTest {
+ @Test
+ public void test() throws ApexModelException {
+ final AxPolicyModel apexModel = new SupportApexPolicyModelCreator().getModel();
+
+ final Set<AxArtifactKey> requiredPolicySet = new TreeSet<AxArtifactKey>();
+ requiredPolicySet.add(new AxArtifactKey("policy", "0.0.1"));
+
+ // There's only one policy so a split of this model on that policy should return the same
+ // model
+ AxPolicyModel splitApexModel = null;
+ splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet);
+
+ // The only difference between the models should be that the unused event outEvent1 should
+ // not be in the split model
+ apexModel.getEvents().getEventMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
+ apexModel.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
+ assertEquals(apexModel, splitApexModel);
+
+ final Set<AxArtifactKey> requiredMissingPolicySet = new TreeSet<AxArtifactKey>();
+ requiredPolicySet.add(new AxArtifactKey("MissingPolicy", "0.0.1"));
+
+ AxPolicyModel missingSplitApexModel = null;
+ missingSplitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredMissingPolicySet);
+ assertNotNull(missingSplitApexModel);
+
+ splitApexModel = null;
+ splitApexModel = PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet, true);
+
+ // The only difference between the models should be that the unused event outEvent1 should
+ // not be in the split model
+ apexModel.getEvents().getEventMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
+ apexModel.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("outEvent1", "0.0.1"));
+ assertEquals(apexModel, splitApexModel);
+
+ // There's only one policy so a split of this model on that policy should return the same
+ // model
+ apexModel.getKey().setName("InvalidPolicyModelName");
+ assertThatThrownBy(() -> PolicyModelSplitter.getSubPolicyModel(apexModel, requiredPolicySet))
+ .hasMessageContaining("source model is invalid: \n***validation of model f");
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/SupportApexPolicyModelCreator.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/SupportApexPolicyModelCreator.java
new file mode 100644
index 000000000..85040221a
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/handling/SupportApexPolicyModelCreator.java
@@ -0,0 +1,406 @@
+/*-
+ * ============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;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+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.test.TestApexModelCreator;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEvents;
+import org.onap.policy.apex.model.eventmodel.concepts.AxField;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicies;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicy;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.apex.model.policymodel.concepts.AxState;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateFinalizerLogic;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskOutputType;
+import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference;
+import org.onap.policy.apex.model.policymodel.concepts.AxTask;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskLogic;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic;
+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> {
+
+ @Override
+ public AxPolicyModel getModel() {
+ final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("eventContextItem0", "0.0.1"), "Java",
+ "java.lang.String");
+ final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("eventContextItem1", "0.0.1"), "Java",
+ "java.lang.Long");
+ final AxContextSchema schema2 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.policymodel.concepts.TestContextItem000");
+ final AxContextSchema schema3 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.policymodel.concepts.TestContextItem00A");
+
+ final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("ContextSchemas", "0.0.1"));
+ schemas.getSchemasMap().put(schema0.getKey(), schema0);
+ schemas.getSchemasMap().put(schema1.getKey(), schema1);
+ schemas.getSchemasMap().put(schema2.getKey(), schema2);
+ schemas.getSchemasMap().put(schema3.getKey(), schema3);
+
+ final AxContextAlbum album0 = new AxContextAlbum(new AxArtifactKey("contextAlbum0", "0.0.1"), "APPLICATION",
+ true, schema3.getKey());
+ final AxContextAlbum album1 = new AxContextAlbum(new AxArtifactKey("contextAlbum1", "0.0.1"), "GLOBAL", false,
+ schema2.getKey());
+
+ final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey("context", "0.0.1"));
+ albums.getAlbumsMap().put(album0.getKey(), album0);
+ albums.getAlbumsMap().put(album1.getKey(), album1);
+
+ final AxEvent inEvent = new AxEvent(new AxArtifactKey("inEvent", "0.0.1"),
+ "org.onap.policy.apex.model.policymodel.events", "Source", "Target");
+ inEvent.getParameterMap().put("IEPAR0",
+ new AxField(new AxReferenceKey(inEvent.getKey(), "IEPAR0"), schema0.getKey()));
+ inEvent.getParameterMap().put("IEPAR1",
+ new AxField(new AxReferenceKey(inEvent.getKey(), "IEPAR1"), schema1.getKey()));
+
+ final AxEvent outEvent0 = new AxEvent(new AxArtifactKey("outEvent0", "0.0.1"),
+ "org.onap.policy.apex.model.policymodel.events", "Source", "Target");
+ outEvent0.getParameterMap().put("OE0PAR0",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE0PAR0"), schema0.getKey()));
+ outEvent0.getParameterMap().put("OE0PAR1",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE0PAR1"), schema1.getKey()));
+ outEvent0.getParameterMap().put("OE1PAR0",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE1PAR0"), schema0.getKey()));
+ outEvent0.getParameterMap().put("OE1PAR1",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE1PAR1"), schema1.getKey()));
+
+ final AxEvent outEvent1 = new AxEvent(new AxArtifactKey("outEvent1", "0.0.1"),
+ "org.onap.policy.apex.model.policymodel.events", "Source", "Target");
+ outEvent1.getParameterMap().put("OE1PAR0",
+ new AxField(new AxReferenceKey(outEvent1.getKey(), "OE1PAR0"), schema0.getKey()));
+ outEvent1.getParameterMap().put("OE1PAR1",
+ new AxField(new AxReferenceKey(outEvent1.getKey(), "OE1PAR1"), schema1.getKey()));
+
+ final AxEvents events = new AxEvents(new AxArtifactKey("events", "0.0.1"));
+ events.getEventMap().put(inEvent.getKey(), inEvent);
+ events.getEventMap().put(outEvent0.getKey(), outEvent0);
+ events.getEventMap().put(outEvent1.getKey(), outEvent1);
+
+ final AxTask task = new AxTask(new AxArtifactKey("task", "0.0.1"));
+
+ 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"),
+ "Task parameter 1 value");
+
+ task.getTaskParameters().put(taskPar0.getKey().getLocalName(), taskPar0);
+ task.getTaskParameters().put(taskPar1.getKey().getLocalName(), taskPar1);
+ task.getContextAlbumReferences().add(album0.getKey());
+ task.getContextAlbumReferences().add(album1.getKey());
+
+ final AxTaskLogic taskLogic = new AxTaskLogic(new AxReferenceKey(task.getKey(), "taskLogic"), "MVEL",
+ "Some task logic");
+ task.setTaskLogic(taskLogic);
+
+ final AxTasks tasks = new AxTasks(new AxArtifactKey("tasks", "0.0.1"));
+ tasks.getTaskMap().put(task.getKey(), task);
+
+ final AxPolicy policy = new AxPolicy(new AxArtifactKey("policy", "0.0.1"));
+ policy.setTemplate("FREEFORM");
+
+ final AxState state = new AxState(new AxReferenceKey(policy.getKey(), "state"));
+ final AxTaskSelectionLogic taskSelectionLogic = new AxTaskSelectionLogic(
+ new AxReferenceKey(state.getKey(), "taskSelectionLogic"), "MVEL", "Some TS logic ");
+
+ state.setTrigger(inEvent.getKey());
+ state.getContextAlbumReferences().add(album0.getKey());
+ state.getContextAlbumReferences().add(album1.getKey());
+ state.setTaskSelectionLogic(taskSelectionLogic);
+ state.setDefaultTask(task.getKey());
+
+ final AxStateOutput stateOutput0 = new AxStateOutput(new AxReferenceKey(state.getKey(), "stateOutput0"),
+ outEvent0.getKey(), AxReferenceKey.getNullKey());
+ state.getStateOutputs().put(stateOutput0.getKey().getLocalName(), stateOutput0);
+
+ final AxStateTaskReference stateTaskReference = new AxStateTaskReference(
+ new AxReferenceKey(state.getKey(), task.getKey().getName()), AxStateTaskOutputType.DIRECT,
+ stateOutput0.getKey());
+
+ state.getTaskReferences().put(task.getKey(), stateTaskReference);
+
+ policy.getStateMap().put(state.getKey().getLocalName(), state);
+ policy.setFirstState(state.getKey().getLocalName());
+
+ final AxPolicies policies = new AxPolicies(new AxArtifactKey("policies", "0.0.1"));
+ policies.getPolicyMap().put(policy.getKey(), policy);
+
+ final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"));
+ final AxPolicyModel policyModel = new AxPolicyModel(new AxArtifactKey("PolicyModel", "0.0.1"));
+ policyModel.setKeyInformation(keyInformation);
+ policyModel.setSchemas(schemas);
+ policyModel.setAlbums(albums);
+ policyModel.setEvents(events);
+ policyModel.setTasks(tasks);
+ policyModel.setPolicies(policies);
+ policyModel.getKeyInformation().generateKeyInfo(policyModel);
+
+ int uuidIncrementer = 0;
+ for (final AxKeyInfo keyInfo : policyModel.getKeyInformation().getKeyInfoMap().values()) {
+ final String uuidString = String.format("ce9168c-e6df-414f-9646-6da464b6e%03d", uuidIncrementer++);
+ keyInfo.setUuid(UUID.fromString(uuidString));
+ }
+
+ final AxValidationResult result = new AxValidationResult();
+ policyModel.validate(result);
+
+ return policyModel;
+ }
+
+ /**
+ * Gets another policy model.
+ *
+ * @return the model
+ */
+ public AxPolicyModel getAnotherModel() {
+ final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("eventContextItemA0", "0.0.1"), "Java",
+ "java.lang.String");
+ final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("eventContextItemA1", "0.0.1"), "Java",
+ "java.lang.Long");
+ final AxContextSchema schema2 = new AxContextSchema(new AxArtifactKey("StringTypeA", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.policymodel.concepts.TestContextItem000");
+ final AxContextSchema schema3 = new AxContextSchema(new AxArtifactKey("MapTypeA", "0.0.1"), "Java",
+ "org.onap.policy.apex.model.policymodel.concepts.TestContextItem00A");
+
+ final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("ContextSchemasA", "0.0.1"));
+ schemas.getSchemasMap().put(schema0.getKey(), schema0);
+ schemas.getSchemasMap().put(schema1.getKey(), schema1);
+ schemas.getSchemasMap().put(schema2.getKey(), schema2);
+ schemas.getSchemasMap().put(schema3.getKey(), schema3);
+
+ final AxContextAlbum album0 = new AxContextAlbum(new AxArtifactKey("contextAlbumA0", "0.0.1"), "APPLICATION",
+ true, schema3.getKey());
+ final AxContextAlbum album1 = new AxContextAlbum(new AxArtifactKey("contextAlbumA1", "0.0.1"), "GLOBAL", false,
+ schema2.getKey());
+
+ final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey("contextA", "0.0.1"));
+ albums.getAlbumsMap().put(album0.getKey(), album0);
+ albums.getAlbumsMap().put(album1.getKey(), album1);
+
+ final AxEvent inEvent = new AxEvent(new AxArtifactKey("inEventA", "0.0.1"),
+ "org.onap.policy.apex.model.policymodel.events", "Source", "Target");
+ inEvent.getParameterMap().put("IEPARA0",
+ new AxField(new AxReferenceKey(inEvent.getKey(), "IEPARA0"), schema0.getKey()));
+ inEvent.getParameterMap().put("IEPARA1",
+ new AxField(new AxReferenceKey(inEvent.getKey(), "IEPARA1"), schema1.getKey()));
+
+ final AxEvent outEvent0 = new AxEvent(new AxArtifactKey("outEventA0", "0.0.1"),
+ "org.onap.policy.apex.model.policymodel.events", "Source", "Target");
+ outEvent0.getParameterMap().put("OE0PARA0",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE0PARA0"), schema0.getKey()));
+ outEvent0.getParameterMap().put("OE0PARA1",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE0PARA1"), schema1.getKey()));
+ outEvent0.getParameterMap().put("OE1PARA0",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE1PARA0"), schema0.getKey()));
+ outEvent0.getParameterMap().put("OE1PARA1",
+ new AxField(new AxReferenceKey(outEvent0.getKey(), "OE1PARA1"), schema1.getKey()));
+
+ final AxEvent outEvent1 = new AxEvent(new AxArtifactKey("outEventA1", "0.0.1"),
+ "org.onap.policy.apex.model.policymodel.events", "Source", "Target");
+ outEvent1.getParameterMap().put("OE1PARA0",
+ new AxField(new AxReferenceKey(outEvent1.getKey(), "OE1PARA0"), schema0.getKey()));
+ outEvent1.getParameterMap().put("OE1PARA1",
+ new AxField(new AxReferenceKey(outEvent1.getKey(), "OE1PARA1"), schema1.getKey()));
+
+ final AxEvents events = new AxEvents(new AxArtifactKey("eventsA", "0.0.1"));
+ events.getEventMap().put(inEvent.getKey(), inEvent);
+ events.getEventMap().put(outEvent0.getKey(), outEvent0);
+ events.getEventMap().put(outEvent1.getKey(), outEvent1);
+
+ final AxTask task = new AxTask(new AxArtifactKey("taskA", "0.0.1"));
+
+ 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"),
+ "Task parameter 1 value");
+
+ task.getTaskParameters().put(taskPar0.getKey().getLocalName(), taskPar0);
+ task.getTaskParameters().put(taskPar1.getKey().getLocalName(), taskPar1);
+ task.getContextAlbumReferences().add(album0.getKey());
+ task.getContextAlbumReferences().add(album1.getKey());
+
+ final AxTaskLogic taskLogic = new AxTaskLogic(new AxReferenceKey(task.getKey(), "taskLogicA"), "MVEL",
+ "Some task logic");
+ task.setTaskLogic(taskLogic);
+
+ final AxTasks tasks = new AxTasks(new AxArtifactKey("tasksA", "0.0.1"));
+ tasks.getTaskMap().put(task.getKey(), task);
+
+ final AxPolicy policy = new AxPolicy(new AxArtifactKey("policyA", "0.0.1"));
+ policy.setTemplate("FREEFORM");
+
+ final AxState state = new AxState(new AxReferenceKey(policy.getKey(), "stateA"));
+ final AxTaskSelectionLogic taskSelectionLogic = new AxTaskSelectionLogic(
+ new AxReferenceKey(state.getKey(), "taskSelectionLogicA"), "MVEL", "Some TS logic ");
+
+ state.setTrigger(inEvent.getKey());
+ state.getContextAlbumReferences().add(album0.getKey());
+ state.getContextAlbumReferences().add(album1.getKey());
+ state.setTaskSelectionLogic(taskSelectionLogic);
+ state.setDefaultTask(task.getKey());
+
+ final AxStateOutput stateOutput0 = new AxStateOutput(new AxReferenceKey(state.getKey(), "stateOutputA0"),
+ outEvent0.getKey(), AxReferenceKey.getNullKey());
+ state.getStateOutputs().put(stateOutput0.getKey().getLocalName(), stateOutput0);
+
+ final AxStateTaskReference stateTaskReference = new AxStateTaskReference(
+ new AxReferenceKey(state.getKey(), task.getKey().getName()), AxStateTaskOutputType.DIRECT,
+ stateOutput0.getKey());
+
+ state.getTaskReferences().put(task.getKey(), stateTaskReference);
+
+ policy.getStateMap().put(state.getKey().getLocalName(), state);
+ policy.setFirstState(state.getKey().getLocalName());
+
+ final AxPolicies policies = new AxPolicies(new AxArtifactKey("policiesA", "0.0.1"));
+ policies.getPolicyMap().put(policy.getKey(), policy);
+
+ final AxKeyInformation keyInformation = new AxKeyInformation(new AxArtifactKey("KeyInfoMapKeyA", "0.0.1"));
+ final AxPolicyModel policyModel = new AxPolicyModel(new AxArtifactKey("PolicyModelA", "0.0.1"));
+ policyModel.setKeyInformation(keyInformation);
+ policyModel.setSchemas(schemas);
+ policyModel.setAlbums(albums);
+ policyModel.setEvents(events);
+ policyModel.setTasks(tasks);
+ policyModel.setPolicies(policies);
+ policyModel.getKeyInformation().generateKeyInfo(policyModel);
+
+ int uuidIncrementer = 0;
+ for (final AxKeyInfo keyInfo : policyModel.getKeyInformation().getKeyInfoMap().values()) {
+ final String uuidString = String.format("ce9168c-e6df-414f-9646-6da464b6e%03d", uuidIncrementer++);
+ keyInfo.setUuid(UUID.fromString(uuidString));
+ }
+
+ final AxValidationResult result = new AxValidationResult();
+ policyModel.validate(result);
+
+ return policyModel;
+ }
+
+ @Override
+ public AxPolicyModel getMalstructuredModel() {
+ final AxPolicyModel policyModel = new AxPolicyModel(new AxArtifactKey("policyModel", "0.0.1"));
+ return policyModel;
+ }
+
+ @Override
+ public AxPolicyModel getObservationModel() {
+ final AxPolicyModel policyModel = getModel();
+
+ final AxState state = policyModel.getPolicies().get("policy").getStateMap().get("state");
+ final AxTask task = policyModel.getTasks().get("task");
+
+ final AxStateFinalizerLogic stateFinalizerLogic = new AxStateFinalizerLogic(
+ new AxReferenceKey(state.getKey(), "SFL"), "MVEL", "Some SF logic ");
+ state.getStateFinalizerLogicMap().put(stateFinalizerLogic.getKey().getLocalName(), stateFinalizerLogic);
+ final AxStateTaskReference stateTaskReference = new AxStateTaskReference(
+ new AxReferenceKey(state.getKey(), task.getKey().getName()), AxStateTaskOutputType.LOGIC,
+ stateFinalizerLogic.getKey());
+
+ state.getTaskReferences().put(task.getKey(), stateTaskReference);
+
+ return policyModel;
+ }
+
+ @Override
+ public AxPolicyModel getWarningModel() {
+ final AxPolicyModel policyModel = getModel();
+
+ final AxState anotherState = new AxState(
+ new AxReferenceKey(new AxArtifactKey("policy", "0.0.1"), "anotherState"));
+
+ final AxEvent inEvent = policyModel.getEvents().getEventMap().get(new AxArtifactKey("inEvent", "0.0.1"));
+ final AxEvent outEvent0 = policyModel.getEvents().getEventMap().get(new AxArtifactKey("outEvent0", "0.0.1"));
+
+ final AxTask anotherTask = new AxTask(new AxArtifactKey("anotherTask", "0.0.1"));
+
+ 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"),
+ "Task parameter 1 value");
+
+ anotherTask.getTaskParameters().put(taskPar0.getKey().getLocalName(), taskPar0);
+ anotherTask.getTaskParameters().put(taskPar1.getKey().getLocalName(), taskPar1);
+
+ final AxTaskLogic taskLogic = new AxTaskLogic(new AxReferenceKey(anotherTask.getKey(), "taskLogic"), "MVEL",
+ "Some task logic");
+ anotherTask.setTaskLogic(taskLogic);
+ policyModel.getTasks().getTaskMap().put(anotherTask.getKey(), anotherTask);
+
+ final AxStateOutput anotherStateOutput0 = new AxStateOutput(
+ new AxReferenceKey(anotherState.getKey(), "stateOutput0"), outEvent0.getKey(),
+ AxReferenceKey.getNullKey());
+ anotherState.setTrigger(inEvent.getKey());
+ anotherState.getStateOutputs().put(anotherStateOutput0.getKey().getLocalName(), anotherStateOutput0);
+ anotherState.setDefaultTask(anotherTask.getKey());
+ final AxStateTaskReference anotherStateTaskReference = new AxStateTaskReference(
+ new AxReferenceKey(anotherState.getKey(), anotherTask.getKey().getName()),
+ AxStateTaskOutputType.DIRECT, anotherStateOutput0.getKey());
+ anotherState.getTaskReferences().put(anotherTask.getKey(), anotherStateTaskReference);
+
+ policyModel.getPolicies().getPolicyMap().get(new AxArtifactKey("policy", "0.0.1")).getStateMap()
+ .put(anotherState.getKey().getLocalName(), anotherState);
+
+ policyModel.getKeyInformation().generateKeyInfo(policyModel);
+
+ return policyModel;
+ }
+
+ @Override
+ public AxPolicyModel getInvalidModel() {
+ final AxPolicyModel policyModel = getModel();
+
+ policyModel.getAlbums().get(new AxArtifactKey("contextAlbum0", "0.0.1")).setScope("UNDEFINED");
+ policyModel.getAlbums().get(new AxArtifactKey("contextAlbum1", "0.0.1")).setScope("UNDEFINED");
+
+ final AxEvent outEvent0 = policyModel.getEvents().get("outEvent0");
+ outEvent0.getParameterMap().remove("OE1PAR0");
+ outEvent0.getParameterMap().remove("OE1PAR1");
+
+ return policyModel;
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/policymodel/utils/SupportPolicyModelValidator.java b/model/src/test/java/org/onap/policy/apex/model/policymodel/utils/SupportPolicyModelValidator.java
new file mode 100644
index 000000000..daff1efa7
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/policymodel/utils/SupportPolicyModelValidator.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.utils;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+
+/**
+ * Main class to run the policy model validator.
+ */
+public class SupportPolicyModelValidator {
+ /**
+ * Main method.
+ * @param args the command line arguments
+ * @throws ApexModelException on errors on the apex model
+ * @throws FileNotFoundException on file find failures
+ */
+ public static void main(final String[] args) throws ApexModelException, FileNotFoundException {
+ final ApexModelReader<AxPolicyModel> policyModelReader = new ApexModelReader<AxPolicyModel>(
+ AxPolicyModel.class);
+
+ final AxPolicyModel policyModel = policyModelReader.read(new FileInputStream(args[0]));
+ final AxValidationResult result = policyModel.validate(new AxValidationResult());
+ System.out.println(result);
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/utilities/CollectionUtilitiesTest.java b/model/src/test/java/org/onap/policy/apex/model/utilities/CollectionUtilitiesTest.java
new file mode 100644
index 000000000..2512133e7
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/utilities/CollectionUtilitiesTest.java
@@ -0,0 +1,87 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.utilities;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+
+public class CollectionUtilitiesTest {
+
+ @Test
+ public void testNullLists() {
+ int result = 0;
+
+ result = CollectionUtils.compareLists(null, null);
+ assertEquals(0, result);
+
+ List<String> leftList = new ArrayList<String>();
+
+ result = CollectionUtils.compareLists(leftList, null);
+ assertEquals(-1, result);
+
+ List<String> rightList = new ArrayList<String>();
+
+ result = CollectionUtils.compareLists(null, rightList);
+ assertEquals(1, result);
+
+ result = CollectionUtils.compareLists(leftList, rightList);
+ assertEquals(0, result);
+
+ leftList.add("AAA");
+ result = CollectionUtils.compareLists(leftList, rightList);
+ assertEquals(-1, result);
+
+ rightList.add("AAA");
+ result = CollectionUtils.compareLists(leftList, rightList);
+ assertEquals(0, result);
+
+ rightList.add("BBB");
+ result = CollectionUtils.compareLists(leftList, rightList);
+ assertEquals(1, result);
+
+ leftList.add("BBB");
+ result = CollectionUtils.compareLists(leftList, rightList);
+ assertEquals(0, result);
+
+ leftList.add("CCA");
+ rightList.add("CCB");
+ result = CollectionUtils.compareLists(leftList, rightList);
+ assertEquals(-1, result);
+
+ leftList.remove(leftList.size() - 1);
+ rightList.remove(rightList.size() - 1);
+ result = CollectionUtils.compareLists(leftList, rightList);
+ assertEquals(0, result);
+
+ leftList.add("CCB");
+ rightList.add("CCA");
+ result = CollectionUtils.compareLists(leftList, rightList);
+ assertEquals(1, result);
+
+ leftList.remove(leftList.size() - 1);
+ rightList.remove(rightList.size() - 1);
+ result = CollectionUtils.compareLists(leftList, rightList);
+ assertEquals(0, result);
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/utilities/DirectoryUtilsTest.java b/model/src/test/java/org/onap/policy/apex/model/utilities/DirectoryUtilsTest.java
new file mode 100644
index 000000000..69c2d4763
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/utilities/DirectoryUtilsTest.java
@@ -0,0 +1,55 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.utilities;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Arrays;
+import org.junit.Test;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+
+public class DirectoryUtilsTest {
+
+ @Test
+ public void test() throws IOException {
+ DirectoryUtils.emptyDirectory(new File("/i/dont/exist"));
+
+ File tempDir = Files.createTempDirectory("test").toFile();
+ assertNotNull(tempDir);
+
+ Files.createTempDirectory(tempDir.toPath(), "testsubprefix");
+
+ TextFileUtils.putStringAsTextFile("Temp File 0 contents", tempDir.getAbsolutePath() + "/tempFile0.tmp");
+ TextFileUtils.putStringAsTextFile("Temp File 1 contents", tempDir.getAbsolutePath() + "/tempFile1.tmp");
+
+ DirectoryUtils.emptyDirectory(tempDir);
+
+ DirectoryUtils.getLocalTempDirectory(null);
+
+ byte[] byteArray = new byte[] {0, 0, 0};
+ DirectoryUtils.getLocalTempDirectory(Arrays.toString(byteArray));
+ }
+
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/utilities/KeyComparerTest.java b/model/src/test/java/org/onap/policy/apex/model/utilities/KeyComparerTest.java
new file mode 100644
index 000000000..20780b271
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/utilities/KeyComparerTest.java
@@ -0,0 +1,53 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.utilities;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.utilities.comparison.KeyComparer;
+import org.onap.policy.apex.model.utilities.comparison.KeyDifference;
+
+/**
+ * Test key comparisons.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class KeyComparerTest {
+
+ @Test
+ public void test() {
+ KeyDifference<String> keyDifference = new KeyComparer<String>().compareKeys("Hello", "Goodbye");
+
+ assertFalse(keyDifference.isEqual());
+ assertEquals("Hello", keyDifference.getLeftKey().toString());
+ assertEquals("Goodbye", keyDifference.getRightKey().toString());
+
+ assertEquals("left key Hello and right key Goodbye differ\n", keyDifference.asString(true));
+ assertEquals("left key Hello and right key Goodbye differ\n", keyDifference.asString(false));
+
+ KeyDifference<String> keyDifference2 = new KeyComparer<String>().compareKeys("Here", "Here");
+ assertEquals("", keyDifference2.asString(true));
+ assertEquals("left key Here equals right key Here\n", keyDifference2.asString(false));
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/utilities/KeyedMapComparerTest.java b/model/src/test/java/org/onap/policy/apex/model/utilities/KeyedMapComparerTest.java
new file mode 100644
index 000000000..b4e88e20d
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/utilities/KeyedMapComparerTest.java
@@ -0,0 +1,76 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.utilities;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.TreeMap;
+import org.junit.Test;
+import org.onap.policy.apex.model.utilities.comparison.KeyedMapComparer;
+import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference;
+
+/**
+ * Test key map comparisons.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class KeyedMapComparerTest {
+
+ @Test
+ public void test() {
+ TreeMap<String, String> leftMap = new TreeMap<String, String>();
+ leftMap.put("B", "BBBBB");
+ leftMap.put("C", "CCCCC");
+ leftMap.put("E", "EEEEE");
+ leftMap.put("G", "GGGGG");
+
+ TreeMap<String, String> rightMap = new TreeMap<String, String>();
+ rightMap.put("A", "AAAAA");
+ rightMap.put("B", "B");
+ rightMap.put("D", "DDDDD");
+ rightMap.put("E", "EEEEE");
+ rightMap.put("F", "FFFFF");
+ rightMap.put("G", "G");
+
+ KeyedMapDifference<String, String> kmComparedSame =
+ new KeyedMapComparer<String, String>().compareMaps(leftMap, leftMap);
+ KeyedMapDifference<String, String> kmComparedDiff =
+ new KeyedMapComparer<String, String>().compareMaps(leftMap, rightMap);
+
+ assertEquals(leftMap, kmComparedSame.getIdenticalValues());
+ assertEquals(1, kmComparedDiff.getLeftOnly().size());
+ assertEquals(3, kmComparedDiff.getRightOnly().size());
+ assertEquals(2, kmComparedDiff.getDifferentValues().size());
+ assertEquals(1, kmComparedDiff.getIdenticalValues().size());
+
+ assertNotNull(kmComparedSame.asString(true, true));
+ assertNotNull(kmComparedSame.asString(true, false));
+ assertNotNull(kmComparedSame.asString(false, false));
+ assertNotNull(kmComparedSame.asString(false, true));
+
+ assertNotNull(kmComparedDiff.asString(true, true));
+ assertNotNull(kmComparedDiff.asString(true, false));
+ assertNotNull(kmComparedDiff.asString(false, false));
+ assertNotNull(kmComparedDiff.asString(false, true));
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/utilities/TextFileUtilsTest.java b/model/src/test/java/org/onap/policy/apex/model/utilities/TextFileUtilsTest.java
new file mode 100644
index 000000000..1d6f29fe5
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/utilities/TextFileUtilsTest.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.utilities;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import org.junit.Test;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+
+/**
+ * Test text file utilities.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TextFileUtilsTest {
+
+ private static final String FILE_CONTENT = "This is the contents of a text file";
+
+ @Test
+ public void test() throws IOException {
+ final File tempTextFile = File.createTempFile("Test", "txt");
+
+ TextFileUtils.putStringAsTextFile(FILE_CONTENT, tempTextFile.getAbsolutePath());
+
+ final String textFileString0 = TextFileUtils.getTextFileAsString(tempTextFile.getAbsolutePath());
+ assertEquals(FILE_CONTENT, textFileString0);
+
+ final FileInputStream fis = new FileInputStream(tempTextFile);
+ final String textFileString1 = TextFileUtils.getStreamAsString(fis);
+ assertEquals(textFileString0, textFileString1);
+
+ }
+
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/utilities/TreeMapUtilsTest.java b/model/src/test/java/org/onap/policy/apex/model/utilities/TreeMapUtilsTest.java
new file mode 100644
index 000000000..c3a36b7b9
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/utilities/TreeMapUtilsTest.java
@@ -0,0 +1,157 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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.utilities;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+import org.junit.Test;
+
+/**
+ * Test the tree map utilities.
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TreeMapUtilsTest {
+
+ private static final int KEY1 = 10;
+ private static final int KEY2 = 20;
+ private static final int KEY3 = 30;
+ private static final String VALUE1 = "a-one";
+ private static final String VALUE2 = "b-two";
+ private static final String VALUE3 = "c-three";
+ private static final String VALUE4 = "d-four";
+
+ @Test
+ public void testFindMatchingEntries() {
+ TreeMap<String, String> testTreeMap = new TreeMap<String, String>();
+ testTreeMap.put("G", "G");
+ testTreeMap.put("H", "H");
+ testTreeMap.put("JA", "JA");
+ testTreeMap.put("JAM", "JAM");
+ testTreeMap.put("JOE", "JOE");
+ testTreeMap.put("JOSH", "JOSH");
+ testTreeMap.put("K", "K");
+
+ List<Entry<String, String>> foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "F");
+ assertEquals(0, foundKeyList.size());
+
+ foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "G");
+ assertEquals("G", foundKeyList.get(0).getKey());
+
+ foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "H");
+ assertEquals("H", foundKeyList.get(0).getKey());
+
+ foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "I");
+ assertEquals(0, foundKeyList.size());
+
+ foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "J");
+ assertEquals("JA", foundKeyList.get(0).getKey());
+
+ foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JA");
+ assertEquals("JA", foundKeyList.get(0).getKey());
+
+ foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JB");
+ assertEquals(0, foundKeyList.size());
+
+ foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JO");
+ assertEquals("JOE", foundKeyList.get(0).getKey());
+
+ foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JOE");
+ assertEquals("JOE", foundKeyList.get(0).getKey());
+
+ foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JOS");
+ assertEquals("JOSH", foundKeyList.get(0).getKey());
+
+ foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "JOSH");
+ assertEquals("JOSH", foundKeyList.get(0).getKey());
+
+ foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "K");
+ assertEquals("K", foundKeyList.get(0).getKey());
+
+ foundKeyList = TreeMapUtils.findMatchingEntries(testTreeMap, "L");
+ assertEquals(0, foundKeyList.size());
+ }
+
+ @Test
+ public void testCompareMaps() {
+ Map<Integer, String> map1 = Map.of();
+ Map<Integer, String> map2 = Map.of();
+
+ // note: using TreeMap so we can control the ordering of the entries
+
+ // compare with self
+ assertThat(TreeMapUtils.compareMaps(map1, map1)).isZero();
+
+ // two empty maps
+ assertThat(TreeMapUtils.compareMaps(map1, map2)).isZero();
+
+ // same content
+ map1 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE3));
+ map2 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE3));
+ assertThat(TreeMapUtils.compareMaps(map1, map1)).isZero();
+ assertThat(TreeMapUtils.compareMaps(map1, map2)).isZero();
+
+ // one is shorter than the other
+ map1 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE3));
+ map2 = new TreeMap<>(Map.of(KEY1, VALUE1));
+ assertThat(TreeMapUtils.compareMaps(map1, map2)).isPositive();
+ assertThat(TreeMapUtils.compareMaps(map2, map1)).isNegative();
+
+ map2 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2));
+ assertThat(TreeMapUtils.compareMaps(map1, map2)).isPositive();
+ assertThat(TreeMapUtils.compareMaps(map2, map1)).isNegative();
+
+ // first key is different
+ map1 = new TreeMap<>(Map.of(KEY3, VALUE1, KEY2, VALUE2));
+ map2 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2));
+ assertThat(TreeMapUtils.compareMaps(map1, map2)).isPositive();
+ assertThat(TreeMapUtils.compareMaps(map2, map1)).isNegative();
+
+ // second key is different
+ map1 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY3, VALUE2));
+ map2 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2));
+ assertThat(TreeMapUtils.compareMaps(map1, map2)).isPositive();
+ assertThat(TreeMapUtils.compareMaps(map2, map1)).isNegative();
+
+ // first value is different
+ map1 = new TreeMap<>(Map.of(KEY1, VALUE4, KEY2, VALUE2, KEY3, VALUE3));
+ map2 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE3));
+ assertThat(TreeMapUtils.compareMaps(map1, map2)).isPositive();
+ assertThat(TreeMapUtils.compareMaps(map2, map1)).isNegative();
+
+ // second value is different
+ map1 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE4, KEY3, VALUE3));
+ map2 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE3));
+ assertThat(TreeMapUtils.compareMaps(map1, map2)).isPositive();
+ assertThat(TreeMapUtils.compareMaps(map2, map1)).isNegative();
+
+ // third value is different
+ map1 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE4));
+ map2 = new TreeMap<>(Map.of(KEY1, VALUE1, KEY2, VALUE2, KEY3, VALUE3));
+ assertThat(TreeMapUtils.compareMaps(map1, map2)).isPositive();
+ assertThat(TreeMapUtils.compareMaps(map2, map1)).isNegative();
+ }
+}
diff --git a/model/src/test/java/org/onap/policy/apex/model/utilities/json/JsonHandlerTest.java b/model/src/test/java/org/onap/policy/apex/model/utilities/json/JsonHandlerTest.java
new file mode 100644
index 000000000..ae5d53ec3
--- /dev/null
+++ b/model/src/test/java/org/onap/policy/apex/model/utilities/json/JsonHandlerTest.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.utilities.json;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.gson.GsonBuilder;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import org.junit.Test;
+
+public class JsonHandlerTest {
+
+ private static final String VALUE = "value";
+
+ @Test
+ public void testAssertions() throws IOException {
+ final OverTheMoonObject jsonObject = new OverTheMoonObject(VALUE);
+ final String jsonString = new GsonBuilder().create().toJson(jsonObject);
+
+ final byte[] bytes = jsonString.getBytes(StandardCharsets.UTF_8);
+ try (final InputStream inputStream = new ByteArrayInputStream(bytes);) {
+
+ final JsonHandler<OverTheMoonObject> objUnderTest = new JsonHandler<>();
+
+ final OverTheMoonObject actualObject = objUnderTest.read(OverTheMoonObject.class, inputStream);
+ assertEquals(VALUE, actualObject.name);
+ }
+
+ }
+
+ private class OverTheMoonObject {
+ private final String name;
+
+ public OverTheMoonObject(final String name) {
+ this.name = name;
+ }
+ }
+}
diff --git a/model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseKeys.txt b/model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseKeys.txt
new file mode 100644
index 000000000..4d00394b7
--- /dev/null
+++ b/model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseKeys.txt
@@ -0,0 +1,12 @@
+****** policy map differences ******
+*** context schema differences ***
+*** event differences ***
+*** context album differences ***
+*** task differences ***
+*** policy differences ***
+*** key information differences ***
+*** list of keys on left only
+key=AxArtifactKey:(name=LeftOnlyKeyInfo,version=0.0.1)
+*** list of keys on right only
+key=AxArtifactKey:(name=RightOnlyKeyInfo,version=0.0.1)
+***********************************
diff --git a/model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseValues.txt b/model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseValues.txt
new file mode 100644
index 000000000..82fecd990
--- /dev/null
+++ b/model/src/test/resources/checkFiles/PolicyModelComparisonDifferentTerseValues.txt
@@ -0,0 +1,12 @@
+****** policy map differences ******
+*** context schema differences ***
+*** event differences ***
+*** context album differences ***
+*** task differences ***
+*** policy differences ***
+*** key information differences ***
+*** list of keys on left only
+key=AxArtifactKey:(name=LeftOnlyKeyInfo,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=LeftOnlyKeyInfo,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6f000,description=Left only key info)
+*** list of keys on right only
+key=AxArtifactKey:(name=RightOnlyKeyInfo,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=RightOnlyKeyInfo,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6f001,description=Right only key info)
+***********************************
diff --git a/model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseKeys.txt b/model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseKeys.txt
new file mode 100644
index 000000000..38623c32a
--- /dev/null
+++ b/model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseKeys.txt
@@ -0,0 +1,70 @@
+****** policy map differences ******
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** context schema differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=MapType,version=0.0.1)
+key=AxArtifactKey:(name=StringType,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1)
+*** event differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=inEvent,version=0.0.1)
+key=AxArtifactKey:(name=outEvent0,version=0.0.1)
+key=AxArtifactKey:(name=outEvent1,version=0.0.1)
+*** context album differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1)
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1)
+*** task differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=task,version=0.0.1)
+*** policy differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=policy,version=0.0.1)
+*** key information differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** list of keys on left only
+key=AxArtifactKey:(name=LeftOnlyKeyInfo,version=0.0.1)
+*** list of keys on right only
+key=AxArtifactKey:(name=RightOnlyKeyInfo,version=0.0.1)
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=ContextSchemas,version=0.0.1)
+key=AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)
+key=AxArtifactKey:(name=MapType,version=0.0.1)
+key=AxArtifactKey:(name=PolicyModel,version=0.0.1)
+key=AxArtifactKey:(name=StringType,version=0.0.1)
+key=AxArtifactKey:(name=context,version=0.0.1)
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1)
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1)
+key=AxArtifactKey:(name=events,version=0.0.1)
+key=AxArtifactKey:(name=inEvent,version=0.0.1)
+key=AxArtifactKey:(name=outEvent0,version=0.0.1)
+key=AxArtifactKey:(name=outEvent1,version=0.0.1)
+key=AxArtifactKey:(name=policies,version=0.0.1)
+key=AxArtifactKey:(name=policy,version=0.0.1)
+key=AxArtifactKey:(name=task,version=0.0.1)
+key=AxArtifactKey:(name=tasks,version=0.0.1)
+*********************************** \ No newline at end of file
diff --git a/model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseValues.txt b/model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseValues.txt
new file mode 100644
index 000000000..53cadd979
--- /dev/null
+++ b/model/src/test/resources/checkFiles/PolicyModelComparisonDifferentVerboseValues.txt
@@ -0,0 +1,70 @@
+****** policy map differences ******
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** context schema differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=MapType,version=0.0.1),value=AxContextSchema(key=AxArtifactKey:(name=MapType,version=0.0.1), schemaFlavour=Java, schemaDefinition=org.onap.policy.apex.model.policymodel.concepts.TestContextItem00A)
+key=AxArtifactKey:(name=StringType,version=0.0.1),value=AxContextSchema(key=AxArtifactKey:(name=StringType,version=0.0.1), schemaFlavour=Java, schemaDefinition=org.onap.policy.apex.model.policymodel.concepts.TestContextItem000)
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1),value=AxContextSchema(key=AxArtifactKey:(name=eventContextItem0,version=0.0.1), schemaFlavour=Java, schemaDefinition=java.lang.String)
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1),value=AxContextSchema(key=AxArtifactKey:(name=eventContextItem1,version=0.0.1), schemaFlavour=Java, schemaDefinition=java.lang.Long)
+*** event differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=inEvent,version=0.0.1),value=AxEvent:(key=AxArtifactKey:(name=inEvent,version=0.0.1),nameSpace=org.onap.policy.apex.model.policymodel.events,source=Source,target=Target,parameter={IEPAR0=AxField:(key=AxReferenceKey:(parentKeyName=inEvent,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=IEPAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), IEPAR1=AxField:(key=AxReferenceKey:(parentKeyName=inEvent,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=IEPAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)},toscaPolicyState=)
+key=AxArtifactKey:(name=outEvent0,version=0.0.1),value=AxEvent:(key=AxArtifactKey:(name=outEvent0,version=0.0.1),nameSpace=org.onap.policy.apex.model.policymodel.events,source=Source,target=Target,parameter={OE0PAR0=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE0PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE0PAR1=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE0PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false), OE1PAR0=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE1PAR1=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)},toscaPolicyState=)
+key=AxArtifactKey:(name=outEvent1,version=0.0.1),value=AxEvent:(key=AxArtifactKey:(name=outEvent1,version=0.0.1),nameSpace=org.onap.policy.apex.model.policymodel.events,source=Source,target=Target,parameter={OE1PAR0=AxField:(key=AxReferenceKey:(parentKeyName=outEvent1,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE1PAR1=AxField:(key=AxReferenceKey:(parentKeyName=outEvent1,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)},toscaPolicyState=)
+*** context album differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1),value=AxContextAlbum(key=AxArtifactKey:(name=contextAlbum0,version=0.0.1), scope=APPLICATION, isWritable=true, itemSchema=AxArtifactKey:(name=MapType,version=0.0.1))
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1),value=AxContextAlbum(key=AxArtifactKey:(name=contextAlbum1,version=0.0.1), scope=GLOBAL, isWritable=false, itemSchema=AxArtifactKey:(name=StringType,version=0.0.1))
+*** task differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=task,version=0.0.1),value=AxTask:(key=AxArtifactKey:(name=task,version=0.0.1),taskParameters={taskParameter0=AxTaskParameter:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=taskParameter0),defaultValue=Task parameter 0 value), taskParameter1=AxTaskParameter:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=taskParameter1),defaultValue=Task parameter 1 value)},contextAlbumReferenceSet=[AxArtifactKey:(name=contextAlbum0,version=0.0.1), AxArtifactKey:(name=contextAlbum1,version=0.0.1)],taskLogic=AxTaskLogic:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=taskLogic),logicFlavour=MVEL,logic=Some task logic))
+*** policy differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=policy,version=0.0.1),value=AxPolicy:(key=AxArtifactKey:(name=policy,version=0.0.1),template=FREEFORM,stateMap={state=AxState:(stateKey=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=state),trigger=AxArtifactKey:(name=inEvent,version=0.0.1),stateOutputs={stateOutput0=AxStateOutput:(stateKey=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=stateOutput0),outgoingEvent=AxArtifactKey:(name=outEvent0,version=0.0.1),nextState=AxReferenceKey:(parentKeyName=NULL,parentKeyVersion=0.0.0,parentLocalName=NULL,localName=NULL))},contextAlbumReferenceSet=[AxArtifactKey:(name=contextAlbum0,version=0.0.1), AxArtifactKey:(name=contextAlbum1,version=0.0.1)],taskSelectionLogic=AxTaskSelectionLogic:(key=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=taskSelectionLogic),logicFlavour=MVEL,logic=Some TS logic),stateFinalizerLogicSet={},defaultTask=AxArtifactKey:(name=task,version=0.0.1),taskReferenceMap={AxArtifactKey:(name=task,version=0.0.1)=AxStateTaskReference:(stateKey=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=task),outputType=DIRECT,output=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=stateOutput0))})},firstState=state)
+*** key information differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** list of keys on left only
+key=AxArtifactKey:(name=LeftOnlyKeyInfo,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=LeftOnlyKeyInfo,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6f000,description=Left only key info)
+*** list of keys on right only
+key=AxArtifactKey:(name=RightOnlyKeyInfo,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=RightOnlyKeyInfo,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6f001,description=Right only key info)
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=ContextSchemas,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=ContextSchemas,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e000,description=Generated description for concept referred to by key "ContextSchemas:0.0.1")
+key=AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e001,description=Generated description for concept referred to by key "KeyInfoMapKey:0.0.1")
+key=AxArtifactKey:(name=MapType,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=MapType,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e002,description=Generated description for concept referred to by key "MapType:0.0.1")
+key=AxArtifactKey:(name=PolicyModel,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=PolicyModel,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e003,description=Generated description for concept referred to by key "PolicyModel:0.0.1")
+key=AxArtifactKey:(name=StringType,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=StringType,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e004,description=Generated description for concept referred to by key "StringType:0.0.1")
+key=AxArtifactKey:(name=context,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=context,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e005,description=Generated description for concept referred to by key "context:0.0.1")
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=contextAlbum0,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e006,description=Generated description for concept referred to by key "contextAlbum0:0.0.1")
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=contextAlbum1,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e007,description=Generated description for concept referred to by key "contextAlbum1:0.0.1")
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=eventContextItem0,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e008,description=Generated description for concept referred to by key "eventContextItem0:0.0.1")
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=eventContextItem1,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e009,description=Generated description for concept referred to by key "eventContextItem1:0.0.1")
+key=AxArtifactKey:(name=events,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=events,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e010,description=Generated description for concept referred to by key "events:0.0.1")
+key=AxArtifactKey:(name=inEvent,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=inEvent,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e011,description=Left InEvent Description)
+key=AxArtifactKey:(name=outEvent0,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=outEvent0,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e012,description=Generated description for concept referred to by key "outEvent0:0.0.1")
+key=AxArtifactKey:(name=outEvent1,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=outEvent1,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e013,description=Generated description for concept referred to by key "outEvent1:0.0.1")
+key=AxArtifactKey:(name=policies,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=policies,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e014,description=Generated description for concept referred to by key "policies:0.0.1")
+key=AxArtifactKey:(name=policy,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=policy,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e015,description=Generated description for concept referred to by key "policy:0.0.1")
+key=AxArtifactKey:(name=task,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=task,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e016,description=Generated description for concept referred to by key "task:0.0.1")
+key=AxArtifactKey:(name=tasks,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=tasks,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e017,description=Generated description for concept referred to by key "tasks:0.0.1")
+*********************************** \ No newline at end of file
diff --git a/model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt b/model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt
new file mode 100644
index 000000000..b9c0decdd
--- /dev/null
+++ b/model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalTerse.txt
@@ -0,0 +1,8 @@
+****** policy map differences ******
+*** context schema differences ***
+*** event differences ***
+*** context album differences ***
+*** task differences ***
+*** policy differences ***
+*** key information differences ***
+*********************************** \ No newline at end of file
diff --git a/model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseKeys.txt b/model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseKeys.txt
new file mode 100644
index 000000000..17862e1b1
--- /dev/null
+++ b/model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseKeys.txt
@@ -0,0 +1,69 @@
+****** policy map differences ******
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** context schema differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=MapType,version=0.0.1)
+key=AxArtifactKey:(name=StringType,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1)
+*** event differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=inEvent,version=0.0.1)
+key=AxArtifactKey:(name=outEvent0,version=0.0.1)
+key=AxArtifactKey:(name=outEvent1,version=0.0.1)
+*** context album differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1)
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1)
+*** task differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=task,version=0.0.1)
+*** policy differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=policy,version=0.0.1)
+*** key information differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=ContextSchemas,version=0.0.1)
+key=AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)
+key=AxArtifactKey:(name=MapType,version=0.0.1)
+key=AxArtifactKey:(name=PolicyModel,version=0.0.1)
+key=AxArtifactKey:(name=StringType,version=0.0.1)
+key=AxArtifactKey:(name=context,version=0.0.1)
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1)
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1)
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1)
+key=AxArtifactKey:(name=events,version=0.0.1)
+key=AxArtifactKey:(name=inEvent,version=0.0.1)
+key=AxArtifactKey:(name=outEvent0,version=0.0.1)
+key=AxArtifactKey:(name=outEvent1,version=0.0.1)
+key=AxArtifactKey:(name=policies,version=0.0.1)
+key=AxArtifactKey:(name=policy,version=0.0.1)
+key=AxArtifactKey:(name=task,version=0.0.1)
+key=AxArtifactKey:(name=tasks,version=0.0.1)
+***********************************
+
diff --git a/model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseValues.txt b/model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseValues.txt
new file mode 100644
index 000000000..4e07c5360
--- /dev/null
+++ b/model/src/test/resources/checkFiles/PolicyModelComparisonIdenticalVerboseValues.txt
@@ -0,0 +1,68 @@
+****** policy map differences ******
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** context schema differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=MapType,version=0.0.1),value=AxContextSchema(key=AxArtifactKey:(name=MapType,version=0.0.1),schemaFlavour=Java,schemaDefinition=org.onap.policy.apex.model.policymodel.concepts.TestContextItem00A)
+key=AxArtifactKey:(name=StringType,version=0.0.1),value=AxContextSchema(key=AxArtifactKey:(name=StringType,version=0.0.1),schemaFlavour=Java,schemaDefinition=org.onap.policy.apex.model.policymodel.concepts.TestContextItem000)
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1),value=AxContextSchema(key=AxArtifactKey:(name=eventContextItem0,version=0.0.1),schemaFlavour=Java,schemaDefinition=java.lang.String)
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1),value=AxContextSchema(key=AxArtifactKey:(name=eventContextItem1,version=0.0.1),schemaFlavour=Java,schemaDefinition=java.lang.Long)
+*** event differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=inEvent,version=0.0.1),value=AxEvent:(key=AxArtifactKey:(name=inEvent,version=0.0.1),nameSpace=org.onap.policy.apex.model.policymodel.events,source=Source,target=Target,parameter={IEPAR0=AxField:(key=AxReferenceKey:(parentKeyName=inEvent,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=IEPAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), IEPAR1=AxField:(key=AxReferenceKey:(parentKeyName=inEvent,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=IEPAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)},toscaPolicyState=)
+key=AxArtifactKey:(name=outEvent0,version=0.0.1),value=AxEvent:(key=AxArtifactKey:(name=outEvent0,version=0.0.1),nameSpace=org.onap.policy.apex.model.policymodel.events,source=Source,target=Target,parameter={OE0PAR0=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE0PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE0PAR1=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE0PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false), OE1PAR0=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE1PAR1=AxField:(key=AxReferenceKey:(parentKeyName=outEvent0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)},toscaPolicyState=)
+key=AxArtifactKey:(name=outEvent1,version=0.0.1),value=AxEvent:(key=AxArtifactKey:(name=outEvent1,version=0.0.1),nameSpace=org.onap.policy.apex.model.policymodel.events,source=Source,target=Target,parameter={OE1PAR0=AxField:(key=AxReferenceKey:(parentKeyName=outEvent1,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR0),fieldSchemaKey=AxArtifactKey:(name=eventContextItem0,version=0.0.1),optional=false), OE1PAR1=AxField:(key=AxReferenceKey:(parentKeyName=outEvent1,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=OE1PAR1),fieldSchemaKey=AxArtifactKey:(name=eventContextItem1,version=0.0.1),optional=false)},toscaPolicyState=)
+*** context album differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1),value=AxContextAlbum(key=AxArtifactKey:(name=contextAlbum0,version=0.0.1),scope=APPLICATION,isWritable=true,itemSchema=AxArtifactKey:(name=MapType,version=0.0.1))
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1),value=AxContextAlbum(key=AxArtifactKey:(name=contextAlbum1,version=0.0.1),scope=GLOBAL,isWritable=false,itemSchema=AxArtifactKey:(name=StringType,version=0.0.1))
+*** task differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=task,version=0.0.1),value=AxTask:(key=AxArtifactKey:(name=task,version=0.0.1),taskParameters={taskParameter0=AxTaskParameter:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=taskParameter0),defaultValue=Task parameter 0 value), taskParameter1=AxTaskParameter:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=taskParameter1),defaultValue=Task parameter 1 value)},contextAlbumReferenceSet=[AxArtifactKey:(name=contextAlbum0,version=0.0.1), AxArtifactKey:(name=contextAlbum1,version=0.0.1)],taskLogic=AxTaskLogic:(key=AxReferenceKey:(parentKeyName=task,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=taskLogic),logicFlavour=MVEL,logic=Some task logic))
+*** policy differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=policy,version=0.0.1),value=AxPolicy:(key=AxArtifactKey:(name=policy,version=0.0.1),template=FREEFORM,stateMap={state=AxState:(stateKey=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=state),trigger=AxArtifactKey:(name=inEvent,version=0.0.1),stateOutputs={stateOutput0=AxStateOutput:(stateKey=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=stateOutput0),outgoingEvent=AxArtifactKey:(name=outEvent0,version=0.0.1),nextState=AxReferenceKey:(parentKeyName=NULL,parentKeyVersion=0.0.0,parentLocalName=NULL,localName=NULL))},contextAlbumReferenceSet=[AxArtifactKey:(name=contextAlbum0,version=0.0.1), AxArtifactKey:(name=contextAlbum1,version=0.0.1)],taskSelectionLogic=AxTaskSelectionLogic:(key=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=taskSelectionLogic),logicFlavour=MVEL,logic=Some TS logic),stateFinalizerLogicSet={},defaultTask=AxArtifactKey:(name=task,version=0.0.1),taskReferenceMap={AxArtifactKey:(name=task,version=0.0.1)=AxStateTaskReference:(stateKey=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=task),outputType=DIRECT,output=AxReferenceKey:(parentKeyName=policy,parentKeyVersion=0.0.1,parentLocalName=state,localName=stateOutput0))})},firstState=state)
+*** key information differences ***
+left key AxArtifactKey:(name=PolicyModel,version=0.0.1) equals right key AxArtifactKey:(name=PolicyModel,version=0.0.1)
+*** all left keys in right
+*** all right keys in left
+*** all values in left and right are identical
+*** list of identical entries in left and right
+key=AxArtifactKey:(name=ContextSchemas,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=ContextSchemas,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e000,description=Generated description for concept referred to by key "ContextSchemas:0.0.1")
+key=AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e001,description=Generated description for concept referred to by key "KeyInfoMapKey:0.0.1")
+key=AxArtifactKey:(name=MapType,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=MapType,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e002,description=Generated description for concept referred to by key "MapType:0.0.1")
+key=AxArtifactKey:(name=PolicyModel,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=PolicyModel,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e003,description=Generated description for concept referred to by key "PolicyModel:0.0.1")
+key=AxArtifactKey:(name=StringType,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=StringType,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e004,description=Generated description for concept referred to by key "StringType:0.0.1")
+key=AxArtifactKey:(name=context,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=context,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e005,description=Generated description for concept referred to by key "context:0.0.1")
+key=AxArtifactKey:(name=contextAlbum0,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=contextAlbum0,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e006,description=Generated description for concept referred to by key "contextAlbum0:0.0.1")
+key=AxArtifactKey:(name=contextAlbum1,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=contextAlbum1,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e007,description=Generated description for concept referred to by key "contextAlbum1:0.0.1")
+key=AxArtifactKey:(name=eventContextItem0,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=eventContextItem0,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e008,description=Generated description for concept referred to by key "eventContextItem0:0.0.1")
+key=AxArtifactKey:(name=eventContextItem1,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=eventContextItem1,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e009,description=Generated description for concept referred to by key "eventContextItem1:0.0.1")
+key=AxArtifactKey:(name=events,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=events,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e010,description=Generated description for concept referred to by key "events:0.0.1")
+key=AxArtifactKey:(name=inEvent,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=inEvent,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e011,description=Generated description for concept referred to by key "inEvent:0.0.1")
+key=AxArtifactKey:(name=outEvent0,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=outEvent0,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e012,description=Generated description for concept referred to by key "outEvent0:0.0.1")
+key=AxArtifactKey:(name=outEvent1,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=outEvent1,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e013,description=Generated description for concept referred to by key "outEvent1:0.0.1")
+key=AxArtifactKey:(name=policies,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=policies,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e014,description=Generated description for concept referred to by key "policies:0.0.1")
+key=AxArtifactKey:(name=policy,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=policy,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e015,description=Generated description for concept referred to by key "policy:0.0.1")
+key=AxArtifactKey:(name=task,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=task,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e016,description=Generated description for concept referred to by key "task:0.0.1")
+key=AxArtifactKey:(name=tasks,version=0.0.1),value=AxKeyInfo:(artifactId=AxArtifactKey:(name=tasks,version=0.0.1),uuid=0ce9168c-e6df-414f-9646-6da464b6e017,description=Generated description for concept referred to by key "tasks:0.0.1")
+*********************************** \ No newline at end of file
diff --git a/model/src/test/resources/logback-test.xml b/model/src/test/resources/logback-test.xml
new file mode 100644
index 000000000..af4993550
--- /dev/null
+++ b/model/src/test/resources/logback-test.xml
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2016-2018 Ericsson. 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=========================================================
+-->
+
+<configuration>
+
+ <contextName>Apex</contextName>
+ <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
+ <property name="LOG_DIR" value="${java.io.tmpdir}/apex_logging/" />
+
+ <!-- USE FOR STD OUT ONLY -->
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
+ </encoder>
+ </appender>
+
+ <root level="INFO">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+ <logger name="org.infinispan" level="INFO" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="org.onap.policy.apex.core.contextmodel" level="INFO" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="org.apache.zookeeper.ClientCnxn" level="OFF" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="org.onap.policy.apex.core" level="INFO" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <file>${LOG_DIR}/apex.log</file>
+ <encoder>
+ <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level
+ %logger{26} - %msg %n %ex{full}</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="CTXT_FILE" class="ch.qos.logback.core.FileAppender">
+ <file>${LOG_DIR}/apex_ctxt.log</file>
+ <encoder>
+ <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level
+ %logger{26} - %msg %n %ex{full}</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="org.onap.policy.apex.core.context.impl.monitoring" level="INFO" additivity="false">
+ <appender-ref ref="CTXT_FILE" />
+ </logger>
+
+ <logger name="org.onap.policy.apex.core.context" level="INFO" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+</configuration>
diff --git a/model/src/test/resources/models/PolicyModel.json b/model/src/test/resources/models/PolicyModel.json
new file mode 100644
index 000000000..fbb91bb0b
--- /dev/null
+++ b/model/src/test/resources/models/PolicyModel.json
@@ -0,0 +1,775 @@
+{
+ "key": {
+ "name": "PolicyModel",
+ "version": "0.0.1"
+ },
+ "keyInformation": {
+ "key": {
+ "name": "KeyInfoMapKey",
+ "version": "0.0.1"
+ },
+ "keyInfoMap": {
+ "entry": [
+ {
+ "key": {
+ "name": "ContextSchemas",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "ContextSchemas",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e000",
+ "description": "Generated description for concept referred to by key \"ContextSchemas:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "KeyInfoMapKey",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "KeyInfoMapKey",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e001",
+ "description": "Generated description for concept referred to by key \"KeyInfoMapKey:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "MapType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "MapType",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e002",
+ "description": "Generated description for concept referred to by key \"MapType:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "PolicyModel",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "PolicyModel",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e003",
+ "description": "Generated description for concept referred to by key \"PolicyModel:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "StringType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "StringType",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e004",
+ "description": "Generated description for concept referred to by key \"StringType:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "context",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "context",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e005",
+ "description": "Generated description for concept referred to by key \"context:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "contextAlbum0",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "contextAlbum0",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e006",
+ "description": "Generated description for concept referred to by key \"contextAlbum0:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "contextAlbum1",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "contextAlbum1",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e007",
+ "description": "Generated description for concept referred to by key \"contextAlbum1:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "eventContextItem0",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "eventContextItem0",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e008",
+ "description": "Generated description for concept referred to by key \"eventContextItem0:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "eventContextItem1",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "eventContextItem1",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e009",
+ "description": "Generated description for concept referred to by key \"eventContextItem1:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "events",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "events",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e010",
+ "description": "Generated description for concept referred to by key \"events:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "inEvent",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "inEvent",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e011",
+ "description": "Generated description for concept referred to by key \"inEvent:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "outEvent0",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "outEvent0",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e012",
+ "description": "Generated description for concept referred to by key \"outEvent0:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "outEvent1",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "outEvent1",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e013",
+ "description": "Generated description for concept referred to by key \"outEvent1:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "policies",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "policies",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e014",
+ "description": "Generated description for concept referred to by key \"policies:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "policy",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "policy",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e015",
+ "description": "Generated description for concept referred to by key \"policy:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "task",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "task",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e016",
+ "description": "Generated description for concept referred to by key \"task:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "tasks",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "tasks",
+ "version": "0.0.1"
+ },
+ "UUID": "0ce9168c-e6df-414f-9646-6da464b6e017",
+ "description": "Generated description for concept referred to by key \"tasks:0.0.1\""
+ }
+ }
+ ]
+ }
+ },
+ "policies": {
+ "key": {
+ "name": "policies",
+ "version": "0.0.1"
+ },
+ "policyMap": {
+ "entry": [
+ {
+ "key": {
+ "name": "policy",
+ "version": "0.0.1"
+ },
+ "value": {
+ "policyKey": {
+ "name": "policy",
+ "version": "0.0.1"
+ },
+ "template": "FREEFORM",
+ "state": {
+ "entry": [
+ {
+ "key": "state",
+ "value": {
+ "stateKey": {
+ "parentKeyName": "policy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "state"
+ },
+ "trigger": {
+ "name": "inEvent",
+ "version": "0.0.1"
+ },
+ "stateOutputs": {
+ "entry": [
+ {
+ "key": "stateOutput0",
+ "value": {
+ "key": {
+ "parentKeyName": "policy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "state",
+ "localName": "stateOutput0"
+ },
+ "outgoingEvent": {
+ "name": "outEvent0",
+ "version": "0.0.1"
+ },
+ "nextState": {
+ "parentKeyName": "NULL",
+ "parentKeyVersion": "0.0.0",
+ "parentLocalName": "NULL",
+ "localName": "NULL"
+ }
+ }
+ }
+ ]
+ },
+ "contextAlbumReference": [
+ {
+ "name": "contextAlbum0",
+ "version": "0.0.1"
+ },
+ {
+ "name": "contextAlbum1",
+ "version": "0.0.1"
+ }
+ ],
+ "taskSelectionLogic": {
+ "key": "taskSelectionLogic",
+ "logicFlavour": "MVEL",
+ "logic": "Some TS logic"
+ },
+ "stateFinalizerLogicMap": {
+ "entry": []
+ },
+ "defaultTask": {
+ "name": "task",
+ "version": "0.0.1"
+ },
+ "taskReferences": {
+ "entry": [
+ {
+ "key": {
+ "name": "task",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "parentKeyName": "policy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "state",
+ "localName": "task"
+ },
+ "outputType": "DIRECT",
+ "output": {
+ "parentKeyName": "policy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "state",
+ "localName": "stateOutput0"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "firstState": "state"
+ }
+ }
+ ]
+ }
+ },
+ "tasks": {
+ "key": {
+ "name": "tasks",
+ "version": "0.0.1"
+ },
+ "taskMap": {
+ "entry": [
+ {
+ "key": {
+ "name": "task",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "task",
+ "version": "0.0.1"
+ },
+ "inputFields": {
+ "entry": [
+ {
+ "key": "IEPAR0",
+ "value": {
+ "key": "IEPAR0",
+ "fieldSchemaKey": {
+ "name": "eventContextItem0",
+ "version": "0.0.1"
+ }
+ }
+ },
+ {
+ "key": "IEPAR1",
+ "value": {
+ "key": "IEPAR1",
+ "fieldSchemaKey": {
+ "name": "eventContextItem1",
+ "version": "0.0.1"
+ }
+ }
+ }
+ ]
+ },
+ "outputFields": {
+ "entry": [
+ {
+ "key": "OE0PAR0",
+ "value": {
+ "key": "OE0PAR0",
+ "fieldSchemaKey": {
+ "name": "eventContextItem0",
+ "version": "0.0.1"
+ }
+ }
+ },
+ {
+ "key": "OE0PAR1",
+ "value": {
+ "key": "OE0PAR1",
+ "fieldSchemaKey": {
+ "name": "eventContextItem1",
+ "version": "0.0.1"
+ }
+ }
+ },
+ {
+ "key": "OE1PAR0",
+ "value": {
+ "key": "OE1PAR0",
+ "fieldSchemaKey": {
+ "name": "eventContextItem0",
+ "version": "0.0.1"
+ }
+ }
+ },
+ {
+ "key": "OE1PAR1",
+ "value": {
+ "key": "OE1PAR1",
+ "fieldSchemaKey": {
+ "name": "eventContextItem1",
+ "version": "0.0.1"
+ }
+ }
+ }
+ ]
+ },
+ "taskParameters": {
+ "entry": [
+ {
+ "key": "taskParameter0",
+ "value": {
+ "key": {
+ "parentKeyName": "task",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "taskParameter0"
+ },
+ "defaultValue": "Task parameter 0 value"
+ }
+ },
+ {
+ "key": "taskParameter1",
+ "value": {
+ "key": {
+ "parentKeyName": "task",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "taskParameter1"
+ },
+ "defaultValue": "Task parameter 1 value"
+ }
+ }
+ ]
+ },
+ "contextAlbumReference": [
+ {
+ "name": "contextAlbum0",
+ "version": "0.0.1"
+ },
+ {
+ "name": "contextAlbum1",
+ "version": "0.0.1"
+ }
+ ],
+ "taskLogic": {
+ "key": "taskLogic",
+ "logicFlavour": "MVEL",
+ "logic": "Some task logic"
+ }
+ }
+ }
+ ]
+ }
+ },
+ "events": {
+ "key": {
+ "name": "events",
+ "version": "0.0.1"
+ },
+ "eventMap": {
+ "entry": [
+ {
+ "key": {
+ "name": "inEvent",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "inEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.model.policymodel.events",
+ "source": "Source",
+ "target": "Target",
+ "parameter": {
+ "entry": [
+ {
+ "key": "IEPAR0",
+ "value": {
+ "key": "IEPAR0",
+ "fieldSchemaKey": {
+ "name": "eventContextItem0",
+ "version": "0.0.1"
+ }
+ }
+ },
+ {
+ "key": "IEPAR1",
+ "value": {
+ "key": "IEPAR1",
+ "fieldSchemaKey": {
+ "name": "eventContextItem1",
+ "version": "0.0.1"
+ }
+ }
+ }
+ ]
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "outEvent0",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "outEvent0",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.model.policymodel.events",
+ "source": "Source",
+ "target": "Target",
+ "parameter": {
+ "entry": [
+ {
+ "key": "OE0PAR0",
+ "value": {
+ "key": "OE0PAR0",
+ "fieldSchemaKey": {
+ "name": "eventContextItem0",
+ "version": "0.0.1"
+ }
+ }
+ },
+ {
+ "key": "OE0PAR1",
+ "value": {
+ "key": "OE0PAR1",
+ "fieldSchemaKey": {
+ "name": "eventContextItem1",
+ "version": "0.0.1"
+ }
+ }
+ },
+ {
+ "key": "OE1PAR0",
+ "value": {
+ "key": "OE1PAR0",
+ "fieldSchemaKey": {
+ "name": "eventContextItem0",
+ "version": "0.0.1"
+ }
+ }
+ },
+ {
+ "key": "OE1PAR1",
+ "value": {
+ "key": "OE1PAR1",
+ "fieldSchemaKey": {
+ "name": "eventContextItem1",
+ "version": "0.0.1"
+ }
+ }
+ }
+ ]
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "outEvent1",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "outEvent1",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.model.policymodel.events",
+ "source": "Source",
+ "target": "Target",
+ "parameter": {
+ "entry": [
+ {
+ "key": "OE1PAR0",
+ "value": {
+ "key": "OE1PAR0",
+ "fieldSchemaKey": {
+ "name": "eventContextItem0",
+ "version": "0.0.1"
+ }
+ }
+ },
+ {
+ "key": "OE1PAR1",
+ "value": {
+ "key": "OE1PAR1",
+ "fieldSchemaKey": {
+ "name": "eventContextItem1",
+ "version": "0.0.1"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ ]
+ }
+ },
+ "albums": {
+ "key": {
+ "name": "context",
+ "version": "0.0.1"
+ },
+ "albums": {
+ "entry": [
+ {
+ "key": {
+ "name": "contextAlbum0",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "contextAlbum0",
+ "version": "0.0.1"
+ },
+ "scope": "APPLICATION",
+ "isWritable": true,
+ "itemSchema": {
+ "name": "MapType",
+ "version": "0.0.1"
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "contextAlbum1",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "contextAlbum1",
+ "version": "0.0.1"
+ },
+ "scope": "GLOBAL",
+ "isWritable": false,
+ "itemSchema": {
+ "name": "StringType",
+ "version": "0.0.1"
+ }
+ }
+ }
+ ]
+ }
+ },
+ "schemas": {
+ "key": {
+ "name": "ContextSchemas",
+ "version": "0.0.1"
+ },
+ "schemas": {
+ "entry": [
+ {
+ "key": {
+ "name": "MapType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "MapType",
+ "version": "0.0.1"
+ },
+ "schemaFlavour": "Java",
+ "schemaDefinition": "org.onap.policy.apex.model.policymodel.concepts.TestContextItem00A"
+ }
+ },
+ {
+ "key": {
+ "name": "StringType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "StringType",
+ "version": "0.0.1"
+ },
+ "schemaFlavour": "Java",
+ "schemaDefinition": "org.onap.policy.apex.model.policymodel.concepts.TestContextItem000"
+ }
+ },
+ {
+ "key": {
+ "name": "eventContextItem0",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "eventContextItem0",
+ "version": "0.0.1"
+ },
+ "schemaFlavour": "Java",
+ "schemaDefinition": "java.lang.String"
+ }
+ },
+ {
+ "key": {
+ "name": "eventContextItem1",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "eventContextItem1",
+ "version": "0.0.1"
+ },
+ "schemaFlavour": "Java",
+ "schemaDefinition": "java.lang.Long"
+ }
+ }
+ ]
+ }
+ }
+}
diff --git a/model/src/test/resources/models/PolicyModel.junk b/model/src/test/resources/models/PolicyModel.junk
new file mode 100644
index 000000000..613a36ad8
--- /dev/null
+++ b/model/src/test/resources/models/PolicyModel.junk
@@ -0,0 +1,9 @@
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse cursus suscipit faucibus. Pellentesque sagittis, erat placerat ultricies maximus, erat nulla efficitur ex, quis hendrerit tellus urna quis libero. Nullam vitae nisl ut nisl condimentum suscipit. Aenean sagittis condimentum nisi quis condimentum. Suspendisse potenti. Aliquam eget purus a risus viverra volutpat eu eu neque. Phasellus in libero id turpis lobortis malesuada. Praesent dignissim tellus imperdiet faucibus interdum. Donec volutpat, eros non lobortis consectetur, felis arcu consequat purus, a pharetra velit nisi at ante. Etiam ut sem imperdiet justo aliquet tempus at ornare quam.
+
+Integer sed maximus tellus. Nulla venenatis congue massa nec vestibulum. Duis ultrices quis neque ultrices semper. Morbi rhoncus gravida nibh, ut consequat ex. Proin eget ex vel lectus luctus varius. Integer nec consectetur ante. Cras ac aliquam nibh, in fermentum metus. Praesent nec ipsum tristique, ultrices arcu vel, bibendum libero. Curabitur ac odio eget felis blandit accumsan viverra vitae nibh. Integer efficitur eros lectus, et convallis elit consectetur nec. Vivamus tellus sem, vestibulum ut faucibus ut, maximus nec nulla. Donec ex eros, tempus ac justo at, posuere finibus purus. Pellentesque lacinia eu eros nec dignissim. Vestibulum tempus lectus in placerat imperdiet. Sed a diam vitae lorem gravida commodo.
+
+Sed at dolor felis. Ut at luctus libero. Ut faucibus elementum sem. Praesent aliquet tempus magna, eget bibendum nisi ultricies eu. Aenean dictum libero dui, et finibus metus consequat sed. Nullam lobortis diam ut sem imperdiet, nec posuere mauris aliquet. Etiam nec laoreet leo. Vestibulum nec turpis ante. Vivamus imperdiet commodo velit in ultricies. Maecenas facilisis maximus odio vel vestibulum.
+
+Aenean dapibus mi eget eros sodales rhoncus. Mauris dolor mi, feugiat quis egestas id, vestibulum at augue. Vivamus sit amet enim metus. Donec nec ultricies felis. Phasellus aliquam urna lectus, mollis rutrum libero ornare nec. Quisque dictum ante ac dapibus placerat. Ut euismod euismod elit eget commodo. Aenean vestibulum tempus elit quis vestibulum. Integer dapibus ultricies bibendum. Vivamus iaculis egestas magna, a ornare lacus eleifend eu. Fusce non massa ut sapien volutpat molestie vel sit amet sapien. Phasellus hendrerit felis magna, quis pharetra dui finibus sed. Praesent quis accumsan purus, hendrerit viverra felis. Pellentesque semper pretium nisl, in auctor enim interdum ut. Nullam placerat erat vel lacus vestibulum vehicula. Morbi at augue in enim luctus feugiat.
+
+Nunc aliquam auctor turpis id pretium. Donec placerat egestas tortor quis blandit. Curabitur sagittis elit eu varius gravida. Fusce eget diam eu sapien convallis pellentesque. Donec ultrices odio id leo pellentesque, eget tempus erat efficitur. Pellentesque ac ultricies purus, ut condimentum libero. Pellentesque pulvinar urna vel sollicitudin commodo. Sed tincidunt sed nulla sed auctor. \ No newline at end of file
diff --git a/model/src/test/resources/models/RealPolicyModel.json b/model/src/test/resources/models/RealPolicyModel.json
new file mode 100644
index 000000000..f084747f2
--- /dev/null
+++ b/model/src/test/resources/models/RealPolicyModel.json
@@ -0,0 +1,3076 @@
+{
+ "key": {
+ "name": "ONAPvCPEPolicyModel",
+ "version": "0.0.1"
+ },
+ "keyInformation": {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_KeyInfo",
+ "version": "0.0.1"
+ },
+ "keyInfoMap": {
+ "entry": [
+ {
+ "key": {
+ "name": "AAILookupTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "AAILookupTask",
+ "version": "0.0.1"
+ },
+ "UUID": "bc77813f-e2fa-33e0-aef0-c5b6a8832698",
+ "description": "Generated description for concept referred to by key \"AAILookupTask:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "APPCLCMRequestType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "APPCLCMRequestType",
+ "version": "0.0.1"
+ },
+ "UUID": "ab26e475-d09d-36cd-a65c-8a8b556f0fa2",
+ "description": "Generated description for concept referred to by key \"APPCLCMRequestType:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "APPCLCMResponseType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "APPCLCMResponseType",
+ "version": "0.0.1"
+ },
+ "UUID": "a60b42bb-c308-30ea-be59-5bc54864508b",
+ "description": "Generated description for concept referred to by key \"APPCLCMResponseType:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "APPCRestartVNFRequestEvent",
+ "version": "2.0.0"
+ },
+ "value": {
+ "key": {
+ "name": "APPCRestartVNFRequestEvent",
+ "version": "2.0.0"
+ },
+ "UUID": "0b16f8d9-6ee9-30d7-bcd2-e4ded9fccf9b",
+ "description": "Generated description for concept referred to by key \"APPCRestartVNFRequestEvent:2.0.0\""
+ }
+ },
+ {
+ "key": {
+ "name": "APPCRestartVNFRequestTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "APPCRestartVNFRequestTask",
+ "version": "0.0.1"
+ },
+ "UUID": "719ae90e-ab01-322e-ace3-8c379e7c1fbf",
+ "description": "Generated description for concept referred to by key \"APPCRestartVNFRequestTask:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "APPCRestartVNFResponseEvent",
+ "version": "2.0.0"
+ },
+ "value": {
+ "key": {
+ "name": "APPCRestartVNFResponseEvent",
+ "version": "2.0.0"
+ },
+ "UUID": "7034c5a9-2ea7-3e9e-9ccf-3610c3bf80d9",
+ "description": "Generated description for concept referred to by key \"APPCRestartVNFResponseEvent:2.0.0\""
+ }
+ },
+ {
+ "key": {
+ "name": "APPCRestartVNFResponseTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "APPCRestartVNFResponseTask",
+ "version": "0.0.1"
+ },
+ "UUID": "fe641fd9-6583-37c5-b317-2a33a3ca5ac7",
+ "description": "Generated description for concept referred to by key \"APPCRestartVNFResponseTask:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "AbatedTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "AbatedTask",
+ "version": "0.0.1"
+ },
+ "UUID": "0eb3974f-4fdc-3c90-b351-34e7e18ff1ab",
+ "description": "Generated description for concept referred to by key \"AbatedTask:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e",
+ "version": "1.0.2"
+ },
+ "value": {
+ "key": {
+ "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e",
+ "version": "1.0.2"
+ },
+ "UUID": "63ff5c25-f245-37e9-a580-6ac274ced3a7",
+ "description": "Generated description for concept referred to by key \"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e:1.0.2\""
+ }
+ },
+ {
+ "key": {
+ "name": "ControlLoopExecutionIDAlbum",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "ControlLoopExecutionIDAlbum",
+ "version": "0.0.1"
+ },
+ "UUID": "5b2bc0cf-0807-3ab1-9004-f21806d800f0",
+ "description": "Generated description for concept referred to by key \"ControlLoopExecutionIDAlbum:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "ControlLoopLogEvent",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "ControlLoopLogEvent",
+ "version": "0.0.1"
+ },
+ "UUID": "ed8a82ad-52c2-3d58-8c08-601606894b86",
+ "description": "Generated description for concept referred to by key \"ControlLoopLogEvent:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "ControlLoopLogTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "ControlLoopLogTask",
+ "version": "0.0.1"
+ },
+ "UUID": "1b175691-6b5d-31f6-bf2d-4be95a01f92e",
+ "description": "Generated description for concept referred to by key \"ControlLoopLogTask:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "DeniedTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "DeniedTask",
+ "version": "0.0.1"
+ },
+ "UUID": "00142e3c-ee3b-323f-9490-6e4b7f34b09f",
+ "description": "Generated description for concept referred to by key \"DeniedTask:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "GetVCPEStateTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "GetVCPEStateTask",
+ "version": "0.0.1"
+ },
+ "UUID": "644d2a3d-0f3a-3664-8000-280c400a5cc1",
+ "description": "Generated description for concept referred to by key \"GetVCPEStateTask:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "GuardDecisionAttributesType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "GuardDecisionAttributesType",
+ "version": "0.0.1"
+ },
+ "UUID": "5f6dff51-c183-322f-9aba-c6074aa0ece5",
+ "description": "Generated description for concept referred to by key \"GuardDecisionAttributesType:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "GuardRequestEvent",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "GuardRequestEvent",
+ "version": "0.0.1"
+ },
+ "UUID": "fb383a58-715b-3972-a3e6-38010a8de234",
+ "description": "Generated description for concept referred to by key \"GuardRequestEvent:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "GuardRequestTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "GuardRequestTask",
+ "version": "0.0.1"
+ },
+ "UUID": "0427d63c-da78-334c-a5bd-95fbbb162398",
+ "description": "Generated description for concept referred to by key \"GuardRequestTask:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "GuardResponseEvent",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "GuardResponseEvent",
+ "version": "0.0.1"
+ },
+ "UUID": "395f6d46-cf24-3d3e-b1fd-1a189a58993d",
+ "description": "Generated description for concept referred to by key \"GuardResponseEvent:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "GuardResponseTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "GuardResponseTask",
+ "version": "0.0.1"
+ },
+ "UUID": "1a8b3f30-a7aa-330b-8131-4aea06ad6934",
+ "description": "Generated description for concept referred to by key \"GuardResponseTask:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "NoAAILookupTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "NoAAILookupTask",
+ "version": "0.0.1"
+ },
+ "UUID": "648bc8f9-ad2b-3a1b-abe2-89401645f191",
+ "description": "Generated description for concept referred to by key \"NoAAILookupTask:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "ONAPvCPEPolicyModel",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "ONAPvCPEPolicyModel",
+ "version": "0.0.1"
+ },
+ "UUID": "cf1aa7f4-6fe3-3cba-90b4-49dcf46f0d57",
+ "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_Albums",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_Albums",
+ "version": "0.0.1"
+ },
+ "UUID": "13f8471b-2b9c-32e0-940b-fe640ea442cf",
+ "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_Albums:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_Events",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_Events",
+ "version": "0.0.1"
+ },
+ "UUID": "4b8e6653-731d-38c5-a195-0cadf533a7a1",
+ "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_Events:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_KeyInfo",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_KeyInfo",
+ "version": "0.0.1"
+ },
+ "UUID": "87a9d6da-7d4b-3041-8a70-49442750d590",
+ "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_KeyInfo:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_Policies",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_Policies",
+ "version": "0.0.1"
+ },
+ "UUID": "6220cca4-66f5-3d1b-9f19-688a9b4b70f5",
+ "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_Policies:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_Schemas",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_Schemas",
+ "version": "0.0.1"
+ },
+ "UUID": "3df4eef8-e764-3398-afe9-86730e20905a",
+ "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_Schemas:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_Tasks",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_Tasks",
+ "version": "0.0.1"
+ },
+ "UUID": "1781b875-a3e8-3407-98bd-ba9580cfc543",
+ "description": "Generated description for concept referred to by key \"ONAPvCPEPolicyModel_Tasks:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "ReceiveEventPolicy",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "ReceiveEventPolicy",
+ "version": "0.0.1"
+ },
+ "UUID": "568b7345-9de1-36d3-b6a3-9b857e6809a1",
+ "description": "Generated description for concept referred to by key \"ReceiveEventPolicy:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "RequestIDVNFIDAlbum",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "RequestIDVNFIDAlbum",
+ "version": "0.0.1"
+ },
+ "UUID": "5d8e8298-ded6-30a5-9825-48111dc17a58",
+ "description": "Generated description for concept referred to by key \"RequestIDVNFIDAlbum:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "RestartAPPCRequestPolicy",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "RestartAPPCRequestPolicy",
+ "version": "0.0.1"
+ },
+ "UUID": "33d02162-314b-352b-b8b9-2862e8883894",
+ "description": "Generated description for concept referred to by key \"RestartAPPCRequestPolicy:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "RestartAPPCResponsePolicy",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "RestartAPPCResponsePolicy",
+ "version": "0.0.1"
+ },
+ "UUID": "ef4fcbd2-1609-377c-9875-8d27f7a901df",
+ "description": "Generated description for concept referred to by key \"RestartAPPCResponsePolicy:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "SimpleBooleanType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "SimpleBooleanType",
+ "version": "0.0.1"
+ },
+ "UUID": "7218fb2f-59e3-321d-9ae1-bc97b19eb4ae",
+ "description": "Generated description for concept referred to by key \"SimpleBooleanType:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "SimpleLongType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "SimpleLongType",
+ "version": "0.0.1"
+ },
+ "UUID": "2dfcd9ec-a6f9-3f9f-958f-9b36cf4ac574",
+ "description": "Generated description for concept referred to by key \"SimpleLongType:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "UUID": "8a4957cf-9493-3a76-8c22-a208e23259af",
+ "description": "Generated description for concept referred to by key \"SimpleStringType:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "UUID": "6a8cc68e-dfc8-3403-9c6d-071c886b319c",
+ "description": "Generated description for concept referred to by key \"UUIDType:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ },
+ "UUID": "47a4403e-3074-3964-83ef-93eefaffd192",
+ "description": "Generated description for concept referred to by key \"VCPEClosedLoopStatusAlbum:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "VCPEClosedLoopStatusType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "VCPEClosedLoopStatusType",
+ "version": "0.0.1"
+ },
+ "UUID": "6e7dced1-53f1-39e2-b4e6-412b75d5b9e6",
+ "description": "Generated description for concept referred to by key \"VCPEClosedLoopStatusType:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "UUID": "5e56a3fd-f82a-3ced-821b-b9fbaf65d367",
+ "description": "Generated description for concept referred to by key \"VCPEStateUpdatedEvent:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "VirtualControlLoopEventType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "VirtualControlLoopEventType",
+ "version": "0.0.1"
+ },
+ "UUID": "15aca887-8f6c-3713-8114-0f49f03adab7",
+ "description": "Generated description for concept referred to by key \"VirtualControlLoopEventType:0.0.1\""
+ }
+ },
+ {
+ "key": {
+ "name": "VirtualControlLoopNotificationType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "VirtualControlLoopNotificationType",
+ "version": "0.0.1"
+ },
+ "UUID": "283f5b0d-d8cd-31b0-91fa-89b9de2e1fda",
+ "description": "Generated description for concept referred to by key \"VirtualControlLoopNotificationType:0.0.1\""
+ }
+ }
+ ]
+ }
+ },
+ "policies": {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_Policies",
+ "version": "0.0.1"
+ },
+ "policyMap": {
+ "entry": [
+ {
+ "key": {
+ "name": "ReceiveEventPolicy",
+ "version": "0.0.1"
+ },
+ "value": {
+ "policyKey": {
+ "name": "ReceiveEventPolicy",
+ "version": "0.0.1"
+ },
+ "template": "Freestyle",
+ "state": {
+ "entry": [
+ {
+ "key": "AbatedState",
+ "value": {
+ "stateKey": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "AbatedState"
+ },
+ "trigger": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "stateOutputs": {
+ "entry": [
+ {
+ "key": "AbatedOutput",
+ "value": {
+ "key": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "AbatedState",
+ "localName": "AbatedOutput"
+ },
+ "outgoingEvent": {
+ "name": "ControlLoopLogEvent",
+ "version": "0.0.1"
+ },
+ "outgoingEventReference": [
+ {
+ "name": "ControlLoopLogEvent",
+ "version": "0.0.1"
+ }
+ ],
+ "nextState": {
+ "parentKeyName": "NULL",
+ "parentKeyVersion": "0.0.0",
+ "parentLocalName": "NULL",
+ "localName": "NULL"
+ }
+ }
+ }
+ ]
+ },
+ "contextAlbumReference": [],
+ "taskSelectionLogic": {
+ "key": "NULL",
+ "logicFlavour": "UNDEFINED",
+ "logic": ""
+ },
+ "stateFinalizerLogicMap": {
+ "entry": []
+ },
+ "defaultTask": {
+ "name": "ControlLoopLogTask",
+ "version": "0.0.1"
+ },
+ "taskReferences": {
+ "entry": [
+ {
+ "key": {
+ "name": "ControlLoopLogTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "AbatedState",
+ "localName": "ReceiveEventPolicy"
+ },
+ "outputType": "DIRECT",
+ "output": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "AbatedState",
+ "localName": "AbatedOutput"
+ }
+ }
+ }
+ ]
+ }
+ }
+ },
+ {
+ "key": "GetVCPEState",
+ "value": {
+ "stateKey": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "GetVCPEState"
+ },
+ "trigger": {
+ "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e",
+ "version": "1.0.2"
+ },
+ "stateOutputs": {
+ "entry": [
+ {
+ "key": "GetVCPEStateOutput",
+ "value": {
+ "key": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "GetVCPEState",
+ "localName": "GetVCPEStateOutput"
+ },
+ "outgoingEvent": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "outgoingEventReference": [
+ {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ }
+ ],
+ "nextState": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "RequestAAIState"
+ }
+ }
+ }
+ ]
+ },
+ "contextAlbumReference": [],
+ "taskSelectionLogic": {
+ "key": "NULL",
+ "logicFlavour": "UNDEFINED",
+ "logic": ""
+ },
+ "stateFinalizerLogicMap": {
+ "entry": []
+ },
+ "defaultTask": {
+ "name": "GetVCPEStateTask",
+ "version": "0.0.1"
+ },
+ "taskReferences": {
+ "entry": [
+ {
+ "key": {
+ "name": "GetVCPEStateTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "GetVCPEState",
+ "localName": "ReceiveEventPolicy"
+ },
+ "outputType": "DIRECT",
+ "output": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "GetVCPEState",
+ "localName": "GetVCPEStateOutput"
+ }
+ }
+ }
+ ]
+ }
+ }
+ },
+ {
+ "key": "OnsetOrAbatedState",
+ "value": {
+ "stateKey": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "OnsetOrAbatedState"
+ },
+ "trigger": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "stateOutputs": {
+ "entry": [
+ {
+ "key": "AbatedOutput",
+ "value": {
+ "key": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "OnsetOrAbatedState",
+ "localName": "AbatedOutput"
+ },
+ "outgoingEvent": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "outgoingEventReference": [
+ {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ }
+ ],
+ "nextState": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "AbatedState"
+ }
+ }
+ },
+ {
+ "key": "OnsetOutput",
+ "value": {
+ "key": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "OnsetOrAbatedState",
+ "localName": "OnsetOutput"
+ },
+ "outgoingEvent": {
+ "name": "GuardRequestEvent",
+ "version": "0.0.1"
+ },
+ "outgoingEventReference": [
+ {
+ "name": "GuardRequestEvent",
+ "version": "0.0.1"
+ }
+ ],
+ "nextState": {
+ "parentKeyName": "NULL",
+ "parentKeyVersion": "0.0.0",
+ "parentLocalName": "NULL",
+ "localName": "NULL"
+ }
+ }
+ }
+ ]
+ },
+ "contextAlbumReference": [
+ {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ }
+ ],
+ "taskSelectionLogic": {
+ "key": "TaskSelectionLogic",
+ "logicFlavour": "JAVASCRIPT",
+ "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar returnValue = true;\nvar status = null;\n\nif( executor.inFields.get(\"vnfID\") == null) {\n executor.logger.info(\"OnsetOrAbatedStateTSL: vnfID is null\");\n var vnfName = executor.inFields.get(\"vnfName\");\n var vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfName\"));\n status = vcpeClosedLoopStatus.get(\"closedLoopEventStatus\").toString();\n} else {\n var vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n status = vcpeClosedLoopStatus.get(\"closedLoopEventStatus\").toString();\n}\n\nif (status == \"ONSET\") {\n executor.subject.getTaskKey(\"GuardRequestTask\").copyTo(executor.selectedTask);\n} else if (status == \"ABATED\") {\n executor.subject.getTaskKey(\"AbatedTask\").copyTo(executor.selectedTask);\n onsetFlag = executor.isFalse;\n} else {\n executor.message = \"closedLoopEventStatus is \\\"\" + status + \"\\\", it must be either \\\"ONSET\\\" or \\\"ABATED\\\"\";\n returnValue = false;\n}\n\nexecutor.logger.info(\"ReceiveEventPolicyOnsetOrAbatedStateTSL State Selected Task:\" + executor.selectedTask);\n\nreturnValue;"
+ },
+ "stateFinalizerLogicMap": {
+ "entry": []
+ },
+ "defaultTask": {
+ "name": "AbatedTask",
+ "version": "0.0.1"
+ },
+ "taskReferences": {
+ "entry": [
+ {
+ "key": {
+ "name": "AbatedTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "OnsetOrAbatedState",
+ "localName": "ReceiveEventPolicy"
+ },
+ "outputType": "DIRECT",
+ "output": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "OnsetOrAbatedState",
+ "localName": "AbatedOutput"
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "GuardRequestTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "OnsetOrAbatedState",
+ "localName": "ReceiveEventPolicy"
+ },
+ "outputType": "DIRECT",
+ "output": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "OnsetOrAbatedState",
+ "localName": "OnsetOutput"
+ }
+ }
+ }
+ ]
+ }
+ }
+ },
+ {
+ "key": "RequestAAIState",
+ "value": {
+ "stateKey": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "RequestAAIState"
+ },
+ "trigger": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "stateOutputs": {
+ "entry": [
+ {
+ "key": "RequestAAIStateOutput",
+ "value": {
+ "key": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "RequestAAIState",
+ "localName": "RequestAAIStateOutput"
+ },
+ "outgoingEvent": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "outgoingEventReference": [
+ {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ }
+ ],
+ "nextState": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "OnsetOrAbatedState"
+ }
+ }
+ }
+ ]
+ },
+ "contextAlbumReference": [
+ {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ }
+ ],
+ "taskSelectionLogic": {
+ "key": "NULL",
+ "logicFlavour": "UNDEFINED",
+ "logic": ""
+ },
+ "stateFinalizerLogicMap": {
+ "entry": []
+ },
+ "defaultTask": {
+ "name": "AAILookupTask",
+ "version": "0.0.1"
+ },
+ "taskReferences": {
+ "entry": [
+ {
+ "key": {
+ "name": "AAILookupTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "RequestAAIState",
+ "localName": "ReceiveEventPolicy"
+ },
+ "outputType": "DIRECT",
+ "output": {
+ "parentKeyName": "ReceiveEventPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "RequestAAIState",
+ "localName": "RequestAAIStateOutput"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "firstState": "GetVCPEState"
+ }
+ },
+ {
+ "key": {
+ "name": "RestartAPPCRequestPolicy",
+ "version": "0.0.1"
+ },
+ "value": {
+ "policyKey": {
+ "name": "RestartAPPCRequestPolicy",
+ "version": "0.0.1"
+ },
+ "template": "Freestyle",
+ "state": {
+ "entry": [
+ {
+ "key": "DeniedState",
+ "value": {
+ "stateKey": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "DeniedState"
+ },
+ "trigger": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "stateOutputs": {
+ "entry": [
+ {
+ "key": "DeniedOutput",
+ "value": {
+ "key": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "DeniedState",
+ "localName": "DeniedOutput"
+ },
+ "outgoingEvent": {
+ "name": "ControlLoopLogEvent",
+ "version": "0.0.1"
+ },
+ "outgoingEventReference": [
+ {
+ "name": "ControlLoopLogEvent",
+ "version": "0.0.1"
+ }
+ ],
+ "nextState": {
+ "parentKeyName": "NULL",
+ "parentKeyVersion": "0.0.0",
+ "parentLocalName": "NULL",
+ "localName": "NULL"
+ }
+ }
+ }
+ ]
+ },
+ "contextAlbumReference": [],
+ "taskSelectionLogic": {
+ "key": "NULL",
+ "logicFlavour": "UNDEFINED",
+ "logic": ""
+ },
+ "stateFinalizerLogicMap": {
+ "entry": []
+ },
+ "defaultTask": {
+ "name": "ControlLoopLogTask",
+ "version": "0.0.1"
+ },
+ "taskReferences": {
+ "entry": [
+ {
+ "key": {
+ "name": "ControlLoopLogTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "DeniedState",
+ "localName": "RestartAPPCRequestPolicy"
+ },
+ "outputType": "DIRECT",
+ "output": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "DeniedState",
+ "localName": "DeniedOutput"
+ }
+ }
+ }
+ ]
+ }
+ }
+ },
+ {
+ "key": "PermitOrDenyState",
+ "value": {
+ "stateKey": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "PermitOrDenyState"
+ },
+ "trigger": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "stateOutputs": {
+ "entry": [
+ {
+ "key": "DenyOutput",
+ "value": {
+ "key": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "PermitOrDenyState",
+ "localName": "DenyOutput"
+ },
+ "outgoingEvent": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "outgoingEventReference": [
+ {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ }
+ ],
+ "nextState": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "DeniedState"
+ }
+ }
+ },
+ {
+ "key": "PermitOutput",
+ "value": {
+ "key": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "PermitOrDenyState",
+ "localName": "PermitOutput"
+ },
+ "outgoingEvent": {
+ "name": "APPCRestartVNFRequestEvent",
+ "version": "2.0.0"
+ },
+ "outgoingEventReference": [
+ {
+ "name": "APPCRestartVNFRequestEvent",
+ "version": "2.0.0"
+ }
+ ],
+ "nextState": {
+ "parentKeyName": "NULL",
+ "parentKeyVersion": "0.0.0",
+ "parentLocalName": "NULL",
+ "localName": "NULL"
+ }
+ }
+ }
+ ]
+ },
+ "contextAlbumReference": [
+ {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ }
+ ],
+ "taskSelectionLogic": {
+ "key": "TaskSelectionLogic",
+ "logicFlavour": "JAVASCRIPT",
+ "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n\nvar guardResult = vcpeClosedLoopStatus.get(\"notification\");\n\nif (guardResult == \"OPERATION: GUARD_PERMIT\") {\n executor.subject.getTaskKey(\"APPCRestartVNFRequestTask\").copyTo(executor.selectedTask);\n} else {\n executor.subject.getTaskKey(\"DeniedTask\").copyTo(executor.selectedTask);\n}\n\nexecutor.logger.info(\"RestartAPPCRequestPolicyPermitOrDenyTSL State Selected Task:\" + executor.selectedTask);\n\ntrue;"
+ },
+ "stateFinalizerLogicMap": {
+ "entry": []
+ },
+ "defaultTask": {
+ "name": "DeniedTask",
+ "version": "0.0.1"
+ },
+ "taskReferences": {
+ "entry": [
+ {
+ "key": {
+ "name": "APPCRestartVNFRequestTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "PermitOrDenyState",
+ "localName": "RestartAPPCRequestPolicy"
+ },
+ "outputType": "DIRECT",
+ "output": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "PermitOrDenyState",
+ "localName": "PermitOutput"
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "DeniedTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "PermitOrDenyState",
+ "localName": "RestartAPPCRequestPolicy"
+ },
+ "outputType": "DIRECT",
+ "output": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "PermitOrDenyState",
+ "localName": "DenyOutput"
+ }
+ }
+ }
+ ]
+ }
+ }
+ },
+ {
+ "key": "PolicyGuardResponseState",
+ "value": {
+ "stateKey": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "PolicyGuardResponseState"
+ },
+ "trigger": {
+ "name": "GuardResponseEvent",
+ "version": "0.0.1"
+ },
+ "stateOutputs": {
+ "entry": [
+ {
+ "key": "GuardResponseOutput",
+ "value": {
+ "key": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "PolicyGuardResponseState",
+ "localName": "GuardResponseOutput"
+ },
+ "outgoingEvent": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "outgoingEventReference": [
+ {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ }
+ ],
+ "nextState": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "PermitOrDenyState"
+ }
+ }
+ }
+ ]
+ },
+ "contextAlbumReference": [],
+ "taskSelectionLogic": {
+ "key": "NULL",
+ "logicFlavour": "UNDEFINED",
+ "logic": ""
+ },
+ "stateFinalizerLogicMap": {
+ "entry": []
+ },
+ "defaultTask": {
+ "name": "GuardResponseTask",
+ "version": "0.0.1"
+ },
+ "taskReferences": {
+ "entry": [
+ {
+ "key": {
+ "name": "GuardResponseTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "PolicyGuardResponseState",
+ "localName": "RestartAPPCRequestPolicy"
+ },
+ "outputType": "DIRECT",
+ "output": {
+ "parentKeyName": "RestartAPPCRequestPolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "PolicyGuardResponseState",
+ "localName": "GuardResponseOutput"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "firstState": "PolicyGuardResponseState"
+ }
+ },
+ {
+ "key": {
+ "name": "RestartAPPCResponsePolicy",
+ "version": "0.0.1"
+ },
+ "value": {
+ "policyKey": {
+ "name": "RestartAPPCResponsePolicy",
+ "version": "0.0.1"
+ },
+ "template": "Freestyle",
+ "state": {
+ "entry": [
+ {
+ "key": "ResponseLogState",
+ "value": {
+ "stateKey": {
+ "parentKeyName": "RestartAPPCResponsePolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "ResponseLogState"
+ },
+ "trigger": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "stateOutputs": {
+ "entry": [
+ {
+ "key": "ResponseLogOutput",
+ "value": {
+ "key": {
+ "parentKeyName": "RestartAPPCResponsePolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "ResponseLogState",
+ "localName": "ResponseLogOutput"
+ },
+ "outgoingEvent": {
+ "name": "ControlLoopLogEvent",
+ "version": "0.0.1"
+ },
+ "outgoingEventReference": [
+ {
+ "name": "ControlLoopLogEvent",
+ "version": "0.0.1"
+ }
+ ],
+ "nextState": {
+ "parentKeyName": "NULL",
+ "parentKeyVersion": "0.0.0",
+ "parentLocalName": "NULL",
+ "localName": "NULL"
+ }
+ }
+ }
+ ]
+ },
+ "contextAlbumReference": [],
+ "taskSelectionLogic": {
+ "key": "NULL",
+ "logicFlavour": "UNDEFINED",
+ "logic": ""
+ },
+ "stateFinalizerLogicMap": {
+ "entry": []
+ },
+ "defaultTask": {
+ "name": "ControlLoopLogTask",
+ "version": "0.0.1"
+ },
+ "taskReferences": {
+ "entry": [
+ {
+ "key": {
+ "name": "ControlLoopLogTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "parentKeyName": "RestartAPPCResponsePolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "ResponseLogState",
+ "localName": "RestartAPPCResponsePolicy"
+ },
+ "outputType": "DIRECT",
+ "output": {
+ "parentKeyName": "RestartAPPCResponsePolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "ResponseLogState",
+ "localName": "ResponseLogOutput"
+ }
+ }
+ }
+ ]
+ }
+ }
+ },
+ {
+ "key": "RestartAPPCResponseState",
+ "value": {
+ "stateKey": {
+ "parentKeyName": "RestartAPPCResponsePolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "RestartAPPCResponseState"
+ },
+ "trigger": {
+ "name": "APPCRestartVNFResponseEvent",
+ "version": "2.0.0"
+ },
+ "stateOutputs": {
+ "entry": [
+ {
+ "key": "APPCRestartVNFResponseOutput",
+ "value": {
+ "key": {
+ "parentKeyName": "RestartAPPCResponsePolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "RestartAPPCResponseState",
+ "localName": "APPCRestartVNFResponseOutput"
+ },
+ "outgoingEvent": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "outgoingEventReference": [
+ {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ }
+ ],
+ "nextState": {
+ "parentKeyName": "RestartAPPCResponsePolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "NULL",
+ "localName": "ResponseLogState"
+ }
+ }
+ }
+ ]
+ },
+ "contextAlbumReference": [],
+ "taskSelectionLogic": {
+ "key": "NULL",
+ "logicFlavour": "UNDEFINED",
+ "logic": ""
+ },
+ "stateFinalizerLogicMap": {
+ "entry": []
+ },
+ "defaultTask": {
+ "name": "APPCRestartVNFResponseTask",
+ "version": "0.0.1"
+ },
+ "taskReferences": {
+ "entry": [
+ {
+ "key": {
+ "name": "APPCRestartVNFResponseTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "parentKeyName": "RestartAPPCResponsePolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "RestartAPPCResponseState",
+ "localName": "RestartAPPCResponsePolicy"
+ },
+ "outputType": "DIRECT",
+ "output": {
+ "parentKeyName": "RestartAPPCResponsePolicy",
+ "parentKeyVersion": "0.0.1",
+ "parentLocalName": "RestartAPPCResponseState",
+ "localName": "APPCRestartVNFResponseOutput"
+ }
+ }
+ }
+ ]
+ }
+ }
+ }
+ ]
+ },
+ "firstState": "RestartAPPCResponseState"
+ }
+ }
+ ]
+ }
+ },
+ "tasks": {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_Tasks",
+ "version": "0.0.1"
+ },
+ "taskMap": {
+ "entry": [
+ {
+ "key": {
+ "name": "AAILookupTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "AAILookupTask",
+ "version": "0.0.1"
+ },
+ "inputEvent": {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "requestID",
+ "value": {
+ "key": "requestID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfID",
+ "value": {
+ "key": "vnfID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfName",
+ "value": {
+ "key": "vnfName",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": true
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ },
+ "outputEvents": {
+ "entry": [
+ {
+ "key": "VCPEStateUpdatedEvent",
+ "value": {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "requestID",
+ "value": {
+ "key": "requestID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfID",
+ "value": {
+ "key": "vnfID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfName",
+ "value": {
+ "key": "vnfName",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": true
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ }
+ ]
+ },
+ "taskParameters": {
+ "entry": []
+ },
+ "contextAlbumReference": [
+ {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ }
+ ],
+ "taskLogic": {
+ "key": "TaskLogic",
+ "logicFlavour": "JAVASCRIPT",
+ "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n\nexecutor.logger.info(\"Executing A&AI Lookup\");\nexecutor.logger.info(vcpeClosedLoopStatus);\n\nvar aaiInfo = vcpeClosedLoopStatus.get(\"AAI\");\nvar returnValue = true;\n\nif (aaiInfo.get(\"vserverName\") == null) {\n executor.message = \"the field vserver.vserver-name must exist in the onset control loop event\";\n executor.logger.warn(executor.message);\n returnValue = false;\n}\nelse if (aaiInfo.get(\"genericVnfVnfId\") == null && aaiInfo.get(\"genericVnfVnfName\") == null) {\n executor.message = \"either the field generic-vnf.vnf-id or generic-vnf.vnf-name must exist\"\n + \" in the onset control loop event\";\n executor.logger.warn(executor.message);\n returnValue = false;\n}\nelse {\n var restManager = new org.onap.policy.rest.RestManager;\n var aaiManager = new org.onap.policy.aai.AaiManager(restManager);\n\n // We need to instantiate the type in order to trigger the static JAXB handling\n // in the AaiCqResponse class\n var aaiCqResponseType = org.onap.policy.aai.AaiCqResponse;\n\n var aaiResponse = aaiManager.getCustomQueryResponse(\n \"http://localhost:54321/OnapVCpeSim/sim\",\n \"aai.username\",\n \"aai.password\",\n executor.inFields.get(\"requestID\"),\n vcpeClosedLoopStatus.get(\"AAI\").get(\"vserverName\")\n );\n\n var genericVnf;\n\n if (aaiInfo.get(\"genericVnfVnfId\") != null) {\n genericVnf = aaiResponse.getGenericVnfByModelInvariantId(aaiInfo.get(\"genericVnfVnfId\"));\n }\n else {\n genericVnf = aaiResponse.getGenericVnfByVnfName(aaiInfo.get(\"genericVnfVnfId\"));\n }\n\n aaiInfo.put(\"genericVnfResourceVersion\", genericVnf.getResourceVersion());\n aaiInfo.put(\"genericVnfVnfName\", genericVnf.getVnfName());\n aaiInfo.put(\"genericVnfProvStatus\", genericVnf.getProvStatus());\n aaiInfo.put(\"genericVnfIsClosedLoopDisabled\", genericVnf.isIsClosedLoopDisabled().toString());\n aaiInfo.put(\"genericVnfVnfType\", genericVnf.getVnfType());\n aaiInfo.put(\"genericVnfInMaint\", genericVnf.isInMaint().toString());\n aaiInfo.put(\"genericVnfServiceId\", genericVnf.getServiceId());\n aaiInfo.put(\"genericVnfVnfId\", genericVnf.getVnfId());\n aaiInfo.put(\"genericVnfOrchestrationStatus\",\n genericVnf.getVfModules().getVfModule().get(0).getOrchestrationStatus());\n\n executor.outFields.put(\"requestID\", executor.inFields.get(\"requestID\"));\n executor.outFields.put(\"vnfID\", executor.inFields.get(\"vnfID\"));\n\n executor.logger.info(executor.outFields);\n}\n\nreturnValue;"
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "APPCRestartVNFRequestTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "APPCRestartVNFRequestTask",
+ "version": "0.0.1"
+ },
+ "inputEvent": {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "requestID",
+ "value": {
+ "key": "requestID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfID",
+ "value": {
+ "key": "vnfID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfName",
+ "value": {
+ "key": "vnfName",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": true
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ },
+ "outputEvents": {
+ "entry": [
+ {
+ "key": "APPCRestartVNFRequestEvent",
+ "value": {
+ "key": {
+ "name": "APPCRestartVNFRequestEvent",
+ "version": "2.0.0"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APPC",
+ "parameter": {
+ "entry": [
+ {
+ "key": "APPCLCMRequestEvent",
+ "value": {
+ "key": "APPCLCMRequestEvent",
+ "fieldSchemaKey": {
+ "name": "APPCLCMRequestType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ }
+ ]
+ },
+ "taskParameters": {
+ "entry": []
+ },
+ "contextAlbumReference": [
+ {
+ "name": "RequestIDVNFIDAlbum",
+ "version": "0.0.1"
+ },
+ {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ }
+ ],
+ "taskLogic": {
+ "key": "TaskLogic",
+ "logicFlavour": "JAVASCRIPT",
+ "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar appcRequest = new org.onap.policy.appclcm.AppcLcmDmaapWrapper;\nappcRequest.setBody(new org.onap.policy.appclcm.AppcLcmBody);\nappcRequest.getBody().setInput(new org.onap.policy.appclcm.AppcLcmInput);\nappcRequest.getBody().getInput().setCommonHeader(\n new org.onap.policy.appclcm.AppcLcmCommonHeader);\n\nappcRequest.setVersion(\"2.0.0\");\nappcRequest.setRpcName(\"restart\");\nappcRequest.setCorrelationId(executor.inFields.get(\"requestID\"));\nappcRequest.setType(\"request\");\n\nvar vcpeClosedLoopStatus = executor\n .getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n\nappcRequest.getBody().getInput().getCommonHeader().setTimeStamp(java.time.Instant.now());\nappcRequest.getBody().getInput().getCommonHeader().setApiVer(\"2.00\");\nappcRequest.getBody().getInput().getCommonHeader().setOriginatorId(\n executor.inFields.get(\"requestID\").toString());\nappcRequest.getBody().getInput().getCommonHeader().setRequestId(\n executor.inFields.get(\"requestID\"));\nappcRequest.getBody().getInput().getCommonHeader().setSubRequestId(\"1\");\nappcRequest.getBody().getInput().getCommonHeader().getFlags().put(\"ttl\", \"10000\");\nappcRequest.getBody().getInput().getCommonHeader().getFlags().put(\"force\", \"TRUE\");\nappcRequest.getBody().getInput().getCommonHeader().getFlags().put(\"mode\", \"EXCLUSIVE\");\n\nappcRequest.getBody().getInput().setAction(\"Restart\");\nappcRequest.getBody().getInput().setActionIdentifiers(new java.util.HashMap());\nappcRequest.getBody().getInput().getActionIdentifiers().put(\"vnf-id\",\n executor.inFields.get(\"vnfID\").toString());\n\nexecutor.getContextAlbum(\"RequestIDVNFIDAlbum\").put(\n executor.inFields.get(\"requestID\").toString(),\n executor.inFields.get(\"vnfID\"));\n\nvcpeClosedLoopStatus.put(\"notification\", \"OPERATION\");\nvcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System\n .currentTimeMillis());\n\nexecutor.outFields.put(\"APPCLCMRequestEvent\", appcRequest);\n\nexecutor.logger.info(executor.outFields);\n\ntrue;"
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "APPCRestartVNFResponseTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "APPCRestartVNFResponseTask",
+ "version": "0.0.1"
+ },
+ "inputEvent": {
+ "key": {
+ "name": "APPCRestartVNFResponseEvent",
+ "version": "2.0.0"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APPC",
+ "parameter": {
+ "entry": [
+ {
+ "key": "APPCLCMResponseEvent",
+ "value": {
+ "key": "APPCLCMResponseEvent",
+ "fieldSchemaKey": {
+ "name": "APPCLCMResponseType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ },
+ "outputEvents": {
+ "entry": [
+ {
+ "key": "VCPEStateUpdatedEvent",
+ "value": {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "requestID",
+ "value": {
+ "key": "requestID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfID",
+ "value": {
+ "key": "vnfID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfName",
+ "value": {
+ "key": "vnfName",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": true
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ }
+ ]
+ },
+ "taskParameters": {
+ "entry": []
+ },
+ "contextAlbumReference": [
+ {
+ "name": "RequestIDVNFIDAlbum",
+ "version": "0.0.1"
+ },
+ {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ }
+ ],
+ "taskLogic": {
+ "key": "TaskLogic",
+ "logicFlavour": "JAVASCRIPT",
+ "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * APPC LCM Response code: 100 ACCEPTED\n * 200 ERROR UNEXPECTED ERROR means failure\n * 312 REJECTED DUPLICATE REQUEST\n * 400 SUCCESS\n *\n * Note: Sometimes the corelationId has a -1 at the tail, need to get rid of it when present.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar appcResponse = executor.inFields.get(\"APPCLCMResponseEvent\");\n\nvar requestIDString = appcResponse.getCorrelationId().substr(0, 36);\nexecutor.logger.info(\"requestIDString = \" + requestIDString);\nvar vnfID = executor.getContextAlbum(\"RequestIDVNFIDAlbum\")\n .get(requestIDString);\nexecutor.logger.info(\"Size of RequestIDVNFIDAlbum = \"\n + executor.getContextAlbum(\"RequestIDVNFIDAlbum\").size());\nexecutor.logger.info(\"vnfID = \" + vnfID);\n\nvar returnValue = true;\n\nif (vnfID != null) {\n var vcpeClosedLoopStatus = executor.getContextAlbum(\n \"VCPEClosedLoopStatusAlbum\").get(vnfID.toString());\n var requestId = java.util.UUID.fromString(vcpeClosedLoopStatus\n .get(\"requestID\"));\n\n vcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System\n .currentTimeMillis());\n\n executor.logger.info(\"Got from APPC code: \"\n + org.onap.policy.appclcm.AppcLcmResponseCode\n .toResponseValue(appcResponse.getBody().getOutput()\n .getStatus().getCode()));\n\n if (org.onap.policy.appclcm.AppcLcmResponseCode\n .toResponseValue(appcResponse.getBody().getOutput().getStatus()\n .getCode()) == org.onap.policy.appclcm.AppcLcmResponseCode.SUCCESS) {\n vcpeClosedLoopStatus.put(\"notification\", \"OPERATION_SUCCESS\");\n vcpeClosedLoopStatus.put(\"message\", \"vCPE restarted\");\n executor.getContextAlbum(\"RequestIDVNFIDAlbum\").remove(requestIDString);\n } else if (org.onap.policy.appclcm.AppcLcmResponseCode\n .toResponseValue(appcResponse.getBody().getOutput().getStatus()\n .getCode()) == \"ACCEPTED\"\n || org.onap.policy.appclcm.AppcLcmResponseCode\n .toResponseValue(appcResponse.getBody().getOutput()\n .getStatus().getCode()) == \"REJECT\") {\n executor.logger\n .info(\"Got ACCEPTED 100 or REJECT 312, keep the context, wait for next response. Code is: \"\n + org.onap.policy.appclcm.AppcLcmResponseCode\n .toResponseValue(appcResponse.getBody()\n .getOutput().getStatus().getCode()));\n } else {\n executor.getContextAlbum(\"RequestIDVNFIDAlbum\").remove(requestIDString);\n vcpeClosedLoopStatus.put(\"notification\", \"OPERATION_FAILURE\");\n vcpeClosedLoopStatus.put(\"message\", \"vCPE restart failed\");\n }\n\n executor.outFields.put(\"requestID\", requestId);\n executor.outFields.put(\"vnfID\", vnfID);\n} else {\n executor.message = \"VNF ID not found in context album for request ID \"\n + requestIDString;\n returnValue = false\n}\n\nexecutor.logger.info(executor.outFields);\n\nreturnValue;"
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "AbatedTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "AbatedTask",
+ "version": "0.0.1"
+ },
+ "inputEvent": {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "requestID",
+ "value": {
+ "key": "requestID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfID",
+ "value": {
+ "key": "vnfID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfName",
+ "value": {
+ "key": "vnfName",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": true
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ },
+ "outputEvents": {
+ "entry": [
+ {
+ "key": "VCPEStateUpdatedEvent",
+ "value": {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "requestID",
+ "value": {
+ "key": "requestID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfID",
+ "value": {
+ "key": "vnfID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfName",
+ "value": {
+ "key": "vnfName",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": true
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ }
+ ]
+ },
+ "taskParameters": {
+ "entry": []
+ },
+ "contextAlbumReference": [
+ {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ }
+ ],
+ "taskLogic": {
+ "key": "TaskLogic",
+ "logicFlavour": "JAVASCRIPT",
+ "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vcpeClosedLoopStatus = null;\nif( executor.inFields.get(\"vnfID\") == null) {\n executor.logger.info(\"AbatedTask: vnfID is null\");\n var vnfName = executor.inFields.get(\"vnfName\");\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfName\"));\n} else {\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n}\n\nvcpeClosedLoopStatus.put(\"notification\", \"FINAL_SUCCESS\");\nvcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System.currentTimeMillis());\nvcpeClosedLoopStatus.put(\"message\", \"situation has been abated\");\n\nexecutor.logger.info(executor.outFields);\n\ntrue;"
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "ControlLoopLogTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "ControlLoopLogTask",
+ "version": "0.0.1"
+ },
+ "inputEvent": {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "requestID",
+ "value": {
+ "key": "requestID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfID",
+ "value": {
+ "key": "vnfID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfName",
+ "value": {
+ "key": "vnfName",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": true
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ },
+ "outputEvents": {
+ "entry": [
+ {
+ "key": "ControlLoopLogEvent",
+ "value": {
+ "key": {
+ "name": "ControlLoopLogEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "VirtualControlLoopNotification",
+ "value": {
+ "key": "VirtualControlLoopNotification",
+ "fieldSchemaKey": {
+ "name": "VirtualControlLoopNotificationType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ }
+ ]
+ },
+ "taskParameters": {
+ "entry": []
+ },
+ "contextAlbumReference": [
+ {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ }
+ ],
+ "taskLogic": {
+ "key": "TaskLogic",
+ "logicFlavour": "JAVASCRIPT",
+ "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vnfID = executor.inFields.get(\"vnfID\");\nif(vnfID == null) {\n vnfID = executor.inFields.get(\"vnfName\");\n}\nexecutor.logger.info(\"vnfID=\" + vnfID);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(vnfID.toString());\n\nexecutor.logger.info(\"Logging context information for VNF \\\"\" + vnfID + \"\\\"\");\n\nvar clNotification = new org.onap.policy.controlloop.VirtualControlLoopNotification();\n\nclNotification.setClosedLoopControlName(vcpeClosedLoopStatus.get(\"closedLoopControlName\"));\nclNotification.setClosedLoopAlarmStart(java.time.Instant.ofEpochMilli(vcpeClosedLoopStatus.get(\"closedLoopAlarmStart\")));\nclNotification.setClosedLoopAlarmEnd(java.time.Instant.ofEpochMilli(vcpeClosedLoopStatus.get(\"closedLoopAlarmEnd\")));\nclNotification.setClosedLoopEventClient(vcpeClosedLoopStatus.get(\"closedLoopEventClient\"));\nclNotification.setVersion(vcpeClosedLoopStatus.get(\"version\"));\nclNotification.setRequestId(java.util.UUID.fromString(vcpeClosedLoopStatus.get(\"requestID\")));\nclNotification.setTargetType(vcpeClosedLoopStatus.get(\"target_type\"));\nclNotification.setTarget(vcpeClosedLoopStatus.get(\"target\"));\nclNotification.setFrom(vcpeClosedLoopStatus.get(\"from\"));\nclNotification.setPolicyScope(vcpeClosedLoopStatus.get(\"policyScope\"));\nclNotification.setPolicyName(vcpeClosedLoopStatus.get(\"policyName\"));\nclNotification.setPolicyVersion(vcpeClosedLoopStatus.get(\"policyVersion\"));\nclNotification.setNotification(org.onap.policy.controlloop.ControlLoopNotificationType.toType(vcpeClosedLoopStatus.get(\"notification\")));\nclNotification.setMessage(vcpeClosedLoopStatus.get(\"message\"));\n\nvar notificationInstant = java.time.Instant.ofEpochSecond(vcpeClosedLoopStatus.get(\"notificationTime\"));\nvar notificationTime = java.time.ZonedDateTime.ofInstant(notificationInstant, java.time.ZoneOffset.UTC);\nclNotification.setNotificationTime(notificationTime);\n\nvar aaiInfo = vcpeClosedLoopStatus.get(\"AAI\");\n\nclNotification.getAai().put(\"generic-vnf.resource-version\", aaiInfo.get(\"genericVnfResourceVersion\"));\nclNotification.getAai().put(\"generic-vnf.vnf-name\", aaiInfo.get(\"genericVnfVnfName\"));\nclNotification.getAai().put(\"generic-vnf.prov-status\", aaiInfo.get(\"genericVnfProvStatus\"));\nclNotification.getAai().put(\"generic-vnf.is-closed-loop-disabled\", aaiInfo.get(\"genericVnfIsClosedLoopDisabled\"));\nclNotification.getAai().put(\"generic-vnf.orchestration-status\", aaiInfo.get(\"genericVnfOrchestrationStatus\"));\nclNotification.getAai().put(\"generic-vnf.vnf-type\", aaiInfo.get(\"genericVnfVnfType\"));\nclNotification.getAai().put(\"generic-vnf.in-maint\", aaiInfo.get(\"genericVnfInMaint\"));\nclNotification.getAai().put(\"generic-vnf.service-id\", aaiInfo.get(\"genericVnfServiceId\"));\n\nif(vnfID != null) {\n clNotification.getAai().put(\"generic-vnf.vnf-id\", aaiInfo.get(\"genericVnfVnfId\"));\n}\nexecutor.outFields.put(\"VirtualControlLoopNotification\", clNotification);\n\nexecutor.logger.info(executor.outFields);\n\ntrue;"
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "DeniedTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "DeniedTask",
+ "version": "0.0.1"
+ },
+ "inputEvent": {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "requestID",
+ "value": {
+ "key": "requestID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfID",
+ "value": {
+ "key": "vnfID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfName",
+ "value": {
+ "key": "vnfName",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": true
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ },
+ "outputEvents": {
+ "entry": [
+ {
+ "key": "VCPEStateUpdatedEvent",
+ "value": {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "requestID",
+ "value": {
+ "key": "requestID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfID",
+ "value": {
+ "key": "vnfID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfName",
+ "value": {
+ "key": "vnfName",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": true
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ }
+ ]
+ },
+ "taskParameters": {
+ "entry": []
+ },
+ "contextAlbumReference": [
+ {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ }
+ ],
+ "taskLogic": {
+ "key": "TaskLogic",
+ "logicFlavour": "JAVASCRIPT",
+ "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n\nvcpeClosedLoopStatus.put(\"notification\", \"REJECTED\");\nvcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System.currentTimeMillis());\n\nexecutor.logger.info(executor.outFields);\n\ntrue;"
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "GetVCPEStateTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "GetVCPEStateTask",
+ "version": "0.0.1"
+ },
+ "inputEvent": {
+ "key": {
+ "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e",
+ "version": "1.0.2"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "DCAE",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "VirtualControlLoopEvent",
+ "value": {
+ "key": "VirtualControlLoopEvent",
+ "fieldSchemaKey": {
+ "name": "VirtualControlLoopEventType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ },
+ "outputEvents": {
+ "entry": [
+ {
+ "key": "VCPEStateUpdatedEvent",
+ "value": {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "requestID",
+ "value": {
+ "key": "requestID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfID",
+ "value": {
+ "key": "vnfID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfName",
+ "value": {
+ "key": "vnfName",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": true
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ }
+ ]
+ },
+ "taskParameters": {
+ "entry": []
+ },
+ "contextAlbumReference": [
+ {
+ "name": "RequestIDVNFIDAlbum",
+ "version": "0.0.1"
+ },
+ {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ }
+ ],
+ "taskLogic": {
+ "key": "TaskLogic",
+ "logicFlavour": "JAVASCRIPT",
+ "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Note: The incoming closedloop message can be ONSET with both VNF-name and VNF-ID\n * or ABATED with only VNF-name. So need to handle differently. For ABATED case,\n * since we still keep the RequireIDVNFID context album, we can get it from there.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar clEventType = org.onap.policy.controlloop.VirtualControlLoopEvent;\nvar longType = java.lang.Long;\nvar uuidType = java.util.UUID;\n\nvar clEvent = executor.inFields.get(\"VirtualControlLoopEvent\");\n\nexecutor.logger.info(clEvent.toString());\nexecutor.logger.info(clEvent.getClosedLoopControlName());\n\nvar requestID = clEvent.getRequestId();\nexecutor.logger.info(\"requestID = \" + requestID);\nvar vnfID = null;\nvar vcpeClosedLoopStatus = null;\n\nif (clEvent.getAai().get(\"generic-vnf.vnf-id\") != null) {\n vnfID = uuidType.fromString(clEvent.getAai().get(\"generic-vnf.vnf-id\"));\n executor.logger.info(\"vnfID = \" + vnfID);\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(vnfID);\n\n if (vcpeClosedLoopStatus == null) {\n executor.logger.info(\"Creating context information for new vCPE VNF \\\"\" + vnfID.toString() + \"\\\"\");\n\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").getSchemaHelper().createNewInstance();\n\n vcpeClosedLoopStatus.put(\"closedLoopControlName\", clEvent.getClosedLoopControlName());\n vcpeClosedLoopStatus.put(\"closedLoopAlarmStart\", clEvent.getClosedLoopAlarmStart().toEpochMilli());\n vcpeClosedLoopStatus.put(\"closedLoopEventClient\", clEvent.getClosedLoopEventClient());\n vcpeClosedLoopStatus.put(\"closedLoopEventStatus\", clEvent.getClosedLoopEventStatus().toString());\n vcpeClosedLoopStatus.put(\"version\", clEvent.getVersion());\n vcpeClosedLoopStatus.put(\"requestID\", clEvent.getRequestId().toString());\n vcpeClosedLoopStatus.put(\"target_type\", clEvent.getTargetType().toString());\n vcpeClosedLoopStatus.put(\"target\", clEvent.getTarget());\n vcpeClosedLoopStatus.put(\"from\", clEvent.getFrom());\n vcpeClosedLoopStatus.put(\"policyScope\", \"vCPE\");\n vcpeClosedLoopStatus.put(\"policyName\", \"ONAPvCPEPolicyModel\");\n vcpeClosedLoopStatus.put(\"policyVersion\", \"0.0.1\");\n vcpeClosedLoopStatus.put(\"notification\", \"ACTIVE\");\n vcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System.currentTimeMillis());\n vcpeClosedLoopStatus.put(\"message\", \"\");\n\n var aaiInfo = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").getSchemaHelper().createNewSubInstance(\"VCPE_AAI_Type\");\n\n aaiInfo.put(\"genericVnfResourceVersion\", clEvent.getAai().get(\"generic-vnf.resource-version\"));\n aaiInfo.put(\"genericVnfVnfName\", clEvent.getAai().get(\"generic-vnf.vnf-name\"));\n aaiInfo.put(\"genericVnfProvStatus\", clEvent.getAai().get(\"generic-vnf.prov-status\"));\n aaiInfo.put(\"genericVnfIsClosedLoopDisabled\", clEvent.getAai().get(\"generic-vnf.is-closed-loop-disabled\"));\n aaiInfo.put(\"genericVnfOrchestrationStatus\", clEvent.getAai().get(\"generic-vnf.orchestration-status\"));\n aaiInfo.put(\"genericVnfVnfType\", clEvent.getAai().get(\"generic-vnf.vnf-type\"));\n aaiInfo.put(\"genericVnfInMaint\", clEvent.getAai().get(\"generic-vnf.in-maint\"));\n aaiInfo.put(\"genericVnfServiceId\", clEvent.getAai().get(\"generic-vnf.service-id\"));\n aaiInfo.put(\"genericVnfVnfId\", clEvent.getAai().get(\"generic-vnf.vnf-id\"));\n aaiInfo.put(\"vserverIsClosedLoopDisabled\", clEvent.getAai().get(\"vserver.is-closed-loop-disabled\"));\n aaiInfo.put(\"vserverProvStatus\", clEvent.getAai().get(\"vserver.prov-status\"));\n aaiInfo.put(\"vserverName\", clEvent.getAai().get(\"vserver.vserver-name\"));\n\n vcpeClosedLoopStatus.put(\"AAI\", aaiInfo);\n\n if (clEvent.getClosedLoopAlarmEnd() != null) {\n vcpeClosedLoopStatus.put(\"closedLoopAlarmEnd\", clEvent.getClosedLoopAlarmEnd().toEpochMilli());\n } else {\n vcpeClosedLoopStatus.put(\"closedLoopAlarmEnd\", java.lang.Long.valueOf(0));\n }\n\n executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").put(vnfID.toString(), vcpeClosedLoopStatus);\n\n executor.logger.info(\"Created context information for new vCPE VNF \\\"\" + vnfID.toString() + \"\\\"\");\n }\n\n executor.outFields.put(\"requestID\", requestID);\n executor.outFields.put(\"vnfID\", vnfID);\n\n executor.logger.info(executor.outFields);\n}\nelse {\n executor.logger.info(\"No vnf-id in VirtualControlLoopEvent, status:\" + clEvent.getClosedLoopEventStatus().toString());\n var vnfName = clEvent.getAai().get(\"generic-vnf.vnf-name\");\n executor.logger.info(\"No vnf-id in VirtualControlLoopEvent for \" + vnfName);\n\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(vnfName.toString());\n\n if (vcpeClosedLoopStatus == null) {\n executor.logger.info(\"Creating context information for new vCPE VNF \\\"\" + vnfName.toString() + \"\\\"\");\n\n vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").getSchemaHelper().createNewInstance();\n\n vcpeClosedLoopStatus.put(\"closedLoopControlName\", clEvent.getClosedLoopControlName());\n vcpeClosedLoopStatus.put(\"closedLoopAlarmStart\", clEvent.getClosedLoopAlarmStart().toEpochMilli());\n vcpeClosedLoopStatus.put(\"closedLoopEventClient\", clEvent.getClosedLoopEventClient());\n vcpeClosedLoopStatus.put(\"closedLoopEventStatus\", clEvent.getClosedLoopEventStatus().toString());\n vcpeClosedLoopStatus.put(\"version\", clEvent.getVersion());\n vcpeClosedLoopStatus.put(\"requestID\", clEvent.getRequestId().toString());\n vcpeClosedLoopStatus.put(\"target_type\", clEvent.getTargetType().toString());\n vcpeClosedLoopStatus.put(\"target\", clEvent.getTarget());\n vcpeClosedLoopStatus.put(\"from\", clEvent.getFrom());\n vcpeClosedLoopStatus.put(\"policyScope\", \"vCPE\");\n vcpeClosedLoopStatus.put(\"policyName\", \"ONAPvCPEPolicyModel\");\n vcpeClosedLoopStatus.put(\"policyVersion\", \"0.0.1\");\n vcpeClosedLoopStatus.put(\"notification\", \"ACTIVE\");\n vcpeClosedLoopStatus.put(\"notificationTime\", java.lang.System.currentTimeMillis());\n vcpeClosedLoopStatus.put(\"message\", \"\");\n\n var aaiInfo = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").getSchemaHelper().createNewSubInstance(\"VCPE_AAI_Type\");\n\n aaiInfo.put(\"genericVnfVnfName\", clEvent.getAai().get(\"generic-vnf.vnf-name\"));\n vcpeClosedLoopStatus.put(\"AAI\", aaiInfo);\n\n if (clEvent.getClosedLoopAlarmEnd() != null) {\n vcpeClosedLoopStatus.put(\"closedLoopAlarmEnd\", clEvent.getClosedLoopAlarmEnd().toEpochMilli());\n } else {\n vcpeClosedLoopStatus.put(\"closedLoopAlarmEnd\", java.lang.Long.valueOf(0));\n }\n\n executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").put(vnfName.toString(), vcpeClosedLoopStatus);\n\n executor.logger.info(\"Created context information for new vCPE VNF \\\"\" + vnfName.toString() + \"\\\"\");\n }\n executor.outFields.put(\"requestID\", requestID);\n executor.outFields.put(\"vnfName\", vnfName);\n executor.logger.info(executor.outFields);\n}\n\ntrue;"
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "GuardRequestTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "GuardRequestTask",
+ "version": "0.0.1"
+ },
+ "inputEvent": {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "requestID",
+ "value": {
+ "key": "requestID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfID",
+ "value": {
+ "key": "vnfID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfName",
+ "value": {
+ "key": "vnfName",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": true
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ },
+ "outputEvents": {
+ "entry": [
+ {
+ "key": "GuardRequestEvent",
+ "value": {
+ "key": {
+ "name": "GuardRequestEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "decisionAttributes",
+ "value": {
+ "key": "decisionAttributes",
+ "fieldSchemaKey": {
+ "name": "GuardDecisionAttributesType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "onapName",
+ "value": {
+ "key": "onapName",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ }
+ ]
+ },
+ "taskParameters": {
+ "entry": []
+ },
+ "contextAlbumReference": [
+ {
+ "name": "ControlLoopExecutionIDAlbum",
+ "version": "0.0.1"
+ },
+ {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ }
+ ],
+ "taskLogic": {
+ "key": "TaskLogic",
+ "logicFlavour": "JAVASCRIPT",
+ "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(\n executor.inFields.get(\"vnfID\").toString());\n\nvar guardDecisionAttributes = executor.subject.getOutFieldSchemaHelper(\"decisionAttributes\").createNewInstance();\n\nguardDecisionAttributes.put(\"actor\", \"APPC\");\nguardDecisionAttributes.put(\"recipe\", \"Restart\");\nguardDecisionAttributes.put(\"target\", executor.inFields.get(\"vnfID\").toString());\nguardDecisionAttributes.put(\"clname\", \"APEXvCPEImplementation\");\n\nexecutor.logger.info(guardDecisionAttributes);\n\nexecutor.outFields.put(\"decisionAttributes\", guardDecisionAttributes);\nexecutor.outFields.put(\"onapName\", \"PDPD\");\n\nexecutor.getContextAlbum(\"ControlLoopExecutionIDAlbum\").put(executor.executionId.toString(),\n executor.inFields.get(\"vnfID\"));\n\nexecutor.logger.info(executor.outFields);\n\ntrue;"
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "GuardResponseTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "GuardResponseTask",
+ "version": "0.0.1"
+ },
+ "inputEvent": {
+ "key": {
+ "name": "GuardResponseEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "decision",
+ "value": {
+ "key": "decision",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "details",
+ "value": {
+ "key": "details",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ },
+ "outputEvents": {
+ "entry": [
+ {
+ "key": "VCPEStateUpdatedEvent",
+ "value": {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "requestID",
+ "value": {
+ "key": "requestID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfID",
+ "value": {
+ "key": "vnfID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfName",
+ "value": {
+ "key": "vnfName",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": true
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ }
+ ]
+ },
+ "taskParameters": {
+ "entry": []
+ },
+ "contextAlbumReference": [
+ {
+ "name": "ControlLoopExecutionIDAlbum",
+ "version": "0.0.1"
+ },
+ {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ }
+ ],
+ "taskLogic": {
+ "key": "TaskLogic",
+ "logicFlavour": "JAVASCRIPT",
+ "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nvar vnfID = executor.getContextAlbum(\"ControlLoopExecutionIDAlbum\").remove(executor.executionId.toString());\n\nexecutor.logger.info(\"Continuing execution with VNF ID: \" + vnfID);\n\nvar vcpeClosedLoopStatus = executor.getContextAlbum(\"VCPEClosedLoopStatusAlbum\").get(vnfID.toString());\nexecutor.logger.info(vcpeClosedLoopStatus);\n\nvar guardResult = executor.inFields.get(\"decision\");\nvar returnValue = true;\n\nif (guardResult == \"PERMIT\") {\n vcpeClosedLoopStatus.put(\"notification\", \"OPERATION: GUARD_PERMIT\");\n} else if (guardResult == \"DENY\") {\n vcpeClosedLoopStatus.put(\"notification\", \"OPERATION: GUARD_DENY\");\n} else {\n executor.message = \"guard result must be either \\\"PERMIT\\\" or \\\"DENY\\\"\";\n returnValue = false;\n}\n\nvar uuidType = java.util.UUID;\nvar requestID = uuidType.fromString(vcpeClosedLoopStatus.get(\"requestID\"));\n\nexecutor.outFields.put(\"requestID\", requestID);\nexecutor.outFields.put(\"vnfID\", vnfID);\n\nexecutor.logger.info(executor.outFields);\n\n\nreturnValue;"
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "NoAAILookupTask",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "NoAAILookupTask",
+ "version": "0.0.1"
+ },
+ "taskParameters": {
+ "entry": []
+ },
+ "contextAlbumReference": [],
+ "taskLogic": {
+ "key": "TaskLogic",
+ "logicFlavour": "JAVASCRIPT",
+ "logic": "/*\n * ============LICENSE_START=======================================================\n * Copyright (C) 2016-2018 Ericsson. All rights reserved.\n * Modifications Copyright (C) 2020 Nordix Foundation.\n * ================================================================================\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n * ============LICENSE_END=========================================================\n */\n\nexecutor.logger.info(executor.subject.id);\nexecutor.logger.info(executor.inFields);\n\nexecutor.logger.info(executor.outFields);\n\ntrue;"
+ }
+ }
+ }
+ ]
+ }
+ },
+ "events": {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_Events",
+ "version": "0.0.1"
+ },
+ "eventMap": {
+ "entry": [
+ {
+ "key": {
+ "name": "APPCRestartVNFRequestEvent",
+ "version": "2.0.0"
+ },
+ "value": {
+ "key": {
+ "name": "APPCRestartVNFRequestEvent",
+ "version": "2.0.0"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APPC",
+ "parameter": {
+ "entry": [
+ {
+ "key": "APPCLCMRequestEvent",
+ "value": {
+ "key": "APPCLCMRequestEvent",
+ "fieldSchemaKey": {
+ "name": "APPCLCMRequestType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ },
+ {
+ "key": {
+ "name": "APPCRestartVNFResponseEvent",
+ "version": "2.0.0"
+ },
+ "value": {
+ "key": {
+ "name": "APPCRestartVNFResponseEvent",
+ "version": "2.0.0"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APPC",
+ "parameter": {
+ "entry": [
+ {
+ "key": "APPCLCMResponseEvent",
+ "value": {
+ "key": "APPCLCMResponseEvent",
+ "fieldSchemaKey": {
+ "name": "APPCLCMResponseType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ },
+ {
+ "key": {
+ "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e",
+ "version": "1.0.2"
+ },
+ "value": {
+ "key": {
+ "name": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e",
+ "version": "1.0.2"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "DCAE",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "VirtualControlLoopEvent",
+ "value": {
+ "key": "VirtualControlLoopEvent",
+ "fieldSchemaKey": {
+ "name": "VirtualControlLoopEventType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ },
+ {
+ "key": {
+ "name": "ControlLoopLogEvent",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "ControlLoopLogEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "VirtualControlLoopNotification",
+ "value": {
+ "key": "VirtualControlLoopNotification",
+ "fieldSchemaKey": {
+ "name": "VirtualControlLoopNotificationType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ },
+ {
+ "key": {
+ "name": "GuardRequestEvent",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "GuardRequestEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "decisionAttributes",
+ "value": {
+ "key": "decisionAttributes",
+ "fieldSchemaKey": {
+ "name": "GuardDecisionAttributesType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "onapName",
+ "value": {
+ "key": "onapName",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ },
+ {
+ "key": {
+ "name": "GuardResponseEvent",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "GuardResponseEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "decision",
+ "value": {
+ "key": "decision",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "details",
+ "value": {
+ "key": "details",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ },
+ {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "VCPEStateUpdatedEvent",
+ "version": "0.0.1"
+ },
+ "nameSpace": "org.onap.policy.apex.onap.vcpe",
+ "source": "APEX",
+ "target": "APEX",
+ "parameter": {
+ "entry": [
+ {
+ "key": "requestID",
+ "value": {
+ "key": "requestID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfID",
+ "value": {
+ "key": "vnfID",
+ "fieldSchemaKey": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "optional": false
+ }
+ },
+ {
+ "key": "vnfName",
+ "value": {
+ "key": "vnfName",
+ "fieldSchemaKey": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "optional": true
+ }
+ }
+ ]
+ },
+ "toscaPolicyState": ""
+ }
+ }
+ ]
+ }
+ },
+ "albums": {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_Albums",
+ "version": "0.0.1"
+ },
+ "albums": {
+ "entry": [
+ {
+ "key": {
+ "name": "ControlLoopExecutionIDAlbum",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "ControlLoopExecutionIDAlbum",
+ "version": "0.0.1"
+ },
+ "scope": "policy",
+ "isWritable": true,
+ "itemSchema": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "RequestIDVNFIDAlbum",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "RequestIDVNFIDAlbum",
+ "version": "0.0.1"
+ },
+ "scope": "policy",
+ "isWritable": true,
+ "itemSchema": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ }
+ }
+ },
+ {
+ "key": {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "VCPEClosedLoopStatusAlbum",
+ "version": "0.0.1"
+ },
+ "scope": "policy",
+ "isWritable": true,
+ "itemSchema": {
+ "name": "VCPEClosedLoopStatusType",
+ "version": "0.0.1"
+ }
+ }
+ }
+ ]
+ }
+ },
+ "schemas": {
+ "key": {
+ "name": "ONAPvCPEPolicyModel_Schemas",
+ "version": "0.0.1"
+ },
+ "schemas": {
+ "entry": [
+ {
+ "key": {
+ "name": "APPCLCMRequestType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "APPCLCMRequestType",
+ "version": "0.0.1"
+ },
+ "schemaFlavour": "Java",
+ "schemaDefinition": "org.onap.policy.appclcm.AppcLcmDmaapWrapper"
+ }
+ },
+ {
+ "key": {
+ "name": "APPCLCMResponseType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "APPCLCMResponseType",
+ "version": "0.0.1"
+ },
+ "schemaFlavour": "Java",
+ "schemaDefinition": "org.onap.policy.appclcm.AppcLcmDmaapWrapper"
+ }
+ },
+ {
+ "key": {
+ "name": "GuardDecisionAttributesType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "GuardDecisionAttributesType",
+ "version": "0.0.1"
+ },
+ "schemaFlavour": "Avro",
+ "schemaDefinition": "{\n \"type\": \"record\",\n \"name\": \"GuardDecisionAttributes_Type\",\n \"namespace\": \"org.onap.policy.apex.onap.vcpe\",\n \"fields\": [\n {\n \"name\": \"actor\",\n \"type\": \"string\"\n },\n {\n \"name\": \"recipe\",\n \"type\": \"string\"\n },\n {\n \"name\": \"target\",\n \"type\": \"string\"\n },\n {\n \"name\": \"clname\",\n \"type\": \"string\"\n }\n ]\n}"
+ }
+ },
+ {
+ "key": {
+ "name": "SimpleBooleanType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "SimpleBooleanType",
+ "version": "0.0.1"
+ },
+ "schemaFlavour": "Java",
+ "schemaDefinition": "java.lang.Boolean"
+ }
+ },
+ {
+ "key": {
+ "name": "SimpleLongType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "SimpleLongType",
+ "version": "0.0.1"
+ },
+ "schemaFlavour": "Java",
+ "schemaDefinition": "java.lang.Long"
+ }
+ },
+ {
+ "key": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "SimpleStringType",
+ "version": "0.0.1"
+ },
+ "schemaFlavour": "Java",
+ "schemaDefinition": "java.lang.String"
+ }
+ },
+ {
+ "key": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "UUIDType",
+ "version": "0.0.1"
+ },
+ "schemaFlavour": "Java",
+ "schemaDefinition": "java.util.UUID"
+ }
+ },
+ {
+ "key": {
+ "name": "VCPEClosedLoopStatusType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "VCPEClosedLoopStatusType",
+ "version": "0.0.1"
+ },
+ "schemaFlavour": "Avro",
+ "schemaDefinition": "{\n \"type\": \"record\",\n \"name\": \"VCPEClosedLoopStatus\",\n \"fields\": [\n {\n \"name\": \"AAI\",\n \"type\": {\n \"type\": \"record\",\n \"name\": \"VCPE_AAI_Type\",\n \"namespace\": \"org.onap.policy.apex.onap.vcpe\",\n \"fields\": [\n {\n \"name\": \"genericVnfResourceVersion\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfVnfName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfProvStatus\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfIsClosedLoopDisabled\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfOrchestrationStatus\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfVnfType\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfInMaint\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfServiceId\",\n \"type\": \"string\"\n },\n {\n \"name\": \"genericVnfVnfId\",\n \"type\": \"string\"\n },\n {\n \"name\": \"vserverIsClosedLoopDisabled\",\n \"type\": \"string\"\n },\n {\n \"name\": \"vserverName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"vserverProvStatus\",\n \"type\": \"string\"\n }\n ]\n }\n },\n {\n \"name\": \"closedLoopAlarmStart\",\n \"type\": \"long\"\n },\n {\n \"name\": \"closedLoopAlarmEnd\",\n \"type\": \"long\"\n },\n {\n \"name\": \"closedLoopControlName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"version\",\n \"type\": \"string\"\n },\n {\n \"name\": \"requestID\",\n \"type\": \"string\"\n },\n {\n \"name\": \"closedLoopEventClient\",\n \"type\": \"string\"\n },\n {\n \"name\": \"closedLoopEventStatus\",\n \"type\": \"string\"\n },\n {\n \"name\": \"target_type\",\n \"type\": \"string\"\n },\n {\n \"name\": \"target\",\n \"type\": \"string\"\n },\n {\n \"name\": \"from\",\n \"type\": \"string\"\n },\n {\n \"name\": \"policyScope\",\n \"type\": \"string\"\n },\n {\n \"name\": \"policyName\",\n \"type\": \"string\"\n },\n {\n \"name\": \"policyVersion\",\n \"type\": \"string\"\n },\n {\n \"name\": \"notification\",\n \"type\": \"string\"\n },\n {\n \"name\": \"notificationTime\",\n \"type\": \"long\"\n },\n {\n \"name\": \"message\",\n \"type\": \"string\"\n }\n ]\n}"
+ }
+ },
+ {
+ "key": {
+ "name": "VirtualControlLoopEventType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "VirtualControlLoopEventType",
+ "version": "0.0.1"
+ },
+ "schemaFlavour": "Java",
+ "schemaDefinition": "org.onap.policy.controlloop.VirtualControlLoopEvent"
+ }
+ },
+ {
+ "key": {
+ "name": "VirtualControlLoopNotificationType",
+ "version": "0.0.1"
+ },
+ "value": {
+ "key": {
+ "name": "VirtualControlLoopNotificationType",
+ "version": "0.0.1"
+ },
+ "schemaFlavour": "Java",
+ "schemaDefinition": "org.onap.policy.controlloop.VirtualControlLoopNotification"
+ }
+ }
+ ]
+ }
+ }
+}
diff --git a/model/src/test/resources/path/to/apex/logic/funkylogic/LogicParentLogicParentLocalNameLogicInstanceName.funkylogic b/model/src/test/resources/path/to/apex/logic/funkylogic/LogicParentLogicParentLocalNameLogicInstanceName.funkylogic
new file mode 100644
index 000000000..7ccf3da88
--- /dev/null
+++ b/model/src/test/resources/path/to/apex/logic/funkylogic/LogicParentLogicParentLocalNameLogicInstanceName.funkylogic
@@ -0,0 +1,21 @@
+#-------------------------------------------------------------------------------
+# ============LICENSE_START=======================================================
+# Copyright (C) 2016-2018 Ericsson. 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=========================================================
+#-------------------------------------------------------------------------------
+
+Way out man, this is funky logic! \ No newline at end of file
diff --git a/model/src/test/resources/testdir/testfile.xml b/model/src/test/resources/testdir/testfile.xml
new file mode 100644
index 000000000..ddffc5822
--- /dev/null
+++ b/model/src/test/resources/testdir/testfile.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2016-2018 Ericsson. 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=========================================================
+-->