org.camunda.bpm.engine.repository.DecisionDefinition Java Examples

The following examples show how to use org.camunda.bpm.engine.repository.DecisionDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EvaluateDecisionAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = DMN_FILE)
public void evaluateDecisionByKey() {

  // given
  DecisionDefinition decisionDefinition = engineRule.getRepositoryService().createDecisionDefinitionQuery().singleResult();

  // when
  authRule.init(scenario).withUser("userId").bindResource("decisionDefinitionKey", DECISION_DEFINITION_KEY).start();

  DmnDecisionTableResult decisionResult = engineRule.getDecisionService().evaluateDecisionTableByKey(decisionDefinition.getKey(), createVariables());

  // then
  if (authRule.assertScenario(scenario)) {
    assertThatDecisionHasExpectedResult(decisionResult);
  }
}
 
Example #2
Source File: MultiTenancyCleanableHistoricDecisionInstanceReportCmdTenantCheckTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void prepareDecisionInstances(String key, int daysInThePast, Integer historyTimeToLive, int instanceCount, String tenantId) {
  List<DecisionDefinition> decisionDefinitions = null;
  if (tenantId != null) {
    decisionDefinitions = repositoryService.createDecisionDefinitionQuery().decisionDefinitionKey(key).tenantIdIn(tenantId).list();
  } else {
    decisionDefinitions = repositoryService.createDecisionDefinitionQuery().decisionDefinitionKey(key).withoutTenantId().list();
  }
  assertEquals(1, decisionDefinitions.size());
  repositoryService.updateDecisionDefinitionHistoryTimeToLive(decisionDefinitions.get(0).getId(), historyTimeToLive);

  Date oldCurrentTime = ClockUtil.getCurrentTime();
  ClockUtil.setCurrentTime(DateUtils.addDays(oldCurrentTime, daysInThePast));

  Map<String, Object> variables = Variables.createVariables().putValue("status", "silver").putValue("sum", 723);
  for (int i = 0; i < instanceCount; i++) {
    if (tenantId != null) {
      engineRule.getDecisionService().evaluateDecisionByKey(key).decisionDefinitionTenantId(tenantId).variables(variables).evaluate();
    } else {
      engineRule.getDecisionService().evaluateDecisionByKey(key).decisionDefinitionWithoutTenantId().variables(variables).evaluate();
    }
  }

  ClockUtil.setCurrentTime(oldCurrentTime);
}
 
Example #3
Source File: DecisionInstanceHistoryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = DECISION_SINGLE_OUTPUT_DMN)
public void testDecisionDefinitionPassedToHistoryLevel() {
  RecordHistoryLevel historyLevel = (RecordHistoryLevel) processEngineConfiguration.getHistoryLevel();
  DecisionDefinition decisionDefinition = repositoryService.createDecisionDefinitionQuery().decisionDefinitionKey("testDecision").singleResult();

  VariableMap variables = Variables.createVariables().putValue("input1", true);
  decisionService.evaluateDecisionTableByKey("testDecision", variables);

  List<RecordHistoryLevel.ProducedHistoryEvent> producedHistoryEvents = historyLevel.getProducedHistoryEvents();
  assertEquals(1, producedHistoryEvents.size());

  RecordHistoryLevel.ProducedHistoryEvent producedHistoryEvent = producedHistoryEvents.get(0);
  assertEquals(HistoryEventTypes.DMN_DECISION_EVALUATE, producedHistoryEvent.eventType);

  DecisionDefinition entity = (DecisionDefinition) producedHistoryEvent.entity;
  assertNotNull(entity);
  assertEquals(decisionDefinition.getId(), entity.getId());
}
 
Example #4
Source File: EvaluateDecisionAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = DMN_FILE)
public void evaluateDecisionById() {

  // given
  DecisionDefinition decisionDefinition = engineRule.getRepositoryService().createDecisionDefinitionQuery().singleResult();

  // when
  authRule.init(scenario).withUser("userId").bindResource("decisionDefinitionKey", DECISION_DEFINITION_KEY).start();

  DmnDecisionTableResult decisionResult = engineRule.getDecisionService().evaluateDecisionTableById(decisionDefinition.getId(), createVariables());

  // then
  if (authRule.assertScenario(scenario)) {
    assertThatDecisionHasExpectedResult(decisionResult);
  }
}
 
