Search in sources :

Example 36 with CaseInstance

use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.

the class CaseCallActivityTest method testDeleteProcessInstance.

@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/callactivity/CaseCallActivityTest.testCallCaseAsConstant.bpmn20.xml", "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testDeleteProcessInstance() {
    // given
    String superProcessInstanceId = startProcessInstanceByKey(PROCESS_DEFINITION_KEY).getId();
    String subCaseInstanceId = queryOneTaskCaseInstance().getId();
    // when
    runtimeService.deleteProcessInstance(superProcessInstanceId, null);
    // then
    assertEquals(0, runtimeService.createProcessInstanceQuery().count());
    CaseInstance subCaseInstance = queryOneTaskCaseInstance();
    assertNotNull(subCaseInstance);
    assertTrue(subCaseInstance.isActive());
    // complete ////////////////////////////////////////////////////////
    terminate(subCaseInstanceId);
    close(subCaseInstanceId);
    assertCaseEnded(subCaseInstanceId);
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 37 with CaseInstance

use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.

the class HistoryCleanupAuthorizationTest method prepareInstances.

protected void prepareInstances(Integer processInstanceTimeToLive, Integer decisionTimeToLive, Integer caseTimeToLive) {
    // update time to live
    disableAuthorization();
    List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().processDefinitionKey("testProcess").list();
    assertEquals(1, processDefinitions.size());
    repositoryService.updateProcessDefinitionHistoryTimeToLive(processDefinitions.get(0).getId(), processInstanceTimeToLive);
    final List<DecisionDefinition> decisionDefinitions = repositoryService.createDecisionDefinitionQuery().decisionDefinitionKey("testDecision").list();
    assertEquals(1, decisionDefinitions.size());
    repositoryService.updateDecisionDefinitionHistoryTimeToLive(decisionDefinitions.get(0).getId(), decisionTimeToLive);
    List<CaseDefinition> caseDefinitions = repositoryService.createCaseDefinitionQuery().caseDefinitionKey("oneTaskCase").list();
    assertEquals(1, caseDefinitions.size());
    repositoryService.updateCaseDefinitionHistoryTimeToLive(caseDefinitions.get(0).getId(), caseTimeToLive);
    Date oldCurrentTime = ClockUtil.getCurrentTime();
    ClockUtil.setCurrentTime(DateUtils.addDays(oldCurrentTime, -6));
    // create 3 process instances
    List<String> processInstanceIds = new ArrayList<String>();
    Map<String, Object> variables = Variables.createVariables().putValue("pojo", new TestPojo("okay", 13.37));
    for (int i = 0; i < 3; i++) {
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess", variables);
        processInstanceIds.add(processInstance.getId());
    }
    runtimeService.deleteProcessInstances(processInstanceIds, null, true, true);
    // +10 standalone decisions
    for (int i = 0; i < 10; i++) {
        decisionService.evaluateDecisionByKey("testDecision").variables(variables).evaluate();
    }
    // create 4 case instances
    for (int i = 0; i < 4; i++) {
        CaseInstance caseInstance = caseService.createCaseInstanceByKey("oneTaskCase", Variables.createVariables().putValue("pojo", new TestPojo("okay", 13.37 + i)));
        caseService.terminateCaseExecution(caseInstance.getId());
        caseService.closeCaseInstance(caseInstance.getId());
    }
    ClockUtil.setCurrentTime(oldCurrentTime);
    enableAuthorization();
}
Also used : ArrayList(java.util.ArrayList) TestPojo(org.camunda.bpm.engine.test.dmn.businessruletask.TestPojo) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Date(java.util.Date) CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) CaseDefinition(org.camunda.bpm.engine.repository.CaseDefinition) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) DecisionDefinition(org.camunda.bpm.engine.repository.DecisionDefinition)

Example 38 with CaseInstance

use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.

