Search in sources :

Example 16 with ContextEntry

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

the class ValidatorContextTest method testCONTEXT_ENTRY_MISSING_VARIABLE_ReaderInput.

@Test
public void testCONTEXT_ENTRY_MISSING_VARIABLE_ReaderInput() throws IOException {
    try (final Reader reader = getReader("context/CONTEXT_ENTRY_MISSING_VARIABLE.dmn")) {
        final List<DMNMessage> validate = validator.validate(reader, VALIDATE_SCHEMA, VALIDATE_MODEL, VALIDATE_COMPILATION);
        assertThat(ValidatorUtil.formatMessages(validate), validate.size(), is(1));
        assertTrue(validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.MISSING_VARIABLE)));
        // check that it reports and error for the second context entry, but not for the last one
        final ContextEntry ce = (ContextEntry) validate.get(0).getSourceReference();
        assertThat(((Context) ce.getParent()).getContextEntry().indexOf(ce), is(1));
    }
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) DMNMessage(org.kie.dmn.api.core.DMNMessage) VALIDATE_COMPILATION(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) ContextEntry(org.kie.dmn.model.api.ContextEntry) IOException(java.io.IOException) Test(org.junit.Test) Reader(java.io.Reader) List(java.util.List) VALIDATE_SCHEMA(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_SCHEMA) Assert(org.junit.Assert) VALIDATE_MODEL(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_MODEL) Context(org.kie.dmn.model.api.Context) Context(org.kie.dmn.model.api.Context) DMNMessage(org.kie.dmn.api.core.DMNMessage) Reader(java.io.Reader) ContextEntry(org.kie.dmn.model.api.ContextEntry) Test(org.junit.Test)

Example 17 with ContextEntry

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

the class ValidatorContextTest method testCONTEXT_ENTRY_MISSING_VARIABLE_FileInput.

@Test
public void testCONTEXT_ENTRY_MISSING_VARIABLE_FileInput() {
    final List<DMNMessage> validate = validator.validate(getFile("context/CONTEXT_ENTRY_MISSING_VARIABLE.dmn"), VALIDATE_SCHEMA, VALIDATE_MODEL, VALIDATE_COMPILATION);
    assertThat(ValidatorUtil.formatMessages(validate), validate.size(), is(1));
    assertTrue(validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.MISSING_VARIABLE)));
    // check that it reports and error for the second context entry, but not for the last one
    final ContextEntry ce = (ContextEntry) validate.get(0).getSourceReference();
    assertThat(((Context) ce.getParent()).getContextEntry().indexOf(ce), is(1));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) DMNMessage(org.kie.dmn.api.core.DMNMessage) VALIDATE_COMPILATION(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) ContextEntry(org.kie.dmn.model.api.ContextEntry) IOException(java.io.IOException) Test(org.junit.Test) Reader(java.io.Reader) List(java.util.List) VALIDATE_SCHEMA(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_SCHEMA) Assert(org.junit.Assert) VALIDATE_MODEL(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_MODEL) Context(org.kie.dmn.model.api.Context) Context(org.kie.dmn.model.api.Context) DMNMessage(org.kie.dmn.api.core.DMNMessage) ContextEntry(org.kie.dmn.model.api.ContextEntry) Test(org.junit.Test)

Example 18 with ContextEntry

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

the class ContextEntryConverter method writeChildren.

@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
    super.writeChildren(writer, context, parent);
    ContextEntry ce = (ContextEntry) parent;
    if (ce.getVariable() != null)
        writeChildrenNode(writer, context, ce.getVariable(), VARIABLE);
    writeChildrenNode(writer, context, ce.getExpression(), MarshallingUtils.defineExpressionNodeName(ce.getExpression()));
}
Also used : TContextEntry(org.kie.dmn.model.v1_1.TContextEntry) ContextEntry(org.kie.dmn.model.api.ContextEntry)

Aggregations

ContextEntry (org.kie.dmn.model.api.ContextEntry)18 Context (org.kie.dmn.model.api.Context)13 List (java.util.List)8 DMNMessage (org.kie.dmn.api.core.DMNMessage)8 IOException (java.io.IOException)6 Reader (java.io.Reader)6 CoreMatchers.is (org.hamcrest.CoreMatchers.is)6 Test (org.junit.Test)6 DMNMessageType (org.kie.dmn.api.core.DMNMessageType)6 VALIDATE_COMPILATION (org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION)6 VALIDATE_MODEL (org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_MODEL)6 VALIDATE_SCHEMA (org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_SCHEMA)6 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)4 QName (javax.xml.namespace.QName)3 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)3 Assert (org.junit.Assert)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 DMNType (org.kie.dmn.api.core.DMNType)3 BusinessKnowledgeModelNode (org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)3 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)3