org.camunda.bpm.dmn.engine.DmnDecisionTableResult Java Examples

The following examples show how to use org.camunda.bpm.dmn.engine.DmnDecisionTableResult. 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: HitPolicyTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@DecisionResource(resource = COLLECT_COMPOUND)
public void testCollectHitPolicyCompoundOutputSingleMatchingRule() {
  DmnDecisionTableResult results = evaluateDecisionTable(true, false, false, "a", "b", "c");
  assertThat(results)
    .hasSingleResult()
    .containsOnly(entry("out1", "a"), entry("out2", "a"), entry("out3", "a"));

  results = evaluateDecisionTable(false, true, false, "a", "b", "c");
  assertThat(results)
    .hasSingleResult()
    .containsOnly(entry("out1", "b"), entry("out2", "b"), entry("out3", "b"));

  results = evaluateDecisionTable(false, false, true, "a", "b", "c");
  assertThat(results)
    .hasSingleResult()
    .containsOnly(entry("out1", "c"), entry("out2", "c"), entry("out3", "c"));
}
 
Example #3
Source File: DmnDecisionTableResultTest.java    From camunda-engine-dmn with Apache License 2.0 6 votes vote down vote up
@Test
@DecisionResource(resource = RESULT_TEST_WITH_TYPES_DMN)
public void testSingleOutputTypedValue() {
  DmnDecisionTableResult decisionResult = evaluateWithMatchingRules(SINGLE_OUTPUT_VALUE);
  assertThat(decisionResult).hasSize(1);

  DmnDecisionRuleResult ruleResult = decisionResult.getFirstResult();

  TypedValue typedValue = ruleResult.getEntryTyped("firstOutput");
  assertThat(typedValue).isEqualTo(Variables.stringValue("singleValue"));

  typedValue = ruleResult.getEntryTyped("secondOutput");
  assertThat(typedValue).isNull();

  typedValue = ruleResult.getFirstEntryTyped();
  assertThat(typedValue).isEqualTo(Variables.stringValue("singleValue"));

  typedValue = ruleResult.getSingleEntryTyped();
  assertThat(typedValue).isEqualTo(Variables.stringValue("singleValue"));
}
 
Example #4
Source File: DmnDecisionEvaluationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldEvaluateDecisionsWithDifferentInputAndOutputTypes() {
  DmnDecisionTableResult results = dmnEngine.evaluateDecisionTable(parseDecisionFromFile("A", DMN_DECISIONS_WITH_DIFFERENT_INPUT_OUTPUT_TYPES) , createVariables()
    .putValue("dd", "5")
    .putValue("ee", 21)
    .asVariableContext());

  assertThat(results.get(0))
    .containsEntry("aa", 7.1);

  results = dmnEngine.evaluateDecisionTable(parseDecisionFromFile("A", DMN_DECISIONS_WITH_DIFFERENT_INPUT_OUTPUT_TYPES) , createVariables()
    .putValue("dd", "5")
    .putValue("ee", 2147483650L)
    .asVariableContext());

  assertThat(results.get(0))
  .containsEntry("aa", 7.0);
}
 
Example #5
Source File: DmnDecisionTableResultTest.java    From camunda-engine-dmn with Apache License 2.0 6 votes vote down vote up
@Test
@DecisionResource(resource = RESULT_TEST_DMN)
public void testOutputList() {
  DmnDecisionTableResult decisionResult = evaluateWithMatchingRules(SINGLE_OUTPUT_VALUE, MULTIPLE_OUTPUT_VALUES);

  List<Map<String, Object>> entryMapList = decisionResult.getResultList();
  assertThat(entryMapList).hasSize(2);

  Map<String, Object> firstResult = entryMapList.get(0);
  assertThat(firstResult).hasSize(1);
  assertThat(firstResult).containsEntry("firstOutput", "singleValue");

  Map<String, Object> secondResult = entryMapList.get(1);
  assertThat(secondResult).hasSize(2);
  assertThat(secondResult).containsEntry("firstOutput", "multipleValues1");
  assertThat(secondResult).containsEntry("secondOutput", "multipleValues2");
}
 
