2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.plugins.executor.java;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.fail;
27 import java.util.HashMap;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.policy.apex.context.ContextException;
34 import org.onap.policy.apex.context.parameters.ContextParameterConstants;
35 import org.onap.policy.apex.context.parameters.DistributorParameters;
36 import org.onap.policy.apex.context.parameters.LockManagerParameters;
37 import org.onap.policy.apex.context.parameters.PersistorParameters;
38 import org.onap.policy.apex.core.engine.context.ApexInternalContext;
39 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
40 import org.onap.policy.apex.model.policymodel.concepts.AxTask;
41 import org.onap.policy.common.parameters.ParameterService;
44 * Test the JavaTaskExecutor class.
47 public class JavaTaskExecutorTest {
49 public void initiateParameters() {
50 ParameterService.register(new DistributorParameters());
51 ParameterService.register(new LockManagerParameters());
52 ParameterService.register(new PersistorParameters());
56 public void clearParameters() {
57 ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
58 ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
59 ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
63 public void testJavaTaskExecutor() {
64 JavaTaskExecutor jte = new JavaTaskExecutor();
69 fail("test should throw an exception here");
70 } catch (Exception jteException) {
71 assertEquals(java.lang.NullPointerException.class, jteException.getClass());
74 AxTask task = new AxTask();
75 ApexInternalContext internalContext = null;
77 internalContext = new ApexInternalContext(new AxPolicyModel());
78 } catch (ContextException e) {
79 fail("test should not throw an exception here");
81 jte.setContext(null, task, internalContext);
85 fail("test should throw an exception here");
86 } catch (Exception jteException) {
87 assertEquals("instantiation error on Java class \"\"", jteException.getMessage());
90 task.getTaskLogic().setLogic("java.lang.String");
94 } catch (Exception jteException) {
95 fail("test should not throw an exception here");
99 jte.execute(-1, null);
100 fail("test should throw an exception here");
101 } catch (Exception jteException) {
102 assertEquals(java.lang.NullPointerException.class, jteException.getClass());
105 Map<String, Object> incomingParameters = new HashMap<>();
107 jte.execute(-1, incomingParameters);
108 fail("test should throw an exception here");
109 } catch (Exception jteException) {
110 assertEquals("task logic failed to run for task \"NULL:0.0.0\"", jteException.getMessage());
113 task.getTaskLogic().setLogic("org.onap.policy.apex.plugins.executor.java.DummyJavaTaskLogic");
116 jte.execute(-1, incomingParameters);
117 fail("test should throw an exception here");
118 } catch (Exception jteException) {
119 assertEquals("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0",
120 jteException.getMessage());
125 Map<String, Object> returnMap = jte.execute(0, incomingParameters);
126 assertEquals(0, returnMap.size());
128 } catch (Exception jteException) {
129 fail("test should not throw an exception here");