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);
}
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));
}
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);
}
}
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();
}
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;
}
Aggregations