Example #6
Source File: DmnDecisionTableResultTest.java    From camunda-engine-dmn with Apache License 2.0 6 votes vote down vote up
@Test
@DecisionResource(resource = RESULT_TEST_DMN)
public void testMultipleOutputValues() {
  DmnDecisionTableResult decisionResult = evaluateWithMatchingRules(MULTIPLE_OUTPUT_VALUES);
  assertThat(decisionResult).hasSize(1);

  assertMultipleOutputValues(decisionResult.getFirstResult());
  
  try {
    decisionResult.getSingleEntry();
    failBecauseExceptionWasNotThrown(DmnDecisionResultException.class);
  }
  catch (DmnDecisionResultException e){
    assertThat(e)
      .hasMessageStartingWith("DMN-01007")
      .hasMessageContaining("multipleValues1")
      .hasMessageContaining("multipleValues2");
  }
}
 
Example #7
Source File: DmnDecisionTableResultTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@DecisionResource(resource = RESULT_TEST_DMN)
public void testMultipleOutputValues() {
  DmnDecisionTableResult decisionResult = evaluateWithMatchingRules(MULTIPLE_OUTPUT_VALUES);
  assertThat(decisionResult).hasSize(1);

  assertMultipleOutputValues(decisionResult.getFirstResult());
  
  try {
    decisionResult.getSingleEntry();
    failBecauseExceptionWasNotThrown(DmnDecisionResultException.class);
  }
  catch (DmnDecisionResultException e){
    assertThat(e)
      .hasMessageStartingWith("DMN-01007")
      .hasMessageContaining("multipleValues1")
      .hasMessageContaining("multipleValues2");
  }
}
 
Example #8
Source File: HitPolicyTest.java    From camunda-engine-dmn with Apache License 2.0 6 votes vote down vote up
@Test
@DecisionResource(resource = COLLECT_COMPOUND)
public void testCollectHitPolicyCompoundOutputSingleMatchingRule() {
  DmnDecisionTableResult results = evaluateDecisionTable(true, false, false, "a", "b", "c");
  assertThat(results)
    .hasSingleResult()
    .containsOnly(entry("out1", "a"), entry("out2", "a"), entry("out3", "a"));

  results = evaluateDecisionTable(false, true, false, "a", "b", "c");
  assertThat(results)
    .hasSingleResult()
    .containsOnly(entry("out1", "b"), entry("out2", "b"), entry("out3", "b"));

  results = evaluateDecisionTable(false, false, true, "a", "b", "c");
  assertThat(results)
    .hasSingleResult()
    .containsOnly(entry("out1", "c"), entry("out2", "c"), entry("out3", "c"));
}
 
Example #9
Source File: DmnDecisionTableResultTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@DecisionResource(resource = RESULT_TEST_DMN)
public void testOutputList() {
  DmnDecisionTableResult decisionResult = evaluateWithMatchingRules(SINGLE_OUTPUT_VALUE, MULTIPLE_OUTPUT_VALUES);

  List<Map<String, Object>> entryMapList = decisionResult.getResultList();
  assertThat(entryMapList).hasSize(2);

  Map<String, Object> firstResult = entryMapList.get(0);
  assertThat(firstResult).hasSize(1);
  assertThat(firstResult).containsEntry("firstOutput", "singleValue");

  Map<String, Object> secondResult = entryMapList.get(1);
  assertThat(secondResult).hasSize(2);
  assertThat(secondResult).containsEntry("firstOutput", "multipleValues1");
  assertThat(secondResult).containsEntry("secondOutput", "multipleValues2");
}
 
Example #10
Source File: DmnDecisionTableResultTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@DecisionResource(resource = RESULT_TEST_WITH_TYPES_DMN)
public void testSingleOutputTypedValue() {
  DmnDecisionTableResult decisionResult = evaluateWithMatchingRules(SINGLE_OUTPUT_VALUE);
  assertThat(decisionResult).hasSize(1);

  DmnDecisionRuleResult ruleResult = decisionResult.getFirstResult();

  TypedValue typedValue = ruleResult.getEntryTyped("firstOutput");
  assertThat(typedValue).isEqualTo(Variables.stringValue("singleValue"));

  typedValue = ruleResult.getEntryTyped("secondOutput");
  assertThat(typedValue).isNull();

  typedValue = ruleResult.getFirstEntryTyped();
  assertThat(typedValue).isEqualTo(Variables.stringValue("singleValue"));

  typedValue = ruleResult.getSingleEntryTyped();
  assertThat(typedValue).isEqualTo(Variables.stringValue("singleValue"));
}
 
