Search in sources :

Example 1 with TestPojo

use of org.camunda.bpm.engine.test.dmn.businessruletask.TestPojo 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 2 with TestPojo

use of org.camunda.bpm.engine.test.dmn.businessruletask.TestPojo in project camunda-bpm-platform by camunda.

the class BulkHistoryDeleteTest method testCleanupHistoryCaseInstanceTaskDetails.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCleanupHistoryCaseInstanceTaskDetails() {
    // given
    // create case instance
    CaseInstance caseInstance = caseService.createCaseInstanceByKey("oneTaskCase");
    Task task = taskService.createTaskQuery().singleResult();
    taskService.setVariable(task.getId(), "boo", new TestPojo("foo", 123.0));
    taskService.setVariable(task.getId(), "goo", 9);
    taskService.setVariable(task.getId(), "boo", new TestPojo("foo", 321.0));
    // assume
    List<HistoricDetail> detailsList = historyService.createHistoricDetailQuery().list();
    assertEquals(3, detailsList.size());
    terminateAndCloseCaseInstance(caseInstance.getId(), taskService.getVariables(task.getId()));
    // when
    historyService.deleteHistoricCaseInstancesBulk(Arrays.asList(caseInstance.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) Task(org.camunda.bpm.engine.task.Task) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) TestPojo(org.camunda.bpm.engine.test.dmn.businessruletask.TestPojo) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 3 with TestPojo

use of org.camunda.bpm.engine.test.dmn.businessruletask.TestPojo in project camunda-bpm-platform by camunda.

the class BulkHistoryDeleteTest method testCleanupHistoryCaseInstanceComplexVariable.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testCleanupHistoryCaseInstanceComplexVariable() {
    // given
    // create case instances
    VariableMap variables = Variables.createVariables();
    CaseInstance caseInstance = caseService.createCaseInstanceByKey("oneTaskCase", variables.putValue("pojo", new TestPojo("okay", 13.37)));
    caseService.setVariable(caseInstance.getId(), "pojo", "theValue");
    // assume
    List<HistoricVariableInstance> variablesInstances = historyService.createHistoricVariableInstanceQuery().list();
    assertEquals(1, variablesInstances.size());
    List<HistoricDetail> detailsList = historyService.createHistoricDetailQuery().list();
    assertEquals(2, detailsList.size());
    terminateAndCloseCaseInstance(caseInstance.getId(), variables);
    // when
    historyService.deleteHistoricCaseInstancesBulk(Arrays.asList(caseInstance.getId()));
    // then
    variablesInstances = historyService.createHistoricVariableInstanceQuery().list();
    assertEquals(0, variablesInstances.size());
    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) VariableMap(org.camunda.bpm.engine.variable.VariableMap) TestPojo(org.camunda.bpm.engine.test.dmn.businessruletask.TestPojo) HistoricVariableInstance(org.camunda.bpm.engine.history.HistoricVariableInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 4 with TestPojo

use of org.camunda.bpm.engine.test.dmn.businessruletask.TestPojo in project camunda-bpm-platform by camunda.

the class BulkHistoryDeleteTest method testCleanupHistoryStandaloneDecisionData.

@Test
@Deployment(resources = { "org/camunda/bpm/engine/test/api/history/testDmnWithPojo.dmn11.xml" })
public void testCleanupHistoryStandaloneDecisionData() {
    // given
    for (int i = 0; i < 5; i++) {
        engineRule.getDecisionService().evaluateDecisionByKey("testDecision").variables(Variables.createVariables().putValue("pojo", new TestPojo("okay", 13.37))).evaluate();
    }
    // remember input and output ids
    List<HistoricDecisionInstance> historicDecisionInstances = historyService.createHistoricDecisionInstanceQuery().includeInputs().includeOutputs().list();
    final List<String> inputIds = new ArrayList<String>();
    final List<String> inputByteArrayIds = new ArrayList<String>();
    collectHistoricDecisionInputIds(historicDecisionInstances, inputIds, inputByteArrayIds);
    final List<String> outputIds = new ArrayList<String>();
    final List<String> outputByteArrayIds = new ArrayList<String>();
    collectHistoricDecisionOutputIds(historicDecisionInstances, outputIds, outputByteArrayIds);
    List<String> decisionInstanceIds = extractIds(historicDecisionInstances);
    // when
    historyService.deleteHistoricDecisionInstancesBulk(decisionInstanceIds);
    // then
    assertEquals(0, historyService.createHistoricProcessInstanceQuery().processDefinitionKey("testProcess").count());
    assertEquals(0, historyService.createHistoricDecisionInstanceQuery().count());
    // check that decision inputs and outputs were removed
    assertDataDeleted(inputIds, inputByteArrayIds, outputIds, outputByteArrayIds);
}
Also used : TestPojo(org.camunda.bpm.engine.test.dmn.businessruletask.TestPojo) ArrayList(java.util.ArrayList) HistoricDecisionInstance(org.camunda.bpm.engine.history.HistoricDecisionInstance) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 5 with TestPojo

use of org.camunda.bpm.engine.test.dmn.businessruletask.TestPojo in project camunda-bpm-platform by camunda.

the class HistoryCleanupTest method prepareInstances.

private void prepareInstances(Integer processInstanceTimeToLive, Integer decisionTimeToLive, Integer caseTimeToLive) {
    // update time to live
    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(new Date(), DAYS_IN_THE_PAST));
    // 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 < PROCESS_INSTANCES_COUNT; 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 < DECISION_INSTANCES_COUNT; i++) {
        engineRule.getDecisionService().evaluateDecisionByKey("testDecision").variables(variables).evaluate();
    }
    // create 4 case instances
    for (int i = 0; i < CASE_INSTANCES_COUNT; 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);
}
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) JSONObject(org.camunda.bpm.engine.impl.util.json.JSONObject) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) DecisionDefinition(org.camunda.bpm.engine.repository.DecisionDefinition)

Aggregations

TestPojo (org.camunda.bpm.engine.test.dmn.businessruletask.TestPojo)5 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)4 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)4 ArrayList (java.util.ArrayList)3 Deployment (org.camunda.bpm.engine.test.Deployment)3 Test (org.junit.Test)3 Date (java.util.Date)2 HistoricDetail (org.camunda.bpm.engine.history.HistoricDetail)2 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)2 CaseDefinition (org.camunda.bpm.engine.repository.CaseDefinition)2 DecisionDefinition (org.camunda.bpm.engine.repository.DecisionDefinition)2 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)2 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)2 LockedExternalTask (org.camunda.bpm.engine.externaltask.LockedExternalTask)1 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)1 HistoricVariableInstance (org.camunda.bpm.engine.history.HistoricVariableInstance)1 JSONObject (org.camunda.bpm.engine.impl.util.json.JSONObject)1 Task (org.camunda.bpm.engine.task.Task)1 VariableMap (org.camunda.bpm.engine.variable.VariableMap)1