Example #5
Source File: DecisionDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryOrderByDecisionRequirementsDefinitionKey() {
  // given
  List<DecisionDefinition> scoreDefinitions = testRule.deploy(DRD_SCORE_RESOURCE).getDeployedDecisionDefinitions();
  List<String> scoreDefinitionIds = asIds(scoreDefinitions);

  List<DecisionDefinition> dishDefinitions = testRule.deploy(DRD_DISH_RESOURCE).getDeployedDecisionDefinitions();
  List<String> dishDefinitionIds = asIds(dishDefinitions);

  // when
  List<DecisionDefinition> decisionDefinitionList = repositoryService
    .createDecisionDefinitionQuery()
    .decisionDefinitionIdIn(merge(scoreDefinitionIds, dishDefinitionIds))
    .orderByDecisionRequirementsDefinitionKey()
    .asc()
    .list();

  // then
  List<DecisionDefinition> firstThreeResults = decisionDefinitionList.subList(0, 3);
  List<DecisionDefinition> lastTwoResults = decisionDefinitionList.subList(3, 5);

  assertThat(firstThreeResults).extracting("id").containsExactlyInAnyOrderElementsOf(dishDefinitionIds);
  assertThat(lastTwoResults).extracting("id").containsExactlyInAnyOrderElementsOf(scoreDefinitionIds);
}
 
Example #6
Source File: DecisionDefinitionDto.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static DecisionDefinitionDto fromDecisionDefinition(DecisionDefinition definition) {
  DecisionDefinitionDto dto = new DecisionDefinitionDto();

  dto.id = definition.getId();
  dto.key = definition.getKey();
  dto.category = definition.getCategory();
  dto.name = definition.getName();
  dto.version = definition.getVersion();
  dto.resource = definition.getResourceName();
  dto.deploymentId = definition.getDeploymentId();
  dto.decisionRequirementsDefinitionId = definition.getDecisionRequirementsDefinitionId();
  dto.decisionRequirementsDefinitionKey = definition.getDecisionRequirementsDefinitionKey();
  dto.tenantId = definition.getTenantId();
  dto.historyTimeToLive = definition.getHistoryTimeToLive();
  dto.versionTag = definition.getVersionTag();

  return dto;
}
 
Example #7
Source File: DecisionDefinitionRestServiceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecisionDefinitionVersionTag() {
  List<DecisionDefinition> decisionDefinitions = Arrays.asList(
    MockProvider.mockDecisionDefinition().versionTag(MockProvider.EXAMPLE_VERSION_TAG).build(),
    MockProvider.mockDecisionDefinition().id(MockProvider.ANOTHER_EXAMPLE_DECISION_DEFINITION_ID).versionTag(MockProvider.ANOTHER_EXAMPLE_VERSION_TAG).build());
  mockedQuery = createMockDecisionDefinitionQuery(decisionDefinitions);

  given()
    .queryParam("versionTag", MockProvider.EXAMPLE_VERSION_TAG)
    .then().expect()
    .statusCode(Status.OK.getStatusCode())
    .when()
    .get(DECISION_DEFINITION_QUERY_URL);

  verify(mockedQuery).versionTag(MockProvider.EXAMPLE_VERSION_TAG);
  verify(mockedQuery).list();
}
 
Example #8
Source File: DecisionDefinitionRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public DecisionDefinitionResource getDecisionDefinitionByKeyAndTenantId(String decisionDefinitionKey, String tenantId) {

    DecisionDefinition decisionDefinition = getProcessEngine()
        .getRepositoryService()
        .createDecisionDefinitionQuery()
        .decisionDefinitionKey(decisionDefinitionKey)
        .tenantIdIn(tenantId)
        .latestVersion()
        .singleResult();

    if (decisionDefinition == null) {
      String errorMessage = String.format("No matching decision definition with key: %s and tenant-id: %s", decisionDefinitionKey, tenantId);
      throw new RestException(Status.NOT_FOUND, errorMessage);

    } else {
      return getDecisionDefinitionById(decisionDefinition.getId());
    }
  }
 
