Search in sources :

Example 6 with Definitions

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

the class ValidatorTest method testDryRun.

@Test
public void testDryRun() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0001-input-data-string.dmn", DMNInputRuntimeTest.class);
    DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/drools/kie-dmn", "_0001-input-data-string");
    assertThat(dmnModel, notNullValue());
    Definitions definitions = dmnModel.getDefinitions();
    assertThat(definitions, notNullValue());
    DMNValidatorFactory.newValidator().validate(definitions);
}
Also used : Definitions(org.kie.dmn.model.v1_1.Definitions) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test) DMNInputRuntimeTest(org.kie.dmn.core.DMNInputRuntimeTest)

Example 7 with Definitions

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

the class DMNRuntimeTest method test_countCSATradeRatings.

@Test
public void test_countCSATradeRatings() {
    // DROOLS-1563
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("countCSATradeRatings.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_1a7d184c-2e38-4462-ae28-15591ef6d534", "countCSATradeRatings");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext ctx = runtime.newContext();
    List<Map<?, ?>> ratings = new ArrayList<>();
    ratings.add(prototype(entry("Agency", "FITCH"), entry("Value", "val1")));
    ratings.add(prototype(entry("Agency", "MOODY"), entry("Value", "val2")));
    ctx.set("CSA Trade Ratings", ratings);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, ctx);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("Trade Ratings"), is(new BigDecimal(2)));
    DMNContext ctx2 = runtime.newContext();
    ctx2.set("CSA Trade Ratings", null);
    DMNResult dmnResult2 = runtime.evaluateAll(dmnModel, ctx2);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult2.getMessages()), dmnResult2.hasErrors(), is(false));
    DMNContext result2 = dmnResult2.getContext();
    assertThat(result2.get("Trade Ratings"), nullValue());
    DMNResult dmnResult3 = runtime.evaluateAll(dmnModel, runtime.newContext());
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult3.getMessages()), dmnResult3.hasErrors(), is(true));
    assertThat(dmnResult3.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) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) BigDecimal(java.math.BigDecimal) DMNModel(org.kie.dmn.api.core.DMNModel) Duration(java.time.Duration) Map(java.util.Map) 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) ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) Collectors(java.util.stream.Collectors) DMNRuntimeUtil(org.kie.dmn.core.util.DMNRuntimeUtil) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) VerificationModeFactory.times(org.mockito.internal.verification.VerificationModeFactory.times) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) DMNContext(org.kie.dmn.api.core.DMNContext) FEELStringMarshaller(org.kie.dmn.feel.marshaller.FEELStringMarshaller) KieHelper(org.kie.dmn.core.util.KieHelper) 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) DynamicTypeUtils.prototype(org.kie.dmn.core.util.DynamicTypeUtils.prototype) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) CoreMatchers.not(org.hamcrest.CoreMatchers.not) DynamicTypeUtils.entry(org.kie.dmn.core.util.DynamicTypeUtils.entry) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentCaptor(org.mockito.ArgumentCaptor) KieServices(org.kie.api.KieServices) Matchers.hasSize(org.hamcrest.Matchers.hasSize) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Period(java.time.Period) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) KieContainer(org.kie.api.runtime.KieContainer) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) Ignore(org.junit.Ignore) 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) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 8 with Definitions

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

the class ItemDefinitionDependenciesGeneratedTest method testOrdering.

@Test
public void testOrdering() {
    logger.debug("Item definitions:");
    itemDefinitions.forEach(itemDefinition -> {
        logger.debug(itemDefinition.getName());
        itemDefinition.getItemComponent().forEach(dependency -> logger.debug(dependency.getName()));
    });
    List<ItemDefinition> orderedList = orderingStrategy(itemDefinitions);
    for (ItemDefinition itemDefinition : itemDefinitions) {
        assertOrdering(itemDefinition, orderedList);
    }
}
Also used : ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) Test(org.junit.Test)

