Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
yesamer committed Nov 27, 2024
1 parent 5378eac commit eb2b80b
Showing 1 changed file with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieRuntimeFactory;
import org.kie.api.io.Resource;
import org.kie.dmn.api.core.DMNContext;
import org.kie.dmn.api.core.DMNMessage;
import org.kie.dmn.api.core.DMNResult;
Expand All @@ -27,11 +25,12 @@
import org.kie.dmn.core.compiler.DMNTypeRegistryV15;
import org.kie.dmn.core.impl.BaseDMNTypeImpl;
import org.kie.dmn.core.impl.SimpleTypeImpl;
import org.kie.dmn.core.internal.utils.DMNRuntimeBuilder;
import org.kie.dmn.feel.lang.Type;
import org.kie.dmn.feel.lang.types.BuiltInType;
import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
import org.kie.dmn.model.api.Definitions;
import org.kie.internal.utils.KieHelper;
import org.kie.internal.io.ResourceFactory;
import org.omg.dmn.tck.marshaller._20160719.TestCaseType;
import org.omg.dmn.tck.marshaller._20160719.TestCases;
import org.omg.dmn.tck.marshaller._20160719.ValueType;
Expand Down Expand Up @@ -227,22 +226,32 @@ public String getResultFileName() {
}

private DMNRuntime createRuntime(URL modelUrl, Collection<? extends URL> additionalModels) {
KieServices ks = KieServices.Factory.get();
KieHelper kieHelper = new KieHelper().addResource(ks.getResources().newFileSystemResource(modelUrl.getFile()));
for (URL a : additionalModels) {
kieHelper.addResource(ks.getResources().newFileSystemResource(a.getFile()));
}
KieContainer kieContainer = kieHelper.getKieContainer();
DMNRuntime runtime = KieRuntimeFactory.of(kieContainer.getKieBase()).get(DMNRuntime.class);
try {
List<Resource> resources = new ArrayList<>();
resources.add(ResourceFactory.newReaderResource(new FileReader(modelUrl.getFile()), "UTF-8"));

if (runtime == null) {
throw new RuntimeException("Unable to create DMN Runtime");
}
for (URL additionalModel : additionalModels) {
resources.add(ResourceFactory.newReaderResource(
new FileReader(additionalModel.getFile()), "UTF-8"));
}

DMNRuntime dmnRuntime = DMNRuntimeBuilder
.usingStrict()
.fromResources(resources)
.getOrElseThrow(RuntimeException::new);

if (runtime.getModels().isEmpty()) {
throw new RuntimeException("Unable to load DMN model for URL '" + modelUrl + "'");
if (dmnRuntime == null) {
throw new RuntimeException("Unable to create DMN Runtime");
}

if (dmnRuntime.getModels().isEmpty()) {
throw new RuntimeException("Unable to load DMN model for URL '" + modelUrl + "'");
}

return dmnRuntime;
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
return runtime;
}

private Object parseValue(TestCases.TestCase.InputNode in, InputDataNode input) {
Expand Down

0 comments on commit eb2b80b

Please sign in to comment.