Search in sources :

Example 36 with Definitions

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

the class ValidatorTest method utilDefinitions.

private Definitions utilDefinitions(String filename, String modelName) {
    // List<DMNMessage> validateXML;
    // try {
    // validateXML = validator.validate( new File(this.getClass().getResource(filename).toURI()), DMNValidator.Validation.VALIDATE_SCHEMA );
    // assertThat( "using unit test method utilDefinitions must received a XML valid DMN file", validateXML, IsEmptyCollection.empty() );
    // } catch (URISyntaxException e) {
    // e.printStackTrace();
    // fail("Unable for the test suite to locate the file for XML validation.");
    // }
    DMNMarshaller marshaller = DMNMarshallerFactory.newDefaultMarshaller();
    try (InputStreamReader isr = new InputStreamReader(getClass().getResourceAsStream(filename))) {
        Definitions definitions = marshaller.unmarshal(isr);
        assertThat(definitions, notNullValue());
        return definitions;
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unable for the test suite to locate the file for validation.");
    }
    return null;
}
Also used : DMNMarshaller(org.kie.dmn.api.marshalling.DMNMarshaller) InputStreamReader(java.io.InputStreamReader) Definitions(org.kie.dmn.model.api.Definitions) IOException(java.io.IOException)

Example 37 with Definitions

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

the class RecommenderHitPolicyTest method testGaps.

@Test
public void testGaps() {
    Definitions definitions = getDefinitions("RecommenderHitPolicy1.dmn", "http://www.trisotech.com/definitions/_50aea0bb-4482-48f6-acfe-4abc1a1bd0d6", "Drawing 1");
    List<DMNMessage> validate = validator.validate(definitions, VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_3aa68aee-6314-482f-a0be-84c2411d65d7");
    debugValidatorMsg(validate);
    assertThat(analysis.getGaps(), hasSize(1));
    assertTrue(validate.stream().noneMatch(m -> m.getMessageType() == DMNMessageType.DECISION_TABLE_HITPOLICY_RECOMMENDER));
}
Also used : Arrays(java.util.Arrays) DecisionTable(org.kie.dmn.model.api.DecisionTable) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) VALIDATE_COMPILATION(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Definitions(org.kie.dmn.model.api.Definitions) HitPolicy(org.kie.dmn.model.api.HitPolicy) List(java.util.List) Decision(org.kie.dmn.model.api.Decision) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ANALYZE_DECISION_TABLE(org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DMNMessage(org.kie.dmn.api.core.DMNMessage) Definitions(org.kie.dmn.model.api.Definitions) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Test(org.junit.Test)

Example 38 with Definitions

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

the class RecommenderHitPolicyTest method getRecommenderHitPolicy2.

private List<DMNMessage> getRecommenderHitPolicy2(HitPolicy hp) {
    Definitions definitions = getDefinitions("RecommenderHitPolicy2.dmn", "http://www.trisotech.com/definitions/_50aea0bb-4482-48f6-acfe-4abc1a1bd0d6", "Drawing 1");
    // mutates XML file in the Hit Policy, accordingly to this test parameter.
    ((DecisionTable) ((Decision) definitions.getDrgElement().get(1)).getExpression()).setHitPolicy(hp);
    List<DMNMessage> validate = validator.validate(definitions, VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_3aa68aee-6314-482f-a0be-84c2411d65d7");
    debugValidatorMsg(validate);
    assertThat(analysis.getGaps(), hasSize(0));
    assertThat(analysis.getOverlaps(), hasSize(0));
    return validate;
}
Also used : DecisionTable(org.kie.dmn.model.api.DecisionTable) DMNMessage(org.kie.dmn.api.core.DMNMessage) Definitions(org.kie.dmn.model.api.Definitions) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis)

Example 39 with Definitions

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

the class RecommenderHitPolicyTest method getRecommenderHitPolicy4.

private List<DMNMessage> getRecommenderHitPolicy4(HitPolicy hp) {
    Definitions definitions = getDefinitions("RecommenderHitPolicy4.dmn", "http://www.trisotech.com/definitions/_50aea0bb-4482-48f6-acfe-4abc1a1bd0d6", "Drawing 1");
    // mutates XML file in the Hit Policy, accordingly to this test parameter.
    ((DecisionTable) ((Decision) definitions.getDrgElement().get(1)).getExpression()).setHitPolicy(hp);
    List<DMNMessage> validate = validator.validate(definitions, VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_3aa68aee-6314-482f-a0be-84c2411d65d7");
    debugValidatorMsg(validate);
    assertThat(analysis.getGaps(), hasSize(0));
    assertThat(analysis.getOverlaps(), hasSize(1));
    return validate;
}
Also used : DecisionTable(org.kie.dmn.model.api.DecisionTable) DMNMessage(org.kie.dmn.api.core.DMNMessage) Definitions(org.kie.dmn.model.api.Definitions) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis)

Example 40 with Definitions

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

the class RecommenderHitPolicyTest method getRecommenderHitPolicy3.

private List<DMNMessage> getRecommenderHitPolicy3(HitPolicy hp) {
    Definitions definitions = getDefinitions("RecommenderHitPolicy3.dmn", "http://www.trisotech.com/definitions/_50aea0bb-4482-48f6-acfe-4abc1a1bd0d6", "Drawing 1");
    // mutates XML file in the Hit Policy, accordingly to this test parameter.
    ((DecisionTable) ((Decision) definitions.getDrgElement().get(1)).getExpression()).setHitPolicy(hp);
    List<DMNMessage> validate = validator.validate(definitions, VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_3aa68aee-6314-482f-a0be-84c2411d65d7");
    debugValidatorMsg(validate);
    assertThat(analysis.getGaps(), hasSize(0));
    assertThat(analysis.getOverlaps(), hasSize(1));
    return validate;
}
Also used : DecisionTable(org.kie.dmn.model.api.DecisionTable) DMNMessage(org.kie.dmn.api.core.DMNMessage) Definitions(org.kie.dmn.model.api.Definitions) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis)

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