Example #11
Source File: HitPolicyTest.java    From camunda-engine-dmn with Apache License 2.0 6 votes vote down vote up
@Test
@DecisionResource(resource = COLLECT_SINGLE)
public void testCollectHitPolicySingleOutputMultipleMatchingRules() {
  DmnDecisionTableResult results = evaluateDecisionTable(true, true, false, "a", "b", "c");
  assertThat(results).hasSize(2);
  assertThat(collectSingleOutputEntries(results)).containsOnlyOnce("a", "b");

  results = evaluateDecisionTable(true, false, true, "a", "b", "c");
  assertThat(results).hasSize(2);
  assertThat(collectSingleOutputEntries(results)).containsOnlyOnce("a", "c");

  results = evaluateDecisionTable(false, true, true, "a", "b", "c");
  assertThat(results).hasSize(2);
  assertThat(collectSingleOutputEntries(results)).containsOnlyOnce("b", "c");

  results = evaluateDecisionTable(true, true, true, "a", "b", "c");
  assertThat(results).hasSize(3);
  assertThat(collectSingleOutputEntries(results)).containsOnlyOnce("a", "b", "c");
}
 
Example #12
Source File: DmnDecisionTableResultTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
@DecisionResource(resource = RESULT_TEST_DMN)
public void testSingleOutputUntypedValue() {
  DmnDecisionTableResult decisionResult = evaluateWithMatchingRules(SINGLE_OUTPUT_VALUE);
  assertThat(decisionResult).hasSize(1);

  DmnDecisionRuleResult ruleResult = decisionResult.getFirstResult();

  TypedValue typedEntry = ruleResult.getEntryTyped("firstOutput");
  assertThat(typedEntry).isEqualTo(Variables.untypedValue("singleValue"));

  typedEntry = ruleResult.getEntryTyped("secondOutput");
  assertThat(typedEntry).isNull();

  typedEntry = ruleResult.getFirstEntryTyped();
  assertThat(typedEntry).isEqualTo(Variables.untypedValue("singleValue"));

  typedEntry = ruleResult.getSingleEntryTyped();
  assertThat(typedEntry).isEqualTo(Variables.untypedValue("singleValue"));
}
 
Example #13
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 evaluateDecisionByKeyAndVersion() {

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

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

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

  // then
  if (authRule.assertScenario(scenario)) {
    assertThatDecisionHasExpectedResult(decisionResult);
  }
}
 
Example #14
Source File: DmnDecisionEvaluationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEvaluateDecisionWithRequiredDecisionAndNoMatchingRuleInParentDecision() {

  DmnDecisionTableResult results = dmnEngine.evaluateDecisionTable(parseDecisionFromFile("A", DMN_DECISIONS_WITH_NO_MATCHING_RULE_IN_PARENT) , createVariables()
    .putValue("dd", "dd")
    .putValue("ee", "ee")
    .asVariableContext());

  List<Map<String, Object>> resultList = results.getResultList();
  assertThat(resultList.size()).isEqualTo(0);

}
 
Example #15
Source File: DmnDecisionEvaluationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEvaluateDecisionsWithRequiredDecisionAndMultipleMatchingRulesMultipleOutputs() {

  DmnDecisionTableResult results = dmnEngine.evaluateDecisionTable(parseDecisionFromFile("A", DMN_DECISIONS_WITH_MULTIPLE_MATCHING_RULES_MULTIPLE_OUTPUTS) , createVariables()
      .putValue("dd", "dd")
      .putValue("ee", "ee")
      .asVariableContext());

  List<Map<String, Object>> resultList = results.getResultList();
  assertThat(resultList.get(0)).containsEntry("aa", "aa");
  assertThat(resultList.get(1)).containsEntry("aa", "aaa");

}
 
Example #16
Source File: MultiTenancyDecisionTableEvaluationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testEvaluateDecisionByKeyWithTenantIdAuthenticatedTenant() {
  identityService.setAuthentication("user", null, Arrays.asList(TENANT_ONE));

  deploymentForTenant(TENANT_ONE, DMN_FILE);
  deploymentForTenant(TENANT_TWO, DMN_FILE);

  DmnDecisionTableResult decisionResult = decisionService.evaluateDecisionTableByKey(DECISION_DEFINITION_KEY)
    .decisionDefinitionTenantId(TENANT_ONE)
    .variables(createVariables())
    .evaluate();

  assertThatDecisionHasResult(decisionResult, RESULT_OF_FIRST_VERSION);
}
 