Example #9
Source File: HistoricDecisionInstanceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void prepareDecisionInstances(String key, int daysInThePast, Integer historyTimeToLive, int instanceCount) {
  DecisionDefinition decisionDefinition = selectDecisionDefinitionByKey(key);
  disableAuthorization();
  repositoryService.updateDecisionDefinitionHistoryTimeToLive(decisionDefinition.getId(), historyTimeToLive);
  enableAuthorization();

  Date oldCurrentTime = ClockUtil.getCurrentTime();
  ClockUtil.setCurrentTime(DateUtils.addDays(oldCurrentTime, daysInThePast));

  Map<String, Object> variables = Variables.createVariables().putValue("input1", null);
  for (int i = 0; i < instanceCount; i++) {
    disableAuthorization();
    decisionService.evaluateDecisionByKey(key).variables(variables).evaluate();
    enableAuthorization();
  }

  ClockUtil.setCurrentTime(oldCurrentTime);
}
 
Example #10
Source File: OptimizeServiceAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void generateTestData() {
  engineRule.getProcessEngineConfiguration().setAuthorizationEnabled(false);

  // completed activity/task/process instance data
  final ProcessDefinition process = selectProcessDefinitionByKey("process");
  runtimeService.startProcessInstanceById(
    process.getId(),
    // variable update data
    Variables.createVariables()
      .putValue("foo", "bar")
  );
  // running activity/task/process instance data
  final ProcessDefinition process2 = selectProcessDefinitionByKey("userTaskProcess");
  ProcessInstance processInstance = runtimeService.startProcessInstanceById(process2.getId());
  // op log data
  runtimeService.suspendProcessInstanceById(processInstance.getId());
  runtimeService.activateProcessInstanceById(processInstance.getId());
  // identity link log data
  completeAllUserTasks();
  // decision instance data
  final DecisionDefinition decision = selectDecisionDefinitionByKey();
  decisionService.evaluateDecisionById(decision.getId())
    .variables(Variables.createVariables().putValue("input1", "a")).evaluate();

  engineRule.getProcessEngineConfiguration().setAuthorizationEnabled(true);
}
 
Example #11
Source File: CleanableHistoricDecisionInstanceReportTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testReportCompact() {
  // given
  List<DecisionDefinition> decisionDefinitions = repositoryService.createDecisionDefinitionQuery().decisionDefinitionKey(DECISION_DEFINITION_KEY).list();
  assertEquals(1, decisionDefinitions.size());

  // assume
  List<CleanableHistoricDecisionInstanceReportResult> resultWithZeros = historyService.createCleanableHistoricDecisionInstanceReport().list();
  assertEquals(1, resultWithZeros.size());
  assertEquals(0, resultWithZeros.get(0).getFinishedDecisionInstanceCount());

  // when
  long resultCountWithoutZeros = historyService.createCleanableHistoricDecisionInstanceReport().compact().count();

  // then
  assertEquals(0, resultCountWithoutZeros);
}
 
Example #12
Source File: EvaluateDecisionCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected DecisionDefinition findByKey(DeploymentCache deploymentCache) {
  DecisionDefinition decisionDefinition = null;

  if (version == null && !isTenandIdSet) {
    decisionDefinition = deploymentCache.findDeployedLatestDecisionDefinitionByKey(decisionDefinitionKey);
  }
  else if (version == null && isTenandIdSet) {
    decisionDefinition = deploymentCache.findDeployedLatestDecisionDefinitionByKeyAndTenantId(decisionDefinitionKey, decisionDefinitionTenantId);
  }
  else if (version != null && !isTenandIdSet) {
    decisionDefinition = deploymentCache.findDeployedDecisionDefinitionByKeyAndVersion(decisionDefinitionKey, version);
  }
  else if (version != null && isTenandIdSet) {
    decisionDefinition = deploymentCache.findDeployedDecisionDefinitionByKeyVersionAndTenantId(decisionDefinitionKey, version, decisionDefinitionTenantId);
  }

  return decisionDefinition;
}
 
