/* 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.
*/
package org.activiti.examples.bpmn.callactivity;
import org.activiti.engine.test.ActivitiRule;
import org.activiti.engine.*;
import org.junit.*;
import static org.junit.Assert.*;
import org.activiti.engine.impl.util.CollectionUtil;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.activiti.engine.test.Deployment;
/**
* @author Joram Barrez
*/
public class CallActivityTest {
@Rule public ActivitiRule activitiRule = new ActivitiRule();
@Deployment(resources={
"org/activiti/examples/bpmn/callactivity/orderProcess.bpmn20.xml",
"org/activiti/examples/bpmn/callactivity/checkCreditProcess.bpmn20.xml"
})
@Test
public void testOrderProcessWithCallActivity() {
// After the process has started, the 'verify credit history' task should be active
RuntimeService runtimeService = activitiRule.getRuntimeService();
ProcessInstance pi = runtimeService.startProcessInstanceByKey("orderProcess");
TaskService taskService = activitiRule.getTaskService();
TaskQuery taskQuery = taskService.createTaskQuery();
Task verifyCreditTask = taskQuery.singleResult();
assertEquals("Verify credit history", verifyCreditTask.getName());
// Verify with Query API
ProcessInstance subProcessInstance = runtimeService.createProcessInstanceQuery().superProcessInstanceId(pi.getId()).singleResult();
assertNotNull(subProcessInstance);
assertEquals(pi.getId(), runtimeService.createProcessInstanceQuery().subProcessInstanceId(subProcessInstance.getId()).singleResult().getId());
// Completing the task with approval, will end the subprocess and continue the original process
taskService.complete(verifyCreditTask.getId(), CollectionUtil.singletonMap("creditApproved", true));
Task prepareAndShipTask = taskQuery.singleResult();
assertEquals("Prepare and Ship", prepareAndShipTask.getName());
}
}