From cd68fc9bae7d6258f77ff59c1431e4f925f61a4c Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 13 Sep 2018 23:48:50 +0100 Subject: Address sonar/Checkstyle Issues Sweep through Apex codebase to fix most ceheckstyle and straightforward sonar issues. Issue-ID: POLICY-1034 Change-Id: I149d9a94ad893affc93573e8de5e3304b6bdde2d Signed-off-by: liamfallon --- .../test/script/engine/TestApexActionListener.java | 101 --------- .../test/script/engine/TestApexEngine.java | 129 ----------- .../test/script/engine/TestApexEngineJRuby.java | 94 -------- .../test/script/engine/TestApexEngineJava.java | 97 --------- .../script/engine/TestApexEngineJavascript.java | 93 -------- .../test/script/engine/TestApexEngineJython.java | 92 -------- .../test/script/engine/TestApexEngineMvel.java | 92 -------- .../test/script/event/TestEventInstantiation.java | 234 -------------------- .../test/script/handling/TestApexModelExport.java | 114 ---------- .../handling/TestApexPolicyModelAnalysis.java | 38 ---- .../TestApexSamplePolicyCreateModelFiles.java | 73 ------- .../handling/TestApexSamplePolicyDBWrite.java | 59 ----- .../script/handling/TestApexSamplePolicyModel.java | 81 ------- .../handling/TestApexSamplePolicyModelCreator.java | 61 ------ .../handling/TestContextUpdateDifferentModels.java | 148 ------------- .../script/handling/TestContextUpdateModel.java | 202 ----------------- .../executor/engine/TestApexActionListener.java | 101 +++++++++ .../executor/engine/TestApexEngine.java | 129 +++++++++++ .../executor/engine/TestApexEngineJRuby.java | 103 +++++++++ .../executor/engine/TestApexEngineJava.java | 103 +++++++++ .../executor/engine/TestApexEngineJavascript.java | 102 +++++++++ .../executor/engine/TestApexEngineJython.java | 101 +++++++++ .../executor/engine/TestApexEngineMvel.java | 101 +++++++++ .../executor/event/TestEventInstantiation.java | 238 +++++++++++++++++++++ .../executor/handling/TestApexModelExport.java | 114 ++++++++++ .../handling/TestApexPolicyModelAnalysis.java | 38 ++++ .../TestApexSamplePolicyCreateModelFiles.java | 73 +++++++ .../handling/TestApexSamplePolicyDbWrite.java | 77 +++++++ .../handling/TestApexSamplePolicyModel.java | 114 ++++++++++ .../handling/TestApexSamplePolicyModelCreator.java | 83 +++++++ .../handling/TestContextUpdateDifferentModels.java | 161 ++++++++++++++ .../executor/handling/TestContextUpdateModel.java | 233 ++++++++++++++++++++ 32 files changed, 1871 insertions(+), 1708 deletions(-) delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexActionListener.java delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngine.java delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJRuby.java delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJava.java delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJavascript.java delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJython.java delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineMvel.java delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/event/TestEventInstantiation.java delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexModelExport.java delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexPolicyModelAnalysis.java delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyCreateModelFiles.java delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyDBWrite.java delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyModel.java delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyModelCreator.java delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestContextUpdateDifferentModels.java delete mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestContextUpdateModel.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexActionListener.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngine.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJRuby.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJava.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJavascript.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJython.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineMvel.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/event/TestEventInstantiation.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexModelExport.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexPolicyModelAnalysis.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyCreateModelFiles.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyDbWrite.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyModel.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyModelCreator.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestContextUpdateDifferentModels.java create mode 100644 testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestContextUpdateModel.java (limited to 'testsuites/integration/integration-executor-test') diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexActionListener.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexActionListener.java deleted file mode 100644 index fa79843e9..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexActionListener.java +++ /dev/null @@ -1,101 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.engine; - -import java.util.ArrayList; -import java.util.List; - -import org.onap.policy.apex.core.engine.engine.EnEventListener; -import org.onap.policy.apex.core.engine.event.EnEvent; -import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The listener interface for receiving testApexAction events. The class that is interested in - * processing a testApexAction event implements this interface, and the object created with that - * class is registered with a component using the component's addTestApexActionListener - * method. When the testApexAction event occurs, that object's appropriate method is invoked. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestApexActionListener implements EnEventListener { - private static final XLogger logger = XLoggerFactory.getXLogger(TestApexActionListener.class); - - private List resultEvents = new ArrayList<>(); - - private final String id; - - /** - * Instantiates a new test apex action listener. - * - * @param id the id - */ - public TestApexActionListener(final String id) { - this.id = id; - } - - /** - * Gets the result. - * - * @param allowNulls if true and the returned event is null, then return, otherwise wait until - * an event is returned. - * @return the result - */ - public EnEvent getResult(final boolean allowNulls) { - EnEvent result = null; - while (true) { - while (resultEvents.isEmpty()) { - ThreadUtilities.sleep(100); - } - result = resultEvents.remove(0); - if (result != null || allowNulls) { - break; - } - } - return result; - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.core.engine.engine.EnEventListener#onEnEvent(org.onap.policy.apex.core. - * engine.event.EnEvent) - */ - @Override - public void onEnEvent(final EnEvent actionEvent) { - ThreadUtilities.sleep(100); - if (actionEvent != null) { - logger.info("Action event from engine: {}", actionEvent.getName()); - } - resultEvents.add(actionEvent); - } - - /** - * Gets the id. - * - * @return the id - */ - public String getId() { - return id; - } -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngine.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngine.java deleted file mode 100644 index b087552eb..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngine.java +++ /dev/null @@ -1,129 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.engine; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -import org.onap.policy.apex.core.engine.EngineParameters; -import org.onap.policy.apex.core.engine.engine.ApexEngine; -import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory; -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.AxArtifactKey; -import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.test.common.model.SampleDomainModelFactory; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -public class TestApexEngine { - // Logger for this class - private static final XLogger logger = XLoggerFactory.getXLogger(TestApexEngine.class); - - /** - * Instantiates a new test apex engine. - * - * @param axLogicExecutorType the type of logic executor to use to construct the sample policy - * model for this test - * @throws ApexException the apex exception - * @throws InterruptedException the interrupted exception - * @throws IOException Signals that an I/O exception has occurred. - */ - public TestApexEngine(final String axLogicExecutorType, final EngineParameters parameters) - throws ApexException, InterruptedException, IOException { - logger.debug("Running TestApexEngine test for + " + axLogicExecutorType + "logic . . ."); - - final AxPolicyModel apexPolicyModel = new SampleDomainModelFactory().getSamplePolicyModel(axLogicExecutorType); - assertNotNull(apexPolicyModel); - final AxArtifactKey key = new AxArtifactKey("TestApexEngine", "0.0.1"); - - final ApexEngine apexEngine = new ApexEngineFactory().createApexEngine(key); - final TestApexActionListener listener = new TestApexActionListener("Test"); - apexEngine.addEventListener("listener", listener); - apexEngine.updateModel(apexPolicyModel); - apexEngine.start(); - - for (final AxEvent axEvent : apexPolicyModel.getEvents().getEventMap().values()) { - final EnEvent event = apexEngine.createEvent(axEvent.getKey()); - - final Date aDate = new Date(1433453067123L); - final Map eventDataMap = new HashMap(); - eventDataMap.put("TestSlogan", "This is a test slogan for event " + event.getName()); - eventDataMap.put("TestMatchCase", new Byte((byte) 123)); - eventDataMap.put("TestTimestamp", aDate.getTime()); - eventDataMap.put("TestTemperature", 34.5445667); - - event.putAll(eventDataMap); - - apexEngine.handleEvent(event); - } - - EnEvent result = listener.getResult(false); - logger.debug("result 1 is:" + result); - checkResult(result); - result = listener.getResult(false); - logger.debug("result 2 is:" + result); - checkResult(result); - - final Map> apexContext = apexEngine.getEngineContext(); - assertNotNull(apexContext); - apexEngine.stop(); - } - - /** - * Check result. - * - * @param result the result - */ - private void checkResult(final EnEvent result) { - if (result.getExceptionMessage() == null) { - assertTrue(result.getName().equals("Event0004") || result.getName().equals("Event0104")); - - assertTrue(((String) result.get("TestSlogan")).startsWith("This is a test slogan for event ")); - assertTrue(((String) result.get("TestSlogan")).contains(result.getName().substring(0, 8))); - - assertEquals((byte) 123, result.get("TestMatchCase")); - assertEquals(34.5445667, result.get("TestTemperature")); - assertTrue( - (Byte) result.get("TestMatchCaseSelected") >= 0 && (Byte) result.get("TestMatchCaseSelected") <= 4); - assertTrue((Byte) result.get("TestEstablishCaseSelected") >= 0 - && (Byte) result.get("TestEstablishCaseSelected") <= 4); - assertTrue((Byte) result.get("TestDecideCaseSelected") >= 0 - && (Byte) result.get("TestDecideCaseSelected") <= 4); - assertTrue((Byte) result.get("TestActCaseSelected") >= 0 && (Byte) result.get("TestActCaseSelected") <= 4); - } else { - assertTrue(result.getName().equals("Event0001") || result.getName().equals("Event0104")); - - assertTrue(((String) result.get("TestSlogan")).startsWith("This is a test slogan for event ")); - assertTrue(((String) result.get("TestSlogan")).contains(result.getName().substring(0, 8))); - - assertEquals((byte) 123, result.get("TestMatchCase")); - assertEquals(34.5445667, result.get("TestTemperature")); - } - } -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJRuby.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJRuby.java deleted file mode 100644 index 916795deb..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJRuby.java +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.engine; - -import java.io.IOException; - -import org.junit.After; -import org.junit.Before; -import org.junit.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; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.core.engine.EngineParameters; -import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters; -import org.onap.policy.common.parameters.ParameterService; - -public class TestApexEngineJRuby { - private SchemaParameters schemaParameters; - private ContextParameters contextParameters; - private EngineParameters engineParameters; - - @Before - public void beforeTest() { - schemaParameters = new SchemaParameters(); - - schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); - schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); - - ParameterService.register(schemaParameters); - - contextParameters = new ContextParameters(); - - contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); - contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); - contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); - contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); - - ParameterService.register(contextParameters); - ParameterService.register(contextParameters.getDistributorParameters()); - ParameterService.register(contextParameters.getLockManagerParameters()); - ParameterService.register(contextParameters.getPersistorParameters()); - - engineParameters = new EngineParameters(); - engineParameters.getExecutorParameterMap().put("JRUBY", new JrubyExecutorParameters()); - ParameterService.register(engineParameters); - } - - @After - public void afterTest() { - ParameterService.deregister(engineParameters); - - ParameterService.deregister(contextParameters.getDistributorParameters()); - ParameterService.deregister(contextParameters.getLockManagerParameters()); - ParameterService.deregister(contextParameters.getPersistorParameters()); - ParameterService.deregister(contextParameters); - - ParameterService.deregister(schemaParameters); - } - - /** - * Test apex engine. - * - * @throws ApexException the apex exception - * @throws InterruptedException the interrupted exception - * @throws IOException Signals that an I/O exception has occurred. - */ - @Test - public void testApexEngineJRuby() throws ApexException, InterruptedException, IOException { - new TestApexEngine("JRUBY", engineParameters); - ThreadUtilities.sleep(5000); - new TestApexEngine("JRUBY", engineParameters); - } -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJava.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJava.java deleted file mode 100644 index c1d68760d..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJava.java +++ /dev/null @@ -1,97 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.engine; - -import java.io.IOException; - -import org.junit.After; -import org.junit.Before; -import org.junit.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; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.core.engine.EngineParameters; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters; -import org.onap.policy.common.parameters.ParameterService; - -/** - * The Class TestApexEngine_Java. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestApexEngineJava { - private SchemaParameters schemaParameters; - private ContextParameters contextParameters; - private EngineParameters engineParameters; - - @Before - public void beforeTest() { - schemaParameters = new SchemaParameters(); - - schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); - schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); - - ParameterService.register(schemaParameters); - - contextParameters = new ContextParameters(); - - contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); - contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); - contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); - contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); - - ParameterService.register(contextParameters); - ParameterService.register(contextParameters.getDistributorParameters()); - ParameterService.register(contextParameters.getLockManagerParameters()); - ParameterService.register(contextParameters.getPersistorParameters()); - - engineParameters = new EngineParameters(); - engineParameters.getExecutorParameterMap().put("JAVA", new JavaExecutorParameters()); - ParameterService.register(engineParameters); - } - - @After - public void afterTest() { - ParameterService.deregister(engineParameters); - - ParameterService.deregister(contextParameters.getDistributorParameters()); - ParameterService.deregister(contextParameters.getLockManagerParameters()); - ParameterService.deregister(contextParameters.getPersistorParameters()); - ParameterService.deregister(contextParameters); - - ParameterService.deregister(schemaParameters); - } - - /** - * Test apex engine. - * - * @throws InterruptedException the interrupted exception - * @throws IOException Signals that an I/O exception has occurred. - * @throws ApexException the apex exception - */ - @Test - public void testApexEngineJava() throws InterruptedException, IOException, ApexException { - new TestApexEngine("JAVA", engineParameters); - new TestApexEngine("JAVA", engineParameters); - } -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJavascript.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJavascript.java deleted file mode 100644 index 1f5c1d4b8..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJavascript.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.engine; - -import java.io.IOException; - -import org.junit.After; -import org.junit.Before; -import org.junit.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; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.core.engine.EngineParameters; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters; -import org.onap.policy.common.parameters.ParameterService; - -public class TestApexEngineJavascript { - private SchemaParameters schemaParameters; - private ContextParameters contextParameters; - private EngineParameters engineParameters; - - @Before - public void beforeTest() { - schemaParameters = new SchemaParameters(); - - schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); - schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); - - ParameterService.register(schemaParameters); - - contextParameters = new ContextParameters(); - - contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); - contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); - contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); - contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); - - ParameterService.register(contextParameters); - ParameterService.register(contextParameters.getDistributorParameters()); - ParameterService.register(contextParameters.getLockManagerParameters()); - ParameterService.register(contextParameters.getPersistorParameters()); - - engineParameters = new EngineParameters(); - engineParameters.getExecutorParameterMap().put("JAVASCRIPT", new JavascriptExecutorParameters()); - ParameterService.register(engineParameters); - } - - @After - public void afterTest() { - ParameterService.deregister(engineParameters); - - ParameterService.deregister(contextParameters.getDistributorParameters()); - ParameterService.deregister(contextParameters.getLockManagerParameters()); - ParameterService.deregister(contextParameters.getPersistorParameters()); - ParameterService.deregister(contextParameters); - - ParameterService.deregister(schemaParameters); - } - - /** - * Test apex engine. - * - * @throws ApexException the apex exception - * @throws InterruptedException the interrupted exception - * @throws IOException Signals that an I/O exception has occurred. - */ - @Test - public void testApexEngineJavascript() throws ApexException, InterruptedException, IOException { - - new TestApexEngine("JAVASCRIPT", engineParameters); - new TestApexEngine("JAVASCRIPT", engineParameters); - } -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJython.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJython.java deleted file mode 100644 index b5b0f9a78..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineJython.java +++ /dev/null @@ -1,92 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.engine; - -import java.io.IOException; - -import org.junit.After; -import org.junit.Before; -import org.junit.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; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.core.engine.EngineParameters; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters; -import org.onap.policy.common.parameters.ParameterService; - -public class TestApexEngineJython { - private SchemaParameters schemaParameters; - private ContextParameters contextParameters; - private EngineParameters engineParameters; - - @Before - public void beforeTest() { - schemaParameters = new SchemaParameters(); - - schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); - schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); - - ParameterService.register(schemaParameters); - - contextParameters = new ContextParameters(); - - contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); - contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); - contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); - contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); - - ParameterService.register(contextParameters); - ParameterService.register(contextParameters.getDistributorParameters()); - ParameterService.register(contextParameters.getLockManagerParameters()); - ParameterService.register(contextParameters.getPersistorParameters()); - - engineParameters = new EngineParameters(); - engineParameters.getExecutorParameterMap().put("JYTHON", new JythonExecutorParameters()); - ParameterService.register(engineParameters); - } - - @After - public void afterTest() { - ParameterService.deregister(engineParameters); - - ParameterService.deregister(contextParameters.getDistributorParameters()); - ParameterService.deregister(contextParameters.getLockManagerParameters()); - ParameterService.deregister(contextParameters.getPersistorParameters()); - ParameterService.deregister(contextParameters); - - ParameterService.deregister(schemaParameters); - } - - /** - * Test apex engine. - * - * @throws ApexException the apex exception - * @throws InterruptedException the interrupted exception - * @throws IOException Signals that an I/O exception has occurred. - */ - @Test - public void testApexEngineJython() throws ApexException, InterruptedException, IOException { - new TestApexEngine("JYTHON", engineParameters); - new TestApexEngine("JYTHON", engineParameters); - } -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineMvel.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineMvel.java deleted file mode 100644 index 4aab859ca..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/engine/TestApexEngineMvel.java +++ /dev/null @@ -1,92 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.engine; - -import java.io.IOException; - -import org.junit.After; -import org.junit.Before; -import org.junit.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; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.core.engine.EngineParameters; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; -import org.onap.policy.common.parameters.ParameterService; - -public class TestApexEngineMvel { - private SchemaParameters schemaParameters; - private ContextParameters contextParameters; - private EngineParameters engineParameters; - - @Before - public void beforeTest() { - schemaParameters = new SchemaParameters(); - - schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); - schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); - - ParameterService.register(schemaParameters); - - contextParameters = new ContextParameters(); - - contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); - contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); - contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); - contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); - - ParameterService.register(contextParameters); - ParameterService.register(contextParameters.getDistributorParameters()); - ParameterService.register(contextParameters.getLockManagerParameters()); - ParameterService.register(contextParameters.getPersistorParameters()); - - engineParameters = new EngineParameters(); - engineParameters.getExecutorParameterMap().put("MVEL", new MvelExecutorParameters()); - ParameterService.register(engineParameters); - } - - @After - public void afterTest() { - ParameterService.deregister(engineParameters); - - ParameterService.deregister(contextParameters.getDistributorParameters()); - ParameterService.deregister(contextParameters.getLockManagerParameters()); - ParameterService.deregister(contextParameters.getPersistorParameters()); - ParameterService.deregister(contextParameters); - - ParameterService.deregister(schemaParameters); - } - - /** - * Test apex engine. - * - * @throws ApexException the apex exception - * @throws InterruptedException the interrupted exception - * @throws IOException Signals that an I/O exception has occurred. - */ - @Test - public void testApexEngineMVEL() throws ApexException, InterruptedException, IOException { - new TestApexEngine("MVEL", engineParameters); - new TestApexEngine("MVEL", engineParameters); - } -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/event/TestEventInstantiation.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/event/TestEventInstantiation.java deleted file mode 100644 index b1542def0..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/event/TestEventInstantiation.java +++ /dev/null @@ -1,234 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.event; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -import org.junit.After; -import org.junit.Before; -import org.junit.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; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.core.engine.EngineParameters; -import org.onap.policy.apex.core.engine.engine.ApexEngine; -import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory; -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.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; -import org.onap.policy.apex.test.common.model.SampleDomainModelFactory; -import org.onap.policy.common.parameters.ParameterService; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class TestEventInstantiation. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestEventInstantiation { - // Logger for this class - private static final XLogger logger = XLoggerFactory.getXLogger(TestEventInstantiation.class); - - private SchemaParameters schemaParameters; - private ContextParameters contextParameters; - private EngineParameters engineParameters; - - @Before - public void beforeTest() { - schemaParameters = new SchemaParameters(); - - schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); - schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); - - ParameterService.register(schemaParameters); - - contextParameters = new ContextParameters(); - - contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); - contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); - contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); - contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); - - ParameterService.register(contextParameters); - ParameterService.register(contextParameters.getDistributorParameters()); - ParameterService.register(contextParameters.getLockManagerParameters()); - ParameterService.register(contextParameters.getPersistorParameters()); - - engineParameters = new EngineParameters(); - engineParameters.getExecutorParameterMap().put("MVEL", new MvelExecutorParameters()); - ParameterService.register(engineParameters); - } - - @After - public void afterTest() { - ParameterService.deregister(engineParameters); - - ParameterService.deregister(contextParameters.getDistributorParameters()); - ParameterService.deregister(contextParameters.getLockManagerParameters()); - ParameterService.deregister(contextParameters.getPersistorParameters()); - ParameterService.deregister(contextParameters); - - ParameterService.deregister(schemaParameters); - } - - /** - * Test event instantiation. - * - * @throws ApexModelException on errors in handling Apex models - * @throws IOException Signals that an I/O exception has occurred. - * @throws ApexException the apex exception - */ - @Test - public void testEventInstantiation() throws ApexModelException, IOException, ApexException { - final String xmlFileName = "xml/ApexModel_MVEL.xml"; - - logger.debug("Running TestEventInstantiation test on file {} . . .", xmlFileName); - - final AxPolicyModel apexPolicyModel = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); - assertNotNull(apexPolicyModel); - - final ApexEngine apexEngine = new ApexEngineFactory().createApexEngine(apexPolicyModel.getKey()); - apexEngine.updateModel(apexPolicyModel); - apexEngine.start(); - - final EnEvent event = apexEngine.createEvent(new AxArtifactKey("Event0000", "0.0.1")); - - Object slogan1 = event.put("TestSlogan", "This is a slogan"); - assertNull(slogan1); - slogan1 = event.get("TestSlogan"); - assertNotNull(slogan1); - assertEquals("This is a slogan", slogan1); - - Object mc1 = event.put("TestMatchCase", new Byte("4")); - assertNull(mc1); - mc1 = event.get("TestMatchCase"); - assertNotNull(mc1); - assertEquals((byte) 4, mc1); - - Object mc2 = event.put("TestMatchCase", new Byte("16")); - assertNotNull(mc2); - assertEquals((byte) 4, mc2); - mc2 = event.get("TestMatchCase"); - assertNotNull(mc2); - assertEquals((byte) 16, mc2); - - final Date timeNow = new Date(); - Object timestamp1 = event.put("TestTimestamp", timeNow.getTime()); - assertNull(timestamp1); - timestamp1 = event.get("TestTimestamp"); - assertNotNull(timestamp1); - assertEquals(timeNow.getTime(), timestamp1); - - final double temperature = 123.456789; - Object temp1 = event.put("TestTemperature", temperature); - assertNull(temp1); - temp1 = event.get("TestTemperature"); - assertNotNull(temp1); - assertEquals(temperature, temp1); - - Object value = event.put("TestMatchCase", null); - assertEquals(16, ((Byte) value).intValue()); - value = event.get("TestMatchCase"); - assertNull(value); - - try { - event.put("TestMatchCase", "Hello"); - } catch (final Exception e) { - assertEquals( - "Event0000:0.0.1:NULL:TestMatchCase: object \"Hello\" of class \"java.lang.String\" not compatible with class \"java.lang.Byte\"", - e.getMessage()); - } - - try { - event.put("TestMatchCase", 123.45); - } catch (final Exception e) { - assertEquals( - "Event0000:0.0.1:NULL:TestMatchCase: object \"123.45\" of class \"java.lang.Double\" not compatible with class \"java.lang.Byte\"", - e.getMessage()); - } - - event.put("TestMatchCase", new Byte("16")); - - final String slogan2 = (String) event.get("TestSlogan"); - assertNotNull(slogan2); - assertEquals("This is a slogan", slogan2); - - final byte mc21 = (byte) event.get("TestMatchCase"); - assertNotNull(mc21); - assertEquals(16, mc21); - - final byte mc22 = (byte) event.get("TestMatchCase"); - assertNotNull(mc22); - assertEquals((byte) 16, mc22); - - final long timestamp2 = (Long) event.get("TestTimestamp"); - assertNotNull(timestamp2); - assertEquals(timestamp2, timestamp1); - - final double temp2 = (double) event.get("TestTemperature"); - assertNotNull(temp2); - assertTrue(temp2 == 123.456789); - - final Double temp3 = (Double) event.get("TestTemperature"); - assertNotNull(temp3); - assertTrue(temp3 == 123.456789); - - final Date aDate = new Date(1433453067123L); - final Map eventDataList = new HashMap(); - eventDataList.put("TestSlogan", "This is a test slogan"); - eventDataList.put("TestMatchCase", new Byte("123")); - eventDataList.put("TestTimestamp", aDate.getTime()); - eventDataList.put("TestTemperature", 34.5445667); - - event.putAll(eventDataList); - - final String slogan3 = (String) event.get("TestSlogan"); - assertNotNull(slogan3); - assertEquals("This is a test slogan", slogan3); - - final byte mc31 = (byte) event.get("TestMatchCase"); - assertNotNull(mc31); - assertEquals((byte) 123, mc31); - - final long timestamp3 = (Long) event.get("TestTimestamp"); - assertNotNull(timestamp3); - assertEquals(timestamp3, aDate.getTime()); - - final double temp4 = (double) event.get("TestTemperature"); - assertNotNull(temp4); - assertTrue(temp4 == 34.5445667); - - logger.debug(event.toString()); - } -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexModelExport.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexModelExport.java deleted file mode 100644 index 6b72faa8f..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexModelExport.java +++ /dev/null @@ -1,114 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.handling; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Before; -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.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.model.policymodel.handling.PolicyModelSplitter; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class TestApexModelReader tests Apex model reading. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestApexModelExport { - private static final XLogger logger = XLoggerFactory.getXLogger(TestApexModelExport.class); - - private AxPolicyModel model = null; - - @Before - public void initApexModelSmall() throws ApexException { - model = new TestApexSamplePolicyModelCreator("MVEL").getModel(); - } - - @Test - public void testApexModelExport() throws Exception { - logger.info("Starting test: testApexModelExport"); - - final List exportPolicyList = new ArrayList(); - exportPolicyList.addAll(model.getPolicies().getPolicyMap().keySet()); - - final AxPolicyModel exportedModel0 = PolicyModelSplitter.getSubPolicyModel(model, exportPolicyList); - - // Remove unused schemas and their keys - model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem000", "0.0.1")); - model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem001", "0.0.1")); - model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem002", "0.0.1")); - model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem003", "0.0.1")); - model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem004", "0.0.1")); - model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem005", "0.0.1")); - model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem006", "0.0.1")); - model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem007", "0.0.1")); - model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem008", "0.0.1")); - model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem009", "0.0.1")); - model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem00A", "0.0.1")); - model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem00B", "0.0.1")); - model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem00C", "0.0.1")); - - model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem000", "0.0.1")); - model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem001", "0.0.1")); - model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem002", "0.0.1")); - model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem003", "0.0.1")); - model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem004", "0.0.1")); - model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem005", "0.0.1")); - model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem006", "0.0.1")); - model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem007", "0.0.1")); - model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem008", "0.0.1")); - model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem009", "0.0.1")); - model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem00A", "0.0.1")); - model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem00B", "0.0.1")); - model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem00C", "0.0.1")); - - assertTrue(model.equals(exportedModel0)); - - exportPolicyList.remove(0); - - final AxPolicyModel exportedModel1 = PolicyModelSplitter.getSubPolicyModel(model, exportPolicyList); - assertFalse(model.equals(exportedModel1)); - assertTrue(model.getPolicies().get("Policy1").equals(exportedModel1.getPolicies().get("Policy1"))); - - exportPolicyList.clear(); - exportPolicyList.add(new AxArtifactKey("NonExistentPolicy", "0.0.1")); - - try { - final AxPolicyModel emptyExportedModel = PolicyModelSplitter.getSubPolicyModel(model, exportPolicyList); - assertNotNull(emptyExportedModel); - } catch (final Exception e) { - assertTrue(e.getMessage() - .equals("new model is invalid:\n" + "***validation of model failed***\n" - + "AxPolicies:Policies:0.0.1 - policyMap may not be null or empty\n" - + "AxEvents:Events:0.0.1 - eventMap may not be null or empty\n" - + "********************************")); - } - } -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexPolicyModelAnalysis.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexPolicyModelAnalysis.java deleted file mode 100644 index 91153d698..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexPolicyModelAnalysis.java +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.handling; - -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.model.policymodel.handling.PolicyAnalyser; -import org.onap.policy.apex.model.policymodel.handling.PolicyAnalysisResult; - -public class TestApexPolicyModelAnalysis { - @Test - public void testApexPolicyModelAnalysis() throws Exception { - final AxPolicyModel model = new TestApexSamplePolicyModelCreator("MVEL").getModel(); - final PolicyAnalysisResult result = new PolicyAnalyser().analyse(model); - - assertNotNull(result); - } -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyCreateModelFiles.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyCreateModelFiles.java deleted file mode 100644 index 384ad5114..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyCreateModelFiles.java +++ /dev/null @@ -1,73 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.handling; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.test.TestApexModel; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; - -public class TestApexSamplePolicyCreateModelFiles { - @Test - public void testModelWriteReadJava() throws Exception { - final TestApexSamplePolicyModelCreator apexPolicyModelCreator = new TestApexSamplePolicyModelCreator("JAVA"); - final TestApexModel testApexPolicyModel = - new TestApexModel(AxPolicyModel.class, apexPolicyModelCreator); - testApexPolicyModel.testApexModelWriteReadXml(); - testApexPolicyModel.testApexModelWriteReadJson(); - } - - @Test - public void testModelWriteReadJavascript() throws Exception { - final TestApexSamplePolicyModelCreator apexPolicyModelCreator = - new TestApexSamplePolicyModelCreator("JAVASCRIPT"); - final TestApexModel testApexPolicyModel = - new TestApexModel(AxPolicyModel.class, apexPolicyModelCreator); - testApexPolicyModel.testApexModelWriteReadXml(); - testApexPolicyModel.testApexModelWriteReadJson(); - } - - @Test - public void testModelWriteReadJRuby() throws Exception { - final TestApexSamplePolicyModelCreator apexPolicyModelCreator = new TestApexSamplePolicyModelCreator("JRUBY"); - final TestApexModel testApexPolicyModel = - new TestApexModel(AxPolicyModel.class, apexPolicyModelCreator); - testApexPolicyModel.testApexModelWriteReadXml(); - testApexPolicyModel.testApexModelWriteReadJson(); - } - - @Test - public void testModelWriteReadJython() throws Exception { - final TestApexSamplePolicyModelCreator apexPolicyModelCreator = new TestApexSamplePolicyModelCreator("JYTHON"); - final TestApexModel testApexPolicyModel = - new TestApexModel(AxPolicyModel.class, apexPolicyModelCreator); - testApexPolicyModel.testApexModelWriteReadXml(); - testApexPolicyModel.testApexModelWriteReadJson(); - } - - @Test - public void testModelWriteReadMvel() throws Exception { - final TestApexSamplePolicyModelCreator apexPolicyModelCreator = new TestApexSamplePolicyModelCreator("MVEL"); - final TestApexModel testApexPolicyModel = - new TestApexModel(AxPolicyModel.class, apexPolicyModelCreator); - testApexPolicyModel.testApexModelWriteReadXml(); - testApexPolicyModel.testApexModelWriteReadJson(); - } -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyDBWrite.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyDBWrite.java deleted file mode 100644 index 45314672e..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyDBWrite.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.handling; - -import java.sql.Connection; -import java.sql.DriverManager; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; -import org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao; -import org.onap.policy.apex.model.basicmodel.test.TestApexModel; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; - -public class TestApexSamplePolicyDBWrite { - private Connection connection; - TestApexModel testApexModel; - - @Before - public void setup() throws Exception { - connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true"); - - final TestApexSamplePolicyModelCreator apexPolicyModelCreator = new TestApexSamplePolicyModelCreator("MVEL"); - testApexModel = new TestApexModel(AxPolicyModel.class, apexPolicyModelCreator); - } - - @After - public void teardown() throws Exception { - connection.close(); - } - - @Test - public void testModelWriteReadJPA() throws Exception { - final DaoParameters DaoParameters = new DaoParameters(); - DaoParameters.setPluginClass(DefaultApexDao.class.getCanonicalName()); - DaoParameters.setPersistenceUnit("SampleModelTest"); - - testApexModel.testApexModelWriteReadJpa(DaoParameters); - } -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyModel.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyModel.java deleted file mode 100644 index 36810b44b..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyModel.java +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.handling; - -import static org.junit.Assert.assertTrue; - -import java.sql.Connection; -import java.sql.DriverManager; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; -import org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao; -import org.onap.policy.apex.model.basicmodel.test.TestApexModel; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; - -public class TestApexSamplePolicyModel { - private static final String VALID_MODEL_STRING = "***validation of model successful***"; - private Connection connection; - private TestApexModel testApexModel; - - @Before - public void setup() throws Exception { - connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true"); - - testApexModel = - new TestApexModel(AxPolicyModel.class, new TestApexSamplePolicyModelCreator("MVEL")); - } - - @After - public void teardown() throws Exception { - connection.close(); - } - - @Test - public void testModelValid() throws Exception { - final AxValidationResult result = testApexModel.testApexModelValid(); - assertTrue(result.toString().equals(VALID_MODEL_STRING)); - } - - @Test - public void testModelWriteReadXML() throws Exception { - testApexModel.testApexModelWriteReadXml(); - } - - @Test - public void testModelWriteReadJSON() throws Exception { - testApexModel.testApexModelWriteReadJson(); - } - - @Test - public void testModelWriteReadJPA() throws Exception { - final DaoParameters DaoParameters = new DaoParameters(); - DaoParameters.setPluginClass(DefaultApexDao.class.getCanonicalName()); - DaoParameters.setPersistenceUnit("SampleModelTest"); - - testApexModel.testApexModelWriteReadJpa(DaoParameters); - } - - -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyModelCreator.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyModelCreator.java deleted file mode 100644 index d5ba53699..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestApexSamplePolicyModelCreator.java +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.handling; - -import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.test.common.model.SampleDomainModelFactory; - -/** - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestApexSamplePolicyModelCreator implements TestApexModelCreator { - private String logicExecutorType; - - public TestApexSamplePolicyModelCreator(final String logicExecutorType) { - this.logicExecutorType = logicExecutorType; - } - - @Override - public AxPolicyModel getModel() { - return new SampleDomainModelFactory().getSamplePolicyModel(logicExecutorType); - } - - @Override - public AxPolicyModel getMalstructuredModel() { - return null; - } - - @Override - public AxPolicyModel getObservationModel() { - return null; - } - - @Override - public AxPolicyModel getWarningModel() { - return getModel(); - } - - @Override - public AxPolicyModel getInvalidModel() { - return null; - } -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestContextUpdateDifferentModels.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestContextUpdateDifferentModels.java deleted file mode 100644 index 20159a3bf..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestContextUpdateDifferentModels.java +++ /dev/null @@ -1,148 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.handling; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.context.ContextAlbum; -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; -import org.onap.policy.apex.context.parameters.SchemaParameters; -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.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; -import org.onap.policy.apex.plugins.executor.test.script.engine.TestApexActionListener; -import org.onap.policy.apex.test.common.model.SampleDomainModelFactory; -import org.onap.policy.common.parameters.ParameterService; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class TestApexEngine. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestContextUpdateDifferentModels { - // Logger for this class - private static final XLogger logger = XLoggerFactory.getXLogger(TestContextUpdateDifferentModels.class); - - private SchemaParameters schemaParameters; - private ContextParameters contextParameters; - private EngineParameters engineParameters; - - @Before - public void beforeTest() { - schemaParameters = new SchemaParameters(); - - schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); - schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); - - ParameterService.register(schemaParameters); - - contextParameters = new ContextParameters(); - - contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); - contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); - contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); - contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); - - ParameterService.register(contextParameters); - ParameterService.register(contextParameters.getDistributorParameters()); - ParameterService.register(contextParameters.getLockManagerParameters()); - ParameterService.register(contextParameters.getPersistorParameters()); - - engineParameters = new EngineParameters(); - engineParameters.getExecutorParameterMap().put("MVEL", new MvelExecutorParameters()); - ParameterService.register(engineParameters); - } - - @After - public void afterTest() { - ParameterService.deregister(engineParameters); - - ParameterService.deregister(contextParameters.getDistributorParameters()); - ParameterService.deregister(contextParameters.getLockManagerParameters()); - ParameterService.deregister(contextParameters.getPersistorParameters()); - ParameterService.deregister(contextParameters); - - ParameterService.deregister(schemaParameters); - } - - @Test - public void testContextUpdateDifferentModels() throws ApexException, InterruptedException, IOException { - logger.debug("Running test testContextUpdateDifferentModels . . ."); - - final AxPolicyModel apexModelSample = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); - assertNotNull(apexModelSample); - - final ApexEngineImpl apexEngine = - (ApexEngineImpl) new ApexEngineFactory().createApexEngine(new AxArtifactKey("TestApexEngine", "0.0.1")); - final TestApexActionListener listener = new TestApexActionListener("Test"); - apexEngine.addEventListener("listener", listener); - apexEngine.updateModel(apexModelSample); - apexEngine.start(); - - apexEngine.stop(); - - final AxPolicyModel someSpuriousModel = new AxPolicyModel(new AxArtifactKey("SomeSpuriousModel", "0.0.1")); - assertNotNull(someSpuriousModel); - - try { - apexEngine.updateModel(null); - fail("null model should throw an exception"); - } catch (final ApexException e) { - assertEquals("updateModel()<-TestApexEngine:0.0.1, Apex model is not defined, it has a null value", - e.getMessage()); - } - assertEquals(apexEngine.getInternalContext().getContextAlbums().size(), - apexModelSample.getAlbums().getAlbumsMap().size()); - for (final ContextAlbum contextAlbum : apexEngine.getInternalContext().getContextAlbums().values()) { - assertTrue( - contextAlbum.getAlbumDefinition().equals(apexModelSample.getAlbums().get(contextAlbum.getKey()))); - } - - apexEngine.updateModel(someSpuriousModel); - assertEquals(apexEngine.getInternalContext().getContextAlbums().size(), - someSpuriousModel.getAlbums().getAlbumsMap().size()); - for (final ContextAlbum contextAlbum : apexEngine.getInternalContext().getContextAlbums().values()) { - assertTrue( - contextAlbum.getAlbumDefinition().equals(someSpuriousModel.getAlbums().get(contextAlbum.getKey()))); - } - - apexEngine.clear(); - - logger.debug("Ran test testContextUpdateDifferentModels"); - } - -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestContextUpdateModel.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestContextUpdateModel.java deleted file mode 100644 index d5605ea4c..000000000 --- a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/plugins/executor/test/script/handling/TestContextUpdateModel.java +++ /dev/null @@ -1,202 +0,0 @@ -/*- - * ============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.plugins.executor.test.script.handling; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.context.ContextException; -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; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.core.engine.EngineParameters; -import org.onap.policy.apex.core.engine.engine.ApexEngine; -import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory; -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.AxArtifactKey; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; -import org.onap.policy.apex.plugins.executor.test.script.engine.TestApexActionListener; -import org.onap.policy.apex.test.common.model.SampleDomainModelFactory; -import org.onap.policy.common.parameters.ParameterService; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * The Class TestApexEngine. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestContextUpdateModel { - // Logger for this class - private static final XLogger logger = XLoggerFactory.getXLogger(TestContextUpdateModel.class); - - private SchemaParameters schemaParameters; - private ContextParameters contextParameters; - private EngineParameters engineParameters; - - @Before - public void beforeTest() { - schemaParameters = new SchemaParameters(); - - schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); - schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); - - ParameterService.register(schemaParameters); - - contextParameters = new ContextParameters(); - - contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); - contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); - contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); - contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); - - ParameterService.register(contextParameters); - ParameterService.register(contextParameters.getDistributorParameters()); - ParameterService.register(contextParameters.getLockManagerParameters()); - ParameterService.register(contextParameters.getPersistorParameters()); - - engineParameters = new EngineParameters(); - engineParameters.getExecutorParameterMap().put("MVEL", new MvelExecutorParameters()); - ParameterService.register(engineParameters); - } - - @After - public void afterTest() { - ParameterService.deregister(engineParameters); - - ParameterService.deregister(contextParameters.getDistributorParameters()); - ParameterService.deregister(contextParameters.getLockManagerParameters()); - ParameterService.deregister(contextParameters.getPersistorParameters()); - ParameterService.deregister(contextParameters); - - ParameterService.deregister(schemaParameters); - } - - @Test - public void testContextUpdateModel() throws ApexException, InterruptedException, IOException { - final AxArtifactKey key = new AxArtifactKey("TestApexEngine", "0.0.1"); - - final ApexEngine apexEngine = new ApexEngineFactory().createApexEngine(key); - final TestApexActionListener listener = new TestApexActionListener("Test"); - apexEngine.addEventListener("listener", listener); - - final AxPolicyModel model1 = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); - assertNotNull(model1); - assertEquals(2, model1.getPolicies().getPolicyMap().size()); - - apexEngine.updateModel(model1); - apexEngine.start(); - sendEvent(apexEngine, listener, "Event0000", true); - sendEvent(apexEngine, listener, "Event0100", true); - apexEngine.stop(); - - final AxPolicyModel model2 = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); - assertNotNull(model2); - model2.getPolicies().getPolicyMap().remove(new AxArtifactKey("Policy0", "0.0.1")); - assertEquals(1, model2.getPolicies().getPolicyMap().size()); - apexEngine.updateModel(model2); - apexEngine.start(); - sendEvent(apexEngine, listener, "Event0000", false); - sendEvent(apexEngine, listener, "Event0100", true); - apexEngine.stop(); - - final AxPolicyModel model3 = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); - assertNotNull(model3); - model3.getPolicies().getPolicyMap().remove(new AxArtifactKey("Policy1", "0.0.1")); - assertEquals(1, model3.getPolicies().getPolicyMap().size()); - apexEngine.updateModel(model3); - apexEngine.start(); - sendEvent(apexEngine, listener, "Event0000", true); - sendEvent(apexEngine, listener, "Event0100", false); - apexEngine.stop(); - - final AxPolicyModel model4 = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); - assertNotNull(model4); - assertEquals(2, model4.getPolicies().getPolicyMap().size()); - apexEngine.updateModel(model4); - apexEngine.start(); - sendEvent(apexEngine, listener, "Event0100", true); - sendEvent(apexEngine, listener, "Event0000", true); - apexEngine.stop(); - - apexEngine.clear(); - } - - @After - public void testContextUpdateModelAfter() {} - - private void sendEvent(final ApexEngine apexEngine, final TestApexActionListener listener, final String eventName, - final boolean shouldWork) throws ContextException { - final Date aDate = new Date(1433453067123L); - final Map eventDataMap = new HashMap(); - eventDataMap.put("TestSlogan", "This is a test slogan"); - eventDataMap.put("TestMatchCase", new Byte((byte) 123)); - eventDataMap.put("TestTimestamp", aDate.getTime()); - eventDataMap.put("TestTemperature", 34.5445667); - - final EnEvent event0 = apexEngine.createEvent(new AxArtifactKey(eventName, "0.0.1")); - event0.putAll(eventDataMap); - apexEngine.handleEvent(event0); - - final EnEvent result = listener.getResult(true); - logger.debug("result 1 is:" + result); - checkResult(result, shouldWork); - } - - private void checkResult(final EnEvent result, final boolean shouldWork) { - if (!shouldWork) { - assertNotNull(result.getExceptionMessage()); - return; - } - - assertTrue(result.getName().equals("Event0004") || result.getName().equals("Event0104")); - - if (result.getName().equals("Event0004")) { - assertEquals("This is a test slogan", result.get("TestSlogan")); - assertEquals((byte) 123, result.get("TestMatchCase")); - assertEquals(34.5445667, result.get("TestTemperature")); - assertEquals((byte) 2, result.get("TestMatchCaseSelected")); - assertEquals((byte) 0, result.get("TestEstablishCaseSelected")); - assertEquals((byte) 1, result.get("TestDecideCaseSelected")); - assertEquals((byte) 3, result.get("TestActCaseSelected")); - } else { - assertEquals("This is a test slogan", result.get("TestSlogan")); - assertEquals((byte) 123, result.get("TestMatchCase")); - assertEquals(34.5445667, result.get("TestTemperature")); - assertEquals((byte) 1, result.get("TestMatchCaseSelected")); - assertEquals((byte) 3, result.get("TestEstablishCaseSelected")); - assertEquals((byte) 1, result.get("TestDecideCaseSelected")); - assertEquals((byte) 2, result.get("TestActCaseSelected")); - } - } -} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexActionListener.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexActionListener.java new file mode 100644 index 000000000..2860f1736 --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexActionListener.java @@ -0,0 +1,101 @@ +/*- + * ============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.testsuites.integration.executor.engine; + +import java.util.ArrayList; +import java.util.List; + +import org.onap.policy.apex.core.engine.engine.EnEventListener; +import org.onap.policy.apex.core.engine.event.EnEvent; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The listener interface for receiving testApexAction events. The class that is interested in + * processing a testApexAction event implements this interface, and the object created with that + * class is registered with a component using the component's addTestApexActionListener + * method. When the testApexAction event occurs, that object's appropriate method is invoked. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestApexActionListener implements EnEventListener { + private static final XLogger logger = XLoggerFactory.getXLogger(TestApexActionListener.class); + + private List resultEvents = new ArrayList<>(); + + private final String id; + + /** + * Instantiates a new test apex action listener. + * + * @param id the id + */ + public TestApexActionListener(final String id) { + this.id = id; + } + + /** + * Gets the result. + * + * @param allowNulls if true and the returned event is null, then return, otherwise wait until + * an event is returned. + * @return the result + */ + public EnEvent getResult(final boolean allowNulls) { + EnEvent result = null; + while (true) { + while (resultEvents.isEmpty()) { + ThreadUtilities.sleep(100); + } + result = resultEvents.remove(0); + if (result != null || allowNulls) { + break; + } + } + return result; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.core.engine.engine.EnEventListener#onEnEvent(org.onap.policy.apex.core. + * engine.event.EnEvent) + */ + @Override + public void onEnEvent(final EnEvent actionEvent) { + ThreadUtilities.sleep(100); + if (actionEvent != null) { + logger.info("Action event from engine: {}", actionEvent.getName()); + } + resultEvents.add(actionEvent); + } + + /** + * Gets the id. + * + * @return the id + */ + public String getId() { + return id; + } +} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngine.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngine.java new file mode 100644 index 000000000..cb51a8e9e --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngine.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.testsuites.integration.executor.engine; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.onap.policy.apex.core.engine.EngineParameters; +import org.onap.policy.apex.core.engine.engine.ApexEngine; +import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory; +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.AxArtifactKey; +import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; +import org.onap.policy.apex.testsuites.integration.common.model.SampleDomainModelFactory; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +public class TestApexEngine { + // Logger for this class + private static final XLogger logger = XLoggerFactory.getXLogger(TestApexEngine.class); + + /** + * Instantiates a new test apex engine. + * + * @param axLogicExecutorType the type of logic executor to use to construct the sample policy + * model for this test + * @throws ApexException the apex exception + * @throws InterruptedException the interrupted exception + * @throws IOException Signals that an I/O exception has occurred. + */ + public TestApexEngine(final String axLogicExecutorType, final EngineParameters parameters) + throws ApexException, InterruptedException, IOException { + logger.debug("Running TestApexEngine test for + " + axLogicExecutorType + "logic . . ."); + + final AxPolicyModel apexPolicyModel = new SampleDomainModelFactory().getSamplePolicyModel(axLogicExecutorType); + assertNotNull(apexPolicyModel); + final AxArtifactKey key = new AxArtifactKey("TestApexEngine", "0.0.1"); + + final ApexEngine apexEngine = new ApexEngineFactory().createApexEngine(key); + final TestApexActionListener listener = new TestApexActionListener("Test"); + apexEngine.addEventListener("listener", listener); + apexEngine.updateModel(apexPolicyModel); + apexEngine.start(); + + for (final AxEvent axEvent : apexPolicyModel.getEvents().getEventMap().values()) { + final EnEvent event = apexEngine.createEvent(axEvent.getKey()); + + final Date aDate = new Date(1433453067123L); + final Map eventDataMap = new HashMap(); + eventDataMap.put("TestSlogan", "This is a test slogan for event " + event.getName()); + eventDataMap.put("TestMatchCase", new Byte((byte) 123)); + eventDataMap.put("TestTimestamp", aDate.getTime()); + eventDataMap.put("TestTemperature", 34.5445667); + + event.putAll(eventDataMap); + + apexEngine.handleEvent(event); + } + + EnEvent result = listener.getResult(false); + logger.debug("result 1 is:" + result); + checkResult(result); + result = listener.getResult(false); + logger.debug("result 2 is:" + result); + checkResult(result); + + final Map> apexContext = apexEngine.getEngineContext(); + assertNotNull(apexContext); + apexEngine.stop(); + } + + /** + * Check result. + * + * @param result the result + */ + private void checkResult(final EnEvent result) { + if (result.getExceptionMessage() == null) { + assertTrue(result.getName().equals("Event0004") || result.getName().equals("Event0104")); + + assertTrue(((String) result.get("TestSlogan")).startsWith("This is a test slogan for event ")); + assertTrue(((String) result.get("TestSlogan")).contains(result.getName().substring(0, 8))); + + assertEquals((byte) 123, result.get("TestMatchCase")); + assertEquals(34.5445667, result.get("TestTemperature")); + assertTrue( + (Byte) result.get("TestMatchCaseSelected") >= 0 && (Byte) result.get("TestMatchCaseSelected") <= 4); + assertTrue((Byte) result.get("TestEstablishCaseSelected") >= 0 + && (Byte) result.get("TestEstablishCaseSelected") <= 4); + assertTrue((Byte) result.get("TestDecideCaseSelected") >= 0 + && (Byte) result.get("TestDecideCaseSelected") <= 4); + assertTrue((Byte) result.get("TestActCaseSelected") >= 0 && (Byte) result.get("TestActCaseSelected") <= 4); + } else { + assertTrue(result.getName().equals("Event0001") || result.getName().equals("Event0104")); + + assertTrue(((String) result.get("TestSlogan")).startsWith("This is a test slogan for event ")); + assertTrue(((String) result.get("TestSlogan")).contains(result.getName().substring(0, 8))); + + assertEquals((byte) 123, result.get("TestMatchCase")); + assertEquals(34.5445667, result.get("TestTemperature")); + } + } +} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJRuby.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJRuby.java new file mode 100644 index 000000000..108e73ac1 --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJRuby.java @@ -0,0 +1,103 @@ +/*- + * ============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.testsuites.integration.executor.engine; + +import java.io.IOException; + +import org.junit.After; +import org.junit.Before; +import org.junit.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; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.core.engine.EngineParameters; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.plugins.executor.jruby.JrubyExecutorParameters; +import org.onap.policy.common.parameters.ParameterService; + +/** + * The Class TestApexEngineJRuby. + */ +public class TestApexEngineJRuby { + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + private EngineParameters engineParameters; + + /** + * Before test. + */ + @Before + public void beforeTest() { + schemaParameters = new SchemaParameters(); + + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + engineParameters = new EngineParameters(); + engineParameters.getExecutorParameterMap().put("JRUBY", new JrubyExecutorParameters()); + ParameterService.register(engineParameters); + } + + /** + * After test. + */ + @After + public void afterTest() { + ParameterService.deregister(engineParameters); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + + ParameterService.deregister(schemaParameters); + } + + /** + * Test apex engine. + * + * @throws ApexException the apex exception + * @throws InterruptedException the interrupted exception + * @throws IOException Signals that an I/O exception has occurred. + */ + @Test + public void testApexEngineJRuby() throws ApexException, InterruptedException, IOException { + new TestApexEngine("JRUBY", engineParameters); + ThreadUtilities.sleep(5000); + new TestApexEngine("JRUBY", engineParameters); + } +} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJava.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJava.java new file mode 100644 index 000000000..b551a061e --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJava.java @@ -0,0 +1,103 @@ +/*- + * ============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.testsuites.integration.executor.engine; + +import java.io.IOException; + +import org.junit.After; +import org.junit.Before; +import org.junit.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; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.core.engine.EngineParameters; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.plugins.executor.java.JavaExecutorParameters; +import org.onap.policy.common.parameters.ParameterService; + +/** + * The Class TestApexEngine_Java. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestApexEngineJava { + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + private EngineParameters engineParameters; + + /** + * Before test. + */ + @Before + public void beforeTest() { + schemaParameters = new SchemaParameters(); + + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + engineParameters = new EngineParameters(); + engineParameters.getExecutorParameterMap().put("JAVA", new JavaExecutorParameters()); + ParameterService.register(engineParameters); + } + + /** + * After test. + */ + @After + public void afterTest() { + ParameterService.deregister(engineParameters); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + + ParameterService.deregister(schemaParameters); + } + + /** + * Test apex engine. + * + * @throws InterruptedException the interrupted exception + * @throws IOException Signals that an I/O exception has occurred. + * @throws ApexException the apex exception + */ + @Test + public void testApexEngineJava() throws InterruptedException, IOException, ApexException { + new TestApexEngine("JAVA", engineParameters); + new TestApexEngine("JAVA", engineParameters); + } +} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJavascript.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJavascript.java new file mode 100644 index 000000000..51e39cfe1 --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJavascript.java @@ -0,0 +1,102 @@ +/*- + * ============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.testsuites.integration.executor.engine; + +import java.io.IOException; + +import org.junit.After; +import org.junit.Before; +import org.junit.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; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.core.engine.EngineParameters; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters; +import org.onap.policy.common.parameters.ParameterService; + +/** + * The Class TestApexEngineJavascript. + */ +public class TestApexEngineJavascript { + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + private EngineParameters engineParameters; + + /** + * Before test. + */ + @Before + public void beforeTest() { + schemaParameters = new SchemaParameters(); + + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + engineParameters = new EngineParameters(); + engineParameters.getExecutorParameterMap().put("JAVASCRIPT", new JavascriptExecutorParameters()); + ParameterService.register(engineParameters); + } + + /** + * After test. + */ + @After + public void afterTest() { + ParameterService.deregister(engineParameters); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + + ParameterService.deregister(schemaParameters); + } + + /** + * Test apex engine. + * + * @throws ApexException the apex exception + * @throws InterruptedException the interrupted exception + * @throws IOException Signals that an I/O exception has occurred. + */ + @Test + public void testApexEngineJavascript() throws ApexException, InterruptedException, IOException { + + new TestApexEngine("JAVASCRIPT", engineParameters); + new TestApexEngine("JAVASCRIPT", engineParameters); + } +} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJython.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJython.java new file mode 100644 index 000000000..163a60d20 --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineJython.java @@ -0,0 +1,101 @@ +/*- + * ============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.testsuites.integration.executor.engine; + +import java.io.IOException; + +import org.junit.After; +import org.junit.Before; +import org.junit.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; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.core.engine.EngineParameters; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.plugins.executor.jython.JythonExecutorParameters; +import org.onap.policy.common.parameters.ParameterService; + +/** + * The Class TestApexEngineJython. + */ +public class TestApexEngineJython { + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + private EngineParameters engineParameters; + + /** + * Before test. + */ + @Before + public void beforeTest() { + schemaParameters = new SchemaParameters(); + + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + engineParameters = new EngineParameters(); + engineParameters.getExecutorParameterMap().put("JYTHON", new JythonExecutorParameters()); + ParameterService.register(engineParameters); + } + + /** + * After test. + */ + @After + public void afterTest() { + ParameterService.deregister(engineParameters); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + + ParameterService.deregister(schemaParameters); + } + + /** + * Test apex engine. + * + * @throws ApexException the apex exception + * @throws InterruptedException the interrupted exception + * @throws IOException Signals that an I/O exception has occurred. + */ + @Test + public void testApexEngineJython() throws ApexException, InterruptedException, IOException { + new TestApexEngine("JYTHON", engineParameters); + new TestApexEngine("JYTHON", engineParameters); + } +} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineMvel.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineMvel.java new file mode 100644 index 000000000..604105a03 --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/engine/TestApexEngineMvel.java @@ -0,0 +1,101 @@ +/*- + * ============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.testsuites.integration.executor.engine; + +import java.io.IOException; + +import org.junit.After; +import org.junit.Before; +import org.junit.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; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.core.engine.EngineParameters; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; +import org.onap.policy.common.parameters.ParameterService; + +/** + * The Class TestApexEngineMvel. + */ +public class TestApexEngineMvel { + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + private EngineParameters engineParameters; + + /** + * Before test. + */ + @Before + public void beforeTest() { + schemaParameters = new SchemaParameters(); + + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + engineParameters = new EngineParameters(); + engineParameters.getExecutorParameterMap().put("MVEL", new MvelExecutorParameters()); + ParameterService.register(engineParameters); + } + + /** + * After test. + */ + @After + public void afterTest() { + ParameterService.deregister(engineParameters); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + + ParameterService.deregister(schemaParameters); + } + + /** + * Test apex engine. + * + * @throws ApexException the apex exception + * @throws InterruptedException the interrupted exception + * @throws IOException Signals that an I/O exception has occurred. + */ + @Test + public void testApexEngineMvel() throws ApexException, InterruptedException, IOException { + new TestApexEngine("MVEL", engineParameters); + new TestApexEngine("MVEL", engineParameters); + } +} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/event/TestEventInstantiation.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/event/TestEventInstantiation.java new file mode 100644 index 000000000..1ae258b01 --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/event/TestEventInstantiation.java @@ -0,0 +1,238 @@ +/*- + * ============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.testsuites.integration.executor.event; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.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; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.core.engine.EngineParameters; +import org.onap.policy.apex.core.engine.engine.ApexEngine; +import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory; +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.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; +import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; +import org.onap.policy.apex.testsuites.integration.common.model.SampleDomainModelFactory; +import org.onap.policy.common.parameters.ParameterService; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class TestEventInstantiation. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestEventInstantiation { + // Logger for this class + private static final XLogger logger = XLoggerFactory.getXLogger(TestEventInstantiation.class); + + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + private EngineParameters engineParameters; + + /** + * Before test. + */ + @Before + public void beforeTest() { + schemaParameters = new SchemaParameters(); + + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + engineParameters = new EngineParameters(); + engineParameters.getExecutorParameterMap().put("MVEL", new MvelExecutorParameters()); + ParameterService.register(engineParameters); + } + + /** + * After test. + */ + @After + public void afterTest() { + ParameterService.deregister(engineParameters); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + + ParameterService.deregister(schemaParameters); + } + + /** + * Test event instantiation. + * + * @throws ApexModelException on errors in handling Apex models + * @throws IOException Signals that an I/O exception has occurred. + * @throws ApexException the apex exception + */ + @Test + public void testEventInstantiation() throws ApexModelException, IOException, ApexException { + final String xmlFileName = "xml/ApexModel_MVEL.xml"; + + logger.debug("Running TestEventInstantiation test on file {} . . .", xmlFileName); + + final AxPolicyModel apexPolicyModel = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); + assertNotNull(apexPolicyModel); + + final ApexEngine apexEngine = new ApexEngineFactory().createApexEngine(apexPolicyModel.getKey()); + apexEngine.updateModel(apexPolicyModel); + apexEngine.start(); + + final EnEvent event = apexEngine.createEvent(new AxArtifactKey("Event0000", "0.0.1")); + + Object slogan1 = event.put("TestSlogan", "This is a slogan"); + assertNull(slogan1); + slogan1 = event.get("TestSlogan"); + assertNotNull(slogan1); + assertEquals("This is a slogan", slogan1); + + Object mc1 = event.put("TestMatchCase", new Byte("4")); + assertNull(mc1); + mc1 = event.get("TestMatchCase"); + assertNotNull(mc1); + assertEquals((byte) 4, mc1); + + Object mc2 = event.put("TestMatchCase", new Byte("16")); + assertNotNull(mc2); + assertEquals((byte) 4, mc2); + mc2 = event.get("TestMatchCase"); + assertNotNull(mc2); + assertEquals((byte) 16, mc2); + + final Date timeNow = new Date(); + Object timestamp1 = event.put("TestTimestamp", timeNow.getTime()); + assertNull(timestamp1); + timestamp1 = event.get("TestTimestamp"); + assertNotNull(timestamp1); + assertEquals(timeNow.getTime(), timestamp1); + + final double temperature = 123.456789; + Object temp1 = event.put("TestTemperature", temperature); + assertNull(temp1); + temp1 = event.get("TestTemperature"); + assertNotNull(temp1); + assertEquals(temperature, temp1); + + Object value = event.put("TestMatchCase", null); + assertEquals(16, ((Byte) value).intValue()); + value = event.get("TestMatchCase"); + assertNull(value); + + try { + event.put("TestMatchCase", "Hello"); + } catch (final Exception e) { + assertEquals("Event0000:0.0.1:NULL:TestMatchCase: object \"Hello\" of class \"java.lang.String\" " + + "not compatible with class \"java.lang.Byte\"", e.getMessage()); + } + + try { + event.put("TestMatchCase", 123.45); + } catch (final Exception e) { + assertEquals("Event0000:0.0.1:NULL:TestMatchCase: object \"123.45\" of class \"java.lang.Double\" " + + "not compatible with class \"java.lang.Byte\"", e.getMessage()); + } + + event.put("TestMatchCase", new Byte("16")); + + final String slogan2 = (String) event.get("TestSlogan"); + assertNotNull(slogan2); + assertEquals("This is a slogan", slogan2); + + final byte mc21 = (byte) event.get("TestMatchCase"); + assertNotNull(mc21); + assertEquals(16, mc21); + + final byte mc22 = (byte) event.get("TestMatchCase"); + assertNotNull(mc22); + assertEquals((byte) 16, mc22); + + final long timestamp2 = (Long) event.get("TestTimestamp"); + assertNotNull(timestamp2); + assertEquals(timestamp2, timestamp1); + + final double temp2 = (double) event.get("TestTemperature"); + assertNotNull(temp2); + assertTrue(temp2 == 123.456789); + + final Double temp3 = (Double) event.get("TestTemperature"); + assertNotNull(temp3); + assertTrue(temp3 == 123.456789); + + final Date aDate = new Date(1433453067123L); + final Map eventDataList = new HashMap(); + eventDataList.put("TestSlogan", "This is a test slogan"); + eventDataList.put("TestMatchCase", new Byte("123")); + eventDataList.put("TestTimestamp", aDate.getTime()); + eventDataList.put("TestTemperature", 34.5445667); + + event.putAll(eventDataList); + + final String slogan3 = (String) event.get("TestSlogan"); + assertNotNull(slogan3); + assertEquals("This is a test slogan", slogan3); + + final byte mc31 = (byte) event.get("TestMatchCase"); + assertNotNull(mc31); + assertEquals((byte) 123, mc31); + + final long timestamp3 = (Long) event.get("TestTimestamp"); + assertNotNull(timestamp3); + assertEquals(timestamp3, aDate.getTime()); + + final double temp4 = (double) event.get("TestTemperature"); + assertNotNull(temp4); + assertTrue(temp4 == 34.5445667); + + logger.debug(event.toString()); + } +} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexModelExport.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexModelExport.java new file mode 100644 index 000000000..1e419521f --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexModelExport.java @@ -0,0 +1,114 @@ +/*- + * ============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.testsuites.integration.executor.handling; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +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.policymodel.concepts.AxPolicyModel; +import org.onap.policy.apex.model.policymodel.handling.PolicyModelSplitter; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class TestApexModelReader tests Apex model reading. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestApexModelExport { + private static final XLogger logger = XLoggerFactory.getXLogger(TestApexModelExport.class); + + private AxPolicyModel model = null; + + @Before + public void initApexModelSmall() throws ApexException { + model = new TestApexSamplePolicyModelCreator("MVEL").getModel(); + } + + @Test + public void testApexModelExport() throws Exception { + logger.info("Starting test: testApexModelExport"); + + final List exportPolicyList = new ArrayList(); + exportPolicyList.addAll(model.getPolicies().getPolicyMap().keySet()); + + final AxPolicyModel exportedModel0 = PolicyModelSplitter.getSubPolicyModel(model, exportPolicyList); + + // Remove unused schemas and their keys + model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem000", "0.0.1")); + model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem001", "0.0.1")); + model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem002", "0.0.1")); + model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem003", "0.0.1")); + model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem004", "0.0.1")); + model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem005", "0.0.1")); + model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem006", "0.0.1")); + model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem007", "0.0.1")); + model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem008", "0.0.1")); + model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem009", "0.0.1")); + model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem00A", "0.0.1")); + model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem00B", "0.0.1")); + model.getSchemas().getSchemasMap().remove(new AxArtifactKey("TestContextItem00C", "0.0.1")); + + model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem000", "0.0.1")); + model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem001", "0.0.1")); + model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem002", "0.0.1")); + model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem003", "0.0.1")); + model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem004", "0.0.1")); + model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem005", "0.0.1")); + model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem006", "0.0.1")); + model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem007", "0.0.1")); + model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem008", "0.0.1")); + model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem009", "0.0.1")); + model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem00A", "0.0.1")); + model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem00B", "0.0.1")); + model.getKeyInformation().getKeyInfoMap().remove(new AxArtifactKey("TestContextItem00C", "0.0.1")); + + assertTrue(model.equals(exportedModel0)); + + exportPolicyList.remove(0); + + final AxPolicyModel exportedModel1 = PolicyModelSplitter.getSubPolicyModel(model, exportPolicyList); + assertFalse(model.equals(exportedModel1)); + assertTrue(model.getPolicies().get("Policy1").equals(exportedModel1.getPolicies().get("Policy1"))); + + exportPolicyList.clear(); + exportPolicyList.add(new AxArtifactKey("NonExistentPolicy", "0.0.1")); + + try { + final AxPolicyModel emptyExportedModel = PolicyModelSplitter.getSubPolicyModel(model, exportPolicyList); + assertNotNull(emptyExportedModel); + } catch (final Exception e) { + assertTrue(e.getMessage() + .equals("new model is invalid:\n" + "***validation of model failed***\n" + + "AxPolicies:Policies:0.0.1 - policyMap may not be null or empty\n" + + "AxEvents:Events:0.0.1 - eventMap may not be null or empty\n" + + "********************************")); + } + } +} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexPolicyModelAnalysis.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexPolicyModelAnalysis.java new file mode 100644 index 000000000..abcd22a47 --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexPolicyModelAnalysis.java @@ -0,0 +1,38 @@ +/*- + * ============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.testsuites.integration.executor.handling; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; +import org.onap.policy.apex.model.policymodel.handling.PolicyAnalyser; +import org.onap.policy.apex.model.policymodel.handling.PolicyAnalysisResult; + +public class TestApexPolicyModelAnalysis { + @Test + public void testApexPolicyModelAnalysis() throws Exception { + final AxPolicyModel model = new TestApexSamplePolicyModelCreator("MVEL").getModel(); + final PolicyAnalysisResult result = new PolicyAnalyser().analyse(model); + + assertNotNull(result); + } +} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyCreateModelFiles.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyCreateModelFiles.java new file mode 100644 index 000000000..a00729268 --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyCreateModelFiles.java @@ -0,0 +1,73 @@ +/*- + * ============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.testsuites.integration.executor.handling; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.test.TestApexModel; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; + +public class TestApexSamplePolicyCreateModelFiles { + @Test + public void testModelWriteReadJava() throws Exception { + final TestApexSamplePolicyModelCreator apexPolicyModelCreator = new TestApexSamplePolicyModelCreator("JAVA"); + final TestApexModel testApexPolicyModel = + new TestApexModel(AxPolicyModel.class, apexPolicyModelCreator); + testApexPolicyModel.testApexModelWriteReadXml(); + testApexPolicyModel.testApexModelWriteReadJson(); + } + + @Test + public void testModelWriteReadJavascript() throws Exception { + final TestApexSamplePolicyModelCreator apexPolicyModelCreator = + new TestApexSamplePolicyModelCreator("JAVASCRIPT"); + final TestApexModel testApexPolicyModel = + new TestApexModel(AxPolicyModel.class, apexPolicyModelCreator); + testApexPolicyModel.testApexModelWriteReadXml(); + testApexPolicyModel.testApexModelWriteReadJson(); + } + + @Test + public void testModelWriteReadJRuby() throws Exception { + final TestApexSamplePolicyModelCreator apexPolicyModelCreator = new TestApexSamplePolicyModelCreator("JRUBY"); + final TestApexModel testApexPolicyModel = + new TestApexModel(AxPolicyModel.class, apexPolicyModelCreator); + testApexPolicyModel.testApexModelWriteReadXml(); + testApexPolicyModel.testApexModelWriteReadJson(); + } + + @Test + public void testModelWriteReadJython() throws Exception { + final TestApexSamplePolicyModelCreator apexPolicyModelCreator = new TestApexSamplePolicyModelCreator("JYTHON"); + final TestApexModel testApexPolicyModel = + new TestApexModel(AxPolicyModel.class, apexPolicyModelCreator); + testApexPolicyModel.testApexModelWriteReadXml(); + testApexPolicyModel.testApexModelWriteReadJson(); + } + + @Test + public void testModelWriteReadMvel() throws Exception { + final TestApexSamplePolicyModelCreator apexPolicyModelCreator = new TestApexSamplePolicyModelCreator("MVEL"); + final TestApexModel testApexPolicyModel = + new TestApexModel(AxPolicyModel.class, apexPolicyModelCreator); + testApexPolicyModel.testApexModelWriteReadXml(); + testApexPolicyModel.testApexModelWriteReadJson(); + } +} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyDbWrite.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyDbWrite.java new file mode 100644 index 000000000..e863a990a --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyDbWrite.java @@ -0,0 +1,77 @@ +/*- + * ============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.testsuites.integration.executor.handling; + +import java.sql.Connection; +import java.sql.DriverManager; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; +import org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao; +import org.onap.policy.apex.model.basicmodel.test.TestApexModel; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; + +/** + * The Class TestApexSamplePolicyDbWrite. + */ +public class TestApexSamplePolicyDbWrite { + private Connection connection; + TestApexModel testApexModel; + + /** + * Setup. + * + * @throws Exception the exception + */ + @Before + public void setup() throws Exception { + connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true"); + + final TestApexSamplePolicyModelCreator apexPolicyModelCreator = new TestApexSamplePolicyModelCreator("MVEL"); + testApexModel = new TestApexModel(AxPolicyModel.class, apexPolicyModelCreator); + } + + /** + * Teardown. + * + * @throws Exception the exception + */ + @After + public void teardown() throws Exception { + connection.close(); + } + + /** + * Test model write read jpa. + * + * @throws Exception the exception + */ + @Test + public void testModelWriteReadJpa() throws Exception { + final DaoParameters DaoParameters = new DaoParameters(); + DaoParameters.setPluginClass(DefaultApexDao.class.getCanonicalName()); + DaoParameters.setPersistenceUnit("SampleModelTest"); + + testApexModel.testApexModelWriteReadJpa(DaoParameters); + } +} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyModel.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyModel.java new file mode 100644 index 000000000..1e7daad03 --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyModel.java @@ -0,0 +1,114 @@ +/*- + * ============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.testsuites.integration.executor.handling; + +import static org.junit.Assert.assertTrue; + +import java.sql.Connection; +import java.sql.DriverManager; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; +import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; +import org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao; +import org.onap.policy.apex.model.basicmodel.test.TestApexModel; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; + +/** + * The Class TestApexSamplePolicyModel. + */ +public class TestApexSamplePolicyModel { + private static final String VALID_MODEL_STRING = "***validation of model successful***"; + private Connection connection; + private TestApexModel testApexModel; + + /** + * Setup. + * + * @throws Exception the exception + */ + @Before + public void setup() throws Exception { + connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true"); + + testApexModel = + new TestApexModel(AxPolicyModel.class, new TestApexSamplePolicyModelCreator("MVEL")); + } + + /** + * Teardown. + * + * @throws Exception the exception + */ + @After + public void teardown() throws Exception { + connection.close(); + } + + /** + * Test model valid. + * + * @throws Exception the exception + */ + @Test + public void testModelValid() throws Exception { + final AxValidationResult result = testApexModel.testApexModelValid(); + assertTrue(result.toString().equals(VALID_MODEL_STRING)); + } + + /** + * Test model write read xml. + * + * @throws Exception the exception + */ + @Test + public void testModelWriteReadXml() throws Exception { + testApexModel.testApexModelWriteReadXml(); + } + + /** + * Test model write read json. + * + * @throws Exception the exception + */ + @Test + public void testModelWriteReadJson() throws Exception { + testApexModel.testApexModelWriteReadJson(); + } + + /** + * Test model write read jpa. + * + * @throws Exception the exception + */ + @Test + public void testModelWriteReadJpa() throws Exception { + final DaoParameters DaoParameters = new DaoParameters(); + DaoParameters.setPluginClass(DefaultApexDao.class.getCanonicalName()); + DaoParameters.setPersistenceUnit("SampleModelTest"); + + testApexModel.testApexModelWriteReadJpa(DaoParameters); + } + + +} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyModelCreator.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyModelCreator.java new file mode 100644 index 000000000..7e44dd32e --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestApexSamplePolicyModelCreator.java @@ -0,0 +1,83 @@ +/*- + * ============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.testsuites.integration.executor.handling; + +import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; +import org.onap.policy.apex.testsuites.integration.common.model.SampleDomainModelFactory; + +/** + * The Class TestApexSamplePolicyModelCreator. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestApexSamplePolicyModelCreator implements TestApexModelCreator { + private String logicExecutorType; + + /** + * Instantiates a new test apex sample policy model creator. + * + * @param logicExecutorType the logic executor type + */ + public TestApexSamplePolicyModelCreator(final String logicExecutorType) { + this.logicExecutorType = logicExecutorType; + } + + /* (non-Javadoc) + * @see org.onap.policy.apex.model.basicmodel.handling.ApexModelCreator#getModel() + */ + @Override + public AxPolicyModel getModel() { + return new SampleDomainModelFactory().getSamplePolicyModel(logicExecutorType); + } + + /* (non-Javadoc) + * @see org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator#getMalstructuredModel() + */ + @Override + public AxPolicyModel getMalstructuredModel() { + return null; + } + + /* (non-Javadoc) + * @see org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator#getObservationModel() + */ + @Override + public AxPolicyModel getObservationModel() { + return null; + } + + /* (non-Javadoc) + * @see org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator#getWarningModel() + */ + @Override + public AxPolicyModel getWarningModel() { + return getModel(); + } + + /* (non-Javadoc) + * @see org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator#getInvalidModel() + */ + @Override + public AxPolicyModel getInvalidModel() { + return null; + } +} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestContextUpdateDifferentModels.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestContextUpdateDifferentModels.java new file mode 100644 index 000000000..e8c45b201 --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestContextUpdateDifferentModels.java @@ -0,0 +1,161 @@ +/*- + * ============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.testsuites.integration.executor.handling; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.context.ContextAlbum; +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; +import org.onap.policy.apex.context.parameters.SchemaParameters; +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.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; +import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; +import org.onap.policy.apex.testsuites.integration.common.model.SampleDomainModelFactory; +import org.onap.policy.apex.testsuites.integration.executor.engine.TestApexActionListener; +import org.onap.policy.common.parameters.ParameterService; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class TestApexEngine. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestContextUpdateDifferentModels { + // Logger for this class + private static final XLogger logger = XLoggerFactory.getXLogger(TestContextUpdateDifferentModels.class); + + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + private EngineParameters engineParameters; + + /** + * Before test. + */ + @Before + public void beforeTest() { + schemaParameters = new SchemaParameters(); + + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + engineParameters = new EngineParameters(); + engineParameters.getExecutorParameterMap().put("MVEL", new MvelExecutorParameters()); + ParameterService.register(engineParameters); + } + + /** + * After test. + */ + @After + public void afterTest() { + ParameterService.deregister(engineParameters); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + + ParameterService.deregister(schemaParameters); + } + + /** + * Test context update different models. + * + * @throws ApexException the apex exception + * @throws InterruptedException the interrupted exception + * @throws IOException Signals that an I/O exception has occurred. + */ + @Test + public void testContextUpdateDifferentModels() throws ApexException, InterruptedException, IOException { + logger.debug("Running test testContextUpdateDifferentModels . . ."); + + final AxPolicyModel apexModelSample = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); + assertNotNull(apexModelSample); + + final ApexEngineImpl apexEngine = + (ApexEngineImpl) new ApexEngineFactory().createApexEngine(new AxArtifactKey("TestApexEngine", "0.0.1")); + final TestApexActionListener listener = new TestApexActionListener("Test"); + apexEngine.addEventListener("listener", listener); + apexEngine.updateModel(apexModelSample); + apexEngine.start(); + + apexEngine.stop(); + + final AxPolicyModel someSpuriousModel = new AxPolicyModel(new AxArtifactKey("SomeSpuriousModel", "0.0.1")); + assertNotNull(someSpuriousModel); + + try { + apexEngine.updateModel(null); + fail("null model should throw an exception"); + } catch (final ApexException e) { + assertEquals("updateModel()<-TestApexEngine:0.0.1, Apex model is not defined, it has a null value", + e.getMessage()); + } + assertEquals(apexEngine.getInternalContext().getContextAlbums().size(), + apexModelSample.getAlbums().getAlbumsMap().size()); + for (final ContextAlbum contextAlbum : apexEngine.getInternalContext().getContextAlbums().values()) { + assertTrue( + contextAlbum.getAlbumDefinition().equals(apexModelSample.getAlbums().get(contextAlbum.getKey()))); + } + + apexEngine.updateModel(someSpuriousModel); + assertEquals(apexEngine.getInternalContext().getContextAlbums().size(), + someSpuriousModel.getAlbums().getAlbumsMap().size()); + for (final ContextAlbum contextAlbum : apexEngine.getInternalContext().getContextAlbums().values()) { + assertTrue( + contextAlbum.getAlbumDefinition().equals(someSpuriousModel.getAlbums().get(contextAlbum.getKey()))); + } + + apexEngine.clear(); + + logger.debug("Ran test testContextUpdateDifferentModels"); + } + +} diff --git a/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestContextUpdateModel.java b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestContextUpdateModel.java new file mode 100644 index 000000000..615781ab3 --- /dev/null +++ b/testsuites/integration/integration-executor-test/src/test/java/org/onap/policy/apex/testsuites/integration/executor/handling/TestContextUpdateModel.java @@ -0,0 +1,233 @@ +/*- + * ============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.testsuites.integration.executor.handling; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.context.ContextException; +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; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.core.engine.EngineParameters; +import org.onap.policy.apex.core.engine.engine.ApexEngine; +import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory; +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.AxArtifactKey; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; +import org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters; +import org.onap.policy.apex.testsuites.integration.common.model.SampleDomainModelFactory; +import org.onap.policy.apex.testsuites.integration.executor.engine.TestApexActionListener; +import org.onap.policy.common.parameters.ParameterService; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class TestApexEngine. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestContextUpdateModel { + // Logger for this class + private static final XLogger logger = XLoggerFactory.getXLogger(TestContextUpdateModel.class); + + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + private EngineParameters engineParameters; + + /** + * Before test. + */ + @Before + public void beforeTest() { + schemaParameters = new SchemaParameters(); + + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + engineParameters = new EngineParameters(); + engineParameters.getExecutorParameterMap().put("MVEL", new MvelExecutorParameters()); + ParameterService.register(engineParameters); + } + + /** + * After test. + */ + @After + public void afterTest() { + ParameterService.deregister(engineParameters); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + + ParameterService.deregister(schemaParameters); + } + + /** + * Test context update model. + * + * @throws ApexException the apex exception + * @throws InterruptedException the interrupted exception + * @throws IOException Signals that an I/O exception has occurred. + */ + @Test + public void testContextUpdateModel() throws ApexException, InterruptedException, IOException { + final AxArtifactKey key = new AxArtifactKey("TestApexEngine", "0.0.1"); + + final ApexEngine apexEngine = new ApexEngineFactory().createApexEngine(key); + final TestApexActionListener listener = new TestApexActionListener("Test"); + apexEngine.addEventListener("listener", listener); + + final AxPolicyModel model1 = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); + assertNotNull(model1); + assertEquals(2, model1.getPolicies().getPolicyMap().size()); + + apexEngine.updateModel(model1); + apexEngine.start(); + sendEvent(apexEngine, listener, "Event0000", true); + sendEvent(apexEngine, listener, "Event0100", true); + apexEngine.stop(); + + final AxPolicyModel model2 = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); + assertNotNull(model2); + model2.getPolicies().getPolicyMap().remove(new AxArtifactKey("Policy0", "0.0.1")); + assertEquals(1, model2.getPolicies().getPolicyMap().size()); + apexEngine.updateModel(model2); + apexEngine.start(); + sendEvent(apexEngine, listener, "Event0000", false); + sendEvent(apexEngine, listener, "Event0100", true); + apexEngine.stop(); + + final AxPolicyModel model3 = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); + assertNotNull(model3); + model3.getPolicies().getPolicyMap().remove(new AxArtifactKey("Policy1", "0.0.1")); + assertEquals(1, model3.getPolicies().getPolicyMap().size()); + apexEngine.updateModel(model3); + apexEngine.start(); + sendEvent(apexEngine, listener, "Event0000", true); + sendEvent(apexEngine, listener, "Event0100", false); + apexEngine.stop(); + + final AxPolicyModel model4 = new SampleDomainModelFactory().getSamplePolicyModel("MVEL"); + assertNotNull(model4); + assertEquals(2, model4.getPolicies().getPolicyMap().size()); + apexEngine.updateModel(model4); + apexEngine.start(); + sendEvent(apexEngine, listener, "Event0100", true); + sendEvent(apexEngine, listener, "Event0000", true); + apexEngine.stop(); + + apexEngine.clear(); + } + + /** + * Test context update model after. + */ + @After + public void testContextUpdateModelAfter() {} + + /** + * Send event. + * + * @param apexEngine the apex engine + * @param listener the listener + * @param eventName the event name + * @param shouldWork the should work + * @throws ContextException the context exception + */ + private void sendEvent(final ApexEngine apexEngine, final TestApexActionListener listener, final String eventName, + final boolean shouldWork) throws ContextException { + final Date aDate = new Date(1433453067123L); + final Map eventDataMap = new HashMap(); + eventDataMap.put("TestSlogan", "This is a test slogan"); + eventDataMap.put("TestMatchCase", new Byte((byte) 123)); + eventDataMap.put("TestTimestamp", aDate.getTime()); + eventDataMap.put("TestTemperature", 34.5445667); + + final EnEvent event0 = apexEngine.createEvent(new AxArtifactKey(eventName, "0.0.1")); + event0.putAll(eventDataMap); + apexEngine.handleEvent(event0); + + final EnEvent result = listener.getResult(true); + logger.debug("result 1 is:" + result); + checkResult(result, shouldWork); + } + + /** + * Check result. + * + * @param result the result + * @param shouldWork the should work + */ + private void checkResult(final EnEvent result, final boolean shouldWork) { + if (!shouldWork) { + assertNotNull(result.getExceptionMessage()); + return; + } + + assertTrue(result.getName().equals("Event0004") || result.getName().equals("Event0104")); + + if (result.getName().equals("Event0004")) { + assertEquals("This is a test slogan", result.get("TestSlogan")); + assertEquals((byte) 123, result.get("TestMatchCase")); + assertEquals(34.5445667, result.get("TestTemperature")); + assertEquals((byte) 2, result.get("TestMatchCaseSelected")); + assertEquals((byte) 0, result.get("TestEstablishCaseSelected")); + assertEquals((byte) 1, result.get("TestDecideCaseSelected")); + assertEquals((byte) 3, result.get("TestActCaseSelected")); + } else { + assertEquals("This is a test slogan", result.get("TestSlogan")); + assertEquals((byte) 123, result.get("TestMatchCase")); + assertEquals(34.5445667, result.get("TestTemperature")); + assertEquals((byte) 1, result.get("TestMatchCaseSelected")); + assertEquals((byte) 3, result.get("TestEstablishCaseSelected")); + assertEquals((byte) 1, result.get("TestDecideCaseSelected")); + assertEquals((byte) 2, result.get("TestActCaseSelected")); + } + } +} -- cgit 1.2.3-korg