Example 9 with Definitions

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

the class DMNValidatorImpl method validate.

@Override
public List<DMNMessage> validate(Reader reader, Validation... options) {
    DMNMessageManager results = new DefaultDMNMessagesManager();
    EnumSet<Validation> flags = EnumSet.copyOf(Arrays.asList(options));
    try {
        String content = readContent(reader);
        if (flags.contains(VALIDATE_SCHEMA)) {
            results.addAll(validateSchema(new StringReader(content)));
        }
        if (flags.contains(VALIDATE_MODEL) || flags.contains(VALIDATE_COMPILATION)) {
            Definitions dmndefs = DMNMarshallerFactory.newDefaultMarshaller().unmarshal(new StringReader(content));
            Definitions.normalize(dmndefs);
            validateModelCompilation(dmndefs, results, flags);
        }
    } catch (Throwable t) {
        MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, null, results, t, null, Msg.FAILED_VALIDATOR);
    }
    return results.getMessages();
}
Also used : DMNMessageManager(org.kie.dmn.core.api.DMNMessageManager) Definitions(org.kie.dmn.model.v1_1.Definitions) StringReader(java.io.StringReader) DefaultDMNMessagesManager(org.kie.dmn.core.util.DefaultDMNMessagesManager)

Example 10 with Definitions

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

the class DMNModelImpl method readExternal.

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    this.serializedAs = (SerializationFormat) in.readObject();
    this.resource = (Resource) in.readObject();
    String xml = (String) in.readObject();
    if (!(in instanceof DroolsObjectInputStream)) {
        throw new UnsupportedOperationException();
    // TODO assume some defaults
    }
    DroolsObjectInputStream is = (DroolsObjectInputStream) in;
    DMNCompilerImpl compiler = (DMNCompilerImpl) is.getCustomExtensions().get(DMNAssemblerService.DMN_COMPILER_CACHE_KEY);
    List<DMNExtensionRegister> dmnRegisteredExtensions = compiler.getRegisteredExtensions();
    Definitions definitions = DMNMarshallerFactory.newMarshallerWithExtensions(dmnRegisteredExtensions).unmarshal(xml);
    this.definitions = definitions;
    DMNModelImpl compiledModel = (DMNModelImpl) compiler.compile(definitions);
    this.inputs = compiledModel.inputs;
    this.decisions = compiledModel.decisions;
    this.bkms = compiledModel.bkms;
    this.itemDefs = compiledModel.itemDefs;
    this.messages = compiledModel.messages;
    this.types = compiledModel.types;
    this.runtimeTypeCheck = compiledModel.runtimeTypeCheck;
}
Also used : DroolsObjectInputStream(org.drools.core.common.DroolsObjectInputStream) DMNCompilerImpl(org.kie.dmn.core.compiler.DMNCompilerImpl) Definitions(org.kie.dmn.model.v1_1.Definitions) DMNExtensionRegister(org.kie.dmn.api.marshalling.v1_1.DMNExtensionRegister)

Aggregations

Test (org.junit.Test)21 Definitions (org.kie.dmn.model.v1_1.Definitions)21 DMNModel (org.kie.dmn.api.core.DMNModel)15 Ignore (org.junit.Ignore)13 DMNMessage (org.kie.dmn.api.core.DMNMessage)13 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)12 ArrayList (java.util.ArrayList)10 ItemDefinition (org.kie.dmn.model.v1_1.ItemDefinition)10 Arrays (java.util.Arrays)9 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 Assert.assertFalse (org.junit.Assert.assertFalse)9 Assert.assertTrue (org.junit.Assert.assertTrue)9 BigDecimal (java.math.BigDecimal)8 Duration (java.time.Duration)8 LocalDate (java.time.LocalDate)8 LocalTime (java.time.LocalTime)8 OffsetTime (java.time.OffsetTime)8 Period (java.time.Period)8 ZoneOffset (java.time.ZoneOffset)8