Search in sources :

Example 66 with Definitions

use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.

the class DMNDecisionTableRuntimeTest method checkDTCollectOperatorsMultipleOutputs.

private void checkDTCollectOperatorsMultipleOutputs(BuiltinAggregator aggregator, int level, int a, int b) {
    // DROOLS-6590 DMN composite output on DT Collect with operators - this is beyond the spec.
    final KieServices ks = KieServices.Factory.get();
    DMNMarshaller marshaller = DMNMarshallerFactory.newDefaultMarshaller();
    final Definitions definitions = marshaller.unmarshal(new InputStreamReader(this.getClass().getResourceAsStream("multipleOutputsCollectDT.dmn")));
    DRGElement drgElement1 = definitions.getDrgElement().get(1);
    assertThat(drgElement1).describedAs("xml of the test changed, unable to locate Decision Node").isInstanceOf(Decision.class);
    ((DecisionTable) ((Decision) drgElement1).getExpression()).setAggregation(aggregator);
    final String dmnXml = marshaller.marshal(definitions);
    final ReleaseId kjarReleaseId = ks.newReleaseId("org.kie.dmn.core", "DMNDecisionTableRuntimeTest", UUID.randomUUID().toString());
    final KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write("src/main/resources/multipleOutputsCollectDT.dmn", dmnXml);
    kfs.generateAndWritePomXML(kjarReleaseId);
    final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    assertTrue(kieBuilder.getResults().getMessages().toString(), kieBuilder.getResults().getMessages().isEmpty());
    final KieContainer container = ks.newKieContainer(kjarReleaseId);
    final DMNRuntime runtime = KieRuntimeFactory.of(container.getKieBase()).get(DMNRuntime.class);
    final DMNModel dmnModel = runtime.getModel("https://kiegroup.org/dmn/_943A3581-5FD1-4BCF-9A52-AC7242CC451C", "multipleOutputsCollectDT");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final DMNContext context = DMNFactory.newContext();
    context.set("level", level);
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    LOG.debug("{}", dmnResult);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    Object decision1 = dmnResult.getDecisionResultByName("Decision-1").getResult();
    assertThat(decision1).hasFieldOrPropertyWithValue("a", new BigDecimal(a));
    assertThat(decision1).hasFieldOrPropertyWithValue("b", new BigDecimal(b));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNMarshaller(org.kie.dmn.api.marshalling.DMNMarshaller) InputStreamReader(java.io.InputStreamReader) KieFileSystem(org.kie.api.builder.KieFileSystem) Definitions(org.kie.dmn.model.api.Definitions) DMNContext(org.kie.dmn.api.core.DMNContext) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) BigDecimal(java.math.BigDecimal) DecisionTable(org.kie.dmn.model.api.DecisionTable) KieBuilder(org.kie.api.builder.KieBuilder) DMNModel(org.kie.dmn.api.core.DMNModel) DRGElement(org.kie.dmn.model.api.DRGElement) KieContainer(org.kie.api.runtime.KieContainer)

Example 67 with Definitions

use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.

