diff options
Diffstat (limited to 'plugins/plugins-executor/plugins-executor-javascript')
16 files changed, 2003 insertions, 319 deletions
diff --git a/plugins/plugins-executor/plugins-executor-javascript/pom.xml b/plugins/plugins-executor/plugins-executor-javascript/pom.xml index 390b803d4..38cca1126 100644 --- a/plugins/plugins-executor/plugins-executor-javascript/pom.xml +++ b/plugins/plugins-executor/plugins-executor-javascript/pom.xml @@ -1,6 +1,7 @@ <!-- ============LICENSE_START======================================================= Copyright (C) 2018 Ericsson. All rights reserved. + Modifications Copyright (C) 2020 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,7 +18,10 @@ SPDX-License-Identifier: Apache-2.0 ============LICENSE_END========================================================= --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.policy.apex-pdp.plugins.plugins-executor</groupId> @@ -29,6 +33,46 @@ <name>${project.artifactId}</name> <description>[${project.parent.artifactId}] Plugin for execution of Javascript logic in Apex</description> + <properties> + <graalvm.version>20.0.0</graalvm.version> + </properties> + + <dependencies> + <dependency> + <groupId>org.graalvm.sdk</groupId> + <artifactId>graal-sdk</artifactId> + <version>${graalvm.version}</version> + </dependency> + <dependency> + <groupId>org.graalvm.truffle</groupId> + <artifactId>truffle-api</artifactId> + <version>${graalvm.version}</version> + </dependency> + <dependency> + <groupId>org.graalvm.js</groupId> + <artifactId>js</artifactId> + <version>${graalvm.version}</version> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.onap.policy.apex-pdp.services</groupId> + <artifactId>services-engine</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <version>4.0.2</version> + <scope>test</scope> + </dependency> + + </dependencies> + <profiles> <profile> <id>apexSite</id> diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutor.java b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutor.java new file mode 100644 index 000000000..93f6216fc --- /dev/null +++ b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutor.java @@ -0,0 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.executor.javascript; + +import org.graalvm.polyglot.Context; +import org.graalvm.polyglot.HostAccess; +import org.graalvm.polyglot.Value; +import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; + +/** + * The Class JavascriptExecutor is the executor for task logic written in Javascript. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class JavascriptExecutor { + // The key of the subject that wants to execute Javascript code + final AxKey subjectKey; + + // The Javascript context + private final Context jsContext; + + /** + * Prepares the executor for processing. + * + * @param subjectKey the key of the subject that is requesting Javascript execution + * @throws StateMachineException thrown when instantiation of the executor fails + */ + public JavascriptExecutor(final AxKey subjectKey) throws StateMachineException { + this.subjectKey = subjectKey; + + // @formatter:off + jsContext = + Context.newBuilder("js") + .allowHostClassLookup(s -> true) + .allowHostAccess(HostAccess.ALL) + .build(); + // @formatter:on + + try { + jsContext.getBindings("js"); + } catch (Exception e) { + jsContext.close(); + throw new StateMachineException( + "prepare: javascript engine failed to initialize properly for \"" + subjectKey.getId() + "\"", e); + } + } + + /** + * Executes the the Javascript code. + * + * @param executionContext the execution context of the subject to be passed to the Javascript context + * @param javascriptCode the Javascript code to execute + * @return true if the Javascript executed properly + * @throws StateMachineException thrown when Javascript execution fails + */ + public boolean execute(final Object executionContext, final String javascriptCode) throws StateMachineException { + try { + // Set up the Javascript engine context + jsContext.getBindings("js").putMember("executor", executionContext); + jsContext.eval("js", javascriptCode); + + } catch (final Exception e) { + throw new StateMachineException("execute: logic failed to run for \"" + subjectKey.getId() + "\"", e); + } + + Value returnValue = jsContext.getBindings("js").getMember("returnValue"); + + if (returnValue == null || returnValue.isNull()) { + throw new StateMachineException( + "execute: logic failed to set a return value for \"" + subjectKey.getId() + "\""); + } + + return returnValue.asBoolean(); + } + + /** + * Cleans up the executor after processing. + * + * @throws StateMachineException thrown when cleanup of the executor fails + */ + public void cleanUp() throws StateMachineException { + try { + jsContext.close(); + } catch (final Exception e) { + throw new StateMachineException( + "cleanUp: executor cleanup failed to close for \"" + subjectKey.getId() + "\"", e); + } + } +} diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutor.java b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutor.java index cd660c807..18a6ef58a 100644 --- a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutor.java +++ b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutor.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,11 +24,6 @@ package org.onap.policy.apex.plugins.executor.javascript; import java.util.Map; import java.util.Properties; -import javax.script.Compilable; -import javax.script.CompiledScript; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.core.engine.executor.StateFinalizerExecutor; import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; @@ -45,9 +40,7 @@ public class JavascriptStateFinalizerExecutor extends StateFinalizerExecutor { // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(JavascriptStateFinalizerExecutor.class); - // Javascript engine - private ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript"); - private CompiledScript compiled = null; + private JavascriptExecutor javascriptExecutor; /** * Prepares the state finalizer for processing. @@ -58,14 +51,8 @@ public class JavascriptStateFinalizerExecutor extends StateFinalizerExecutor { public void prepare() throws StateMachineException { // Call generic prepare logic super.prepare(); - try { - compiled = ((Compilable) engine).compile(getSubject().getLogic()); - } catch (final ScriptException e) { - LOGGER.error("execute: state finalizer logic failed to compile for state finalizer \"" - + getSubject().getKey().getId() + "\""); - throw new StateMachineException("state finalizer logic failed to compile for state finalizer \"" - + getSubject().getKey().getId() + "\"", e); - } + + javascriptExecutor = new JavascriptExecutor(getSubject().getKey()); } /** @@ -84,25 +71,8 @@ public class JavascriptStateFinalizerExecutor extends StateFinalizerExecutor { // Do execution pre work executePre(executionId, executionProperties, incomingFields); - // Set up the Javascript engine - engine.put("executor", getExecutionContext()); - - // Check and execute the Javascript logic - try { - if (compiled == null) { - engine.eval(getSubject().getLogic()); - } else { - compiled.eval(engine.getContext()); - } - } catch (final ScriptException e) { - LOGGER.error("execute: state finalizer logic failed to run for state finalizer \"" - + getSubject().getKey().getId() + "\""); - throw new StateMachineException("state finalizer logic failed to run for state finalizer \"" - + getSubject().getKey().getId() + "\"", e); - } - - // Do the execution post work - executePost((boolean) engine.get("returnValue")); + // Execute the Javascript and do post processing + executePost(javascriptExecutor.execute(getExecutionContext(), getSubject().getLogic())); return getOutgoing(); } @@ -116,6 +86,7 @@ public class JavascriptStateFinalizerExecutor extends StateFinalizerExecutor { public void cleanUp() throws StateMachineException { LOGGER.debug("cleanUp:" + getSubject().getKey().getId() + "," + getSubject().getLogicFlavour() + "," + getSubject().getLogic()); - engine = null; + + javascriptExecutor.cleanUp(); } } diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutor.java b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutor.java index 9769f42db..29fae193e 100644 --- a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutor.java +++ b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutor.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,11 +24,6 @@ package org.onap.policy.apex.plugins.executor.javascript; import java.util.Map; import java.util.Properties; -import javax.script.Compilable; -import javax.script.CompiledScript; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.core.engine.executor.TaskExecutor; import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; @@ -45,9 +40,7 @@ public class JavascriptTaskExecutor extends TaskExecutor { // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(JavascriptTaskExecutor.class); - // Javascript engine - private ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript"); - private CompiledScript compiled = null; + private JavascriptExecutor javascriptExecutor; /** * Prepares the task for processing. @@ -58,13 +51,8 @@ public class JavascriptTaskExecutor extends TaskExecutor { public void prepare() throws StateMachineException { // Call generic prepare logic super.prepare(); - try { - compiled = ((Compilable) engine).compile(getSubject().getTaskLogic().getLogic()); - } catch (final ScriptException e) { - LOGGER.error("execute: task logic failed to compile for task \"" + getSubject().getKey().getId() + "\""); - throw new StateMachineException( - "task logic failed to compile for task \"" + getSubject().getKey().getId() + "\"", e); - } + + javascriptExecutor = new JavascriptExecutor(getSubject().getKey()); } /** @@ -83,32 +71,8 @@ public class JavascriptTaskExecutor extends TaskExecutor { // Do execution pre work executePre(executionId, executionProperties, incomingFields); - // Set up the Javascript engine - engine.put("executor", getExecutionContext()); - - // Check and execute the Javascript logic - try { - if (compiled == null) { - engine.eval(getSubject().getTaskLogic().getLogic()); - } else { - compiled.eval(engine.getContext()); - } - } catch (final ScriptException e) { - LOGGER.error("execute: task logic failed to run for task \"" + getSubject().getKey().getId() + "\""); - throw new StateMachineException( - "task logic failed to run for task \"" + getSubject().getKey().getId() + "\"", e); - } - - final Object ret = engine.get("returnValue"); - if (ret == null) { - LOGGER.error("execute: task logic failed to set a return value for task \"" + getSubject().getKey().getId() - + "\""); - throw new StateMachineException("execute: task logic failed to set a return value for task \"" - + getSubject().getKey().getId() + "\""); - } - - // Do the execution post work - executePost((Boolean) ret); + // Execute the Javascript and do post processing + executePost(javascriptExecutor.execute(getExecutionContext(), getSubject().getTaskLogic().getLogic())); return getOutgoing(); } @@ -122,6 +86,7 @@ public class JavascriptTaskExecutor extends TaskExecutor { public void cleanUp() throws StateMachineException { LOGGER.debug("cleanUp:" + getSubject().getKey().getId() + "," + getSubject().getTaskLogic().getLogicFlavour() + "," + getSubject().getTaskLogic().getLogic()); - engine = null; + + javascriptExecutor.cleanUp(); } } diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutor.java b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutor.java index afc7d0183..41585fbd0 100644 --- a/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutor.java +++ b/plugins/plugins-executor/plugins-executor-javascript/src/main/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutor.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,11 +23,6 @@ package org.onap.policy.apex.plugins.executor.javascript; import java.util.Properties; -import javax.script.Compilable; -import javax.script.CompiledScript; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; import org.onap.policy.apex.context.ContextException; import org.onap.policy.apex.core.engine.event.EnEvent; import org.onap.policy.apex.core.engine.executor.TaskSelectExecutor; @@ -46,16 +41,10 @@ public class JavascriptTaskSelectExecutor extends TaskSelectExecutor { // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(JavascriptTaskSelectExecutor.class); - // Recurring string constants - private static final String TSL_FAILED_PREFIX = - "execute: task selection logic failed to set a return value for state \""; - - // Javascript engine - private ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript"); - private CompiledScript compiled = null; + private JavascriptExecutor javascriptExecutor; /** - * Prepares the task for processing. + * Prepares the task selection logic for processing. * * @throws StateMachineException thrown when a state machine execution error occurs */ @@ -63,15 +52,8 @@ public class JavascriptTaskSelectExecutor extends TaskSelectExecutor { public void prepare() throws StateMachineException { // Call generic prepare logic super.prepare(); - try { - compiled = ((Compilable) engine).compile(getSubject().getTaskSelectionLogic().getLogic()); - } catch (final ScriptException e) { - LOGGER.error("execute: task selection logic failed to compile for state \"" + getSubject().getKey().getId() - + "\""); - throw new StateMachineException( - "task selection logic failed to compile for state \"" + getSubject().getKey().getId() + "\"", e); - } + javascriptExecutor = new JavascriptExecutor(getSubject().getKey()); } /** @@ -90,31 +72,8 @@ public class JavascriptTaskSelectExecutor extends TaskSelectExecutor { // Do execution pre work executePre(executionId, executionProperties, incomingEvent); - // Set up the Javascript engine - engine.put("executor", getExecutionContext()); - - // Check and execute the Javascript logic - try { - if (compiled == null) { - engine.eval(getSubject().getTaskSelectionLogic().getLogic()); - } else { - compiled.eval(engine.getContext()); - } - } catch (final ScriptException e) { - LOGGER.error( - "execute: task selection logic failed to run for state \"" + getSubject().getKey().getId() + "\""); - throw new StateMachineException( - "task selection logic failed to run for state \"" + getSubject().getKey().getId() + "\"", e); - } - - final Object ret = engine.get("returnValue"); - if (ret == null) { - LOGGER.error(TSL_FAILED_PREFIX + getSubject().getKey().getId() + "\""); - throw new StateMachineException(TSL_FAILED_PREFIX + getSubject().getKey().getId() + "\""); - } - - // Do the execution post work - executePost((Boolean) ret); + // Execute the Javascript and do post processing + executePost(javascriptExecutor.execute(getExecutionContext(), getSubject().getTaskSelectionLogic().getLogic())); return getOutgoing(); } @@ -129,6 +88,7 @@ public class JavascriptTaskSelectExecutor extends TaskSelectExecutor { LOGGER.debug("cleanUp:" + getSubject().getKey().getId() + "," + getSubject().getTaskSelectionLogic().getLogicFlavour() + "," + getSubject().getTaskSelectionLogic().getLogic()); - engine = null; + + javascriptExecutor.cleanUp(); } } diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorFullApexTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorFullApexTest.java new file mode 100644 index 000000000..1ac052456 --- /dev/null +++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorFullApexTest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.executor.javascript; + +import static org.awaitility.Awaitility.await; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.service.engine.main.ApexMain; +import org.onap.policy.common.utils.resources.TextFileUtils; + +public class JavascriptExecutorFullApexTest { + + @Test + public void testFullApexPolicy() throws ApexException { + final String[] args = {"src/test/resources/prodcons/File2File.json"}; + + final File outFile0 = new File("src/test/resources/events/EventsOut0.json"); + final File outFile1 = new File("src/test/resources/events/EventsOut1.json"); + outFile0.deleteOnExit(); + outFile1.deleteOnExit(); + + final ApexMain apexMain = new ApexMain(args); + assertNotNull(apexMain); + + await().atMost(10, TimeUnit.SECONDS).until(() -> outFile0.exists()); + await().atMost(10, TimeUnit.SECONDS).until(() -> outFile1.exists()); + + await().atMost(10, TimeUnit.SECONDS).until(() -> fileHasOccurencesOf(outFile0, "BasicEventOut0", 50)); + await().atMost(10, TimeUnit.SECONDS).until(() -> fileHasOccurencesOf(outFile1, "BasicEventOut1", 50)); + + apexMain.shutdown(); + } + + private boolean fileHasOccurencesOf(final File file, final String token, final int occurenceCount) + throws IOException { + + return occurenceCount == StringUtils.countMatches(TextFileUtils.getTextFileAsString(file.getAbsolutePath()), + token); + } +} diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java index 724c70bd2..5ccbd255f 100644 --- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java +++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ package org.onap.policy.apex.plugins.executor.javascript; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; @@ -31,7 +32,6 @@ import java.util.Properties; 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.parameters.ContextParameterConstants; import org.onap.policy.apex.context.parameters.DistributorParameters; import org.onap.policy.apex.context.parameters.LockManagerParameters; @@ -41,7 +41,6 @@ import org.onap.policy.apex.core.engine.EngineParameters; import org.onap.policy.apex.core.engine.context.ApexInternalContext; import org.onap.policy.apex.core.engine.event.EnEvent; import org.onap.policy.apex.core.engine.executor.StateExecutor; -import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; import org.onap.policy.apex.core.engine.executor.impl.ExecutorFactoryImpl; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; @@ -78,30 +77,16 @@ public class JavascriptStateFinalizerExecutorTest { } @Test - public void testJavaStateFinalizerExecutor() { + public void testJavaStateFinalizerExecutor() throws Exception { JavascriptStateFinalizerExecutor jsfe = new JavascriptStateFinalizerExecutor(); assertNotNull(jsfe); - try { + assertThatThrownBy(() -> { jsfe.prepare(); - fail("test should throw an exception here"); - } catch (Exception jtseException) { - assertEquals(java.lang.NullPointerException.class, jtseException.getClass()); - } - - ApexInternalContext internalContext = null; - try { - internalContext = new ApexInternalContext(new AxPolicyModel()); - } catch (ContextException e) { - fail("test should not throw an exception here"); - } - - StateExecutor parentStateExcutor = null; - try { - parentStateExcutor = new StateExecutor(new ExecutorFactoryImpl()); - } catch (StateMachineException e) { - fail("test should not throw an exception here"); - } + }).isInstanceOf(java.lang.NullPointerException.class); + + ApexInternalContext internalContext = new ApexInternalContext(new AxPolicyModel()); + StateExecutor parentStateExcutor = new StateExecutor(new ExecutorFactoryImpl()); AxState state = new AxState(); parentStateExcutor.setContext(null, state, internalContext); @@ -109,29 +94,16 @@ public class JavascriptStateFinalizerExecutorTest { jsfe.setContext(parentStateExcutor, stateFinalizerLogic, internalContext); stateFinalizerLogic.setLogic("return false"); - try { - jsfe.prepare(); - fail("test should throw an exception here"); - } catch (Exception jtseException) { - assertEquals("state finalizer logic failed to compile for state finalizer \"NULL:0.0.0:NULL:NULL\"", - jtseException.getMessage()); - } + jsfe.prepare(); Map<String, Object> incomingParameters1 = new HashMap<>(); - try { + assertThatThrownBy(() -> { jsfe.execute(-1, new Properties(), incomingParameters1); fail("test should throw an exception here"); - } catch (Exception jteException) { - assertEquals("state finalizer logic failed to run for state finalizer \"NULL:0.0.0:NULL:NULL\"", - jteException.getMessage()); - } + }).hasMessage("execute: logic failed to run for \"NULL:0.0.0:NULL:NULL\""); stateFinalizerLogic.setLogic("java.lang.String"); - try { - jsfe.prepare(); - } catch (Exception jtseException) { - fail("test should not throw an exception here"); - } + jsfe.prepare(); AxEvent axEvent = new AxEvent(new AxArtifactKey("Event", "0.0.1")); EnEvent event = new EnEvent(axEvent); @@ -141,26 +113,19 @@ public class JavascriptStateFinalizerExecutorTest { + "executor.setSelectedStateOutputName(\"SelectedOutputIsMe\");\n" + "var returnValueType = Java.type(\"java.lang.Boolean\");\n" + "\n" + "var returnValue = new returnValueType(true);}"); - try { + + assertThatThrownBy(() -> { jsfe.prepare(); jsfe.execute(-1, new Properties(), event); - fail("test should throw an exception here"); - } catch (Exception jtseException) { - assertEquals( - "execute-post: state finalizer logic execution failure on state \"NULL:0.0.0:NULL:NULL\" " - + "on finalizer logic NULL:0.0.0:NULL:NULL", - jtseException.getMessage()); - } + }).hasMessage("execute-post: state finalizer logic execution failure on state \"NULL:0.0.0:NULL:NULL\" " + + "on finalizer logic NULL:0.0.0:NULL:NULL"); state.getStateOutputs().put("SelectedOutputIsMe", null); - try { - jsfe.prepare(); - String stateOutput = jsfe.execute(0, new Properties(), event); - assertEquals("SelectedOutputIsMe", stateOutput); - jsfe.cleanUp(); - } catch (Exception jtseException) { - jtseException.printStackTrace(); - fail("test should not throw an exception here"); - } + + jsfe.prepare(); + String stateOutput = jsfe.execute(0, new Properties(), event); + assertEquals("SelectedOutputIsMe", stateOutput); + + jsfe.cleanUp(); } } diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java index fed293921..786cebcc3 100644 --- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java +++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,26 +20,37 @@ package org.onap.policy.apex.plugins.executor.javascript; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Properties; -import org.junit.After; -import org.junit.Before; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; +import org.onap.policy.apex.context.ContextAlbum; import org.onap.policy.apex.context.ContextException; +import org.onap.policy.apex.context.Distributor; +import org.onap.policy.apex.context.impl.ContextAlbumImpl; +import org.onap.policy.apex.context.impl.distribution.jvmlocal.JvmLocalDistributor; +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.DistributorParameters; -import org.onap.policy.apex.context.parameters.LockManagerParameters; -import org.onap.policy.apex.context.parameters.PersistorParameters; +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.parameters.SchemaParameters; import org.onap.policy.apex.core.engine.context.ApexInternalContext; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.service.ModelService; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; import org.onap.policy.apex.model.policymodel.concepts.AxTask; import org.onap.policy.common.parameters.ParameterService; +import org.onap.policy.common.utils.resources.TextFileUtils; /** * Test the JavaTaskExecutor class. @@ -47,106 +58,147 @@ import org.onap.policy.common.parameters.ParameterService; */ public class JavascriptTaskExecutorTest { /** - * Initiate Parameters. + * Set ups everything for the test. */ - @Before - public void initiateParameters() { - ParameterService.register(new DistributorParameters()); - ParameterService.register(new LockManagerParameters()); - ParameterService.register(new PersistorParameters()); + @BeforeClass + public static void prepareForTest() { + final ContextParameters contextParameters = new ContextParameters(); + contextParameters.getLockManagerParameters() + .setPluginClass("org.onap.policy.apex.context.impl.locking.jvmlocal.JvmLocalLockManager"); + + 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()); + + final SchemaParameters schemaParameters = new SchemaParameters(); + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); } /** - * Clear Parameters. + * Clear down the test data. */ - @After - public void clearParameters() { + @AfterClass + public static void cleanUpAfterTest() { ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME); ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME); + ParameterService.deregister(ContextParameterConstants.MAIN_GROUP_NAME); + ParameterService.clear(); } @Test - public void testJavascriptTaskExecutor() { + public void testJavascriptTaskExecutor() throws Exception { JavascriptTaskExecutor jte = new JavascriptTaskExecutor(); assertNotNull(jte); - try { + assertThatThrownBy(() -> { jte.prepare(); - fail("test should throw an exception here"); - } catch (Exception jteException) { - assertEquals(java.lang.NullPointerException.class, jteException.getClass()); - } + }).isInstanceOf(NullPointerException.class); AxTask task = new AxTask(); - ApexInternalContext internalContext = null; - try { - internalContext = new ApexInternalContext(new AxPolicyModel()); - } catch (ContextException e) { - fail("test should not throw an exception here"); - } + final ApexInternalContext internalContext = new ApexInternalContext(new AxPolicyModel()); + jte.setContext(null, task, internalContext); - task.getTaskLogic().setLogic("return boolean"); - try { - jte.prepare(); - fail("test should throw an exception here"); - } catch (Exception jteException) { - assertEquals("task logic failed to compile for task \"NULL:0.0.0\"", jteException.getMessage()); - } + task.getTaskLogic().setLogic("return boolean;"); + jte.prepare(); Map<String, Object> incomingParameters2 = new HashMap<>(); - try { + assertThatThrownBy(() -> { jte.execute(-1, new Properties(), incomingParameters2); - fail("test should throw an exception here"); - } catch (Exception jteException) { - assertEquals("task logic failed to run for task \"NULL:0.0.0\"", jteException.getMessage()); - } + }).hasMessage("execute: logic failed to run for \"NULL:0.0.0\""); - task.getTaskLogic().setLogic("java.lang.String"); - - try { - jte.prepare(); - } catch (Exception jteException) { - fail("test should not throw an exception here"); - } + task.getTaskLogic().setLogic("var x = 5;"); + jte.prepare(); - try { + assertThatThrownBy(() -> { jte.execute(-1, new Properties(), null); - fail("test should throw an exception here"); - } catch (Exception jteException) { - assertEquals(java.lang.NullPointerException.class, jteException.getClass()); - } + }).isInstanceOf(NullPointerException.class); Map<String, Object> incomingParameters = new HashMap<>(); - try { + assertThatThrownBy(() -> { jte.execute(-1, new Properties(), incomingParameters); - fail("test should throw an exception here"); - } catch (Exception jteException) { - assertEquals("execute: task logic failed to set a return value for task \"NULL:0.0.0\"", - jteException.getMessage()); - } + }).hasMessage("execute: logic failed to set a return value for \"NULL:0.0.0\""); - task.getTaskLogic().setLogic("var returnValueType = Java.type(\"java.lang.Boolean\");\r\n" + task.getTaskLogic().setLogic("var returnValueType = Java.type(\"java.lang.Boolean\");\n" + "var returnValue = new returnValueType(false); "); - try { + + assertThatThrownBy(() -> { jte.prepare(); jte.execute(-1, new Properties(), incomingParameters); - fail("test should throw an exception here"); - } catch (Exception jteException) { - assertEquals("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0", - jteException.getMessage()); - } + }).hasMessage("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0"); task.getTaskLogic().setLogic("var returnValueType = Java.type(\"java.lang.Boolean\");\r\n" + "var returnValue = new returnValueType(true); "); - try { + + jte.prepare(); + Map<String, Object> returnMap = jte.execute(0, new Properties(), incomingParameters); + assertEquals(0, returnMap.size()); + jte.cleanUp(); + } + + @Test + public void testJavascriptTaskExecutorLogic() throws Exception { + JavascriptTaskExecutor jte = new JavascriptTaskExecutor(); + assertNotNull(jte); + + assertThatThrownBy(() -> { jte.prepare(); - Map<String, Object> returnMap = jte.execute(0, new Properties(), incomingParameters); - assertEquals(0, returnMap.size()); - jte.cleanUp(); - } catch (Exception jteException) { - fail("test should not throw an exception here"); - } + }).isInstanceOf(NullPointerException.class); + + AxTask task = new AxTask(new AxArtifactKey("TestTask:0.0.1")); + + ContextAlbum contextAlbum = createTestContextAlbum(); + + final ApexInternalContext internalContext = new ApexInternalContext(new AxPolicyModel()); + internalContext.getContextAlbums().put(contextAlbum.getKey(), contextAlbum); + + task.getContextAlbumReferences().add(contextAlbum.getKey()); + task.getOutputFields().put("par0", null); + task.getOutputFields().put("par1", null); + + jte.setContext(null, task, internalContext); + + Map<String, Object> incomingParameters = new HashMap<>(); + incomingParameters.put("par0", "value0"); + + task.getTaskLogic().setLogic(TextFileUtils.getTextFileAsString("src/test/resources/javascript/TestLogic00.js")); + + jte.prepare(); + jte.execute(-1, new Properties(), incomingParameters); + + task.getTaskLogic().setLogic(TextFileUtils.getTextFileAsString("src/test/resources/javascript/TestLogic01.js")); + jte.prepare(); + + Map<String, Object> outcomingParameters = jte.execute(-1, new Properties(), incomingParameters); + + assertEquals("returnVal0", outcomingParameters.get("par0")); + assertEquals("returnVal1", outcomingParameters.get("par1")); + } + + private ContextAlbum createTestContextAlbum() throws ContextException { + AxContextSchemas schemas = new AxContextSchemas(); + AxContextSchema simpleStringSchema = + new AxContextSchema(new AxArtifactKey("SimpleStringSchema", "0.0.1"), "JAVA", "java.lang.String"); + schemas.getSchemasMap().put(simpleStringSchema.getKey(), simpleStringSchema); + ModelService.registerModel(AxContextSchemas.class, schemas); + + AxContextAlbum axContextAlbum = new AxContextAlbum(new AxArtifactKey("TestContextAlbum", "0.0.1"), "Policy", + true, AxArtifactKey.getNullKey()); + + axContextAlbum.setItemSchema(simpleStringSchema.getKey()); + Distributor distributor = new JvmLocalDistributor(); + distributor.init(axContextAlbum.getKey()); + return new ContextAlbumImpl(axContextAlbum, distributor, new LinkedHashMap<String, Object>()); } } diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java index 9a705020c..abbcd19b7 100644 --- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java +++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ package org.onap.policy.apex.plugins.executor.javascript; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; @@ -29,7 +30,6 @@ import java.util.Properties; 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.parameters.ContextParameterConstants; import org.onap.policy.apex.context.parameters.DistributorParameters; import org.onap.policy.apex.context.parameters.LockManagerParameters; @@ -68,92 +68,55 @@ public class JavascriptTaskSelectExecutorTest { } @Test - public void testJavascriptTaskSelectExecutor() { + public void testJavascriptTaskSelectExecutor() throws Exception { JavascriptTaskSelectExecutor jtse = new JavascriptTaskSelectExecutor(); assertNotNull(jtse); - try { + assertThatThrownBy(() -> { jtse.prepare(); fail("test should throw an exception here"); - } catch (Exception jtseException) { - assertEquals(java.lang.NullPointerException.class, jtseException.getClass()); - } + }).isInstanceOf(NullPointerException.class); AxState state = new AxState(); - ApexInternalContext internalContext = null; - try { - internalContext = new ApexInternalContext(new AxPolicyModel()); - } catch (ContextException e) { - fail("test should not throw an exception here"); - } + ApexInternalContext internalContext = new ApexInternalContext(new AxPolicyModel()); jtse.setContext(null, state, internalContext); - - state.getTaskSelectionLogic().setLogic("x!0"); - try { - jtse.prepare(); - fail("test should throw an exception here"); - } catch (Exception jtseException) { - assertEquals("task selection logic failed to compile for state \"NULL:0.0.0:NULL:NULL\"", - jtseException.getMessage()); - } + jtse.prepare(); AxEvent axEvent1 = new AxEvent(new AxArtifactKey("Event", "0.0.1")); EnEvent event1 = new EnEvent(axEvent1); - try { + + assertThatThrownBy(() -> { jtse.execute(-1, new Properties(), event1); - fail("test should throw an exception here"); - } catch (Exception jtseException) { - assertEquals( - "task selection logic failed to run for state \"NULL:0.0.0:NULL:NULL\"", - jtseException.getMessage()); - } + }).hasMessage("execute: logic failed to set a return value for \"NULL:0.0.0:NULL:NULL\""); state.getTaskSelectionLogic().setLogic("java.lang.String"); + jtse.prepare(); - try { - jtse.prepare(); - } catch (Exception jtseException) { - fail("test should not throw an exception here"); - } - - try { + assertThatThrownBy(() -> { jtse.execute(-1, new Properties(), null); - fail("test should throw an exception here"); - } catch (Exception jtseException) { - assertEquals(java.lang.NullPointerException.class, jtseException.getClass()); - } + }).isInstanceOf(NullPointerException.class); AxEvent axEvent = new AxEvent(new AxArtifactKey("Event", "0.0.1")); EnEvent event = new EnEvent(axEvent); - try { + + assertThatThrownBy(() -> { jtse.execute(-1, new Properties(), event); - fail("test should throw an exception here"); - } catch (Exception jtseException) { - assertEquals( - "execute: task selection logic failed to set a return value for state \"NULL:0.0.0:NULL:NULL\"", - jtseException.getMessage()); - } + }).hasMessage("execute: logic failed to set a return value for \"NULL:0.0.0:NULL:NULL\""); state.getTaskSelectionLogic().setLogic("var returnValueType = Java.type(\"java.lang.Boolean\");\r\n" + "var returnValue = new returnValueType(false); "); - try { + + assertThatThrownBy(() -> { jtse.prepare(); jtse.execute(-1, new Properties(), event); - fail("test should throw an exception here"); - } catch (Exception jtseException) { - assertEquals("execute-post: task selection logic failed on state \"NULL:0.0.0:NULL:NULL\"", - jtseException.getMessage()); - } + }).hasMessage("execute-post: task selection logic failed on state \"NULL:0.0.0:NULL:NULL\""); state.getTaskSelectionLogic().setLogic("var returnValueType = Java.type(\"java.lang.Boolean\");\r\n" + "var returnValue = new returnValueType(true); "); - try { - jtse.prepare(); - AxArtifactKey taskKey = jtse.execute(0, new Properties(), event); - assertEquals("NULL:0.0.0", taskKey.getId()); - jtse.cleanUp(); - } catch (Exception jtseException) { - fail("test should not throw an exception here"); - } + + jtse.prepare(); + AxArtifactKey taskKey = jtse.execute(0, new Properties(), event); + assertEquals("NULL:0.0.0", taskKey.getId()); + jtse.cleanUp(); } } diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/events/EventsIn0.json b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/events/EventsIn0.json new file mode 100644 index 000000000..d16431457 --- /dev/null +++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/events/EventsIn0.json @@ -0,0 +1,400 @@ +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn0", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/events/EventsIn1.json b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/events/EventsIn1.json new file mode 100644 index 000000000..574af5a3c --- /dev/null +++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/events/EventsIn1.json @@ -0,0 +1,400 @@ +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} +{ + "nameSpace": "org.onap.policy.apex.events", + "name": "BasicEventIn1", + "version": "0.0.1", + "source": "test", + "target": "apex", + "intPar": 12345 +} diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/PolicyTaskLogic.js b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/PolicyTaskLogic.js new file mode 100644 index 000000000..a7bb81666 --- /dev/null +++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/PolicyTaskLogic.js @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +executor.logger.info(executor.subject.getId()); +var gc = executor.getContextAlbum("BasicContextAlbum"); +executor.logger.info(gc.getName()); +executor.logger.info("incoming value: " + executor.inFields.get("intPar").toString()); + +var intPar = executor.inFields.get("intPar"); + +executor.logger.info("read value: " + intPar.toString()); + +var intParBy2 = intPar * 2; + +executor.outFields.put("intPar", intParBy2); + +executor.logger.info("outgoing value: " + executor.outFields.get("intPar").toString()); + +var returnValue = executor.isTrue;
\ No newline at end of file diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic00.js b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic00.js new file mode 100644 index 000000000..8b3bff425 --- /dev/null +++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic00.js @@ -0,0 +1,21 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +var x = 1; +var returnValue = true; diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic01.js b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic01.js new file mode 100644 index 000000000..7c8a44962 --- /dev/null +++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/javascript/TestLogic01.js @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +executor.logger.info("hello world"); + +executor.logger.info(executor.subject.getId()); +var gc = executor.getContextAlbum("TestContextAlbum"); +executor.logger.info(gc.getName()); +executor.logger.info(executor.inFields.get("par0")); + +executor.outFields.put("par0", "returnVal0"); +executor.outFields.put("par1", "returnVal1"); + +executor.logger.info(executor.outFields.get("par0")); +executor.logger.info(executor.outFields.get("par1")); + +var returnValue = executor.isTrue; diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/policymodels/ExecutorModel.json b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/policymodels/ExecutorModel.json new file mode 100644 index 000000000..79f08e279 --- /dev/null +++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/policymodels/ExecutorModel.json @@ -0,0 +1,635 @@ +{ + "apexPolicyModel" : { + "key" : { + "name" : "SmallModel", + "version" : "0.0.1" + }, + "keyInformation" : { + "key" : { + "name" : "SmallModel_KeyInfo", + "version" : "0.0.1" + }, + "keyInfoMap" : { + "entry" : [ { + "key" : { + "name" : "BasicContextAlbum", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "BasicContextAlbum", + "version" : "0.0.1" + }, + "UUID" : "fec1b353-b35f-4384-b7d9-69622059c248", + "description" : "Generated description for a concept called \"BasicContextAlbum\" with version \"0.0.1\" and UUID \"fec1b353-b35f-4384-b7d9-69622059c248\"" + } + }, { + "key" : { + "name" : "BasicEventIn0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "BasicEventIn0", + "version" : "0.0.1" + }, + "UUID" : "cab51283-6a38-31f6-81e8-33c381fcba77", + "description" : "Generated description for a concept called \"BasicEventIn0\" with version \"0.0.1\" and UUID \"8bfd4010-1b5b-45c0-b237-dc27d553d446\"" + } + }, { + "key" : { + "name" : "BasicEventIn1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "BasicEventIn1", + "version" : "0.0.1" + }, + "UUID" : "b51b63bf-29b5-3104-99c7-990e6a7d703d", + "description" : "Generated description for a concept called \"BasicEventIn1\" with version \"0.0.1\" and UUID \"9f3bc09e-1070-437c-8039-bf7bc696e4cc\"" + } + }, { + "key" : { + "name" : "BasicEventOut0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "BasicEventOut0", + "version" : "0.0.1" + }, + "UUID" : "6846fd9b-775d-3df8-afe2-7ea6898de9d6", + "description" : "Generated description for a concept called \"BasicEventOut0\" with version \"0.0.1\" and UUID \"8a22a808-98a9-41ff-93c2-c01ae73b79b2\"" + } + }, { + "key" : { + "name" : "BasicEventOut1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "BasicEventOut1", + "version" : "0.0.1" + }, + "UUID" : "28c4cf58-cfc4-3c15-bebf-7046df303a31", + "description" : "Generated description for a concept called \"BasicEventOut1\" with version \"0.0.1\" and UUID \"f43989a7-fe36-4359-bb32-3e50799790ae\"" + } + }, { + "key" : { + "name" : "BasicTask", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "BasicTask", + "version" : "0.0.1" + }, + "UUID" : "5757b356-875b-35b1-872c-1bb8cdfe233f", + "description" : "Generated description for a concept called \"BasicTask\" with version \"0.0.1\" and UUID \"c5651414-fc1c-493b-878d-75f0ce685c36\"" + } + }, { + "key" : { + "name" : "IntType", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "IntType", + "version" : "0.0.1" + }, + "UUID" : "790ff718-8dc0-44e0-89d8-1b3bbe238310", + "description" : "Generated description for a concept called \"IntType\" with version \"0.0.1\" and UUID \"790ff718-8dc0-44e0-89d8-1b3bbe238310\"" + } + }, { + "key" : { + "name" : "Policy0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Policy0", + "version" : "0.0.1" + }, + "UUID" : "d2b04a23-ec6d-4626-a18b-03c36fc2e1ba", + "description" : "Generated description for a concept called \"Policy0\" with version \"0.0.1\" and UUID \"d2b04a23-ec6d-4626-a18b-03c36fc2e1ba\"" + } + }, { + "key" : { + "name" : "Policy1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "Policy1", + "version" : "0.0.1" + }, + "UUID" : "00105b10-3f0e-49b1-bfdf-96d27b08fd54", + "description" : "Generated description for a concept called \"Policy1\" with version \"0.0.1\" and UUID \"00105b10-3f0e-49b1-bfdf-96d27b08fd54\"" + } + }, { + "key" : { + "name" : "SmallModel", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "SmallModel", + "version" : "0.0.1" + }, + "UUID" : "a1bd1f4e-713b-456b-b1a8-bb48beee28e8", + "description" : "Generated description for a concept called \"SmallModel\" with version \"0.0.1\" and UUID \"a1bd1f4e-713b-456b-b1a8-bb48beee28e8\"" + } + }, { + "key" : { + "name" : "SmallModel_Albums", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "SmallModel_Albums", + "version" : "0.0.1" + }, + "UUID" : "72bed9af-ab7d-3379-b9f7-b5eca5c9ef22", + "description" : "Generated description for concept referred to by key \"SmallModel_Albums:0.0.1\"" + } + }, { + "key" : { + "name" : "SmallModel_Events", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "SmallModel_Events", + "version" : "0.0.1" + }, + "UUID" : "796dc6b0-627d-34ae-a5e2-1bc4b4b486b8", + "description" : "Generated description for concept referred to by key \"SmallModel_Events:0.0.1\"" + } + }, { + "key" : { + "name" : "SmallModel_KeyInfo", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "SmallModel_KeyInfo", + "version" : "0.0.1" + }, + "UUID" : "b4876774-6907-3d27-a2b8-f05737c5ee4a", + "description" : "Generated description for concept referred to by key \"SmallModel_KeyInfo:0.0.1\"" + } + }, { + "key" : { + "name" : "SmallModel_Policies", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "SmallModel_Policies", + "version" : "0.0.1" + }, + "UUID" : "5bcf946b-67be-3190-a906-f954896f999f", + "description" : "Generated description for concept referred to by key \"SmallModel_Policies:0.0.1\"" + } + }, { + "key" : { + "name" : "SmallModel_Schemas", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "SmallModel_Schemas", + "version" : "0.0.1" + }, + "UUID" : "c25bf5c3-7f1e-3667-b8a9-971ba21517bc", + "description" : "Generated description for concept referred to by key \"SmallModel_Schemas:0.0.1\"" + } + }, { + "key" : { + "name" : "SmallModel_Tasks", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "SmallModel_Tasks", + "version" : "0.0.1" + }, + "UUID" : "43b015ca-2ed1-3a35-b103-e8a5aa68f1ef", + "description" : "Generated description for concept referred to by key \"SmallModel_Tasks:0.0.1\"" + } + } ] + } + }, + "policies" : { + "key" : { + "name" : "SmallModel_Policies", + "version" : "0.0.1" + }, + "policyMap" : { + "entry" : [ { + "key" : { + "name" : "Policy0", + "version" : "0.0.1" + }, + "value" : { + "policyKey" : { + "name" : "Policy0", + "version" : "0.0.1" + }, + "template" : "FREEFORM", + "state" : { + "entry" : [ { + "key" : "State0", + "value" : { + "stateKey" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "State0" + }, + "trigger" : { + "name" : "BasicEventIn0", + "version" : "0.0.1" + }, + "stateOutputs" : { + "entry" : [ { + "key" : "State0Output", + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "State0", + "localName" : "State0Output" + }, + "outgoingEvent" : { + "name" : "BasicEventOut0", + "version" : "0.0.1" + }, + "nextState" : { + "parentKeyName" : "NULL", + "parentKeyVersion" : "0.0.0", + "parentLocalName" : "NULL", + "localName" : "NULL" + } + } + } ] + }, + "contextAlbumReference" : [ ], + "taskSelectionLogic" : { + "key" : "NULL", + "logicFlavour" : "UNDEFINED", + "logic" : "" + }, + "stateFinalizerLogicMap" : { + "entry" : [ ] + }, + "defaultTask" : { + "name" : "BasicTask", + "version" : "0.0.1" + }, + "taskReferences" : { + "entry" : [ { + "key" : { + "name" : "BasicTask", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "State0", + "localName" : "BasicTask" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy0", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "State0", + "localName" : "State0Output" + } + } + } ] + } + } + } ] + }, + "firstState" : "State0" + } + }, { + "key" : { + "name" : "Policy1", + "version" : "0.0.1" + }, + "value" : { + "policyKey" : { + "name" : "Policy1", + "version" : "0.0.1" + }, + "template" : "FREEFORM", + "state" : { + "entry" : [ { + "key" : "State1", + "value" : { + "stateKey" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "NULL", + "localName" : "State1" + }, + "trigger" : { + "name" : "BasicEventIn1", + "version" : "0.0.1" + }, + "stateOutputs" : { + "entry" : [ { + "key" : "State1Output", + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "State1", + "localName" : "State1Output" + }, + "outgoingEvent" : { + "name" : "BasicEventOut1", + "version" : "0.0.1" + }, + "nextState" : { + "parentKeyName" : "NULL", + "parentKeyVersion" : "0.0.0", + "parentLocalName" : "NULL", + "localName" : "NULL" + } + } + } ] + }, + "contextAlbumReference" : [ ], + "taskSelectionLogic" : { + "key" : "NULL", + "logicFlavour" : "UNDEFINED", + "logic" : "" + }, + "stateFinalizerLogicMap" : { + "entry" : [ ] + }, + "defaultTask" : { + "name" : "BasicTask", + "version" : "0.0.1" + }, + "taskReferences" : { + "entry" : [ { + "key" : { + "name" : "BasicTask", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "State1", + "localName" : "Task1" + }, + "outputType" : "DIRECT", + "output" : { + "parentKeyName" : "Policy1", + "parentKeyVersion" : "0.0.1", + "parentLocalName" : "State1", + "localName" : "State1Output" + } + } + } ] + } + } + } ] + }, + "firstState" : "State1" + } + } ] + } + }, + "tasks" : { + "key" : { + "name" : "SmallModel_Tasks", + "version" : "0.0.1" + }, + "taskMap" : { + "entry" : [ { + "key" : { + "name" : "BasicTask", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "BasicTask", + "version" : "0.0.1" + }, + "inputFields" : { + "entry" : [ { + "key" : "intPar", + "value" : { + "key" : "intPar", + "fieldSchemaKey" : { + "name" : "IntType", + "version" : "0.0.1" + }, + "optional" : false + } + } ] + }, + "outputFields" : { + "entry" : [ { + "key" : "intPar", + "value" : { + "key" : "intPar", + "fieldSchemaKey" : { + "name" : "IntType", + "version" : "0.0.1" + }, + "optional" : false + } + } ] + }, + "taskParameters" : { + "entry" : [ ] + }, + "contextAlbumReference" : [ { + "name" : "BasicContextAlbum", + "version" : "0.0.1" + } ], + "taskLogic" : { + "key" : "TaskLogic", + "logicFlavour" : "JAVASCRIPT", + "logic" : "executor.logger.debug(executor.subject.getId());\nvar gc = executor.getContextAlbum(\"BasicContextAlbum\");\nexecutor.logger.debug(gc.getName());\nexecutor.logger.debug(\"incoming value: \" + executor.inFields.get(\"intPar\").toString());\n\nvar intPar = executor.inFields.get(\"intPar\");\n\nexecutor.logger.debug(\"read value: \" + intPar.toString());\n\nvar intParBy2 = intPar * 2;\n\nexecutor.outFields.put(\"intPar\", intParBy2);\n\nexecutor.logger.debug(\"outgoing value: \" + executor.outFields.get(\"intPar\").toString());\n\nvar returnValue = executor.isTrue;" + } + } + } ] + } + }, + "events" : { + "key" : { + "name" : "SmallModel_Events", + "version" : "0.0.1" + }, + "eventMap" : { + "entry" : [ { + "key" : { + "name" : "BasicEventIn0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "BasicEventIn0", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.events", + "source" : "External", + "target" : "Apex", + "parameter" : { + "entry" : [ { + "key" : "intPar", + "value" : { + "key" : "intPar", + "fieldSchemaKey" : { + "name" : "IntType", + "version" : "0.0.1" + }, + "optional" : false + } + } ] + } + } + }, { + "key" : { + "name" : "BasicEventIn1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "BasicEventIn1", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.events", + "source" : "External", + "target" : "Apex", + "parameter" : { + "entry" : [ { + "key" : "intPar", + "value" : { + "key" : "intPar", + "fieldSchemaKey" : { + "name" : "IntType", + "version" : "0.0.1" + }, + "optional" : false + } + } ] + } + } + }, { + "key" : { + "name" : "BasicEventOut0", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "BasicEventOut0", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.events", + "source" : "Apex", + "target" : "External", + "parameter" : { + "entry" : [ { + "key" : "intPar", + "value" : { + "key" : "intPar", + "fieldSchemaKey" : { + "name" : "IntType", + "version" : "0.0.1" + }, + "optional" : false + } + } ] + } + } + }, { + "key" : { + "name" : "BasicEventOut1", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "BasicEventOut1", + "version" : "0.0.1" + }, + "nameSpace" : "org.onap.policy.apex.events", + "source" : "Apex", + "target" : "External", + "parameter" : { + "entry" : [ { + "key" : "intPar", + "value" : { + "key" : "intPar", + "fieldSchemaKey" : { + "name" : "IntType", + "version" : "0.0.1" + }, + "optional" : false + } + } ] + } + } + } ] + } + }, + "albums" : { + "key" : { + "name" : "SmallModel_Albums", + "version" : "0.0.1" + }, + "albums" : { + "entry" : [ { + "key" : { + "name" : "BasicContextAlbum", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "BasicContextAlbum", + "version" : "0.0.1" + }, + "scope" : "GLOBAL", + "isWritable" : true, + "itemSchema" : { + "name" : "IntType", + "version" : "0.0.1" + } + } + } ] + } + }, + "schemas" : { + "key" : { + "name" : "SmallModel_Schemas", + "version" : "0.0.1" + }, + "schemas" : { + "entry" : [ { + "key" : { + "name" : "IntType", + "version" : "0.0.1" + }, + "value" : { + "key" : { + "name" : "IntType", + "version" : "0.0.1" + }, + "schemaFlavour" : "Java", + "schemaDefinition" : "java.lang.Integer" + } + } ] + } + } + } +} diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/prodcons/File2File.json b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/prodcons/File2File.json new file mode 100644 index 000000000..0a1014ae9 --- /dev/null +++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/resources/prodcons/File2File.json @@ -0,0 +1,67 @@ +{ + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12561, + "policyModelFileName": "src/test/resources/policymodels/ExecutorModel.json", + "engineParameters": { + "executorParameters": { + "JAVASCRIPT": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters" + } + } + } + }, + "eventInputParameters": { + "File0Consumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsIn0.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + }, + "File1Consumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsIn1.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + }, + "eventOutputParameters": { + "File0Producer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsOut0.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "BasicEventOut0" + }, + "File1Producer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "src/test/resources/events/EventsOut1.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + }, + "eventNameFilter": "BasicEventOut1" + } + } +} |