Example #13
Source File: DefaultDmnHistoryEventProducer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected HistoricDecisionInstanceEntity createDecisionEvaluatedEvt(DmnDecisionLogicEvaluationEvent evaluationEvent, HistoricDecisionInstanceEntity rootDecisionInstance) {
  // create event instance
  HistoricDecisionInstanceEntity event = newDecisionInstanceEventEntity(evaluationEvent);
  // initialize event
  initDecisionInstanceEvent(event, evaluationEvent, HistoryEventTypes.DMN_DECISION_EVALUATE, rootDecisionInstance);

  // set the user id if there is an authenticated user and no process instance
  setUserId(event);

  DecisionDefinition decisionDefinition = (DecisionDefinition) evaluationEvent.getDecision();
  String tenantId = decisionDefinition.getTenantId();
  if (tenantId == null) {
    tenantId = provideTenantId(decisionDefinition, event);
  }
  event.setTenantId(tenantId);
  return event;
}
 
Example #14
Source File: DecisionDefinitionRestServiceImpl.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public List<DecisionDefinitionDto> getDecisionDefinitions(UriInfo uriInfo, Integer firstResult, Integer maxResults) {
  DecisionDefinitionQueryDto queryDto = new DecisionDefinitionQueryDto(getObjectMapper(), uriInfo.getQueryParameters());
  List<DecisionDefinitionDto> definitions = new ArrayList<DecisionDefinitionDto>();

  ProcessEngine engine = getProcessEngine();
  DecisionDefinitionQuery query = queryDto.toQuery(engine);

  List<DecisionDefinition> matchingDefinitions = null;

  if (firstResult != null || maxResults != null) {
    matchingDefinitions = executePaginatedQuery(query, firstResult, maxResults);
  } else {
    matchingDefinitions = query.list();
  }

  for (DecisionDefinition definition : matchingDefinitions) {
    DecisionDefinitionDto def = DecisionDefinitionDto.fromDecisionDefinition(definition);
    definitions.add(def);
  }
  return definitions;
}
 
Example #15
Source File: DecisionDefinitionRestServiceInteractionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void setUpRuntimeData(DecisionDefinition mockDecisionDefinition) {
  repositoryServiceMock = mock(RepositoryService.class);

  when(processEngine.getRepositoryService()).thenReturn(repositoryServiceMock);
  when(repositoryServiceMock.getDecisionDefinition(eq(MockProvider.EXAMPLE_DECISION_DEFINITION_ID))).thenReturn(mockDecisionDefinition);
  when(repositoryServiceMock.getDecisionModel(eq(MockProvider.EXAMPLE_DECISION_DEFINITION_ID))).thenReturn(createMockDecisionDefinitionDmnXml());

  decisionDefinitionQueryMock = mock(DecisionDefinitionQuery.class);
  when(decisionDefinitionQueryMock.decisionDefinitionKey(MockProvider.EXAMPLE_DECISION_DEFINITION_KEY)).thenReturn(decisionDefinitionQueryMock);
  when(decisionDefinitionQueryMock.tenantIdIn(anyString())).thenReturn(decisionDefinitionQueryMock);
  when(decisionDefinitionQueryMock.withoutTenantId()).thenReturn(decisionDefinitionQueryMock);
  when(decisionDefinitionQueryMock.latestVersion()).thenReturn(decisionDefinitionQueryMock);
  when(decisionDefinitionQueryMock.singleResult()).thenReturn(mockDecisionDefinition);
  when(decisionDefinitionQueryMock.list()).thenReturn(Collections.singletonList(mockDecisionDefinition));
  when(repositoryServiceMock.createDecisionDefinitionQuery()).thenReturn(decisionDefinitionQueryMock);
}
 
