2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.bpmn.core;
23 import static org.junit.Assert.assertNotNull;
25 import java.util.HashMap;
28 import org.camunda.bpm.engine.RuntimeService;
29 import org.camunda.bpm.engine.delegate.DelegateExecution;
30 import org.camunda.bpm.engine.delegate.Expression;
31 import org.camunda.bpm.engine.test.Deployment;
32 import org.camunda.bpm.engine.test.ProcessEngineRule;
33 import org.junit.Assert;
34 import org.junit.Before;
35 import org.junit.BeforeClass;
36 import org.junit.Rule;
37 import org.junit.Test;
39 import org.openecomp.mso.bpmn.core.utils.CamundaDBSetup;
40 import org.openecomp.mso.logger.MsoLogger;
43 * Unit test for BaseTask class.
45 public class TestBaseTask {
48 public ProcessEngineRule processEngineRule = new ProcessEngineRule();
51 public static void setUpClass() {
52 System.setProperty("mso.config.path", "src/test/resources");
53 PropertyConfiguration.resetPropertyConfigurationSingletonInstance();
57 public void beforeTest() throws Exception {
58 CamundaDBSetup.configure();
59 PropertyConfigurationSetup.init();
63 @Deployment(resources={"BaseTaskTest.bpmn"})
64 public void shouldInvokeService() {
65 Map<String, Object> variables = new HashMap<>();
66 variables.put("firstName", "Jane");
67 variables.put("lastName", "Doe");
68 variables.put("age", 25);
69 variables.put("lastVisit", 1438270117000L);
71 RuntimeService runtimeService = processEngineRule.getRuntimeService();
72 assertNotNull(runtimeService);
73 processEngineRule.getTaskService();
74 runtimeService.startProcessInstanceByKey("BaseTaskTest", variables);
78 * Unit test code for BaseTask.
80 public static class TestTask extends BaseTask {
81 private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
83 private Expression existingString;
84 private Expression nonExistingString;
85 private Expression existingStringFromVar;
86 private Expression nonExistingStringFromVar;
88 private Expression existingInteger;
89 private Expression nonExistingInteger;
90 private Expression existingIntegerFromVar;
91 private Expression nonExistingIntegerFromVar;
93 private Expression existingLong;
94 private Expression nonExistingLong;
95 private Expression existingLongFromVar;
96 private Expression nonExistingLongFromVar;
98 private Expression existingOutputVar;
99 private Expression nonExistingOutputVar;
100 private Expression existingBadOutputVar;
102 public void execute(DelegateExecution execution) throws Exception {
103 msoLogger.debug("Started executing " + getClass().getSimpleName());
105 /*********************************************************************/
106 msoLogger.debug("Running String Field Tests");
107 /*********************************************************************/
109 String s = getStringField(existingString, execution, "existingString");
110 Assert.assertEquals("Hello World", s);
113 s = getStringField(nonExistingString, execution, "nonExistingString");
114 Assert.fail("Expected BadInjectedFieldException for nonExistingString");
115 } catch (Exception e) {
116 if (!(e instanceof BadInjectedFieldException)) {
117 Assert.fail("Expected BadInjectedFieldException for nonExistingString");
121 s = getOptionalStringField(existingString, execution, "existingString");
122 Assert.assertEquals("Hello World", s);
124 s = getOptionalStringField(nonExistingString, execution, "nonExistingString");
125 Assert.assertEquals(null, s);
127 /*********************************************************************/
128 msoLogger.debug("Running String Expression Tests");
129 /*********************************************************************/
131 s = getStringField(existingStringFromVar, execution, "existingStringFromVar");
132 Assert.assertEquals("Jane", s);
135 s = getStringField(nonExistingStringFromVar, execution, "nonExistingStringFromVar");
136 Assert.fail("Expected BadInjectedFieldException for nonExistingString");
137 } catch (Exception e) {
138 if (!(e instanceof BadInjectedFieldException)) {
139 Assert.fail("Expected BadInjectedFieldException for nonExistingStringFromVar");
143 s = getOptionalStringField(existingStringFromVar, execution, "existingStringFromVar");
144 Assert.assertEquals("Jane", s);
146 s = getOptionalStringField(nonExistingStringFromVar, execution, "nonExistingStringFromVar");
147 Assert.assertEquals(null, s);
149 /*********************************************************************/
150 msoLogger.debug("Running Integer Field Tests");
151 /*********************************************************************/
153 Integer i = getIntegerField(existingInteger, execution, "existingInteger");
154 Assert.assertEquals((Integer)42, i);
157 i = getIntegerField(nonExistingInteger, execution, "nonExistingInteger");
158 Assert.fail("Expected BadInjectedFieldException for nonExistingInteger");
159 } catch (Exception e) {
160 if (!(e instanceof BadInjectedFieldException)) {
161 Assert.fail("Expected BadInjectedFieldException for nonExistingInteger");
165 i = getOptionalIntegerField(existingInteger, execution, "existingInteger");
166 Assert.assertEquals((Integer)42, i);
168 i = getOptionalIntegerField(nonExistingInteger, execution, "nonExistingInteger");
169 Assert.assertEquals(null, i);
171 /*********************************************************************/
172 msoLogger.debug("Running Integer Expression Tests");
173 /*********************************************************************/
175 i = getIntegerField(existingIntegerFromVar, execution, "existingIntegerFromVar");
176 Assert.assertEquals((Integer)25, i);
179 i = getIntegerField(nonExistingIntegerFromVar, execution, "nonExistingIntegerFromVar");
180 Assert.fail("Expected BadInjectedFieldException for nonExistingInteger");
181 } catch (Exception e) {
182 if (!(e instanceof BadInjectedFieldException)) {
183 Assert.fail("Expected BadInjectedFieldException for nonExistingIntegerFromVar");
187 i = getOptionalIntegerField(existingIntegerFromVar, execution, "existingIntegerFromVar");
188 Assert.assertEquals((Integer)25, i);
190 i = getOptionalIntegerField(nonExistingIntegerFromVar, execution, "nonExistingIntegerFromVar");
191 Assert.assertEquals(null, i);
193 /*********************************************************************/
194 msoLogger.debug("Running Long Field Tests");
195 /*********************************************************************/
197 Long l = getLongField(existingLong, execution, "existingLong");
198 Assert.assertEquals((Long)123456789L, l);
201 l = getLongField(nonExistingLong, execution, "nonExistingLong");
202 Assert.fail("Expected BadInjectedFieldException for nonExistingLong");
203 } catch (Exception e) {
204 if (!(e instanceof BadInjectedFieldException)) {
205 Assert.fail("Expected BadInjectedFieldException for nonExistingLong");
209 l = getOptionalLongField(existingLong, execution, "existingLong");
210 Assert.assertEquals((Long)123456789L, l);
212 l = getOptionalLongField(nonExistingLong, execution, "nonExistingLong");
213 Assert.assertEquals(null, l);
215 /*********************************************************************/
216 msoLogger.debug("Running Long Expression Tests");
217 /*********************************************************************/
219 l = getLongField(existingLongFromVar, execution, "existingLongFromVar");
220 Assert.assertEquals((Long)1438270117000L, l);
223 l = getLongField(nonExistingLongFromVar, execution, "nonExistingLongFromVar");
224 Assert.fail("Expected BadInjectedFieldException for nonExistingLong");
225 } catch (Exception e) {
226 if (!(e instanceof BadInjectedFieldException)) {
227 Assert.fail("Expected BadInjectedFieldException for nonExistingLongFromVar");
231 l = getOptionalLongField(existingLongFromVar, execution, "existingLongFromVar");
232 Assert.assertEquals((Long)1438270117000L, l);
234 l = getOptionalLongField(nonExistingLongFromVar, execution, "nonExistingLongFromVar");
235 Assert.assertEquals(null, i);
237 /*********************************************************************/
238 msoLogger.debug("Running Output Variable Field Tests");
239 /*********************************************************************/
241 String var = getOutputField(existingOutputVar, execution, "existingOutputVar");
242 Assert.assertEquals("goodVariable", var);
245 var = getOutputField(nonExistingOutputVar, execution, "nonExistingOutputVar");
246 Assert.fail("Expected BadInjectedFieldException for nonExistingString");
247 } catch (Exception e) {
248 if (!(e instanceof BadInjectedFieldException)) {
249 Assert.fail("Expected BadInjectedFieldException for nonExistingString");
253 var = getOptionalOutputField(existingOutputVar, execution, "existingOutputVar");
254 Assert.assertEquals("goodVariable", var);
256 var = getOptionalOutputField(nonExistingOutputVar, execution, "nonExistingOutputVar");
257 Assert.assertEquals(null, var);
260 var = getOutputField(existingBadOutputVar, execution, "existingBadOutputVar");
261 Assert.fail("Expected BadInjectedFieldException for nonExistingString");
262 } catch (Exception e) {
263 if (!(e instanceof BadInjectedFieldException)) {
264 Assert.fail("Expected BadInjectedFieldException for nonExistingString");
268 msoLogger.debug("Finished executing " + getClass().getSimpleName());