use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.
the class CaseServiceImplTest method testAddSubprocessToEmptyCase.
@Test
public void testAddSubprocessToEmptyCase() {
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
// add dynamic user task to empty case instance - first by case id
Map<String, Object> parameters = new HashMap<>();
caseService.addDynamicSubprocess(FIRST_CASE_ID, SUBPROCESS_P_ID, parameters);
// second task add by process instance id
Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(2, caseProcessInstances.size());
ProcessInstanceDesc casePI = caseProcessInstances.iterator().next();
assertNotNull(casePI);
assertEquals(FIRST_CASE_ID, casePI.getCorrelationKey());
Collection<NodeInstanceDesc> nodes = runtimeDataService.getProcessInstanceHistoryCompleted(casePI.getId(), new QueryContext());
assertNotNull(nodes);
assertEquals(3, nodes.size());
Map<String, String> nodesByName = nodes.stream().collect(toMap(NodeInstanceDesc::getName, NodeInstanceDesc::getNodeType));
assertTrue(nodesByName.containsKey("StartProcess"));
assertTrue(nodesByName.containsKey("EndProcess"));
assertTrue(nodesByName.containsKey("[Dynamic] Sub Process"));
assertEquals("StartNode", nodesByName.get("StartProcess"));
assertEquals("EndNode", nodesByName.get("EndProcess"));
assertEquals("SubProcessNode", nodesByName.get("[Dynamic] Sub Process"));
caseService.addDynamicSubprocess(casePI.getId(), SUBPROCESS_P_ID, parameters);
// let's verify that there are three process instances related to this case
caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(3, caseProcessInstances.size());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartCaseWithoutStartNode.
@Test
public void testStartCaseWithoutStartNode() {
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), NO_START_NODE_CASE_P_ID);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(((CaseInstanceImpl) cInstance).getProcessInstanceId(), new org.kie.api.runtime.query.QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
NodeInstanceDesc active = activeNodes.iterator().next();
assertEquals("Initial step", active.getName());
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
userTaskService.completeAutoProgress(task.getId(), "john", new HashMap<>());
activeNodes = runtimeDataService.getProcessInstanceHistoryActive(((CaseInstanceImpl) cInstance).getProcessInstanceId(), new org.kie.api.runtime.query.QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
active = activeNodes.iterator().next();
assertEquals("stage", active.getName());
caseService.cancelCase(caseId);
CaseInstance instance = caseService.getCaseInstance(caseId);
Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
caseId = null;
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.
the class ETransactionTest method testStartProcessCommit.
@Test
public void testStartProcessCommit() throws Exception {
UserTransaction ut = InitialContext.doLookup(USER_TRANSACTION_NAME);
ut.begin();
Long processInstanceId = null;
ProcessInstanceDesc processDesc = null;
List<NodeInstanceDesc> processInstanceHistory = null;
try {
processInstanceId = startProcessInstance(PROCESS_ID);
checkProcessInstanceIsActive(processInstanceId);
} catch (Exception e) {
ut.rollback();
throw e;
}
ut.commit();
checkProcessInstanceIsActive(processInstanceId);
}
use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.
the class ETransactionTest method testStartProcessRollback.
@Test
public void testStartProcessRollback() throws Exception {
UserTransaction ut = InitialContext.doLookup(USER_TRANSACTION_NAME);
ut.begin();
Long processInstanceId = null;
ProcessInstanceDesc processDesc = null;
List<NodeInstanceDesc> processInstanceHistory = null;
try {
processInstanceId = startProcessInstance(PROCESS_ID);
checkProcessInstanceIsActive(processInstanceId);
} catch (Exception e) {
ut.rollback();
throw e;
}
ut.rollback();
try {
processDesc = runtimeDataService.getProcessInstanceById(processInstanceId);
Assertions.assertThat(processDesc).isNull();
processInstanceHistory = getProcessInstanceHistory(processInstanceId);
Assertions.assertThat(processInstanceHistory).isNullOrEmpty();
} catch (NullPointerException npe) {
LOGGER.error("Non-XA database thrown NPE on process started before rollback", npe);
}
}
use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.
the class ETransactionTest method checkProcessInstanceIsActive.
private void checkProcessInstanceIsActive(Long processInstanceId) {
ProcessInstanceDesc processDesc = runtimeDataService.getProcessInstanceById(processInstanceId);
Assertions.assertThat(processDesc).isNotNull();
Assertions.assertThat(processDesc.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<NodeInstanceDesc> processInstanceHistory = getProcessInstanceHistory(processInstanceId);
Assertions.assertThat(processInstanceHistory).isNotNull().isNotEmpty();
}
Aggregations