Example #16
Source File: MultiTenancyDecisionDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testQueryByLatestWithTenantIds() {
  // deploy a second version for tenant one
  deploymentForTenant(TENANT_ONE, DMN);

  DecisionDefinitionQuery query = repositoryService
      .createDecisionDefinitionQuery()
      .decisionDefinitionKey(DECISION_DEFINITION_KEY)
      .latestVersion()
      .tenantIdIn(TENANT_ONE, TENANT_TWO)
      .orderByTenantId()
      .asc();
  // one definition for each tenant
  assertThat(query.count(), is(2L));

  Map<String, DecisionDefinition> decisionDefinitionsForTenant = getDecisionDefinitionsForTenant(query.list());
  assertThat(decisionDefinitionsForTenant.get(TENANT_ONE).getVersion(), is(2));
  assertThat(decisionDefinitionsForTenant.get(TENANT_TWO).getVersion(), is(1));
}
 
Example #17
Source File: DecisionEvaluationUtil.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public static void evaluateDecision(AbstractVariableScope execution, BaseCallableElement callableElement,
    String resultVariable, DecisionResultMapper decisionResultMapper) throws Exception {

  DecisionDefinition decisionDefinition = resolveDecisionDefinition(callableElement, execution);
  DecisionInvocation invocation = createInvocation(decisionDefinition, execution);

  invoke(invocation);

  DmnDecisionResult result = invocation.getInvocationResult();
  if (result != null) {
    execution.setVariableLocalTransient(DECISION_RESULT_VARIABLE, result);

    if (resultVariable != null && decisionResultMapper != null) {
      Object mappedDecisionResult = decisionResultMapper.mapDecisionResult(result);
      execution.setVariable(resultVariable, mappedDecisionResult);
    }
  }
}
 
Example #18
Source File: DecisionServiceUserOperationLogTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = DMN_DECISION_TABLE)
@Test
public void logCreationOnEvaluateDecisionTableById() {
  // given
  DecisionDefinition decisionDefinition = repositoryService.createDecisionDefinitionQuery().singleResult();

  // when
  identityService.setAuthenticatedUserId(USER_ID);
  decisionService.evaluateDecisionTableById(decisionDefinition.getId(), createVariables());
  identityService.clearAuthentication();

  // then
  assertOperationLog(decisionDefinition);
}
 
Example #19
Source File: DecisionDefinitionRestServiceQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecisionDefinitionTenantIdList() {
  List<DecisionDefinition> decisionDefinitions = Arrays.asList(
      MockProvider.mockDecisionDefinition().tenantId(MockProvider.EXAMPLE_TENANT_ID).build(),
      MockProvider.mockDecisionDefinition().id(MockProvider.ANOTHER_EXAMPLE_CASE_DEFINITION_ID).tenantId(MockProvider.ANOTHER_EXAMPLE_TENANT_ID).build());
  mockedQuery = createMockDecisionDefinitionQuery(decisionDefinitions);

  Response response = given()
    .queryParam("tenantIdIn", MockProvider.EXAMPLE_TENANT_ID_LIST)
  .then().expect()
    .statusCode(Status.OK.getStatusCode())
  .when()
    .get(DECISION_DEFINITION_QUERY_URL);

  verify(mockedQuery).tenantIdIn(MockProvider.EXAMPLE_TENANT_ID, MockProvider.ANOTHER_EXAMPLE_TENANT_ID);
  verify(mockedQuery).list();

  String content = response.asString();
  List<String> definitions = from(content).getList("");
  assertThat(definitions).hasSize(2);

  String returnedTenantId1 = from(content).getString("[0].tenantId");
  String returnedTenantId2 = from(content).getString("[1].tenantId");

  assertThat(returnedTenantId1).isEqualTo(MockProvider.EXAMPLE_TENANT_ID);
  assertThat(returnedTenantId2).isEqualTo(MockProvider.ANOTHER_EXAMPLE_TENANT_ID);
}
 
