2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
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.mvel;
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.Properties;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.policy.apex.context.ContextException;
32 import org.onap.policy.apex.context.parameters.ContextParameterConstants;
33 import org.onap.policy.apex.context.parameters.DistributorParameters;
34 import org.onap.policy.apex.context.parameters.LockManagerParameters;
35 import org.onap.policy.apex.context.parameters.PersistorParameters;
36 import org.onap.policy.apex.core.engine.context.ApexInternalContext;
37 import org.onap.policy.apex.core.engine.event.EnEvent;
38 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
39 import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
40 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
41 import org.onap.policy.apex.model.policymodel.concepts.AxState;
42 import org.onap.policy.common.parameters.ParameterService;
45 * Test the MvelTaskSelectExecutor class.
48 public class MvelTaskSelectExecutorTest {
50 * Initiate Parameters.
53 public void initiateParameters() {
54 ParameterService.register(new DistributorParameters());
55 ParameterService.register(new LockManagerParameters());
56 ParameterService.register(new PersistorParameters());
63 public void clearParameters() {
64 ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
65 ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
66 ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
70 public void testJavaTaskSelectExecutor() {
71 MvelTaskSelectExecutor mtse = new MvelTaskSelectExecutor();
76 fail("test should throw an exception here");
77 } catch (Exception mtseException) {
78 assertEquals(java.lang.NullPointerException.class, mtseException.getClass());
81 AxState state = new AxState();
82 ApexInternalContext internalContext = null;
84 internalContext = new ApexInternalContext(new AxPolicyModel());
85 } catch (ContextException e) {
86 fail("test should not throw an exception here");
88 mtse.setContext(null, state, internalContext);
90 state.getTaskSelectionLogic().setLogic("x > 1 2 ()");
93 fail("test should throw an exception here");
94 } catch (Exception mtseException) {
95 assertEquals("failed to compile MVEL code for state NULL:0.0.0:NULL:NULL", mtseException.getMessage());
98 state.getTaskSelectionLogic().setLogic("java.lang.String");
102 } catch (Exception mtseException) {
103 fail("test should not throw an exception here");
107 mtse.execute(-1, new Properties(), null);
108 fail("test should throw an exception here");
109 } catch (Exception mtseException) {
110 assertEquals(java.lang.NullPointerException.class, mtseException.getClass());
113 AxEvent axEvent = new AxEvent(new AxArtifactKey("Event", "0.0.1"));
114 EnEvent event = new EnEvent(axEvent);
116 mtse.execute(-1, new Properties(), event);
117 fail("test should throw an exception here");
118 } catch (Exception mtseException) {
119 assertEquals("failed to execute MVEL code for state NULL:0.0.0:NULL:NULL",
120 mtseException.getMessage());
123 state.getTaskSelectionLogic().setLogic("executionId != -1");
126 mtse.execute(-1, new Properties(), event);
127 fail("test should throw an exception here");
128 } catch (Exception mtseException) {
129 assertEquals("execute-post: task selection logic failed on state \"NULL:0.0.0:NULL:NULL\"",
130 mtseException.getMessage());
135 AxArtifactKey taskKey = mtse.execute(0, new Properties(), event);
136 assertEquals("NULL:0.0.0", taskKey.getId());
138 } catch (Exception mtseException) {
139 fail("test should not throw an exception here");