Example #17
Source File: DmnDecisionEvaluationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEvaluateDecisionsWithRequiredDecisionAndParentDecision() {

 DmnDecisionTableResult results = dmnEngine.evaluateDecisionTable(parseDecisionFromFile("A", DMN_DECISIONS_WITH_PARENT_DECISION) , createVariables()
   .putValue("ff", true)
   .putValue("dd", 5)
   .asVariableContext());

 assertThat(results)
   .hasSingleResult()
   .containsEntry("aa", 7.0);
}
 
Example #18
Source File: HitPolicyTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public DmnDecisionTableResult evaluateDecisionTable(Boolean input1, Boolean input2, Boolean input3, Object output1, Object output2, Object output3) {
  variables.put("input1", input1);
  variables.put("input2", input2);
  variables.put("input3", input3);
  variables.put("output1", output1);
  variables.put("output2", output2);
  variables.put("output3", output3);

  return evaluateDecisionTable();
}
 
Example #19
Source File: DmnDecisionTableResultTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@DecisionResource(resource = RESULT_TEST_DMN)
public void testSingleEntryUntypedValue() {
  DmnDecisionTableResult decisionResult = evaluateWithMatchingRules(SINGLE_OUTPUT_VALUE);

  TypedValue typedValue = decisionResult.getSingleEntryTyped();
  assertThat(typedValue).isEqualTo(Variables.untypedValue("singleValue"));
}
 
Example #20
Source File: DmnDecisionEvaluationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEvaluateDecisionsWithRequiredDecisionAndMultipleMatchingRules() {

  DmnDecisionTableResult results = dmnEngine.evaluateDecisionTable(parseDecisionFromFile("A", DMN_DECISIONS_WITH_MULTIPLE_MATCHING_RULES) , createVariables()
      .putValue("dd", 3)
      .putValue("ee", "ee")
      .asVariableContext());

  List<Map<String, Object>> resultList = results.getResultList();
  assertThat(resultList.get(0)).containsEntry("aa", "aa");
  assertThat(resultList.get(1)).containsEntry("aa", "aaa");
}
 
Example #21
Source File: DefaultDmnEngine.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public DmnDecisionTableResult evaluateDecisionTable(String decisionKey, InputStream inputStream, VariableContext variableContext) {
  ensureNotNull("decisionKey", decisionKey);
  List<DmnDecision> decisions = parseDecisions(inputStream);
  for (DmnDecision decision : decisions) {
    if (decisionKey.equals(decision.getKey())) {
      return evaluateDecisionTable(decision, variableContext);
    }
  }
  throw LOG.unableToFindDecisionWithKey(decisionKey);
}
 
Example #22
Source File: DmnDecisionTableResultTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
@DecisionResource(resource = RESULT_TEST_DMN)
public void testNoResult() {
  DmnDecisionTableResult results = evaluateWithMatchingRules();

  assertThat(results).isEmpty();
  assertThat(results.getFirstResult()).isNull();
  assertThat(results.getSingleResult()).isNull();
  
  assertThat((Object) results.getSingleEntry()).isNull();
  assertThat((Object) results.getSingleEntryTyped()).isNull();
}
 
Example #23
Source File: DmnDecisionTableEvaluationListenerTest.java    From camunda-engine-dmn with Apache License 2.0 5 votes vote down vote up
public DmnDecisionTableResult evaluateDecisionTable(Object input1, Object input2, Object input3, Object output1) {
  variables.put("input1", input1);
  variables.put("input2", input2);
  variables.put("input3", input3);
  variables.put("output1", output1);

  return evaluateDecisionTable();
}
 
