Search in sources :

Example 1 with DMNValidator

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));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) DMNValidator(org.kie.dmn.validation.DMNValidator) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNMessage(org.kie.dmn.api.core.DMNMessage) KieBuilder(org.kie.api.builder.KieBuilder) DMNModel(org.kie.dmn.api.core.DMNModel) DMNProfile(org.kie.dmn.core.compiler.DMNProfile) KieContainer(org.kie.api.runtime.KieContainer) AbstractValidatorTest(org.kie.dmn.validation.AbstractValidatorTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 KieServices (org.kie.api.KieServices)1 KieBuilder (org.kie.api.builder.KieBuilder)1 KieFileSystem (org.kie.api.builder.KieFileSystem)1 ReleaseId (org.kie.api.builder.ReleaseId)1 KieContainer (org.kie.api.runtime.KieContainer)1 DMNMessage (org.kie.dmn.api.core.DMNMessage)1 DMNModel (org.kie.dmn.api.core.DMNModel)1 DMNResult (org.kie.dmn.api.core.DMNResult)1 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)1 DMNProfile (org.kie.dmn.core.compiler.DMNProfile)1 AbstractValidatorTest (org.kie.dmn.validation.AbstractValidatorTest)1 DMNValidator (org.kie.dmn.validation.DMNValidator)1