use of org.kie.dmn.model.v1_1.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method testJavaFunctionContext_withErrors.
@Test
public void testJavaFunctionContext_withErrors() {
// DROOLS-1568
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("java_function_context_with_errors.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_b42317c4-4f0c-474e-a0bf-2895b0b3c314", "Dessin 1");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(true));
assertThat(dmnModel.getMessages().size(), is(2));
List<String> sourceIDs = dmnModel.getMessages().stream().map(m -> m.getSourceId()).collect(Collectors.toList());
assertTrue(sourceIDs.contains("_a72a7aff-48c3-4806-83ca-fc1f1fe34320"));
assertTrue(sourceIDs.contains("_a72a7aff-48c3-4806-83ca-fc1f1fe34321"));
}
use of org.kie.dmn.model.v1_1.Definitions in project drools by kiegroup.
the class DMNRuntimeTest method testUnionofLetters.
@Test
public void testUnionofLetters() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Union_of_letters.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_76362694-41e8-400c-8dea-e5f033d4f405", "Union of letters");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext ctx1 = runtime.newContext();
ctx1.set("A1", Arrays.asList(new String[] { "a", "b" }));
ctx1.set("A2", Arrays.asList(new String[] { "b", "c" }));
DMNResult dmnResult1 = runtime.evaluateAll(dmnModel, ctx1);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult1.getMessages()), dmnResult1.hasErrors(), is(false));
assertThat((List<?>) dmnResult1.getContext().get("D1"), contains("a", "b", "c"));
DMNContext ctx2 = runtime.newContext();
ctx2.set("A1", Arrays.asList(new String[] { "a", "b" }));
ctx2.set("A2", Arrays.asList(new String[] { "b", "x" }));
DMNResult dmnResult2 = runtime.evaluateAll(dmnModel, ctx2);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult2.getMessages()), dmnResult2.hasErrors(), is(true));
assertThat(dmnResult2.getMessages().stream().anyMatch(m -> m.getMessageType().equals(DMNMessageType.ERROR_EVAL_NODE)), is(true));
}
use of org.kie.dmn.model.v1_1.Definitions in project drools by kiegroup.
the class DMNValidatorImpl method validate.
@Override
public List<DMNMessage> validate(File xmlFile, Validation... options) {
DMNMessageManager results = new DefaultDMNMessagesManager();
EnumSet<Validation> flags = EnumSet.copyOf(Arrays.asList(options));
if (flags.contains(VALIDATE_SCHEMA)) {
results.addAll(validateSchema(xmlFile));
}
if (flags.contains(VALIDATE_MODEL) || flags.contains(VALIDATE_COMPILATION)) {
Definitions dmndefs = null;
try {
dmndefs = DMNMarshallerFactory.newDefaultMarshaller().unmarshal(new FileReader(xmlFile));
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();
}
use of org.kie.dmn.model.v1_1.Definitions in project drools by kiegroup.
the class AbstractValidatorTest method getDefinitions.
protected Definitions getDefinitions(final String resourceName, final String namespace, final String modelName) {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime(resourceName, this.getClass());
final DMNModel dmnModel = runtime.getModel(namespace, modelName);
assertThat(dmnModel, notNullValue());
final Definitions definitions = dmnModel.getDefinitions();
assertThat(definitions, notNullValue());
return definitions;
}
Aggregations