Search in sources :

Example 1 with CaseStatus

use of org.jbpm.casemgmt.api.model.CaseStatus in project jbpm by kiegroup.

the class CaseDynamicNodesTest method testAddDynamicSubprocessWithNotExistingProcessId.

@Test
public void testAddDynamicSubprocessWithNotExistingProcessId() {
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
    assertThat(caseInstance).isNotNull();
    CaseStatus initialStatus = CaseStatus.fromId(caseInstance.getStatus());
    assertThatThrownBy(() -> caseService.addDynamicSubprocess(caseId, NOT_EXISTING_SUBPROCESS, Collections.emptyMap())).isInstanceOf(ProcessDefinitionNotFoundException.class);
    // case instance status should not have changed
    caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
    assertThat(caseInstance).isNotNull();
    CaseStatus afterStatus = CaseStatus.fromId(caseInstance.getStatus());
    assertThat(initialStatus).isEqualTo(afterStatus);
}
Also used : CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 2 with CaseStatus

use of org.jbpm.casemgmt.api.model.CaseStatus in project jbpm by kiegroup.

the class CaseServiceImplTest method testCaseRolesWithQueries.

@Test
public void testCaseRolesWithQueries() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    roleAssignments.put("contact", new GroupImpl("HR"));
    Map<String, Object> data = new HashMap<>();
    data.put("s", "description");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(HR_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(HR_CASE_ID, cInstance.getCaseId());
        assertEquals(CaseStatus.OPEN.getId(), cInstance.getStatus().intValue());
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        // only john is now included in case roles
        Collection<CaseInstance> instances = caseRuntimeDataService.getCaseInstancesAnyRole(null, new QueryContext());
        assertNotNull(instances);
        assertEquals(0, instances.size());
        List<CaseStatus> status = Arrays.asList(CaseStatus.CANCELLED);
        instances = caseRuntimeDataService.getCaseInstancesAnyRole(status, new QueryContext());
        assertNotNull(instances);
        assertFalse("Opened case was returned when searching for cancelled case instances.", instances.stream().anyMatch(n -> n.getCaseId().equals(caseId)));
        status = Arrays.asList(CaseStatus.OPEN);
        instances = caseRuntimeDataService.getCaseInstancesAnyRole(status, new QueryContext());
        assertNotNull(instances);
        assertEquals(1, instances.size());
        instances = caseRuntimeDataService.getCaseInstancesByRole(null, status, new QueryContext());
        assertNotNull(instances);
        assertEquals(0, instances.size());
        instances = caseRuntimeDataService.getCaseInstancesByRole("owner", status, new QueryContext());
        assertNotNull(instances);
        assertEquals(1, instances.size());
        identityProvider.setName("mary");
        instances = caseRuntimeDataService.getCaseInstancesByRole("owner", status, new QueryContext());
        assertNotNull(instances);
        assertEquals("Mary shouldn't be owner of any opened case instance.", 0, instances.size());
        identityProvider.setRoles(Arrays.asList("HR"));
        instances = caseRuntimeDataService.getCaseInstancesByRole("contact", status, new QueryContext());
        assertNotNull(instances);
        assertEquals(1, instances.size());
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        identityProvider.setName("john");
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : TaskSummary(org.kie.api.task.model.TaskSummary) Arrays(java.util.Arrays) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) Date(java.util.Date) CommentSortBy(org.jbpm.casemgmt.api.model.instance.CommentSortBy) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) LoggerFactory(org.slf4j.LoggerFactory) CaseAssignment(org.kie.api.runtime.process.CaseAssignment) CommentInstance(org.jbpm.casemgmt.api.model.instance.CommentInstance) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) KieInternalServices(org.kie.internal.KieInternalServices) Assertions(org.assertj.core.api.Assertions) AuthorizationManager(org.jbpm.casemgmt.api.auth.AuthorizationManager) CaseMilestoneInstance(org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) Collection(java.util.Collection) UUID(java.util.UUID) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileItem(org.jbpm.casemgmt.api.model.CaseFileItem) List(java.util.List) Assertions.fail(org.assertj.core.api.Assertions.fail) Assert.assertFalse(org.junit.Assert.assertFalse) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) Person(org.jbpm.bpmn2.objects.Person) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) Status(org.kie.api.task.model.Status) UserImpl(org.jbpm.services.task.impl.model.UserImpl) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) HashMap(java.util.HashMap) QueryFilter(org.kie.internal.query.QueryFilter) ArrayList(java.util.ArrayList) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) StageStatus(org.jbpm.casemgmt.api.model.instance.StageStatus) CaseInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) VariableDesc(org.jbpm.services.api.model.VariableDesc) CorrelationKey(org.kie.internal.process.CorrelationKey) Assert.assertNotNull(org.junit.Assert.assertNotNull) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) GroupImpl(org.jbpm.services.task.impl.model.GroupImpl) MilestoneStatus(org.jbpm.casemgmt.api.model.instance.MilestoneStatus) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) Assert.assertNull(org.junit.Assert.assertNull) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) Document(org.jbpm.document.Document) EchoService(org.jbpm.casemgmt.impl.objects.EchoService) Collections(java.util.Collections) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) Assert.assertEquals(org.junit.Assert.assertEquals) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) QueryContext(org.kie.api.runtime.query.QueryContext) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) GroupImpl(org.jbpm.services.task.impl.model.GroupImpl) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) UserImpl(org.jbpm.services.task.impl.model.UserImpl) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 3 with CaseStatus

use of org.jbpm.casemgmt.api.model.CaseStatus in project jbpm by kiegroup.

the class CaseDynamicNodesTest method testAddDynamicSubprocessToStageWithNotExistingProcessId.

@Test
public void testAddDynamicSubprocessToStageWithNotExistingProcessId() {
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
    assertThat(caseInstance).isNotNull();
    assertThat(caseInstance.getCaseStages()).hasSize(1);
    CaseStatus initialStatus = CaseStatus.fromId(caseInstance.getStatus());
    String stageId = caseInstance.getCaseStages().iterator().next().getId();
    assertThat(stageId).isNotNull();
    assertThatThrownBy(() -> caseService.addDynamicSubprocessToStage(caseId, stageId, NOT_EXISTING_SUBPROCESS, Collections.emptyMap())).isInstanceOf(ProcessDefinitionNotFoundException.class);
    // case instance status should not have changed
    caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
    assertThat(caseInstance).isNotNull();
    CaseStatus afterStatus = CaseStatus.fromId(caseInstance.getStatus());
    assertThat(initialStatus).isEqualTo(afterStatus);
}
Also used : CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Aggregations

CaseStatus (org.jbpm.casemgmt.api.model.CaseStatus)3 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)3 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Assertions (org.assertj.core.api.Assertions)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.fail (org.assertj.core.api.Assertions.fail)1 Person (org.jbpm.bpmn2.objects.Person)1 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)1