use of org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartThenReopenEmptyCase.
@Test
public void testStartThenReopenEmptyCase() {
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(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
assertEquals("my first case", cInstance.getCaseDescription());
long firstCaseProcessInstanceId = ((CaseInstanceImpl) cInstance).getProcessInstanceId();
caseService.cancelCase(caseId);
CaseInstance instance = caseService.getCaseInstance(caseId);
Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
caseService.reopenCase(caseId, deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID);
cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
assertEquals("my first case", cInstance.getCaseDescription());
long secondCaseProcessInstanceId = ((CaseInstanceImpl) cInstance).getProcessInstanceId();
assertTrue(secondCaseProcessInstanceId > firstCaseProcessInstanceId);
caseService.destroyCase(caseId);
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.casemgmt.impl.model.instance.CaseInstanceImpl in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartEmptyCaseUsingCaseFileOwnerAsLoggedInUser.
@Test
public void testStartEmptyCaseUsingCaseFileOwnerAsLoggedInUser() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("mary"));
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data, roleAssignments);
identityProvider.setName("mary");
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("mary", cInstance.getOwner());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
String initiator = (String) processService.getProcessInstanceVariable(((CaseInstanceImpl) cInstance).getProcessInstanceId(), "initiator");
assertEquals("mary", initiator);
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.casemgmt.impl.model.instance.CaseInstanceImpl in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartThenReopenEmptyCaseUpdateDescription.
@Test
public void testStartThenReopenEmptyCaseUpdateDescription() {
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
assertEquals("#{name}", cInstance.getCaseDescription());
long firstCaseProcessInstanceId = ((CaseInstanceImpl) cInstance).getProcessInstanceId();
caseService.cancelCase(caseId);
CaseInstance instance = caseService.getCaseInstance(caseId);
Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
caseService.reopenCase(caseId, deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data);
cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
assertEquals("my first case", cInstance.getCaseDescription());
long secondCaseProcessInstanceId = ((CaseInstanceImpl) cInstance).getProcessInstanceId();
assertTrue(secondCaseProcessInstanceId > firstCaseProcessInstanceId);
caseService.destroyCase(caseId);
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.casemgmt.impl.model.instance.CaseInstanceImpl 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.casemgmt.impl.model.instance.CaseInstanceImpl in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartEmptyCaseWithCaseFile.
@Test
public void testStartEmptyCaseWithCaseFile() {
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, true, false, false, false);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
assertNotNull(cInstance.getCaseFile());
assertEquals("my first case", cInstance.getCaseFile().getData("name"));
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Collection<VariableDesc> vars = runtimeDataService.getVariablesCurrentState(((CaseInstanceImpl) cInstance).getProcessInstanceId());
assertNotNull(vars);
assertEquals(3, vars.size());
Map<String, Object> mappedVars = vars.stream().collect(toMap(v -> v.getVariableId(), v -> v.getNewValue()));
assertEquals("my first case", mappedVars.get("caseFile_name"));
assertEquals(FIRST_CASE_ID, mappedVars.get("CaseId"));
assertEquals("john", mappedVars.get("initiator"));
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);
}
}
}
Aggregations