Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drools - Fix TCK tests failing because of a compilation failure #685

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading