Search in sources :

Example 31 with DmnDecisionResult

use of org.camunda.bpm.dmn.engine.DmnDecisionResult in project camunda-bpm-platform by camunda.

the class DecisionEvaluationUtil method evaluateDecision.

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);
        }
    }
}
Also used : DmnDecisionResult(org.camunda.bpm.dmn.engine.DmnDecisionResult) DecisionInvocation(org.camunda.bpm.engine.impl.dmn.invocation.DecisionInvocation) DecisionDefinition(org.camunda.bpm.engine.repository.DecisionDefinition)

Example 32 with DmnDecisionResult

use of org.camunda.bpm.dmn.engine.DmnDecisionResult in project camunda-bpm-platform by camunda.

the class DecisionDefinitionRestServiceInteractionTest method testEvaluateDecisionMultipleDecisionOutputs.

@Test
public void testEvaluateDecisionMultipleDecisionOutputs() {
    DmnDecisionResult decisionResult = new MockDecisionResultBuilder().resultEntries().entry("status", Variables.stringValue("gold")).resultEntries().entry("assignee", Variables.stringValue("manager")).build();
    when(decisionEvaluationBuilderMock.evaluate()).thenReturn(decisionResult);
    Map<String, Object> json = new HashMap<String, Object>();
    json.put("variables", Collections.emptyMap());
    given().pathParam("id", MockProvider.EXAMPLE_DECISION_DEFINITION_ID).contentType(POST_JSON_CONTENT_TYPE).body(json).then().expect().statusCode(Status.OK.getStatusCode()).body("size()", is(2)).body("[0].size()", is(1)).body("[0].status.value", is("gold")).body("[1].size()", is(1)).body("[1].assignee.value", is("manager")).when().post(EVALUATE_DECISION_URL);
}
Also used : DmnDecisionResult(org.camunda.bpm.dmn.engine.DmnDecisionResult) MockDecisionResultBuilder(org.camunda.bpm.engine.rest.helper.MockDecisionResultBuilder) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 33 with DmnDecisionResult

use of org.camunda.bpm.dmn.engine.DmnDecisionResult in project camunda-bpm-platform by camunda.

the class DecisionDefinitionRestServiceInteractionTest method testEvaluateDecisionByKey.

@Test
public void testEvaluateDecisionByKey() {
    DmnDecisionResult decisionResult = MockProvider.createMockDecisionResult();
    when(decisionEvaluationBuilderMock.evaluate()).thenReturn(decisionResult);
    Map<String, Object> json = new HashMap<String, Object>();
    json.put("variables", VariablesBuilder.create().variable("amount", 420).variable("invoiceCategory", "MISC").getVariables());
    given().pathParam("key", MockProvider.EXAMPLE_DECISION_DEFINITION_KEY).contentType(POST_JSON_CONTENT_TYPE).body(json).then().expect().statusCode(Status.OK.getStatusCode()).when().post(EVALUATE_DECISION_BY_KEY_URL);
    Map<String, Object> expectedVariables = new HashMap<String, Object>();
    expectedVariables.put("amount", 420);
    expectedVariables.put("invoiceCategory", "MISC");
    verify(decisionEvaluationBuilderMock).variables(expectedVariables);
    verify(decisionEvaluationBuilderMock).evaluate();
}
Also used : DmnDecisionResult(org.camunda.bpm.dmn.engine.DmnDecisionResult) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 34 with DmnDecisionResult

use of org.camunda.bpm.dmn.engine.DmnDecisionResult in project camunda-bpm-platform by camunda.

the class DecisionDefinitionRestServiceInteractionTest method testEvaluateDecisionByKeyAndTenantId.

