Search in sources :

Example 11 with CaseDefinition

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

the class CaseDynamicNodesTest method testAddDynamicSubprocessToNotActiveStage.

@Test
public void testAddDynamicSubprocessToNotActiveStage() {
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    CaseDefinition caseDefinition = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID);
    assertThat(caseDefinition).isNotNull();
    assertThat(caseDefinition.getCaseStages()).hasSize(2);
    Iterator<CaseStage> caseStageIterator = caseDefinition.getCaseStages().iterator();
    caseStageIterator.next();
    String stageId = caseStageIterator.next().getId();
    assertThatThrownBy(() -> caseService.addDynamicSubprocessToStage(caseId, stageId, SUBPROCESS, Collections.emptyMap())).isInstanceOf(StageNotFoundException.class);
}
Also used : CaseStage(org.jbpm.casemgmt.api.model.CaseStage) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 12 with CaseDefinition

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

the class CaseDynamicNodesTest method testAddDynamicTaskToNotActiveStage.

@Test
public void testAddDynamicTaskToNotActiveStage() {
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    CaseDefinition caseDefinition = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID);
    assertThat(caseDefinition).isNotNull();
    assertThat(caseDefinition.getCaseStages()).hasSize(2);
    Iterator<CaseStage> caseStageIterator = caseDefinition.getCaseStages().iterator();
    caseStageIterator.next();
    String stageId = caseStageIterator.next().getId();
    assertThatThrownBy(() -> caseService.addDynamicTaskToStage(caseId, stageId, createUserTask())).isInstanceOf(StageNotFoundException.class);
}
Also used : CaseStage(org.jbpm.casemgmt.api.model.CaseStage) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 13 with CaseDefinition

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

the class CaseRuntimeDataServiceDefinitionImplTest method testGetCaseDefinitionsByDeploymentId.

@Test
public void testGetCaseDefinitionsByDeploymentId() {
    Collection<CaseDefinition> cases = caseRuntimeDataService.getCasesByDeployment(deploymentUnit.getIdentifier(), new QueryContext());
    assertNotNull(cases);
    assertEquals(5, cases.size());
    Map<String, CaseDefinition> mappedCases = mapCases(cases);
    assertTrue(mappedCases.containsKey("EmptyCase"));
    assertTrue(mappedCases.containsKey("UserTaskCase"));
    assertTrue(mappedCases.containsKey("UserTaskCaseBoundary"));
    assertTrue(mappedCases.containsKey("UserTaskWithStageCase"));
    cases = caseRuntimeDataService.getCasesByDeployment("not-existing", new QueryContext());
    assertNotNull(cases);
    assertEquals(0, cases.size());
}
Also used : CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) QueryContext(org.kie.api.runtime.query.QueryContext) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 14 with CaseDefinition

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

the class CaseRuntimeDataServiceDefinitionImplTest method testGetCaseDefinitionById.

@Test
public void testGetCaseDefinitionById() {
    CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), "UserTaskWithStageCase");
    // UserTaskWithStageCase asserts
    assertNotNull(caseDef);
    assertEquals("UserTaskWithStageCase", caseDef.getId());
    assertEquals("UserTaskWithStageCase", caseDef.getName());
    assertEquals("1.0", caseDef.getVersion());
    assertEquals(CaseDefinition.DEFAULT_PREFIX, caseDef.getIdentifierPrefix());
    assertNotNull(caseDef.getCaseMilestones());
    assertEquals(0, caseDef.getCaseMilestones().size());
    assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
    assertNotNull(caseDef.getCaseStages());
    assertEquals(1, caseDef.getCaseStages().size());
    Map<String, CaseStage> mappedStages = mapStages(caseDef.getCaseStages());
    assertTrue(mappedStages.containsKey("Collect input"));
    CaseStage caseStage = mappedStages.get("Collect input");
    assertNotNull(caseStage);
    assertEquals("Collect input", caseStage.getName());
    assertEquals(2, caseStage.getAdHocFragments().size());
    Map<String, AdHocFragment> mappedFragments = mapAdHocFragments(caseStage.getAdHocFragments());
    assertTrue(mappedFragments.containsKey("Missing data"));
    assertEquals("HumanTaskNode", mappedFragments.get("Missing data").getType());
    assertTrue(mappedFragments.containsKey("Verification of data"));
    assertEquals("SubProcessNode", mappedFragments.get("Verification of data").getType());
    assertNotNull(caseDef.getCaseRoles());
    assertEquals(3, caseDef.getCaseRoles().size());
    Map<String, CaseRole> mappedRoles = mapRoles(caseDef.getCaseRoles());
    assertTrue(mappedRoles.containsKey("owner"));
    assertTrue(mappedRoles.containsKey("contact"));
    assertTrue(mappedRoles.containsKey("participant"));
    assertEquals(1, mappedRoles.get("owner").getCardinality().intValue());
    assertEquals(2, mappedRoles.get("contact").getCardinality().intValue());
    assertEquals(-1, mappedRoles.get("participant").getCardinality().intValue());
}
Also used : CaseStage(org.jbpm.casemgmt.api.model.CaseStage) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) CaseRole(org.jbpm.casemgmt.api.model.CaseRole) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 15 with CaseDefinition

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

