use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartEmptyCaseUsingLoggedInOwner.
@Test
public void testStartEmptyCaseUsingLoggedInOwner() {
identityProvider.setName("mary");
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("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.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartThenCancelRetrieveCaseFile.
@Test
public void testStartThenCancelRetrieveCaseFile() {
try {
caseService.getCaseFileInstance(FIRST_CASE_ID);
fail("There is no case yet started");
} catch (CaseNotFoundException e) {
// expected
}
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());
CaseFileInstance caseFileFromCase = caseService.getCaseFileInstance(FIRST_CASE_ID);
assertNotNull(caseFileFromCase);
caseService.cancelCase(caseId);
CaseInstance instance = caseService.getCaseInstance(caseId);
Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
caseFileFromCase = caseService.getCaseFileInstance(FIRST_CASE_ID);
assertNotNull(caseFileFromCase);
caseService.destroyCase(caseId);
CaseInstance caseInstance = caseService.getCaseInstance(caseId);
assertThat(caseInstance.getStatus()).isIn(CaseStatus.CLOSED.getId(), CaseStatus.CANCELLED.getId());
caseId = null;
try {
caseService.getCaseFileInstance(FIRST_CASE_ID);
fail("There is no case yet started");
} catch (CaseNotFoundException e) {
// expected
}
} 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.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartEmptyCaseViaProcessServiceWithoutCorrelationKeyWithMilestones.
@Test
public void testStartEmptyCaseViaProcessServiceWithoutCorrelationKeyWithMilestones() {
Map<String, Object> params = new HashMap<>();
params.put("s", "my case via process service");
Long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, params);
assertNotNull(processInstanceId);
String caseId = processInstanceId.toString();
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
assertEquals(caseId, cInstance.getCaseId());
Collection<CaseMilestoneInstance> milestones = caseRuntimeDataService.getCaseInstanceMilestones(caseId, true, new QueryContext());
assertNotNull(milestones);
assertEquals(0, milestones.size());
// trigger milestone node
caseService.triggerAdHocFragment(caseId, "Milestone1", null);
milestones = caseRuntimeDataService.getCaseInstanceMilestones(caseId, true, new QueryContext());
assertNotNull(milestones);
assertEquals(1, milestones.size());
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.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartEmptyCaseUsingCaseFileOwner.
@Test
public void testStartEmptyCaseUsingCaseFileOwner() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
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);
identityProvider.setName("john");
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals("john", 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.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testCaseWithCommentsPagination.
@Test
public void testCaseWithCommentsPagination() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_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());
for (int i = 0; i < 55; i++) {
caseService.addCaseComment(FIRST_CASE_ID, "anna", "comment" + i);
}
int pageSize = 20;
int firstPageOffset = 0 * pageSize;
Collection<CommentInstance> firstPage = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext(firstPageOffset, pageSize));
assertNotNull(firstPage);
assertEquals(20, firstPage.size());
Iterator<CommentInstance> firstPageIter = firstPage.iterator();
for (int i = 0; firstPageIter.hasNext(); i++) {
assertComment(firstPageIter.next(), "anna", "comment" + i);
}
int secondPageOffset = 1 * pageSize;
Collection<CommentInstance> secondPage = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext(secondPageOffset, pageSize));
assertNotNull(secondPage);
assertEquals(20, secondPage.size());
Iterator<CommentInstance> secondPageIter = secondPage.iterator();
for (int i = 20; secondPageIter.hasNext(); i++) {
assertComment(secondPageIter.next(), "anna", "comment" + i);
}
int thirdPageOffset = 2 * pageSize;
Collection<CommentInstance> thirdPage = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext(thirdPageOffset, pageSize));
assertNotNull(thirdPage);
assertEquals(15, thirdPage.size());
Iterator<CommentInstance> thirdPageIter = thirdPage.iterator();
for (int i = 40; thirdPageIter.hasNext(); i++) {
assertComment(thirdPageIter.next(), "anna", "comment" + i);
}
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations