diff options
Diffstat (limited to 'examples/examples-myfirstpolicy')
5 files changed, 150 insertions, 163 deletions
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 b3c35a310..19bdc8575 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 @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,15 +21,15 @@ package org.onap.policy.apex.examples.myfirstpolicy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; 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; @@ -40,15 +40,15 @@ import org.onap.policy.common.utils.resources.ResourceUtils; /** * The Class TestMfpLogic. */ -public class MfpLogicTest { +class MfpLogicTest { private static final Map<String, String> LOGICEXTENSIONS = new LinkedHashMap<>(); /** * Test setup. */ - @BeforeClass - public static void testMfpUseCaseSetup() { + @BeforeAll + static void testMfpUseCaseSetup() { LOGICEXTENSIONS.put("MVEL", "mvel"); LOGICEXTENSIONS.put("JAVASCRIPT", "js"); } @@ -57,7 +57,7 @@ public class MfpLogicTest { * Check logic for MyFirstPolicy#1. */ @Test - public void testMfp1TaskLogic() { + void testMfp1TaskLogic() { final AxPolicyModel apexPolicyModel = new MfpDomainModelFactory().getMfp1PolicyModel(); assertNotNull(apexPolicyModel); @@ -65,16 +65,15 @@ public class MfpLogicTest { logics.putAll(getTslLogics(apexPolicyModel)); logics.putAll(getTaskLogics(apexPolicyModel)); - for (final Entry<String, String> logicvalue : logics.entrySet()) { - final String filename = "examples/models/MyFirstPolicy/1/" + logicvalue.getKey(); - final String logic = logicvalue.getValue(); - final String expectedlogic = ResourceUtils.getResourceAsString(filename); - assertNotNull("File " + filename + " was not found. It should contain logic for PolicyModel " - + apexPolicyModel.getKey(), expectedlogic); - assertEquals( - "The task in " + filename + " is not the same as the relevant logic in PolicyModel " - + apexPolicyModel.getKey(), - expectedlogic.replaceAll("\\s", ""), logic.replaceAll("\\s", "")); + for (final Entry<String, String> logicValue : logics.entrySet()) { + final String filename = "examples/models/MyFirstPolicy/1/" + logicValue.getKey(); + final String logic = logicValue.getValue(); + final String expectedLogic = ResourceUtils.getResourceAsString(filename); + assertNotNull(expectedLogic, "File " + filename + " was not found. It should contain logic for PolicyModel " + + apexPolicyModel.getKey()); + assertEquals(expectedLogic.replaceAll("\\s", ""), logic.replaceAll("\\s", ""), + "The task in " + filename + " is not the same as the relevant logic in PolicyModel " + + apexPolicyModel.getKey()); } } @@ -82,7 +81,7 @@ public class MfpLogicTest { * Check logic for MyFirstPolicyAlt#1. */ @Test - public void testMfp1AltTaskLogic() { + void testMfp1AltTaskLogic() { final AxPolicyModel apexPolicyModel = new MfpDomainModelFactory().getMfp1AltPolicyModel(); assertNotNull(apexPolicyModel); @@ -90,16 +89,15 @@ public class MfpLogicTest { logics.putAll(getTslLogics(apexPolicyModel)); logics.putAll(getTaskLogics(apexPolicyModel)); - for (final Entry<String, String> logicvalue : logics.entrySet()) { - final String filename = "examples/models/MyFirstPolicy/1/" + logicvalue.getKey(); - final String logic = logicvalue.getValue(); - final String expectedlogic = ResourceUtils.getResourceAsString(filename); - assertNotNull("File " + filename + " was not found. It should contain logic for PolicyModel " - + apexPolicyModel.getKey(), expectedlogic); - assertEquals( - "The task in " + filename + " is not the same as the relevant logic in PolicyModel " - + apexPolicyModel.getKey(), - expectedlogic.replaceAll("\\s", ""), logic.replaceAll("\\s", "")); + for (final Entry<String, String> logicValue : logics.entrySet()) { + final String filename = "examples/models/MyFirstPolicy/1/" + logicValue.getKey(); + final String logic = logicValue.getValue(); + final String expectedLogic = ResourceUtils.getResourceAsString(filename); + assertNotNull(expectedLogic, "File " + filename + " was not found. It should contain logic for PolicyModel " + + apexPolicyModel.getKey()); + assertEquals(expectedLogic.replaceAll("\\s", ""), logic.replaceAll("\\s", ""), + "The task in " + filename + " is not the same as the relevant logic in PolicyModel " + + apexPolicyModel.getKey()); } } @@ -107,7 +105,7 @@ public class MfpLogicTest { * Check logic for MyFirstPolicy2. */ @Test - public void testMfp2TaskLogic() { + void testMfp2TaskLogic() { final AxPolicyModel apexPolicyModel = new MfpDomainModelFactory().getMfp2PolicyModel(); assertNotNull(apexPolicyModel); @@ -115,16 +113,15 @@ public class MfpLogicTest { logics.putAll(getTslLogics(apexPolicyModel)); logics.putAll(getTaskLogics(apexPolicyModel)); - for (final Entry<String, String> logicvalue : logics.entrySet()) { - final String logic = logicvalue.getValue(); - final String filename = "examples/models/MyFirstPolicy/2/" + logicvalue.getKey(); - final String expectedlogic = ResourceUtils.getResourceAsString(filename); - assertNotNull("File " + filename + " was not found. It should contain logic for PolicyModel " - + apexPolicyModel.getKey(), expectedlogic); - assertEquals( - "The task in " + filename + " is not the same as the relevant logic in PolicyModel " - + apexPolicyModel.getKey(), - expectedlogic.replaceAll("\\s", ""), logic.replaceAll("\\s", "")); + for (final Entry<String, String> logicValue : logics.entrySet()) { + final String logic = logicValue.getValue(); + final String filename = "examples/models/MyFirstPolicy/2/" + logicValue.getKey(); + final String expectedLogic = ResourceUtils.getResourceAsString(filename); + assertNotNull(expectedLogic, "File " + filename + " was not found. It should contain logic for PolicyModel " + + apexPolicyModel.getKey()); + assertEquals(expectedLogic.replaceAll("\\s", ""), logic.replaceAll("\\s", ""), + "The task in " + filename + " is not the same as the relevant logic in PolicyModel " + + apexPolicyModel.getKey()); } } @@ -136,20 +133,19 @@ public class MfpLogicTest { */ private Map<String, String> getTslLogics(final AxPolicyModel apexPolicyModel) { final Map<String, String> ret = new LinkedHashMap<>(); - for (final Entry<AxArtifactKey, AxPolicy> policyentry : apexPolicyModel.getPolicies().getPolicyMap() - .entrySet()) { + for (final Entry<AxArtifactKey, AxPolicy> policyentry : + apexPolicyModel.getPolicies().getPolicyMap().entrySet()) { for (final Entry<String, AxState> statesentry : policyentry.getValue().getStateMap().entrySet()) { final AxState state = statesentry.getValue(); - final String tsllogic = state.getTaskSelectionLogic().getLogic(); - final String tsllogicflavour = state.getTaskSelectionLogic().getLogicFlavour(); - if (tsllogic != null && tsllogic.trim().length() > 0) { - assertNotNull( - "Logic Type \"" + tsllogicflavour + "\" in state " + statesentry.getKey() + " in policy " - + policyentry.getKey() + " is not supported in this test", - LOGICEXTENSIONS.get(tsllogicflavour.toUpperCase())); + final String tslLogic = state.getTaskSelectionLogic().getLogic(); + final String tslLogicFlavour = state.getTaskSelectionLogic().getLogicFlavour(); + if (tslLogic != null && !tslLogic.trim().isEmpty()) { + assertNotNull(LOGICEXTENSIONS.get(tslLogicFlavour.toUpperCase()), + "Logic Type \"" + tslLogicFlavour + "\" in state " + statesentry.getKey() + " in policy " + + policyentry.getKey() + " is not supported in this test"); final String filename = policyentry.getKey().getName() + "_" + statesentry.getKey() + "TSL." - + LOGICEXTENSIONS.get(tsllogicflavour.toUpperCase()); - ret.put(filename, tsllogic); + + LOGICEXTENSIONS.get(tslLogicFlavour.toUpperCase()); + ret.put(filename, tslLogic); } } } @@ -166,15 +162,16 @@ public class MfpLogicTest { final Map<String, String> ret = new LinkedHashMap<>(); for (final Entry<AxArtifactKey, AxTask> taskentry : apexPolicyModel.getTasks().getTaskMap().entrySet()) { final AxTask task = taskentry.getValue(); - final String tasklogic = task.getTaskLogic().getLogic(); - final String tasklogicflavour = task.getTaskLogic().getLogicFlavour(); - assertTrue("No/Blank logic found in task " + taskentry.getKey(), - (tasklogic != null && tasklogic.trim().length() > 0)); - assertNotNull("Logic Type \"" + tasklogicflavour + "\" in task " + taskentry.getKey() - + " is not supported in this test", LOGICEXTENSIONS.get(tasklogicflavour.toUpperCase())); + final String taskLogic = task.getTaskLogic().getLogic(); + final String taskLogicFlavour = task.getTaskLogic().getLogicFlavour(); + assertTrue((taskLogic != null && !taskLogic.trim().isEmpty()), + "No/Blank logic found in task " + taskentry.getKey()); + assertNotNull(LOGICEXTENSIONS.get(taskLogicFlavour.toUpperCase()), + "Logic Type \"" + taskLogicFlavour + "\" in task " + taskentry.getKey() + + " is not supported in this test"); final String filename = - taskentry.getKey().getName() + "." + LOGICEXTENSIONS.get(tasklogicflavour.toUpperCase()); - ret.put(filename, tasklogic); + taskentry.getKey().getName() + "." + LOGICEXTENSIONS.get(taskLogicFlavour.toUpperCase()); + ret.put(filename, taskLogic); } return ret; } 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 45281524c..cb3aa7666 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 @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,12 +21,12 @@ package org.onap.policy.apex.examples.myfirstpolicy; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.File; import java.io.IOException; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain; import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; @@ -36,17 +36,15 @@ import org.onap.policy.common.utils.resources.TextFileUtils; /** * Test MyFirstPolicyModel CLI. */ -public class MfpModelCliTest { +class MfpModelCliTest { private static AxPolicyModel testApexModel1; private static AxPolicyModel testApexModel2; /** - * Setup the test. - * - * @throws Exception if there is an error + * Set up the test. */ - @BeforeClass - public static void setup() throws Exception { + @BeforeAll + static void setup() { testApexModel1 = new TestMfpModelCreator.TestMfp1ModelCreator().getModel(); testApexModel2 = new TestMfpModelCreator.TestMfp2ModelCreator().getModel(); } @@ -54,11 +52,11 @@ public class MfpModelCliTest { /** * Test CLI policy. * - * @throws IOException Signals that an I/O exception has occurred. + * @throws IOException Signals that an I/O exception has occurred. * @throws ApexModelException ifd there is an Apex Error */ @Test - public void testCliPolicy() throws IOException, ApexModelException { + void testCliPolicy() throws IOException, ApexModelException { final File tempLogFile1 = File.createTempFile("TestMyFirstPolicy1CLI", ".log"); final File tempModelFile1 = File.createTempFile("TestMyFirstPolicy1CLI", ".json"); @@ -89,17 +87,19 @@ public class MfpModelCliTest { final ApexModelReader<AxPolicyModel> reader = new ApexModelReader<>(AxPolicyModel.class); AxPolicyModel generatedmodel = reader.read(TextFileUtils.getTextFileAsString(tempModelFile1.getAbsolutePath())); - assertEquals("Model generated from the CLI (" + testApexModel1CliArgs[1] + ") into file " + assertEquals(testApexModel1, generatedmodel, + "Model generated from the CLI (" + testApexModel1CliArgs[1] + ") into file " + tempModelFile1.getAbsolutePath() + " is not the same as the test Model for " - + testApexModel1.getKey(), testApexModel1, generatedmodel); + + testApexModel1.getKey()); tempLogFile1.delete(); tempModelFile1.delete(); generatedmodel = reader.read(TextFileUtils.getTextFileAsString(tempModelFile2.getAbsolutePath())); - assertEquals("Model generated from the CLI (" + testApexModel2CliArgs[1] + ") into file " + assertEquals(testApexModel2, generatedmodel, + "Model generated from the CLI (" + testApexModel2CliArgs[1] + ") into file " + tempModelFile2.getAbsolutePath() + " is not the same as the test Model for " - + testApexModel2.getKey(), testApexModel2, generatedmodel); + + testApexModel2.getKey()); tempLogFile2.delete(); tempModelFile2.delete(); diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelTest.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelTest.java index 2472cb466..38db6510a 100644 --- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelTest.java +++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2022 Nordix Foundation. + * Modifications Copyright (C) 2022, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,10 @@ package org.onap.policy.apex.examples.myfirstpolicy; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.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; @@ -34,17 +34,15 @@ import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; * * @author John Keeney (john.keeney@ericsson.com) */ -public class MfpModelTest { +class MfpModelTest { private static TestApexModel<AxPolicyModel> testApexModel1; private static TestApexModel<AxPolicyModel> testApexModel2; /** * Setup. - * - * @throws Exception if there is an error */ - @BeforeClass - public static void setup() throws Exception { + @BeforeAll + static void setup() { testApexModel1 = new TestApexModel<>(AxPolicyModel.class, new TestMfpModelCreator.TestMfp1ModelCreator()); testApexModel2 = new TestApexModel<>(AxPolicyModel.class, new TestMfpModelCreator.TestMfp2ModelCreator()); } @@ -55,12 +53,12 @@ public class MfpModelTest { * @throws Exception if there is an error */ @Test - public void testModelValid() throws Exception { + void testModelValid() throws Exception { AxValidationResult result = testApexModel1.testApexModelValid(); - assertTrue("Model did not validate cleanly", result.isOk()); + assertTrue(result.isOk(), "Model did not validate cleanly"); result = testApexModel2.testApexModelValid(); - assertTrue("Model did not validate cleanly", result.isOk()); + assertTrue(result.isOk(), "Model did not validate cleanly"); } /** @@ -69,7 +67,7 @@ public class MfpModelTest { * @throws Exception if there is an error */ @Test - public void testModelWriteReadJson() throws Exception { + void testModelWriteReadJson() throws Exception { testApexModel1.testApexModelWriteReadJson(); testApexModel2.testApexModelWriteReadJson(); } 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 8afe7d7cd..654823f15 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-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,19 +21,18 @@ package org.onap.policy.apex.examples.myfirstpolicy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; -import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.Map; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters; import org.onap.policy.apex.context.parameters.ContextParameterConstants; import org.onap.policy.apex.context.parameters.ContextParameters; @@ -55,7 +54,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils; /** * Test MyFirstPolicy Use Case. */ -public class MfpUseCaseTest { +class MfpUseCaseTest { // CHECKSTYLE:OFF: MagicNumber private static ApexEngineImpl apexEngine; @@ -63,8 +62,8 @@ public class MfpUseCaseTest { /** * Test MFP use case setup. */ - @BeforeClass - public static void testMfpUseCaseSetup() { + @BeforeAll + static void testMfpUseCaseSetup() { final AxArtifactKey key = new AxArtifactKey("MyFirstPolicyApexEngine", "0.0.1"); apexEngine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(key); } @@ -76,8 +75,8 @@ public class MfpUseCaseTest { /** * Before test. */ - @BeforeClass - public static void beforeTest() { + @BeforeAll + static void beforeTest() { schemaParameters = new SchemaParameters(); schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); @@ -106,8 +105,8 @@ public class MfpUseCaseTest { /** * After test. */ - @AfterClass - public static void afterTest() { + @AfterAll + static void afterTest() { ParameterService.deregister(engineParameters); ParameterService.deregister(contextParameters.getDistributorParameters()); @@ -122,11 +121,9 @@ 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 testMfp1Case() throws ApexException, InterruptedException, IOException { + void testMfp1Case() throws ApexException { final AxPolicyModel apexPolicyModel = new MfpDomainModelFactory().getMfp1PolicyModel(); assertNotNull(apexPolicyModel); @@ -144,24 +141,22 @@ public class MfpUseCaseTest { apexEngine.handleEvent(event); EnEvent resultout = listener.getResult(); EnEvent resulexpected = - fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_084106GMT.json"); + fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_084106GMT.json"); 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"); - assertEquals(resulexpected, resultout); - assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId()); + fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_201713GMT.json"); + assertHandledEventResult(resulexpected, resultout, event); 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"); - assertEquals(resulexpected, resultout); - assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId()); + fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_NonBoozeItem_101309GMT.json"); + assertHandledEventResult(resulexpected, resultout, event); apexEngine.stop(); } @@ -170,11 +165,9 @@ 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 { + void testMfp1AltCase() throws ApexException { final AxPolicyModel apexPolicyModel = new MfpDomainModelFactory().getMfp1AltPolicyModel(); assertNotNull(apexPolicyModel); @@ -192,7 +185,7 @@ public class MfpUseCaseTest { apexEngine.handleEvent(event); EnEvent resultout = listener.getResult(); EnEvent resulexpected = - fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_084106GMT.json"); + fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_084106GMT.json"); resultout.put("message", ""); resulexpected.put("message", ""); assertEquals(resulexpected, resultout); @@ -201,21 +194,19 @@ public class MfpUseCaseTest { apexEngine.handleEvent(event); resultout = listener.getResult(); resulexpected = - fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_201713GMT.json"); + 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()); + assertHandledEventResult(resulexpected, resultout, event); 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"); + 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()); + assertHandledEventResult(resulexpected, resultout, event); apexEngine.stop(); } @@ -224,11 +215,9 @@ public class MfpUseCaseTest { * Test MyFirstPolicy#2 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 testMfp2Case() throws ApexException, InterruptedException, IOException { + void testMfp2Case() throws ApexException { final AxPolicyModel apexPolicyModel = new MfpDomainModelFactory().getMfp2PolicyModel(); assertNotNull(apexPolicyModel); @@ -246,57 +235,56 @@ public class MfpUseCaseTest { apexEngine.handleEvent(event); EnEvent resultout = listener.getResult(); EnEvent resultexpected = - fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_084106GMT.json"); - assertEquals(resultexpected, resultout); - assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId()); + fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_084106GMT.json"); + assertHandledEventResult(resultexpected, resultout, event); event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/1/EventIn_BoozeItem_201713GMT.json"); apexEngine.handleEvent(event); resultout = listener.getResult(); resultexpected = - fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_201713GMT.json"); - assertEquals(resultexpected, resultout); - assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId()); + fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_201713GMT.json"); + assertHandledEventResult(resultexpected, resultout, event); event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/1/EventIn_NonBoozeItem_101309GMT.json"); apexEngine.handleEvent(event); resultout = listener.getResult(); resultexpected = - fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_NonBoozeItem_101309GMT.json"); - assertEquals(resultexpected, resultout); - assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId()); + fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_NonBoozeItem_101309GMT.json"); + assertHandledEventResult(resultexpected, resultout, event); event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/2/EventIn_BoozeItem_101433CET_thurs.json"); apexEngine.handleEvent(event); resultout = listener.getResult(); resultexpected = - fillResultEvent(axEventout, "examples/events/MyFirstPolicy/2/EventOut_BoozeItem_101433CET_thurs.json"); - assertEquals(resultexpected, resultout); - assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId()); + fillResultEvent(axEventout, "examples/events/MyFirstPolicy/2/EventOut_BoozeItem_101433CET_thurs.json"); + assertHandledEventResult(resultexpected, resultout, event); event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/2/EventIn_BoozeItem_171937CET_sun.json"); apexEngine.handleEvent(event); resultout = listener.getResult(); resultexpected = - fillResultEvent(axEventout, "examples/events/MyFirstPolicy/2/EventOut_BoozeItem_171937CET_sun.json"); - assertEquals(resultexpected, resultout); - assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId()); + fillResultEvent(axEventout, "examples/events/MyFirstPolicy/2/EventOut_BoozeItem_171937CET_sun.json"); + assertHandledEventResult(resultexpected, resultout, event); event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/2/EventIn_NonBoozeItem_111309CET_mon.json"); apexEngine.handleEvent(event); resultout = listener.getResult(); resultexpected = - fillResultEvent(axEventout, "examples/events/MyFirstPolicy/2/EventOut_NonBoozeItem_111309CET_mon.json"); - assertEquals(resultexpected, resultout); - assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId()); + fillResultEvent(axEventout, "examples/events/MyFirstPolicy/2/EventOut_NonBoozeItem_111309CET_mon.json"); + assertHandledEventResult(resultexpected, resultout, event); apexEngine.stop(); } + private static void assertHandledEventResult(EnEvent resultexpected, EnEvent resultout, EnEvent event) { + assertEquals(resultexpected, resultout); + assertEquals(event.getExecutionId(), resultout.getExecutionId()); + } + /** * Fill trigger event for test. * - * @param event the event + * @param event the event * @param inputFile the input file * @return the filled event */ @@ -305,7 +293,7 @@ public class MfpUseCaseTest { final GsonBuilder gb = new GsonBuilder(); gb.serializeNulls().enableComplexMapKeySerialization(); final JsonObject jsonObject = - gb.create().fromJson(ResourceUtils.getResourceAsString(inputFile), JsonObject.class); + gb.create().fromJson(ResourceUtils.getResourceAsString(inputFile), JsonObject.class); assertNotNull(jsonObject); assertTrue(jsonObject.has("name")); assertEquals(ret.getName(), jsonObject.get("name").getAsString()); @@ -319,16 +307,18 @@ public class MfpUseCaseTest { if (reserved.contains(e.getKey())) { continue; } - assertTrue("Event file " + inputFile + " has a field " + e.getKey() + " but this is not defined for " - + event.getId(), (event.getParameterMap().containsKey(e.getKey()))); + assertTrue((event.getParameterMap().containsKey(e.getKey())), + "Event file " + inputFile + " has a field " + e.getKey() + " but this is not defined for " + + event.getId()); if (jsonObject.get(e.getKey()).isJsonNull()) { ret.put(e.getKey(), null); } } for (final AxField field : event.getFields()) { if (!field.getOptional()) { - assertTrue("Event file " + inputFile + " is missing a mandatory field " + field.getKey().getLocalName() - + " for " + event.getId(), jsonObject.has(field.getKey().getLocalName())); + assertTrue(jsonObject.has(field.getKey().getLocalName()), + "Event file " + inputFile + " is missing a mandatory field " + field.getKey().getLocalName() + + " for " + event.getId()); } else { ret.put(field.getKey().getLocalName(), null); } @@ -363,7 +353,7 @@ public class MfpUseCaseTest { /** * Fill result event for test. * - * @param event the event + * @param event the event * @param inputFile the input file * @return the filled event */ @@ -372,7 +362,7 @@ public class MfpUseCaseTest { final GsonBuilder gb = new GsonBuilder(); gb.serializeNulls().enableComplexMapKeySerialization(); final JsonObject jsonObject = - gb.create().fromJson(ResourceUtils.getResourceAsString(inputFile), JsonObject.class); + gb.create().fromJson(ResourceUtils.getResourceAsString(inputFile), JsonObject.class); assertNotNull(jsonObject); assertTrue(jsonObject.has("name")); assertEquals(ret.getName(), jsonObject.get("name").getAsString()); @@ -386,16 +376,18 @@ public class MfpUseCaseTest { if (reserved.contains(e.getKey())) { continue; } - assertTrue("Event file " + inputFile + " has a field " + e.getKey() + " but this is not defined for " - + event.getId(), (event.getParameterMap().containsKey(e.getKey()))); + assertTrue((event.getParameterMap().containsKey(e.getKey())), + "Event file " + inputFile + " has a field " + e.getKey() + " but this is not defined for " + + event.getId()); if (jsonObject.get(e.getKey()).isJsonNull()) { ret.put(e.getKey(), null); } } for (final AxField field : event.getFields()) { if (!field.getOptional()) { - assertTrue("Event file " + inputFile + " is missing a mandatory field " + field.getKey().getLocalName() - + " for " + event.getId(), jsonObject.has(field.getKey().getLocalName())); + assertTrue(jsonObject.has(field.getKey().getLocalName()), + "Event file " + inputFile + " is missing a mandatory field " + field.getKey().getLocalName() + + " for " + event.getId()); } else { ret.put(field.getKey().getLocalName(), null); } 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 01c24d6de..14a75fa30 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 @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020, 2024 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -63,10 +63,10 @@ public class TestSaleAuthListener implements EnEventListener { * {@inheritDoc}. */ @Override - public void onEnEvent(final EnEvent saleauthEvent) { - if (saleauthEvent != null) { - System.out.println("SaleAuth event from engine:" + saleauthEvent.getName()); - resultEvents.add(saleauthEvent); + public void onEnEvent(final EnEvent saleAuthEvent) { + if (saleAuthEvent != null) { + System.out.println("SaleAuth event from engine:" + saleAuthEvent.getName()); + resultEvents.add(saleAuthEvent); } } } |