the class BulkHistoryDeleteTest method testCleanupHistoryCaseInstanceDetails.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCleanupHistoryCaseInstanceDetails() {
    // given
    // create case instances
    String variableNameCase1 = "varName1";
    CaseInstance caseInstance1 = caseService.createCaseInstanceByKey("oneTaskCase", Variables.createVariables().putValue(variableNameCase1, "value1"));
    CaseInstance caseInstance2 = caseService.createCaseInstanceByKey("oneTaskCase", Variables.createVariables().putValue("varName2", "value2"));
    caseService.setVariable(caseInstance1.getId(), variableNameCase1, "theValue");
    // assume
    List<HistoricDetail> detailsList = historyService.createHistoricDetailQuery().list();
    assertEquals(3, detailsList.size());
    caseService.terminateCaseExecution(caseInstance1.getId(), caseService.getVariables(caseInstance1.getId()));
    caseService.terminateCaseExecution(caseInstance2.getId(), caseService.getVariables(caseInstance2.getId()));
    caseService.closeCaseInstance(caseInstance1.getId());
    caseService.closeCaseInstance(caseInstance2.getId());
    // when
    historyService.deleteHistoricCaseInstancesBulk(Arrays.asList(caseInstance1.getId(), caseInstance2.getId()));
    // then
    detailsList = historyService.createHistoricDetailQuery().list();
    assertEquals(0, detailsList.size());
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) HistoricDetail(org.camunda.bpm.engine.history.HistoricDetail) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 39 with CaseInstance

use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.

the class HistoryCleanupTest method prepareCMMNData.

private void prepareCMMNData(int instanceCount) {
    Date oldCurrentTime = ClockUtil.getCurrentTime();
    ClockUtil.setCurrentTime(DateUtils.addDays(new Date(), DAYS_IN_THE_PAST));
    for (int i = 0; i < instanceCount; i++) {
        CaseInstance caseInstance = caseService.createCaseInstanceByKey(ONE_TASK_CASE);
        caseService.terminateCaseExecution(caseInstance.getId());
        caseService.closeCaseInstance(caseInstance.getId());
    }
    ClockUtil.setCurrentTime(oldCurrentTime);
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) Date(java.util.Date)

Example 40 with CaseInstance

use of org.camunda.bpm.engine.runtime.CaseInstance in project camunda-bpm-platform by camunda.

the class CaseInstanceQueryTest method testCaseInstanceProperties.

public void testCaseInstanceProperties() {
    String caseDefinitionId = repositoryService.createCaseDefinitionQuery().caseDefinitionKey(CASE_DEFINITION_KEY_2).singleResult().getId();
    CaseInstance caseInstance = caseService.createCaseInstanceQuery().caseDefinitionKey(CASE_DEFINITION_KEY_2).singleResult();
    assertNotNull(caseInstance.getId());
    assertEquals(caseInstance.getId(), caseInstance.getCaseInstanceId());
    assertEquals("1", caseInstance.getBusinessKey());
    assertEquals(caseDefinitionId, caseInstance.getCaseDefinitionId());
    assertEquals("CasePlanModel_1", caseInstance.getActivityId());
    assertNull(caseInstance.getActivityName());
    assertNull(caseInstance.getParentId());
    assertTrue(caseInstance.isActive());
    assertFalse(caseInstance.isEnabled());
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance)

Aggregations

CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)183 Deployment (org.camunda.bpm.engine.test.Deployment)149 CaseExecution (org.camunda.bpm.engine.runtime.CaseExecution)62 VariableInstance (org.camunda.bpm.engine.runtime.VariableInstance)23 Test (org.junit.Test)21 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)18 Task (org.camunda.bpm.engine.task.Task)18 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)16 CaseDefinition (org.camunda.bpm.engine.repository.CaseDefinition)13 VariableInstanceQuery (org.camunda.bpm.engine.runtime.VariableInstanceQuery)10 HashMap (java.util.HashMap)9 CaseInstanceQuery (org.camunda.bpm.engine.runtime.CaseInstanceQuery)9 ArrayList (java.util.ArrayList)6 CaseService (org.camunda.bpm.engine.CaseService)6 HistoricDetail (org.camunda.bpm.engine.history.HistoricDetail)6 Date (java.util.Date)5 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 NotAllowedException (org.camunda.bpm.engine.exception.NotAllowedException)5 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)5 VariableMap (org.camunda.bpm.engine.variable.VariableMap)5