Search in sources :

Example 56 with CaseDefinition

use of org.camunda.bpm.engine.repository.CaseDefinition in project camunda-bpm-platform by camunda.

the class RepositoryServiceTest method testGetCaseModel.

@Deployment(resources = { "org/camunda/bpm/engine/test/repository/one.cmmn" })
public void testGetCaseModel() throws Exception {
    CaseDefinitionQuery query = repositoryService.createCaseDefinitionQuery();
    CaseDefinition caseDefinition = query.singleResult();
    String caseDefinitionId = caseDefinition.getId();
    InputStream caseModel = repositoryService.getCaseModel(caseDefinitionId);
    assertNotNull(caseModel);
    byte[] readInputStream = IoUtil.readInputStream(caseModel, "caseModel");
    String model = new String(readInputStream, "UTF-8");
    assertTrue(model.contains("<case id=\"one\" name=\"One\">"));
    IoUtil.closeSilently(caseModel);
}
Also used : InputStream(java.io.InputStream) CaseDefinition(org.camunda.bpm.engine.repository.CaseDefinition) CaseDefinitionQuery(org.camunda.bpm.engine.repository.CaseDefinitionQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 57 with CaseDefinition

use of org.camunda.bpm.engine.repository.CaseDefinition in project camunda-bpm-platform by camunda.

the class RepositoryServiceTest method testUpdateHistoryTimeToLiveNegative.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testUpdateHistoryTimeToLiveNegative() {
    // given
    // there exists a deployment containing a case definition with key "oneTaskCase"
    CaseDefinition caseDefinition = findOnlyCaseDefinition();
    // when
    try {
        repositoryService.updateCaseDefinitionHistoryTimeToLive(caseDefinition.getId(), -1);
        fail("Exception is expected, that negative value is not allowed.");
    } catch (BadUserRequestException ex) {
        assertTrue(ex.getMessage().contains("greater than"));
    }
}
Also used : CaseDefinition(org.camunda.bpm.engine.repository.CaseDefinition) BadUserRequestException(org.camunda.bpm.engine.BadUserRequestException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 58 with CaseDefinition

use of org.camunda.bpm.engine.repository.CaseDefinition in project camunda-bpm-platform by camunda.

the class HistoricTaskInstanceTest method testQueryByCaseDefinitionName.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/cmmn/oneTaskCase.cmmn" })
public void testQueryByCaseDefinitionName() {
    // given
    CaseDefinition caseDefinition = repositoryService.createCaseDefinitionQuery().singleResult();
    String caseDefinitionName = caseDefinition.getName();
    String caseDefinitionId = caseDefinition.getId();
    String caseInstanceId = caseService.withCaseDefinitionByKey("oneTaskCase").create().getId();
    String humanTaskId = caseService.createCaseExecutionQuery().activityId("PI_HumanTask_1").singleResult().getId();
    // then
    HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery();
    query.caseDefinitionName(caseDefinitionName);
    assertEquals(1, query.count());
    assertEquals(1, query.list().size());
    assertNotNull(query.singleResult());
    HistoricTaskInstance task = query.singleResult();
    assertNotNull(task);
    assertEquals(caseDefinitionId, task.getCaseDefinitionId());
    assertEquals(caseInstanceId, task.getCaseInstanceId());
    assertEquals(humanTaskId, task.getCaseExecutionId());
}
Also used : HistoricTaskInstance(org.camunda.bpm.engine.history.HistoricTaskInstance) CaseDefinition(org.camunda.bpm.engine.repository.CaseDefinition) HistoricTaskInstanceQuery(org.camunda.bpm.engine.history.HistoricTaskInstanceQuery) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 59 with CaseDefinition

use of org.camunda.bpm.engine.repository.CaseDefinition in project camunda-bpm-platform by camunda.

the class CleanableHistoricCaseInstanceReportTest method prepareCaseInstances.

private void prepareCaseInstances(String key, int daysInThePast, Integer historyTimeToLive, int instanceCount) {
    // update time to live
    List<CaseDefinition> caseDefinitions = repositoryService.createCaseDefinitionQuery().caseDefinitionKey(key).list();
    assertEquals(1, caseDefinitions.size());
    repositoryService.updateCaseDefinitionHistoryTimeToLive(caseDefinitions.get(0).getId(), historyTimeToLive);
    Date oldCurrentTime = ClockUtil.getCurrentTime();
    ClockUtil.setCurrentTime(DateUtils.addDays(oldCurrentTime, daysInThePast));
    for (int i = 0; i < instanceCount; i++) {
        CaseInstance caseInstance = caseService.createCaseInstanceByKey(key);
        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) CaseDefinition(org.camunda.bpm.engine.repository.CaseDefinition) Date(java.util.Date)

Example 60 with CaseDefinition

use of org.camunda.bpm.engine.repository.CaseDefinition in project camunda-bpm-platform by camunda.

the class HistoricDecisionInstanceTest method testCaseDecisionEvaluatedWithDecisionServiceInsideDelegate.

@Deployment(resources = { DECISION_CASE_WITH_DECISION_SERVICE, DECISION_SINGLE_OUTPUT_DMN })
public void testCaseDecisionEvaluatedWithDecisionServiceInsideDelegate() {
    CaseInstance caseInstance = createCaseInstanceAndEvaluateDecision();
    CaseDefinition caseDefinition = repositoryService.createCaseDefinitionQuery().caseDefinitionId(caseInstance.getCaseDefinitionId()).singleResult();
    String decisionDefinitionId = repositoryService.createDecisionDefinitionQuery().decisionDefinitionKey(DECISION_DEFINITION_KEY).singleResult().getId();
    String activityInstanceId = historyService.createHistoricCaseActivityInstanceQuery().caseActivityId("PI_HumanTask_1").singleResult().getId();
    HistoricDecisionInstance historicDecisionInstance = historyService.createHistoricDecisionInstanceQuery().singleResult();
    assertThat(historicDecisionInstance, is(notNullValue()));
    assertThat(historicDecisionInstance.getDecisionDefinitionId(), is(decisionDefinitionId));
    assertThat(historicDecisionInstance.getDecisionDefinitionKey(), is(DECISION_DEFINITION_KEY));
    assertThat(historicDecisionInstance.getDecisionDefinitionName(), is("sample decision"));
    // references to case instance should be set since the decision is evaluated while executing a case instance
    assertThat(historicDecisionInstance.getProcessDefinitionKey(), is(nullValue()));
    assertThat(historicDecisionInstance.getProcessDefinitionId(), is(nullValue()));
    assertThat(historicDecisionInstance.getProcessInstanceId(), is(nullValue()));
    assertThat(historicDecisionInstance.getCaseDefinitionKey(), is(caseDefinition.getKey()));
    assertThat(historicDecisionInstance.getCaseDefinitionId(), is(caseDefinition.getId()));
    assertThat(historicDecisionInstance.getCaseInstanceId(), is(caseInstance.getId()));
    assertThat(historicDecisionInstance.getActivityId(), is("PI_HumanTask_1"));
    assertThat(historicDecisionInstance.getActivityInstanceId(), is(activityInstanceId));
    assertThat(historicDecisionInstance.getEvaluationTime(), is(notNullValue()));
}
Also used : CaseInstance(org.camunda.bpm.engine.runtime.CaseInstance) CaseDefinition(org.camunda.bpm.engine.repository.CaseDefinition) HistoricDecisionInstance(org.camunda.bpm.engine.history.HistoricDecisionInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

CaseDefinition (org.camunda.bpm.engine.repository.CaseDefinition)65 Deployment (org.camunda.bpm.engine.test.Deployment)17 Test (org.junit.Test)14 CaseInstance (org.camunda.bpm.engine.runtime.CaseInstance)13 CaseDefinitionQuery (org.camunda.bpm.engine.repository.CaseDefinitionQuery)12 ArrayList (java.util.ArrayList)8 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)5 Response (com.jayway.restassured.response.Response)4 Date (java.util.Date)4 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)4 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)3 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)3 CaseInstanceQuery (org.camunda.bpm.engine.runtime.CaseInstanceQuery)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 RepositoryService (org.camunda.bpm.engine.RepositoryService)2 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)2 User (org.camunda.bpm.engine.identity.User)2