use of org.kie.dmn.validation.DMNValidator in project drools by kiegroup.
the class ValidatorClassloaderTest method test.
@Test
public void test() {
String JAVA_SOURCE = "package com.acme.functions;\n" + "public class Dummy {\n" + " public static String hello() {\n" + " return \"Hello World\";\n" + " }\n" + "}";
final KieServices ks = KieServices.Factory.get();
final ReleaseId kjarReleaseId = ks.newReleaseId("org.kie.dmn.validation", "testValidatorClassloaderTest", UUID.randomUUID().toString());
final KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/java/com/acme/functions/Dummy.java", JAVA_SOURCE);
kfs.write(ks.getResources().newClassPathResource("DummyInvocation.dmn", this.getClass()));
kfs.generateAndWritePomXML(kjarReleaseId);
final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertTrue(kieBuilder.getResults().getMessages().toString(), kieBuilder.getResults().getMessages().isEmpty());
final KieContainer container = ks.newKieContainer(kjarReleaseId);
final DMNRuntime runtime = KieRuntimeFactory.of(container.getKieBase()).get(DMNRuntime.class);
final DMNModel dmnModel = runtime.getModel("https://kiegroup.org/dmn/_69EA2E1A-F706-4CFB-8026-9E41397F6301", "DummyInvocation");
DMNResult evaluateAll = runtime.evaluateAll(dmnModel, runtime.newContext());
LOG.debug("{}", evaluateAll);
assertThat(evaluateAll.getDecisionResultByName("Decision-1").getResult(), is("Hello World"));
final ClassLoader kieProjectCL = container.getClassLoader();
List<DMNProfile> defaultDMNProfiles = DMNAssemblerService.getDefaultDMNProfiles(ChainedProperties.getChainedProperties(kieProjectCL));
final DMNValidator validatorWithCustomCL = DMNValidatorFactory.newValidator(kieProjectCL, defaultDMNProfiles);
List<DMNMessage> validate = validatorWithCustomCL.validateUsing(VALIDATE_SCHEMA, VALIDATE_MODEL, VALIDATE_COMPILATION).theseModels(getReader("DummyInvocation.dmn"));
assertThat(ValidatorUtil.formatMessages(validate), validate.size(), is(0));
}
Aggregations