summaryrefslogtreecommitdiffstats
path: root/services/services-engine/src/test
diff options
context:
space:
mode:
authorRashmi Pujar <rashmi.pujar1@bell.ca>2022-01-22 00:37:28 -0500
committerRashmi Pujar <rashmi.pujar1@bell.ca>2022-01-24 14:06:57 -0500
commit632899642b6a1d1489a0b96932c9c38863a53a26 (patch)
treeab9665853aa637ab1d76d7c25523c77835d3ca3e /services/services-engine/src/test
parentc719ee941bd4202b617544e351a11a35b20b8a6a (diff)
Add TOSCA policy status header field to APEX event create CLI
In order to expose the processing status of a TOSCA policy to APEX-PDP, a new header field for APEX concept "event" has been introduced to track this within an APEX policy implementation. This field will be leveraged to extract the TOSCA policy execution metrics. Note, that the field is marked as optional for backward compatibility. Unit tests have been augmented to test for the field wherever applicable and the default empty value is retained for the others. "example-grpc" module has been updated to include this field. Exposing the TOSCA policy execution metrics is outside the scope of this patch since the current changes are already very large owing to the atomic nature of the change introduced. Issue-ID: POLICY-3845 Signed-off-by: Rashmi Pujar <rashmi.pujar1@bell.ca> Change-Id: Ief6d70f9abcfc8414e10aa51a27815ee9028e4c8
Diffstat (limited to 'services/services-engine/src/test')
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexEventTest.java23
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java5
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java8
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java25
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java9
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java9
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java4
7 files changed, 56 insertions, 27 deletions
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexEventTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexEventTest.java
index bb299a834..0f17bf193 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexEventTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexEventTest.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021. 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.
@@ -42,7 +43,7 @@ public class ApexEventTest {
@Before
public void setUp() throws Exception {
apexEvent =
- new ApexEvent("name", "version", "namespace", "source", "target");
+ new ApexEvent("name", "version", "namespace", "source", "target", "");
}
@@ -50,7 +51,7 @@ public class ApexEventTest {
public void invalidEventName() {
final String name = "++" + RandomStringUtils.randomAlphabetic(5);
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent(name, "version", "namespace", "source", "target"))
+ apexEvent = new ApexEvent(name, "version", "namespace", "source", "target", ""))
.isInstanceOf(ApexEventException.class);
}
@@ -58,7 +59,7 @@ public class ApexEventTest {
public void invalidEventVersion() {
final String version = "++" + RandomStringUtils.randomAlphabetic(5);
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent("name", version, "namespace", "source", "target"))
+ apexEvent = new ApexEvent("name", version, "namespace", "source", "target", ""))
.isInstanceOf(ApexEventException.class);
}
@@ -66,7 +67,7 @@ public class ApexEventTest {
public void invalidEventNamespace() {
final String namespace = "++" + RandomStringUtils.randomAlphabetic(5);
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent("name", "version", namespace, "source", "target"))
+ apexEvent = new ApexEvent("name", "version", namespace, "source", "target", ""))
.isInstanceOf(ApexEventException.class);
}
@@ -74,7 +75,7 @@ public class ApexEventTest {
public void invalidEventSource() {
final String source = "++" + RandomStringUtils.randomAlphabetic(5);
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent("name", "version", "namespace", source, "target"))
+ apexEvent = new ApexEvent("name", "version", "namespace", source, "target", ""))
.isInstanceOf(ApexEventException.class);
}
@@ -82,11 +83,19 @@ public class ApexEventTest {
public void invalidEventTarget() {
final String target = "++" + RandomStringUtils.randomAlphabetic(5);
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent("name", "version", "namespace", "source", target))
+ apexEvent = new ApexEvent("name", "version", "namespace", "source", target, ""))
.isInstanceOf(ApexEventException.class);
}
@Test
+ public void invalidEventStatus() {
+ final String toscaPolicyState = "INVALID_STATUS";
+ Assertions.assertThatCode(() ->
+ apexEvent = new ApexEvent("name", "version", "namespace", "source", "target", toscaPolicyState))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+ @Test
public void setExecutionId() {
final int executionId = random.nextInt();
apexEvent.setExecutionId(executionId);
@@ -161,4 +170,4 @@ public class ApexEventTest {
assertThat(actual2).isNull();
assertThat(actual3).isNull();
}
-}
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java
index a7d08bb55..ed1e09b2a 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 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.
@@ -59,7 +60,7 @@ public class JsonEventConverterTest {
assertThatThrownBy(() -> converter.fromApexEvent(null))
.hasMessage("event processing failed, Apex event is null");
assertThatThrownBy(() -> converter.fromApexEvent(new ApexEvent("Event", "0.0.1", "a.name.space",
- "here", "there")))
+ "here", "there", "")))
.hasMessage("Model for org.onap.policy.apex.model.eventmodel.concepts.AxEvents not found in model service");
}
-}
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java
index fdb886e10..dd7acddaa 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 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.
@@ -38,6 +39,7 @@ import org.junit.Test;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.SchemaParameters;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxToscaPolicyProcessingStatus;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
import org.onap.policy.apex.model.basicmodel.service.ModelService;
@@ -250,7 +252,8 @@ public class JsonEventHandlerTest {
basicEventMap.put("intPar", 12345);
final ApexEvent basicEvent =
- new ApexEvent("BasicEvent", "0.0.1", "org.onap.policy.apex.events", "test", "apex");
+ new ApexEvent("BasicEvent", "0.0.1", "org.onap.policy.apex.events", "test", "apex",
+ AxToscaPolicyProcessingStatus.ENTRY.name());
basicEvent.putAll(basicEventMap);
final String apexEvent0000JsonString = (String) jsonEventConverter.fromApexEvent(basicEvent);
@@ -263,5 +266,6 @@ public class JsonEventHandlerTest {
assertTrue(apexEvent0000JsonString.contains("\"source\": \"test\""));
assertTrue(apexEvent0000JsonString.contains("\"target\": \"apex\""));
assertTrue(apexEvent0000JsonString.contains("\"intPar\": 12345"));
+ assertTrue(apexEvent0000JsonString.contains("\"toscaPolicyState\": \"ENTRY\""));
}
-}
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java
index 04e87ee42..9a61f8739 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 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.
@@ -29,6 +30,7 @@ import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxToscaPolicyProcessingStatus;
import org.onap.policy.apex.service.engine.event.ApexEvent;
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.ApexEventList;
@@ -76,8 +78,9 @@ public class Apex2ApexEventConverterTest {
final String nameSpace = "a" + RandomStringUtils.randomAlphanumeric(7);
final String source = RandomStringUtils.randomAlphanumeric(8);
final String target = RandomStringUtils.randomAlphanumeric(9);
+ final String toscaPolicyState = AxToscaPolicyProcessingStatus.ENTRY.name();
- final ApexEvent event = new ApexEvent(name, version, nameSpace, source, target);
+ final ApexEvent event = new ApexEvent(name, version, nameSpace, source, target, toscaPolicyState);
final List<ApexEvent> result = converter.toApexEvent(eventName, event);
assertThat(result).isEmpty();
}
@@ -90,8 +93,9 @@ public class Apex2ApexEventConverterTest {
final String nameSpace1 = "a" + RandomStringUtils.randomAlphanumeric(7);
final String source1 = RandomStringUtils.randomAlphanumeric(8);
final String target1 = RandomStringUtils.randomAlphanumeric(9);
+ final String toscaPolicyState1 = AxToscaPolicyProcessingStatus.ENTRY.name();
- final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1);
+ final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1, toscaPolicyState1);
final String key = RandomStringUtils.randomAlphabetic(3);
event.put(key, new Object());
@@ -108,8 +112,9 @@ public class Apex2ApexEventConverterTest {
final String nameSpace1 = "a" + RandomStringUtils.randomAlphanumeric(7);
final String source1 = RandomStringUtils.randomAlphanumeric(8);
final String target1 = RandomStringUtils.randomAlphanumeric(9);
+ final String toscaPolicyState1 = AxToscaPolicyProcessingStatus.ENTRY.name();
- final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1);
+ final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1, toscaPolicyState1);
final ApexEventList eventList = new ApexEventList();
eventList.add(event);
@@ -119,8 +124,9 @@ public class Apex2ApexEventConverterTest {
final String nameSpace2 = "b" + RandomStringUtils.randomAlphanumeric(17);
final String source2 = RandomStringUtils.randomAlphanumeric(18);
final String target2 = RandomStringUtils.randomAlphanumeric(19);
+ final String toscaPolicyState2 = AxToscaPolicyProcessingStatus.EXIT_SUCCESS.name();
- final ApexEvent parentEvent = new ApexEvent(name2, version2, nameSpace2, source2, target2);
+ final ApexEvent parentEvent = new ApexEvent(name2, version2, nameSpace2, source2, target2, toscaPolicyState2);
final String key = RandomStringUtils.randomAlphabetic(3);
parentEvent.put(key, eventList);
final List<ApexEvent> result = converter.toApexEvent(eventName, parentEvent);
@@ -136,8 +142,9 @@ public class Apex2ApexEventConverterTest {
final String nameSpace1 = "a" + RandomStringUtils.randomAlphanumeric(7);
final String source1 = RandomStringUtils.randomAlphanumeric(8);
final String target1 = RandomStringUtils.randomAlphanumeric(9);
+ final String toscaPolicyState1 = AxToscaPolicyProcessingStatus.ENTRY.name();
- final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1);
+ final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1, toscaPolicyState1);
final ApexEventList eventList = new ApexEventList();
eventList.add(event);
@@ -147,8 +154,9 @@ public class Apex2ApexEventConverterTest {
final String nameSpace2 = "b" + RandomStringUtils.randomAlphanumeric(17);
final String source2 = RandomStringUtils.randomAlphanumeric(18);
final String target2 = RandomStringUtils.randomAlphanumeric(19);
+ final String toscaPolicyState2 = AxToscaPolicyProcessingStatus.EXIT_FAILURE.name();
- final ApexEvent parentEvent = new ApexEvent(name2, version2, nameSpace2, source2, target2);
+ final ApexEvent parentEvent = new ApexEvent(name2, version2, nameSpace2, source2, target2, toscaPolicyState2);
final String key1 = RandomStringUtils.randomAlphabetic(3);
final String key2 = RandomStringUtils.randomAlphabetic(2);
parentEvent.put(key1, eventList);
@@ -170,11 +178,12 @@ public class Apex2ApexEventConverterTest {
final String nameSpace1 = "a" + RandomStringUtils.randomAlphanumeric(7);
final String source1 = RandomStringUtils.randomAlphanumeric(8);
final String target1 = RandomStringUtils.randomAlphanumeric(9);
+ final String toscaPolicyState1 = AxToscaPolicyProcessingStatus.ENTRY.name();
- final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1);
+ final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1, toscaPolicyState1);
final Object actual = converter.fromApexEvent(event);
assertSame(event, actual);
}
-}
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java
index 562760f69..4d36b7be4 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 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.
@@ -29,6 +30,7 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.policy.apex.core.engine.event.EnEvent;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxToscaPolicyProcessingStatus;
import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
import org.onap.policy.apex.service.engine.event.ApexEvent;
import org.onap.policy.apex.service.engine.event.ApexEventException;
@@ -58,8 +60,9 @@ public class ApexEvent2EnEventConverterTest {
final String nameSpace = "a" + RandomStringUtils.randomAlphanumeric(7);
final String source = RandomStringUtils.randomAlphanumeric(8);
final String target = RandomStringUtils.randomAlphanumeric(9);
+ final String toscaPolicyState = AxToscaPolicyProcessingStatus.ENTRY.name();
- final ApexEvent event = new ApexEvent(name, version, nameSpace, source, target);
+ final ApexEvent event = new ApexEvent(name, version, nameSpace, source, target, toscaPolicyState);
assertThatThrownBy(() -> converter.toApexEvent(eventName, event))
.isInstanceOf(ApexEventRuntimeException.class);
@@ -73,6 +76,7 @@ public class ApexEvent2EnEventConverterTest {
final String nameSpace = "b" + RandomStringUtils.randomAlphabetic(7);
final String source = RandomStringUtils.randomAlphabetic(8);
final String target = RandomStringUtils.randomAlphabetic(9);
+ final String toscaPolicyState = AxToscaPolicyProcessingStatus.ENTRY.name();
final int executionId = random.nextInt(1000);
final String exceptionMessage = RandomStringUtils.randomAlphabetic(11);
@@ -83,12 +87,13 @@ public class ApexEvent2EnEventConverterTest {
axEvent.setNameSpace(nameSpace);
axEvent.setSource(source);
axEvent.setTarget(target);
+ axEvent.setToscaPolicyState(toscaPolicyState);
final EnEvent enEvent = new EnEvent(axEvent);
enEvent.setExecutionId(executionId);
enEvent.setExceptionMessage(exceptionMessage);
// prepare expected event
- final ApexEvent apexEvent = new ApexEvent(name, version, nameSpace, source, target);
+ final ApexEvent apexEvent = new ApexEvent(name, version, nameSpace, source, target, toscaPolicyState);
apexEvent.setExecutionId(executionId);
apexEvent.setExceptionMessage(exceptionMessage);
final Object[] expected = {apexEvent};
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java
index ed1afe4da..0095c9630 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020-2021 Nordix Foundation.
- * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -239,7 +239,7 @@ public class EngineServiceImplTest {
esImpl.stop();
esImpl.sendEvent(null);
- esImpl.sendEvent(new ApexEvent("SomeEvent", "0.0.1", "the.event.namespace", "EventSource", "EventTarget"));
+ esImpl.sendEvent(new ApexEvent("SomeEvent", "0.0.1", "the.event.namespace", "EventSource", "EventTarget", ""));
esImpl.startPeriodicEvents(100000);
@@ -381,7 +381,8 @@ public class EngineServiceImplTest {
}
try {
- esImpl.sendEvent(new ApexEvent("SomeEvent", "0.0.1", "the.event.namespace", "EventSource", "EventTarget"));
+ esImpl.sendEvent(new ApexEvent("SomeEvent", "0.0.1", "the.event.namespace", "EventSource", "EventTarget",
+ ""));
} catch (ApexException apEx) {
fail("test should not throw an exception");
}
@@ -420,4 +421,4 @@ public class EngineServiceImplTest {
fail("test should not throw an exception");
}
}
-}
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java
index 504e8df14..c95b465cf 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation.
- * Modifications Copyright (C) 2021 Bell Canada Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021-2022 Bell Canada 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.
@@ -348,7 +348,7 @@ public class EngineWorkerTest {
fail("test should not throw an exception");
}
- eventQueue.add(new ApexEvent("SomeEvent", "0.0.1", "the.event.namespace", "EventSource", "EventTarget"));
+ eventQueue.add(new ApexEvent("SomeEvent", "0.0.1", "the.event.namespace", "EventSource", "EventTarget", ""));
try {
worker.updateModel(worker.getKey(), differentModelString, false);