the class DefinitionsConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    Definitions def = (Definitions) parent;
    for (Import i : def.getImport()) {
        writeChildrenNode(writer, context, i, IMPORT);
    }
    for (ItemDefinition id : def.getItemDefinition()) {
        writeChildrenNode(writer, context, id, ITEM_DEFINITION);
    }
    for (DRGElement e : def.getDrgElement()) {
        String nodeName = DRG_ELEMENT;
        if (e instanceof BusinessKnowledgeModel) {
            nodeName = "businessKnowledgeModel";
        } else if (e instanceof Decision) {
            nodeName = "decision";
        } else if (e instanceof InputData) {
            nodeName = "inputData";
        } else if (e instanceof KnowledgeSource) {
            nodeName = "knowledgeSource";
        } else if (e instanceof DecisionService) {
            nodeName = "decisionService";
        }
        writeChildrenNode(writer, context, e, nodeName);
    }
    for (Artifact a : def.getArtifact()) {
        String nodeName = ARTIFACT;
        if (a instanceof Association) {
            nodeName = "association";
        } else if (a instanceof TextAnnotation) {
            nodeName = "textAnnotation";
        }
        writeChildrenNode(writer, context, a, nodeName);
    }
    for (ElementCollection ec : def.getElementCollection()) {
        writeChildrenNode(writer, context, ec, ELEMENT_COLLECTION);
    }
    for (BusinessContextElement bce : def.getBusinessContextElement()) {
        String nodeName = BUSINESS_CONTEXT_ELEMENT;
        if (bce instanceof OrganizationUnit) {
            nodeName = "organizationUnit";
        } else if (bce instanceof PerformanceIndicator) {
            nodeName = "performanceIndicator";
        }
        writeChildrenNode(writer, context, bce, nodeName);
    }
    if (def.getDMNDI() != null) {
        writeChildrenNode(writer, context, def.getDMNDI(), "DMNDI");
    }
}
Also used : Import(org.kie.dmn.model.api.Import) PerformanceIndicator(org.kie.dmn.model.api.PerformanceIndicator) TDefinitions(org.kie.dmn.model.v1_2.TDefinitions) Definitions(org.kie.dmn.model.api.Definitions) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) BusinessContextElement(org.kie.dmn.model.api.BusinessContextElement) Decision(org.kie.dmn.model.api.Decision) Artifact(org.kie.dmn.model.api.Artifact) DecisionService(org.kie.dmn.model.api.DecisionService) Association(org.kie.dmn.model.api.Association) KnowledgeSource(org.kie.dmn.model.api.KnowledgeSource) OrganizationUnit(org.kie.dmn.model.api.OrganizationUnit) BusinessKnowledgeModel(org.kie.dmn.model.api.BusinessKnowledgeModel) ElementCollection(org.kie.dmn.model.api.ElementCollection) InputData(org.kie.dmn.model.api.InputData) TextAnnotation(org.kie.dmn.model.api.TextAnnotation) DRGElement(org.kie.dmn.model.api.DRGElement)

Example 68 with Definitions

use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.

the class DefinitionsConverter method assignAttributes.

@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
    super.assignAttributes(reader, parent);
    Definitions def = (Definitions) parent;
    String exprLang = reader.getAttribute(EXPRESSION_LANGUAGE);
    String typeLang = reader.getAttribute(TYPE_LANGUAGE);
    String namespace = reader.getAttribute(NAMESPACE);
    String exporter = reader.getAttribute(EXPORTER);
    String exporterVersion = reader.getAttribute(EXPORTER_VERSION);
    def.setExpressionLanguage(exprLang);
    def.setTypeLanguage(typeLang);
    def.setNamespace(namespace);
    def.setExporter(exporter);
    def.setExporterVersion(exporterVersion);
}
Also used : TDefinitions(org.kie.dmn.model.v1_2.TDefinitions) Definitions(org.kie.dmn.model.api.Definitions)

Example 69 with Definitions

use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.

the class DMNRuntimeTest method buildSimplifiedDefinitions.

private Definitions buildSimplifiedDefinitions(final String namespace, final String... decisions) {
    final Definitions def = new TDefinitions();
    def.setNamespace(namespace);
    for (final String d : decisions) {
        final Decision dec = new TDecision();
        dec.setName(d);
        def.getDrgElement().add(dec);
        def.addChildren(dec);
        dec.setParent(def);
    }
    return def;
}
Also used : TDefinitions(org.kie.dmn.model.v1_1.TDefinitions) Definitions(org.kie.dmn.model.api.Definitions) TDecision(org.kie.dmn.model.v1_1.TDecision) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) TDefinitions(org.kie.dmn.model.v1_1.TDefinitions) TDecision(org.kie.dmn.model.v1_1.TDecision) Decision(org.kie.dmn.model.api.Decision)

Example 70 with Definitions

use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.

the class DMNRuntimeTest method testNPE.

