Search in sources :

Example 6 with Context

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

the class ValidatorContextTest method testCONTEXT_MISSING_EXPR_ReaderInput.

@Test
public void testCONTEXT_MISSING_EXPR_ReaderInput() throws IOException {
    try (final Reader reader = getReader("context/CONTEXT_MISSING_EXPR.dmn")) {
        final List<DMNMessage> validate = validator.validate(reader, VALIDATE_SCHEMA, VALIDATE_MODEL, VALIDATE_COMPILATION);
        assertThat(ValidatorUtil.formatMessages(validate), validate.size(), is(2));
        // this is schema validation
        assertTrue(validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.FAILED_XML_VALIDATION)));
        assertTrue(validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.MISSING_EXPRESSION)));
    }
}
Also used : AbstractValidatorTest(org.kie.dmn.validation.AbstractValidatorTest) CoreMatchers.is(org.hamcrest.CoreMatchers.is) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) ContextEntry(org.kie.dmn.model.api.ContextEntry) VALIDATE_COMPILATION(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Reader(java.io.Reader) ValidatorUtil(org.kie.dmn.validation.ValidatorUtil) List(java.util.List) VALIDATE_SCHEMA(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_SCHEMA) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Context(org.kie.dmn.model.api.Context) VALIDATE_MODEL(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_MODEL) DMNMessage(org.kie.dmn.api.core.DMNMessage) Reader(java.io.Reader) AbstractValidatorTest(org.kie.dmn.validation.AbstractValidatorTest) Test(org.junit.Test)

Example 7 with Context

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

the class ValidatorContextTest method testCONTEXT_ENTRY_MISSING_VARIABLE_DefinitionsInput.

@Test
public void testCONTEXT_ENTRY_MISSING_VARIABLE_DefinitionsInput() {
    final List<DMNMessage> validate = validator.validate(getDefinitions("context/CONTEXT_ENTRY_MISSING_VARIABLE.dmn", "https://github.com/kiegroup/kie-dmn", "CONTEXT_MISSING_EXPR"), 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 : AbstractValidatorTest(org.kie.dmn.validation.AbstractValidatorTest) CoreMatchers.is(org.hamcrest.CoreMatchers.is) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) ContextEntry(org.kie.dmn.model.api.ContextEntry) VALIDATE_COMPILATION(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Reader(java.io.Reader) ValidatorUtil(org.kie.dmn.validation.ValidatorUtil) List(java.util.List) VALIDATE_SCHEMA(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_SCHEMA) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Context(org.kie.dmn.model.api.Context) VALIDATE_MODEL(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_MODEL) Context(org.kie.dmn.model.api.Context) DMNMessage(org.kie.dmn.api.core.DMNMessage) ContextEntry(org.kie.dmn.model.api.ContextEntry) AbstractValidatorTest(org.kie.dmn.validation.AbstractValidatorTest) Test(org.junit.Test)

Example 8 with Context

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

the class ValidatorContextTest method testCONTEXT_ENTRY_MISSING_VARIABLE_DefinitionsInput.

@Test
public void testCONTEXT_ENTRY_MISSING_VARIABLE_DefinitionsInput() {
    final List<DMNMessage> validate = validator.validate(getDefinitions("context/CONTEXT_ENTRY_MISSING_VARIABLE.dmn", "https://github.com/kiegroup/kie-dmn", "CONTEXT_MISSING_EXPR"), 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 9 with Context

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

the class ValidatorContextTest method testCONTEXT_ENTRY_NOTYPEREF_ReaderInput.

@Test
public void testCONTEXT_ENTRY_NOTYPEREF_ReaderInput() throws IOException {
    try (final Reader reader = getReader("context/CONTEXT_ENTRY_NOTYPEREF.dmn")) {
        final List<DMNMessage> validate = validator.validate(reader, VALIDATE_SCHEMA, VALIDATE_MODEL, VALIDATE_COMPILATION);
        assertThat(ValidatorUtil.formatMessages(validate), validate.size(), is(2));
        assertTrue(validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.MISSING_TYPE_REF)));
    }
}
Also used : AbstractValidatorTest(org.kie.dmn.validation.AbstractValidatorTest) CoreMatchers.is(org.hamcrest.CoreMatchers.is) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) ContextEntry(org.kie.dmn.model.api.ContextEntry) VALIDATE_COMPILATION(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Reader(java.io.Reader) ValidatorUtil(org.kie.dmn.validation.ValidatorUtil) List(java.util.List) VALIDATE_SCHEMA(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_SCHEMA) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Context(org.kie.dmn.model.api.Context) VALIDATE_MODEL(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_MODEL) DMNMessage(org.kie.dmn.api.core.DMNMessage) Reader(java.io.Reader) AbstractValidatorTest(org.kie.dmn.validation.AbstractValidatorTest) Test(org.junit.Test)

Example 10 with Context

use of org.kie.dmn.model.api.Context 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 : AbstractValidatorTest(org.kie.dmn.validation.AbstractValidatorTest) CoreMatchers.is(org.hamcrest.CoreMatchers.is) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) ContextEntry(org.kie.dmn.model.api.ContextEntry) VALIDATE_COMPILATION(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Reader(java.io.Reader) ValidatorUtil(org.kie.dmn.validation.ValidatorUtil) List(java.util.List) VALIDATE_SCHEMA(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_SCHEMA) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Context(org.kie.dmn.model.api.Context) VALIDATE_MODEL(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_MODEL) Context(org.kie.dmn.model.api.Context) DMNMessage(org.kie.dmn.api.core.DMNMessage) ContextEntry(org.kie.dmn.model.api.ContextEntry) AbstractValidatorTest(org.kie.dmn.validation.AbstractValidatorTest) Test(org.junit.Test)

Aggregations

Context (org.kie.dmn.model.api.Context)21 ContextEntry (org.kie.dmn.model.api.ContextEntry)21 List (java.util.List)16 DMNMessage (org.kie.dmn.api.core.DMNMessage)16 IOException (java.io.IOException)14 Reader (java.io.Reader)14 CoreMatchers.is (org.hamcrest.CoreMatchers.is)14 Test (org.junit.Test)14 DMNMessageType (org.kie.dmn.api.core.DMNMessageType)14 VALIDATE_COMPILATION (org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION)14 VALIDATE_MODEL (org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_MODEL)14 VALIDATE_SCHEMA (org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_SCHEMA)14 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)7 Assert (org.junit.Assert)7 Assert.assertTrue (org.junit.Assert.assertTrue)7 AbstractValidatorTest (org.kie.dmn.validation.AbstractValidatorTest)7 ValidatorUtil (org.kie.dmn.validation.ValidatorUtil)7 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)4 DMNType (org.kie.dmn.api.core.DMNType)3 BusinessKnowledgeModelNode (org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)3