summaryrefslogtreecommitdiffstats
path: root/examples/examples-myfirstpolicy/src/test
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-03-11 17:17:14 +0000
committerliamfallon <liam.fallon@est.tech>2020-03-11 18:34:55 +0000
commitb87ab1696010ca0bbed5db99c140cf908722df57 (patch)
tree160ed6eafc600d126465e846f18b70bd199edbed /examples/examples-myfirstpolicy/src/test
parent7c28f233037e768cde426f78d61cf959d2053fdb (diff)
Convert examples to Rhino Javascript format
All examples are converted to Rhino Javascript from Nashorn Javascript. Issue-ID: POLICY-2106 Change-Id: Ia6fec5b57b1e6131799b4b069968e4766ce54c96 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'examples/examples-myfirstpolicy/src/test')
-rw-r--r--examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpDomainModelFactory.java90
-rw-r--r--examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpLogicTest.java1
-rw-r--r--examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelCliTest.java2
-rw-r--r--examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java57
-rw-r--r--examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestMfpModelCreator.java2
-rw-r--r--examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java4
6 files changed, 149 insertions, 7 deletions
diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpDomainModelFactory.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpDomainModelFactory.java
new file mode 100644
index 000000000..65dad94c4
--- /dev/null
+++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpDomainModelFactory.java
@@ -0,0 +1,90 @@
+/*-
+ * ============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.examples.myfirstpolicy;
+
+import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException;
+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.ResourceUtils;
+
+/**
+ * A factory for creating MFPDomainModel objects.
+ *
+ * @author John Keeney (john.keeney@ericsson.com)
+ */
+public class MfpDomainModelFactory {
+
+ private static final String MFP1PATH =
+ "target/classes/examples/models/MyFirstPolicy/1/MyFirstPolicyModelMvel_0.0.1.json";
+ private static final String MFP1_ALT_PATH =
+ "target/classes/examples/models/MyFirstPolicy/1/MyFirstPolicyModelJavascript_0.0.1.json";
+ private static final String MFP2PATH =
+ "target/classes/examples/models/MyFirstPolicy/2/MyFirstPolicyModel_0.0.1.json";
+
+ /**
+ * Gets the MyFirstPolicy#1 policy model.
+ *
+ * @return the MyFirstPolicy#1 policy model
+ */
+ public AxPolicyModel getMfp1PolicyModel() {
+ java.util.TimeZone.getTimeZone("gmt");
+ try {
+ final ApexModelReader<AxPolicyModel> reader = new ApexModelReader<>(AxPolicyModel.class);
+ return reader.read(ResourceUtils.getResourceAsString(MfpDomainModelFactory.MFP1PATH));
+ } catch (final Exception e) {
+ throw new ApexRuntimeException("Failed to build MyFirstPolicy from path: " + MfpDomainModelFactory.MFP1PATH,
+ e);
+ }
+ }
+
+ /**
+ * Gets the MyFirstPolicy#1 policy model, with alternate JavaScript task logic.
+ *
+ * @return the MyFirstPolicy#1 policy model
+ */
+ public AxPolicyModel getMfp1AltPolicyModel() {
+ java.util.TimeZone.getTimeZone("gmt");
+ try {
+ final ApexModelReader<AxPolicyModel> reader = new ApexModelReader<>(AxPolicyModel.class);
+ return reader.read(ResourceUtils.getResourceAsString(MfpDomainModelFactory.MFP1_ALT_PATH));
+ } catch (final Exception e) {
+ throw new ApexRuntimeException(
+ "Failed to build MyFirstPolicy_ALT from path: " + MfpDomainModelFactory.MFP1_ALT_PATH, e);
+ }
+ }
+
+ /**
+ * Gets the MyFirstPolicy#1 policy model.
+ *
+ * @return the MyFirstPolicy#1 policy model
+ */
+ public AxPolicyModel getMfp2PolicyModel() {
+ try {
+ final ApexModelReader<AxPolicyModel> reader = new ApexModelReader<>(AxPolicyModel.class);
+ return reader.read(ResourceUtils.getResourceAsString(MfpDomainModelFactory.MFP2PATH));
+ } catch (final Exception e) {
+ throw new ApexRuntimeException("Failed to build MyFirstPolicy from path: " + MfpDomainModelFactory.MFP2PATH,
+ e);
+ }
+ }
+
+}
diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpLogicTest.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpLogicTest.java
index 3ebf8155e..c470e9356 100644
--- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpLogicTest.java
+++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpLogicTest.java
@@ -31,7 +31,6 @@ import java.util.Map.Entry;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.onap.policy.apex.examples.myfirstpolicy.model.MfpDomainModelFactory;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicy;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelCliTest.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelCliTest.java
index af0e44450..90859794e 100644
--- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelCliTest.java
+++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelCliTest.java
@@ -68,7 +68,7 @@ public class MfpModelCliTest {
// @formatter:off
final String[] testApexModel1CliArgs = {
"-c",
- "src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModel_0.0.1.apex",
+ "src/main/resources/examples/models/MyFirstPolicy/1/MyFirstPolicyModelMvel_0.0.1.apex",
"-l",
tempLogFile1.getAbsolutePath(),
"-o",
diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java
index 0d6192988..fb4103c99 100644
--- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java
+++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * 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.
@@ -44,7 +44,6 @@ import org.onap.policy.apex.core.engine.EngineParameters;
import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory;
import org.onap.policy.apex.core.engine.engine.impl.ApexEngineImpl;
import org.onap.policy.apex.core.engine.event.EnEvent;
-import org.onap.policy.apex.examples.myfirstpolicy.model.MfpDomainModelFactory;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
@@ -170,6 +169,60 @@ public class MfpUseCaseTest {
}
/**
+ * Test MyFirstPolicy#1 use case.
+ *
+ * @throws ApexException if there is an Apex error
+ * @throws InterruptedException if there is an Interruption.
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ @Test
+ public void testMfp1AltCase() throws ApexException, InterruptedException, IOException {
+ final AxPolicyModel apexPolicyModel = new MfpDomainModelFactory().getMfp1AltPolicyModel();
+ assertNotNull(apexPolicyModel);
+
+ final TestSaleAuthListener listener = new TestSaleAuthListener("Test");
+ apexEngine.addEventListener("listener", listener);
+ apexEngine.updateModel(apexPolicyModel, false);
+ apexEngine.start();
+
+ final AxEvent axEventin = apexPolicyModel.getEvents().get(new AxArtifactKey("SALE_INPUT:0.0.1"));
+ assertNotNull(axEventin);
+ final AxEvent axEventout = apexPolicyModel.getEvents().get(new AxArtifactKey("SALE_AUTH:0.0.1"));
+ assertNotNull(axEventout);
+
+ EnEvent event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/1/EventIn_BoozeItem_084106GMT.json");
+ apexEngine.handleEvent(event);
+ EnEvent resultout = listener.getResult();
+ EnEvent resulexpected =
+ fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_084106GMT.json");
+ resultout.put("message", "");
+ resulexpected.put("message", "");
+ assertEquals(resulexpected, resultout);
+
+ event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/1/EventIn_BoozeItem_201713GMT.json");
+ apexEngine.handleEvent(event);
+ resultout = listener.getResult();
+ resulexpected =
+ fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_201713GMT.json");
+ resultout.put("message", "");
+ resulexpected.put("message", "");
+ assertEquals(resulexpected, resultout);
+ assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId());
+
+ event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/1/EventIn_NonBoozeItem_101309GMT.json");
+ apexEngine.handleEvent(event);
+ resultout = listener.getResult();
+ resulexpected =
+ fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_NonBoozeItem_101309GMT.json");
+ resultout.put("message", "");
+ resulexpected.put("message", "");
+ assertEquals(resulexpected, resultout);
+ assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId());
+
+ apexEngine.stop();
+ }
+
+ /**
* Test MyFirstPolicy#2 use case.
*
* @throws ApexException if there is an Apex error
diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestMfpModelCreator.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestMfpModelCreator.java
index 540d1e341..24f85833a 100644
--- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestMfpModelCreator.java
+++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestMfpModelCreator.java
@@ -1,6 +1,7 @@
/*-
* ============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.
@@ -20,7 +21,6 @@
package org.onap.policy.apex.examples.myfirstpolicy;
-import org.onap.policy.apex.examples.myfirstpolicy.model.MfpDomainModelFactory;
import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java
index 0169d14cb..44c4306b9 100644
--- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java
+++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java
@@ -21,6 +21,8 @@
package org.onap.policy.apex.examples.myfirstpolicy;
+import static org.awaitility.Awaitility.await;
+
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -28,8 +30,6 @@ import java.util.concurrent.TimeUnit;
import org.onap.policy.apex.core.engine.engine.EnEventListener;
import org.onap.policy.apex.core.engine.event.EnEvent;
-import static org.awaitility.Awaitility.await;
-
/**
* The listener interface for receiving SaleAuth events. The class that is interested in processing a SaleAuth event
* implements this interface, and the object created with that class is registered with a component using the