@Test
public void testEvaluateDecisionByKeyAndTenantId() {
    DecisionDefinition mockDefinition = MockProvider.mockDecisionDefinition().tenantId(MockProvider.EXAMPLE_TENANT_ID).build();
    setUpRuntimeData(mockDefinition);
    DmnDecisionResult decisionResult = MockProvider.createMockDecisionResult();
    when(decisionEvaluationBuilderMock.evaluate()).thenReturn(decisionResult);
    Map<String, Object> json = new HashMap<String, Object>();
    json.put("variables", VariablesBuilder.create().variable("amount", 420).variable("invoiceCategory", "MISC").getVariables());
    given().pathParam("key", MockProvider.EXAMPLE_DECISION_DEFINITION_KEY).pathParam("tenant-id", MockProvider.EXAMPLE_TENANT_ID).contentType(POST_JSON_CONTENT_TYPE).body(json).then().expect().statusCode(Status.OK.getStatusCode()).when().post(EVALUATE_DECISION_BY_KEY_AND_TENANT_ID_URL);
    Map<String, Object> expectedVariables = new HashMap<String, Object>();
    expectedVariables.put("amount", 420);
    expectedVariables.put("invoiceCategory", "MISC");
    verify(decisionDefinitionQueryMock).tenantIdIn(MockProvider.EXAMPLE_TENANT_ID);
    verify(decisionEvaluationBuilderMock).variables(expectedVariables);
    verify(decisionEvaluationBuilderMock).evaluate();
}
Also used : DmnDecisionResult(org.camunda.bpm.dmn.engine.DmnDecisionResult) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) DecisionDefinition(org.camunda.bpm.engine.repository.DecisionDefinition) Test(org.junit.Test)

Example 35 with DmnDecisionResult

use of org.camunda.bpm.dmn.engine.DmnDecisionResult in project camunda-bpm-platform by camunda.

the class DecisionDefinitionRestServiceInteractionTest method testEvaluateDecisionSingleDecisionOutput.

@Test
public void testEvaluateDecisionSingleDecisionOutput() {
    DmnDecisionResult decisionResult = new MockDecisionResultBuilder().resultEntries().entry("status", Variables.stringValue("gold")).build();
    when(decisionEvaluationBuilderMock.evaluate()).thenReturn(decisionResult);
    Map<String, Object> json = new HashMap<String, Object>();
    json.put("variables", Collections.emptyMap());
    given().pathParam("id", MockProvider.EXAMPLE_DECISION_DEFINITION_ID).contentType(POST_JSON_CONTENT_TYPE).body(json).then().expect().statusCode(Status.OK.getStatusCode()).body("size()", is(1)).body("[0].size()", is(1)).body("[0].status", is(notNullValue())).body("[0].status.value", is("gold")).when().post(EVALUATE_DECISION_URL);
}
Also used : DmnDecisionResult(org.camunda.bpm.dmn.engine.DmnDecisionResult) MockDecisionResultBuilder(org.camunda.bpm.engine.rest.helper.MockDecisionResultBuilder) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

DmnDecisionResult (org.camunda.bpm.dmn.engine.DmnDecisionResult)54 Test (org.junit.Test)40 DmnEngineTest (org.camunda.bpm.dmn.engine.test.DmnEngineTest)29 DecisionResource (org.camunda.bpm.dmn.engine.test.DecisionResource)25 HashMap (java.util.HashMap)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 Matchers.anyString (org.mockito.Matchers.anyString)6 Deployment (org.camunda.bpm.engine.test.Deployment)5 DmnDecisionResultEntries (org.camunda.bpm.dmn.engine.DmnDecisionResultEntries)4 DecisionDefinition (org.camunda.bpm.engine.repository.DecisionDefinition)4 VariableContext (org.camunda.bpm.engine.variable.context.VariableContext)4 TypedValue (org.camunda.bpm.engine.variable.value.TypedValue)4 DmnEngine (org.camunda.bpm.dmn.engine.DmnEngine)3 DefaultDmnEngineConfiguration (org.camunda.bpm.dmn.engine.impl.DefaultDmnEngineConfiguration)3 MockDecisionResultBuilder (org.camunda.bpm.engine.rest.helper.MockDecisionResultBuilder)3 DmnDecisionRequirementsGraph (org.camunda.bpm.dmn.engine.DmnDecisionRequirementsGraph)2 DmnDecisionResultException (org.camunda.bpm.dmn.engine.impl.DmnDecisionResultException)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 DmnDecision (org.camunda.bpm.dmn.engine.DmnDecision)1