SONAR assertions apex-pdp
[policy/apex-pdp.git] / testsuites / integration / integration-executor-test / src / test / java / org / onap / policy / apex / testsuites / integration / executor / engine / TestApexEngineJython.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.testsuites.integration.executor.engine;
23
24 import static org.assertj.core.api.Assertions.assertThatCode;
25
26 import java.io.IOException;
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters;
31 import org.onap.policy.apex.context.parameters.ContextParameterConstants;
32 import org.onap.policy.apex.context.parameters.ContextParameters;
33 import org.onap.policy.apex.context.parameters.SchemaParameters;
34 import org.onap.policy.apex.core.engine.EngineParameters;
35 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
36 import org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters;
37 import org.onap.policy.common.parameters.ParameterService;
38
39 /**
40  * The Class TestApexEngineJython should be the test class for the Jython interpreter.
41  *
42  * <p>It actually reruns the javascript tests as a placeholder until the Jython security issues are resolved.
43  *
44  */
45 public class TestApexEngineJython {
46     private SchemaParameters schemaParameters;
47     private ContextParameters contextParameters;
48     private EngineParameters engineParameters;
49
50     /**
51      * Before test.
52      */
53     @Before
54     public void beforeTest() {
55         schemaParameters = new SchemaParameters();
56
57         schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
58         schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters());
59
60         ParameterService.register(schemaParameters);
61
62         contextParameters = new ContextParameters();
63
64         contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME);
65         contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
66         contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME);
67         contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
68
69         ParameterService.register(contextParameters);
70         ParameterService.register(contextParameters.getDistributorParameters());
71         ParameterService.register(contextParameters.getLockManagerParameters());
72         ParameterService.register(contextParameters.getPersistorParameters());
73
74         engineParameters = new EngineParameters();
75         engineParameters.getExecutorParameterMap().put("JAVASCRIPT", new JavascriptExecutorParameters());
76         ParameterService.register(engineParameters);
77     }
78
79     /**
80      * After test.
81      */
82     @After
83     public void afterTest() {
84         ParameterService.deregister(engineParameters);
85
86         ParameterService.deregister(contextParameters.getDistributorParameters());
87         ParameterService.deregister(contextParameters.getLockManagerParameters());
88         ParameterService.deregister(contextParameters.getPersistorParameters());
89         ParameterService.deregister(contextParameters);
90
91         ParameterService.deregister(schemaParameters);
92     }
93
94     /**
95      * Test apex engine.
96      *
97      * @throws ApexException the apex exception
98      * @throws InterruptedException the interrupted exception
99      * @throws IOException Signals that an I/O exception has occurred.
100      */
101     @Test
102     public void testApexEngineJython() throws ApexException, InterruptedException, IOException {
103         assertThatCode(() -> {
104             new TestApexEngine("JAVASCRIPT", engineParameters);
105             new TestApexEngine("JAVASCRIPT", engineParameters);
106         }).doesNotThrowAnyException();
107     }
108 }