Example #20
Source File: EvaluateDecisionTableCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected DecisionDefinition getDecisionDefinition(CommandContext commandContext) {
  DeploymentCache deploymentCache = commandContext.getProcessEngineConfiguration().getDeploymentCache();

  if (decisionDefinitionId != null) {
    return findById(deploymentCache);
  } else {
    return findByKey(deploymentCache);
  }
}
 
Example #21
Source File: DecisionDefinitionAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQueryWithReadPermissionOnOneDecisionDefinition() {
  // given user gets read permission on the decision definition
  createGrantAuthorization(DECISION_DEFINITION, DECISION_DEFINITION_KEY, userId, READ);

  // when
  DecisionDefinitionQuery query = repositoryService.createDecisionDefinitionQuery();

  // then
  verifyQueryResults(query, 1);

  DecisionDefinition definition = query.singleResult();
  assertNotNull(definition);
  assertEquals(DECISION_DEFINITION_KEY, definition.getKey());
}
 
Example #22
Source File: MultiTenancyDecisionDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected Map<String, DecisionDefinition> getDecisionDefinitionsForTenant(List<DecisionDefinition> decisionDefinitions) {
  Map<String, DecisionDefinition> definitionsForTenant = new HashMap<String, DecisionDefinition>();

  for (DecisionDefinition definition : decisionDefinitions) {
    definitionsForTenant.put(definition.getTenantId(), definition);
  }
  return definitionsForTenant;
}
 
Example #23
Source File: XlsxDeploymentTest.java    From camunda-dmn-xlsx with Apache License 2.0 5 votes vote down vote up
@Test
public void testXlsxDeployment() {
  // when
  deployment = rule.getRepositoryService()
    .createDeployment()
    .addClasspathResource("test1.xlsx")
    .deploy()
    .getId();

  // then
  DecisionDefinition decisionDefinition = rule.getRepositoryService().createDecisionDefinitionQuery().singleResult();
  assertThat(decisionDefinition).isNotNull();
}
 
Example #24
Source File: DecisionServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = DMN_DECISION_TABLE)
 @Test
public void evaluateDecisionTableByKeyWithNonExistingVersion() {
   DecisionDefinition decisionDefinition = repositoryService.createDecisionDefinitionQuery().singleResult();

   thrown.expect(NotFoundException.class);
   thrown.expectMessage("no decision definition deployed with key = 'decision' and version = '42'");

   decisionService.evaluateDecisionTableByKeyAndVersion(decisionDefinition.getKey(), 42, null);
 }
 
Example #25
Source File: HistoryCleanupRemovalTimeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = {
  "org/camunda/bpm/engine/test/dmn/deployment/drdDish.dmn11.xml"
})
public void shouldCleanupStandaloneDecisionInstance() {
  // given
  ClockUtil.setCurrentTime(END_DATE);

  DecisionDefinition decisionDefinition = repositoryService.createDecisionDefinitionQuery()
    .decisionDefinitionKey("dish-decision")
    .singleResult();
  repositoryService.updateDecisionDefinitionHistoryTimeToLive(decisionDefinition.getId(), 5);


  // when
  decisionService.evaluateDecisionTableByKey("dish-decision", Variables.createVariables()
    .putValue("temperature", 32)
    .putValue("dayType", "Weekend"));

  List<HistoricDecisionInstance> historicDecisionInstances = historyService.createHistoricDecisionInstanceQuery()
    .includeInputs()
    .includeOutputs()
    .list();

  // assume
  assertThat(historicDecisionInstances.size(), is(3));

  ClockUtil.setCurrentTime(addDays(END_DATE, 6));

  // when
  runHistoryCleanup();

  historicDecisionInstances = historyService.createHistoricDecisionInstanceQuery()
    .includeInputs()
    .includeOutputs()
    .list();

  // then
  assertThat(historicDecisionInstances.size(), is(0));
}
 
