use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method testCycleDetectionSelfReference.
@Test
public void testCycleDetectionSelfReference() {
final Definitions defs = buildSimplifiedDefinitions("ns", "self");
final DecisionNodeImpl decision = buildSimplifiedDecisionNode(defs, "self");
decision.addDependency("self", decision);
final DMNModelImpl model = new DMNModelImpl(defs);
model.setDefinitions(defs);
model.addDecision(decision);
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime(this.getClass());
final DMNResult result = runtime.evaluateAll(model, DMNFactory.newContext());
assertTrue(result.hasErrors());
}
use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method testCycleDetection.
@Test
public void testCycleDetection() {
final Definitions defs = buildSimplifiedDefinitions("ns", "a", "b");
final DecisionNodeImpl a = buildSimplifiedDecisionNode(defs, "a");
final DecisionNodeImpl b = buildSimplifiedDecisionNode(defs, "b");
a.addDependency("b", b);
b.addDependency("a", b);
final DMNModelImpl model = new DMNModelImpl(defs);
model.setDefinitions(defs);
model.addDecision(a);
model.addDecision(b);
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime(this.getClass());
final DMNResult result = runtime.evaluateAll(model, DMNFactory.newContext());
assertTrue(result.hasErrors());
}
use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method testList_of_Vowels.
@Test
public void testList_of_Vowels() {
// DROOLS-2357
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("List_of_Vowels.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_c5f007ce-4d45-4aac-8729-991d4abc7826", "List of Vowels");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
final DMNContext emptyContext = DMNFactory.newContext();
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, emptyContext);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(true));
assertThat(dmnResult.getMessages().stream().filter(m -> m.getMessageType() == DMNMessageType.ERROR_EVAL_NODE).anyMatch(m -> m.getSourceId().equals("_b2205027-d06c-41b5-8419-e14b501e14a6")), is(true));
final DMNContext result = dmnResult.getContext();
assertThat(result.get("Decide Vowel a"), is("a"));
assertThat(result.get("Decide BAD"), nullValue());
}
use of org.kie.dmn.model.api.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method testDROOLS2147_message.
@Test
public void testDROOLS2147_message() {
// DROOLS-2147 truncate message length
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Ex_4_3simplified.dmn", this.getClass());
final 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));
final DMNContext context = DMNFactory.newContext();
final StringBuilder sb = new StringBuilder("abcdefghijklmnopqrstuvwxyz");
for (int i = 0; i < 100; i++) {
sb.append("abcdefghijklmnopqrstuvwxyz");
}
context.set("number", sb.toString());
final 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.api.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method buildSimplifiedDefinitions.
private Definitions buildSimplifiedDefinitions(final String namespace, final String... decisions) {
final Definitions def = new TDefinitions();
def.setNamespace(namespace);
for (final String d : decisions) {
final Decision dec = new TDecision();
dec.setName(d);
def.getDrgElement().add(dec);
def.addChildren(dec);
dec.setParent(def);
}
return def;
}
Aggregations