the class CaseServiceImplTest method testTriggerTaskAndMilestoneInCase.

@Test
public void testTriggerTaskAndMilestoneInCase() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    Map<String, Object> data = new HashMap<>();
    data.put("s", "description");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
    CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID);
    assertNotNull(caseDef);
    assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
    assertEquals(3, caseDef.getAdHocFragments().size());
    Map<String, AdHocFragment> mappedFragments = mapAdHocFragments(caseDef.getAdHocFragments());
    assertTrue(mappedFragments.containsKey("Hello2"));
    assertTrue(mappedFragments.containsKey("Milestone1"));
    assertTrue(mappedFragments.containsKey("Milestone2"));
    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(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary task = tasks.get(0);
        assertNotNull(task);
        assertEquals("Hello1", task.getName());
        assertEquals("john", task.getActualOwnerId());
        assertEquals(Status.Reserved, task.getStatus());
        // now let's trigger one (human task) fragment
        Map<String, Object> taskData = new HashMap<>();
        taskData.put("test", "value");
        taskData.put("fromVar", "#{s}");
        caseService.triggerAdHocFragment(HR_CASE_ID, "Hello2", taskData);
        tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
        assertNotNull(tasks);
        assertEquals(2, tasks.size());
        task = tasks.get(0);
        assertNotNull(task);
        assertEquals("Hello2", task.getName());
        assertEquals("john", task.getActualOwnerId());
        assertEquals(Status.Reserved, task.getStatus());
        Map<String, Object> taskInputs = userTaskService.getTaskInputContentByTaskId(task.getId());
        assertNotNull(taskInputs);
        assertTrue(taskInputs.containsKey("test"));
        assertTrue(taskInputs.containsKey("fromVar"));
        assertEquals("value", taskInputs.get("test"));
        assertEquals("description", taskInputs.get("fromVar"));
        task = tasks.get(1);
        assertNotNull(task);
        assertEquals("Hello1", task.getName());
        assertEquals("john", task.getActualOwnerId());
        assertEquals(Status.Reserved, task.getStatus());
        Collection<CaseMilestoneInstance> milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, true, new QueryContext());
        assertNotNull(milestones);
        assertEquals(0, milestones.size());
        milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, false, new QueryContext());
        assertNotNull(milestones);
        assertEquals(2, milestones.size());
        List<String> expectedMilestones = Arrays.asList("Milestone1", "Milestone2");
        for (CaseMilestoneInstance mi : milestones) {
            assertTrue("Expected mile stopne not found", expectedMilestones.contains(mi.getName()));
            assertEquals("Wrong milestone status", MilestoneStatus.Available, mi.getStatus());
            assertFalse("Should not be achieved", mi.isAchieved());
            assertNull("Achieved date should be null", mi.getAchievedAt());
        }
        // trigger milestone node
        caseService.triggerAdHocFragment(HR_CASE_ID, "Milestone1", null);
        milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, true, new QueryContext());
        assertNotNull(milestones);
        assertEquals(1, milestones.size());
        CaseMilestoneInstance msInstance = milestones.iterator().next();
        assertNotNull(msInstance);
        assertEquals("Milestone1", msInstance.getName());
        assertEquals(true, msInstance.isAchieved());
        assertNotNull(msInstance.getAchievedAt());
        // trigger another milestone node that has condition so it should not be achieved
        caseService.triggerAdHocFragment(HR_CASE_ID, "Milestone2", null);
        milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, true, new QueryContext());
        assertNotNull(milestones);
        assertEquals(1, milestones.size());
        milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, false, new QueryContext());
        assertNotNull(milestones);
        assertEquals(2, milestones.size());
        // add dataComplete to case file to achieve milestone
        caseService.addDataToCaseFile(HR_CASE_ID, "dataComplete", true);
        milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, true, new QueryContext());
        assertNotNull(milestones);
        assertEquals(2, milestones.size());
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) CaseMilestoneInstance(org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance) QueryContext(org.kie.api.runtime.query.QueryContext) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) 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) QueryFilter(org.kie.internal.query.QueryFilter) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) UserImpl(org.jbpm.services.task.impl.model.UserImpl) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Aggregations

CaseDefinition (org.jbpm.casemgmt.api.model.CaseDefinition)27 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)17 Test (org.junit.Test)17 QueryContext (org.kie.api.runtime.query.QueryContext)13 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)10 CaseStage (org.jbpm.casemgmt.api.model.CaseStage)10 ArrayList (java.util.ArrayList)9 AdHocFragment (org.jbpm.casemgmt.api.model.AdHocFragment)9 HashMap (java.util.HashMap)7 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)7 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)6 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)6 TaskSummary (org.kie.api.task.model.TaskSummary)6 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)5 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)5 CaseRole (org.jbpm.casemgmt.api.model.CaseRole)5 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)5 CaseStageInstance (org.jbpm.casemgmt.api.model.instance.CaseStageInstance)5 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)5 UserImpl (org.jbpm.services.task.impl.model.UserImpl)5