Example #24
Source File: DmnExampleVerifier.java    From camunda-engine-dmn with Apache License 2.0 5 votes vote down vote up
public static void assertExample(DmnEngine engine, DmnDecision decision) {
  VariableMap variables = Variables.createVariables();
  variables.put("status", "bronze");
  variables.put("sum", 200);

  DmnDecisionTableResult results = engine.evaluateDecisionTable(decision, variables);
  assertThat(results)
    .hasSingleResult()
    .containsKeys("result", "reason")
    .containsEntry("result", "notok")
    .containsEntry("reason", "work on your status first, as bronze you're not going to get anything");

  variables.put("status", "silver");

  results = engine.evaluateDecisionTable(decision, variables);
  assertThat(results)
    .hasSingleResult()
    .containsKeys("result", "reason")
    .containsEntry("result", "ok")
    .containsEntry("reason", "you little fish will get what you want");

  variables.put("sum", 1200);

  results = engine.evaluateDecisionTable(decision, variables);
  assertThat(results)
    .hasSingleResult()
    .containsKeys("result", "reason")
    .containsEntry("result", "notok")
    .containsEntry("reason", "you took too much man, you took too much!");

  variables.put("status", "gold");
  variables.put("sum", 200);

  results = engine.evaluateDecisionTable(decision, variables);
  assertThat(results)
    .hasSingleResult()
    .containsKeys("result", "reason")
    .containsEntry("result", "ok")
    .containsEntry("reason", "you get anything you want");
}
 
Example #25
Source File: DefaultDmnEngine.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public DmnDecisionTableResult evaluateDecisionTable(DmnDecision decision, VariableContext variableContext) {
  ensureNotNull("decision", decision);
  ensureNotNull("variableContext", variableContext);

  if (decision instanceof DmnDecisionImpl && decision.isDecisionTable()) {
    DefaultDmnDecisionContext decisionContext = new DefaultDmnDecisionContext(dmnEngineConfiguration);

    DmnDecisionResult decisionResult = decisionContext.evaluateDecision(decision, variableContext);
    return DmnDecisionTableResultImpl.wrap(decisionResult);
  }
  else {
    throw LOG.decisionIsNotADecisionTable(decision);
  }
}
 
Example #26
Source File: MultiTenancyDecisionTableEvaluationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testEvaluateDecisionByKeyWithoutTenantIdNoAuthenticatedTenants() {
  identityService.setAuthentication("user", null, null);

  deployment(DMN_FILE);

  DmnDecisionTableResult decisionResult = decisionService.evaluateDecisionTableByKey(DECISION_DEFINITION_KEY)
      .decisionDefinitionWithoutTenantId()
      .variables(createVariables())
      .evaluate();

  assertThatDecisionHasResult(decisionResult, RESULT_OF_FIRST_VERSION);
}
 
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 evaluateDecisionTableByKeyAndLatestVersion() {
   testRule.deploy(DMN_DECISION_TABLE_V2);

   DmnDecisionTableResult decisionResult = decisionService.evaluateDecisionTableByKey(DECISION_DEFINITION_KEY, createVariables());

   assertThatDecisionHasResult(decisionResult, RESULT_OF_SECOND_VERSION);
 }
 
Example #28
Source File: XlsxDeploymentTest.java    From camunda-dmn-xlsx with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = "test1.xlsx")
public void testXlsxEvaluation() {
  // given
  DecisionDefinition decisionDefinition = rule.getRepositoryService().createDecisionDefinitionQuery().singleResult();

  // when
  DmnDecisionTableResult result = rule.getDecisionService().evaluateDecisionTableById(decisionDefinition.getId(),
      Variables.createVariables().putValue("input1", "foo").putValue("input2", 15));

  // then
  assertThat(result.getResultList()).hasSize(1);
  assertThat(result.getSingleResult().getEntryMap()).hasSize(1);
  assertThat(result.getSingleResult().getSingleEntry()).isEqualTo("foofoo");
}
 
Example #29
Source File: MultiTenancyDecisionTableEvaluationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testEvaluateDecisionByKeyAndTenantId() {
  deploymentForTenant(TENANT_ONE, DMN_FILE);
  deploymentForTenant(TENANT_TWO, DMN_FILE_SECOND_VERSION);

  DmnDecisionTableResult decisionResult = decisionService.evaluateDecisionTableByKey(DECISION_DEFINITION_KEY)
      .variables(createVariables())
      .decisionDefinitionTenantId(TENANT_ONE)
      .evaluate();

  assertThatDecisionHasResult(decisionResult, RESULT_OF_FIRST_VERSION);
}
 
Example #30
Source File: DmnDecisionEvaluationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEvaluateSharedDecisions() {

  DmnDecisionTableResult results = dmnEngine.evaluateDecisionTable(parseDecisionFromFile("A", DMN_SHARED_DECISIONS) , createVariables()
    .putValue("ff", "ff")
    .asVariableContext());

  assertThat(results)
    .hasSingleResult()
    .containsEntry("aa", "aa");
}