use of org.kie.dmn.model.v1_1.Definitions in project drools by kiegroup.
the class DMNCompilerTest method testImport.
@Test
public void testImport() {
System.out.println(null instanceof Definitions);
DMNRuntime runtime = DMNRuntimeUtil.createRuntimeWithAdditionalResources("Importing_Model.dmn", this.getClass(), "Imported_Model.dmn");
DMNModel importedModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df36", "Imported Model");
assertThat(importedModel, notNullValue());
for (DMNMessage message : importedModel.getMessages()) {
LOG.debug("{}", message);
}
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edab52", "Importing Model");
assertThat(dmnModel, notNullValue());
for (DMNMessage message : dmnModel.getMessages()) {
LOG.debug("{}", message);
}
DMNContext context = runtime.newContext();
context.set("A Person", mapOf(entry("name", "John"), entry("age", 47)));
DMNResult evaluateAll = runtime.evaluateAll(dmnModel, context);
for (DMNMessage message : evaluateAll.getMessages()) {
LOG.debug("{}", message);
}
LOG.debug("{}", evaluateAll);
assertThat(evaluateAll.getDecisionResultByName("Greeting").getResult(), is("Hello John!"));
}
use of org.kie.dmn.model.v1_1.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method testDROOLS2147_message.
@Test
public void testDROOLS2147_message() {
// DROOLS-2147 truncate message length
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Ex_4_3simplified.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_5c5a9c72-627e-4666-ae85-31356fed3658", "Ex_4_3simplified");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext context = DMNFactory.newContext();
StringBuilder sb = new StringBuilder("abcdefghijklmnopqrstuvwxyz");
for (int i = 0; i < 100; i++) {
sb.append("abcdefghijklmnopqrstuvwxyz");
}
context.set("number", sb.toString());
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
System.out.println(dmnResult);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(true));
assertThat(dmnResult.getMessages().stream().filter(m -> m.getMessageType() == DMNMessageType.ERROR_EVAL_NODE).anyMatch(m -> m.getMessage().contains("... [string clipped after 50 chars, total length is")), is(true));
}
use of org.kie.dmn.model.v1_1.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method testUnknownVariable1.
@Test
public void testUnknownVariable1() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("unknown_variable1.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_9105d4a6-6049-4ace-a9cd-88f18d29bc8f", "Loan Recommendation - context");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.getMessages().size(), is(2));
assertEquals(1, dmnModel.getMessages().stream().filter(m -> m.getMessageType().equals(DMNMessageType.ERR_COMPILING_FEEL)).filter(m -> m.getMessage().contains("Unknown variable 'NonSalaryPct'")).count());
}
use of org.kie.dmn.model.v1_1.Definitions in project drools by kiegroup.
the class XStreamMarshaller method unmarshal.
@Override
public Definitions unmarshal(Reader isr) {
try {
XStream xStream = newXStream();
Definitions def = (Definitions) xStream.fromXML(isr);
return def;
} catch (Exception e) {
logger.error("Error unmarshalling DMN model from reader.", e);
}
return null;
}
use of org.kie.dmn.model.v1_1.Definitions in project drools by kiegroup.
the class DMNXMLLoaderTest method testLoadingExample.
@Test
@Ignore("No unmarshaller implemented")
public void testLoadingExample() {
final DMNMarshaller DMNMarshaller = DMNMarshallerFactory.newDefaultMarshaller();
final InputStream is = this.getClass().getResourceAsStream("/src/test/resources/ch11example.xml");
final InputStreamReader isr = new InputStreamReader(is);
final Object o = DMNMarshaller.unmarshal(isr);
final Definitions root = (Definitions) o;
assertNotNull(root);
}
Aggregations