Search in sources :

Example 1 with DMNDecisionResult

use of org.kie.dmn.api.core.DMNDecisionResult in project drools by kiegroup.

the class DMNRuntimeTest method testInvalidFunction.

@Test
public void testInvalidFunction() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntimeWithAdditionalResources("InvalidFunction.dmn", this.getClass());
    final DMNModel model = runtime.getModel("http://www.trisotech.com/definitions/_84453b71-5d23-479f-9481-5196d92bacae", "0003-iteration-augmented");
    assertThat(model, notNullValue());
    final DMNContext context = DMNFactory.newContext();
    context.set("Loans", new HashMap<>());
    final DMNResult result = runtime.evaluateAll(model, context);
    final List<DMNDecisionResult> decisionResults = result.getDecisionResults();
    FEELStringMarshaller.INSTANCE.marshall(Arrays.asList(decisionResults.get(0).getResult(), decisionResults.get(1).getResult()));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 2 with DMNDecisionResult

use of org.kie.dmn.api.core.DMNDecisionResult in project drools by kiegroup.

the class DMNRuntimeTypeCheckTest method assertPerformTypeCheck.

private void assertPerformTypeCheck(DMNRuntime runtime) {
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_6d8af9a2-dcf4-4b9e-8d90-6ccddc8c1bbd", "forTypeCheckTest");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("a number", "ciao");
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat("Should throw several errors, not only for 1 specific Decision: " + DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.getMessages(DMNMessage.Severity.ERROR).stream().allMatch(m -> m.getSourceId().equals(dmnModel.getDecisionByName("hundred minus number").getId())), is(false));
    DMNDecisionResult textPlusNumberDR = dmnResult.getDecisionResultByName("text plus number");
    // dependency failed type check
    assertThat(textPlusNumberDR.getEvaluationStatus(), is(DecisionEvaluationStatus.SKIPPED));
    DMNDecisionResult hundredMinusNumber = dmnResult.getDecisionResultByName("hundred minus number");
    // dependency failed type check
    assertThat(textPlusNumberDR.getEvaluationStatus(), is(DecisionEvaluationStatus.SKIPPED));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) KieFileSystem(org.kie.api.builder.KieFileSystem) DMNFactory(org.kie.dmn.core.api.DMNFactory) KieBuilder(org.kie.api.builder.KieBuilder) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNResult(org.kie.dmn.api.core.DMNResult) Results(org.kie.api.builder.Results) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test) UUID(java.util.UUID) DMNRuntimeImpl(org.kie.dmn.core.impl.DMNRuntimeImpl) DMNRuntimeUtil(org.kie.dmn.core.util.DMNRuntimeUtil) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) RuntimeTypeCheckOption(org.kie.dmn.core.compiler.RuntimeTypeCheckOption) Assert.assertThat(org.junit.Assert.assertThat) Resource(org.kie.api.io.Resource) DMNModel(org.kie.dmn.api.core.DMNModel) KieModuleModel(org.kie.api.builder.model.KieModuleModel) DecisionEvaluationStatus(org.kie.dmn.api.core.DMNDecisionResult.DecisionEvaluationStatus) KieServices(org.kie.api.KieServices) DMNContext(org.kie.dmn.api.core.DMNContext) KieHelper(org.kie.dmn.core.util.KieHelper) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) DMNModel(org.kie.dmn.api.core.DMNModel)

Example 3 with DMNDecisionResult

use of org.kie.dmn.api.core.DMNDecisionResult in project drools by kiegroup.

the class DMNRuntimeTypeCheckTest method assertNoTypeCheck.

private void assertNoTypeCheck(DMNRuntime runtime) {
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_6d8af9a2-dcf4-4b9e-8d90-6ccddc8c1bbd", "forTypeCheckTest");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("a number", "ciao");
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.getMessages(DMNMessage.Severity.ERROR).stream().allMatch(m -> m.getSourceId().equals(dmnModel.getDecisionByName("hundred minus number").getId())), is(true));
    DMNDecisionResult textPlusNumberDR = dmnResult.getDecisionResultByName("text plus number");
    assertThat(textPlusNumberDR.getEvaluationStatus(), is(DecisionEvaluationStatus.SUCCEEDED));
    assertThat(textPlusNumberDR.getResult(), is("The input number is: ciao"));
    DMNDecisionResult hundredMinusNumber = dmnResult.getDecisionResultByName("hundred minus number");
    assertThat(hundredMinusNumber.getEvaluationStatus(), is(DecisionEvaluationStatus.FAILED));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) KieFileSystem(org.kie.api.builder.KieFileSystem) DMNFactory(org.kie.dmn.core.api.DMNFactory) KieBuilder(org.kie.api.builder.KieBuilder) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNResult(org.kie.dmn.api.core.DMNResult) Results(org.kie.api.builder.Results) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test) UUID(java.util.UUID) DMNRuntimeImpl(org.kie.dmn.core.impl.DMNRuntimeImpl) DMNRuntimeUtil(org.kie.dmn.core.util.DMNRuntimeUtil) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) RuntimeTypeCheckOption(org.kie.dmn.core.compiler.RuntimeTypeCheckOption) Assert.assertThat(org.junit.Assert.assertThat) Resource(org.kie.api.io.Resource) DMNModel(org.kie.dmn.api.core.DMNModel) KieModuleModel(org.kie.api.builder.model.KieModuleModel) DecisionEvaluationStatus(org.kie.dmn.api.core.DMNDecisionResult.DecisionEvaluationStatus) KieServices(org.kie.api.KieServices) DMNContext(org.kie.dmn.api.core.DMNContext) KieHelper(org.kie.dmn.core.util.KieHelper) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) DMNModel(org.kie.dmn.api.core.DMNModel)

Aggregations

Test (org.junit.Test)3 DMNContext (org.kie.dmn.api.core.DMNContext)3 DMNDecisionResult (org.kie.dmn.api.core.DMNDecisionResult)3 DMNModel (org.kie.dmn.api.core.DMNModel)3 DMNResult (org.kie.dmn.api.core.DMNResult)3 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)3 UUID (java.util.UUID)2 CoreMatchers.is (org.hamcrest.CoreMatchers.is)2 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)2 Assert.assertThat (org.junit.Assert.assertThat)2 KieServices (org.kie.api.KieServices)2 KieBuilder (org.kie.api.builder.KieBuilder)2 KieFileSystem (org.kie.api.builder.KieFileSystem)2 Results (org.kie.api.builder.Results)2 KieModuleModel (org.kie.api.builder.model.KieModuleModel)2 Resource (org.kie.api.io.Resource)2 KieContainer (org.kie.api.runtime.KieContainer)2 DecisionEvaluationStatus (org.kie.dmn.api.core.DMNDecisionResult.DecisionEvaluationStatus)2 DMNMessage (org.kie.dmn.api.core.DMNMessage)2 DMNFactory (org.kie.dmn.core.api.DMNFactory)2