Example #26
Source File: MultiTenancyDecisionDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testQuerySortingAsc() {
  // exclude definitions without tenant id because of database-specific ordering
  List<DecisionDefinition> decisionDefinitions = repositoryService
      .createDecisionDefinitionQuery()
      .tenantIdIn(TENANT_ONE, TENANT_TWO)
      .orderByTenantId()
      .asc()
      .list();

  assertThat(decisionDefinitions.size(), is(2));
  assertThat(decisionDefinitions.get(0).getTenantId(), is(TENANT_ONE));
  assertThat(decisionDefinitions.get(1).getTenantId(), is(TENANT_TWO));
}
 
Example #27
Source File: DecisionServiceTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = DMN_DECISION_TABLE)
 @Test
public void evaluateDecisionTableById() {
   DecisionDefinition decisionDefinition = repositoryService.createDecisionDefinitionQuery().singleResult();

   DmnDecisionTableResult decisionResult = decisionService.evaluateDecisionTableById(decisionDefinition.getId(), createVariables());

   assertThatDecisionHasResult(decisionResult, RESULT_OF_FIRST_VERSION);
 }
 
Example #28
Source File: DecisionDefinitionQueryTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void decisionDefinitionProperties() {
  List<DecisionDefinition> decisionDefinitions = repositoryService
    .createDecisionDefinitionQuery()
    .orderByDecisionDefinitionName().asc()
    .orderByDecisionDefinitionVersion().asc()
    .orderByDecisionDefinitionCategory()
    .asc()
    .list();

  DecisionDefinition decisionDefinition = decisionDefinitions.get(0);
  assertThat(decisionDefinition.getKey()).isEqualTo("one");
  assertThat(decisionDefinition.getName()).isEqualTo("One");
  assertThat(decisionDefinition.getId()).startsWith("one:1");
  assertThat(decisionDefinition.getCategory()).isEqualTo("Examples");
  assertThat(decisionDefinition.getVersion()).isEqualTo(1);
  assertThat(decisionDefinition.getResourceName()).isEqualTo("org/camunda/bpm/engine/test/repository/one.dmn");
  assertThat(decisionDefinition.getDeploymentId()).isEqualTo(firstDeploymentId);

  decisionDefinition = decisionDefinitions.get(1);
  assertThat(decisionDefinition.getKey()).isEqualTo("one");
  assertThat(decisionDefinition.getName()).isEqualTo("One");
  assertThat(decisionDefinition.getId()).startsWith("one:2");
  assertThat(decisionDefinition.getCategory()).isEqualTo("Examples");
  assertThat(decisionDefinition.getVersion()).isEqualTo(2);
  assertThat(decisionDefinition.getResourceName()).isEqualTo("org/camunda/bpm/engine/test/repository/one.dmn");
  assertThat(decisionDefinition.getDeploymentId()).isEqualTo(secondDeploymentId);

  decisionDefinition = decisionDefinitions.get(2);
  assertThat(decisionDefinition.getKey()).isEqualTo("two");
  assertThat(decisionDefinition.getName()).isEqualTo("Two");
  assertThat(decisionDefinition.getId()).startsWith("two:1");
  assertThat(decisionDefinition.getCategory()).isEqualTo("Examples2");
  assertThat(decisionDefinition.getVersion()).isEqualTo(1);
  assertThat(decisionDefinition.getResourceName()).isEqualTo("org/camunda/bpm/engine/test/repository/two.dmn");
  assertThat(decisionDefinition.getDeploymentId()).isEqualTo(firstDeploymentId);
}
 
Example #29
Source File: EvaluateDecisionTableCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected DmnDecisionTableResult doEvaluateDecision(DecisionDefinition decisionDefinition, VariableMap variables) {
  try {
    return evaluateDecisionTable(decisionDefinition, variables);
  }
  catch (Exception e) {
    throw new ProcessEngineException("Exception while evaluating decision with key '"+decisionDefinitionKey+"'", e);
  }
}
 
Example #30
Source File: EvaluateDecisionCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected DmnDecisionResult doEvaluateDecision(DecisionDefinition decisionDefinition, VariableMap variables) {
  try {
    return evaluateDecision(decisionDefinition, variables);
  }
  catch (Exception e) {
    throw new ProcessEngineException("Exception while evaluating decision with key '"+decisionDefinitionKey+"'", e);
  }
}