@Test
public void testNPE() {
    // DROOLS-1512
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("NPE.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_95b7ee22-1964-4be5-b7db-7db66692c707", "Dessin 1");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final DMNContext context = runtime.newContext();
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(true));
    assertThat(dmnResult.getMessages().stream().anyMatch(m -> m.getMessageType().equals(DMNMessageType.REQ_NOT_FOUND)), is(true));
}
Also used : BeforeEvaluateDecisionTableEvent(org.kie.dmn.api.core.event.BeforeEvaluateDecisionTableEvent) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNResult(org.kie.dmn.api.core.DMNResult) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FEELProperty(org.kie.dmn.feel.lang.FEELProperty) TDefinitions(org.kie.dmn.model.v1_1.TDefinitions) LoggerFactory(org.slf4j.LoggerFactory) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) BigDecimal(java.math.BigDecimal) DMNModel(org.kie.dmn.api.core.DMNModel) AfterEvaluateContextEntryEvent(org.kie.dmn.api.core.event.AfterEvaluateContextEntryEvent) Person(org.kie.dmn.core.model.Person) Duration(java.time.Duration) Map(java.util.Map) DecisionEvaluationStatus(org.kie.dmn.api.core.DMNDecisionResult.DecisionEvaluationStatus) LocalTime(java.time.LocalTime) ZoneOffset(java.time.ZoneOffset) OffsetTime(java.time.OffsetTime) BeforeEvaluateDecisionEvent(org.kie.dmn.api.core.event.BeforeEvaluateDecisionEvent) DMNRuntimeEventListener(org.kie.dmn.api.core.event.DMNRuntimeEventListener) DMNFactory(org.kie.dmn.core.api.DMNFactory) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Collection(java.util.Collection) BuiltInType(org.kie.dmn.feel.lang.types.BuiltInType) DMNModelImpl(org.kie.dmn.core.impl.DMNModelImpl) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) DMNRuntimeUtil(org.kie.dmn.core.util.DMNRuntimeUtil) List(java.util.List) Matchers.anything(org.hamcrest.Matchers.anything) Matchers.contains(org.hamcrest.Matchers.contains) VerificationModeFactory.times(org.mockito.internal.verification.VerificationModeFactory.times) ComparablePeriod(org.kie.dmn.feel.lang.types.impl.ComparablePeriod) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) DMNContext(org.kie.dmn.api.core.DMNContext) FEELStringMarshaller(org.kie.dmn.feel.marshaller.FEELStringMarshaller) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) KieHelper(org.kie.dmn.core.util.KieHelper) ChronoPeriod(java.time.chrono.ChronoPeriod) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) AfterEvaluateDecisionEvent(org.kie.dmn.api.core.event.AfterEvaluateDecisionEvent) EvalHelper(org.kie.dmn.feel.util.EvalHelper) Mockito.mock(org.mockito.Mockito.mock) AfterEvaluateDecisionTableEvent(org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DMNContextEvaluator(org.kie.dmn.core.ast.DMNContextEvaluator) DynamicTypeUtils.prototype(org.kie.dmn.core.util.DynamicTypeUtils.prototype) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) LocalDateTime(java.time.LocalDateTime) CoreMatchers.not(org.hamcrest.CoreMatchers.not) DynamicTypeUtils.entry(org.kie.dmn.core.util.DynamicTypeUtils.entry) HashMap(java.util.HashMap) Definitions(org.kie.dmn.model.api.Definitions) ArrayList(java.util.ArrayList) ArgumentCaptor(org.mockito.ArgumentCaptor) TDecision(org.kie.dmn.model.v1_1.TDecision) KieServices(org.kie.api.KieServices) Decision(org.kie.dmn.model.api.Decision) Matchers.hasSize(org.hamcrest.Matchers.hasSize) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Period(java.time.Period) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) Logger(org.slf4j.Logger) DMNTestUtil.getAndAssertModelNoErrors(org.kie.dmn.core.util.DMNTestUtil.getAndAssertModelNoErrors) KieContainer(org.kie.api.runtime.KieContainer) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Severity(org.kie.dmn.api.core.DMNMessage.Severity) BeforeEvaluateContextEntryEvent(org.kie.dmn.api.core.event.BeforeEvaluateContextEntryEvent) Mockito.verify(org.mockito.Mockito.verify) DynamicTypeUtils.mapOf(org.kie.dmn.core.util.DynamicTypeUtils.mapOf) ChronoUnit(java.time.temporal.ChronoUnit) Ignore(org.junit.Ignore) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl) DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Aggregations

Definitions (org.kie.dmn.model.api.Definitions)114 Test (org.junit.Test)71 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)39 DMNMessage (org.kie.dmn.api.core.DMNMessage)37 DMNModel (org.kie.dmn.api.core.DMNModel)34 DMNResult (org.kie.dmn.api.core.DMNResult)32 TDefinitions (org.kie.dmn.model.v1_1.TDefinitions)31 Arrays (java.util.Arrays)28 Assert.assertTrue (org.junit.Assert.assertTrue)28 List (java.util.List)26 ItemDefinition (org.kie.dmn.model.api.ItemDefinition)26 Logger (org.slf4j.Logger)26 LoggerFactory (org.slf4j.LoggerFactory)26 HashMap (java.util.HashMap)25 Decision (org.kie.dmn.model.api.Decision)25 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)24 Assert.assertFalse (org.junit.Assert.assertFalse)24 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)24 DMNModelImpl (org.kie.dmn.core.impl.DMNModelImpl)24 ArrayList (java.util.ArrayList)23