use of org.kie.api.builder.Results in project drools by kiegroup.
the class SequentialTest method testSequentialWithNoLoop.
@Test(timeout = 10000L)
public void testSequentialWithNoLoop() throws Exception {
// BZ-1228098
String str = "package org.drools.compiler.test\n" + "import \n" + Message.class.getCanonicalName() + ";" + "rule R1 no-loop when\n" + " $s : String( )" + " $m : Message( )\n" + "then\n" + " modify($m) { setMessage($s) };\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/r0.drl", str);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results results = kieBuilder.getResults();
if (results.hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
throw new RuntimeException(results.getMessages().toString());
}
KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
KieBaseConfiguration kieBaseConf = ks.newKieBaseConfiguration();
kieBaseConf.setOption(SequentialOption.YES);
StatelessKieSession sequentialKsession = kieContainer.newKieBase(kieBaseConf).newStatelessKieSession();
List result = (List) sequentialKsession.execute(CommandFactory.newInsertElements(Arrays.asList("test", new Message())));
assertEquals(2, result.size());
StatelessKieSession ksession = kieContainer.getKieBase().newStatelessKieSession();
result = (List) ksession.execute(CommandFactory.newInsertElements(Arrays.asList("test", new Message())));
assertEquals(2, result.size());
}
use of org.kie.api.builder.Results in project drools by kiegroup.
the class QueryTest method testQueryWithSyntaxError.
@Test
public void testQueryWithSyntaxError() {
String drl = "global java.util.List list; " + "" + "query foo( Integer $i ) end " + "" + "rule React \n" + "when\n" + " $i : Integer() " + // missing ";" should result in 1 compilation error
" foo( $i ) " + "then\n" + "end";
KieHelper helper = new KieHelper();
helper.addContent(drl, ResourceType.DRL);
Results results = helper.verify();
assertTrue(results.hasMessages(Message.Level.ERROR));
assertEquals(1, results.getMessages(Message.Level.ERROR).size());
}
use of org.kie.api.builder.Results in project drools by kiegroup.
the class KieContainerImpl method updateToVersion.
public Results updateToVersion(ReleaseId newReleaseId) {
checkNotClasspathKieProject();
Results results = update(((KieModuleKieProject) kProject).getInternalKieModule(), newReleaseId);
if (results != null) {
containerReleaseId = newReleaseId;
} else {
results = new ResultsImpl();
((ResultsImpl) results).addMessage(Message.Level.ERROR, null, "Cannot find KieModule with ReleaseId: " + newReleaseId);
}
return results;
}
use of org.kie.api.builder.Results in project drools by kiegroup.
the class OOPathCastTest method testInvalidCast.
@Test
public void testInvalidCast() {
final String drl = "import org.drools.compiler.oopath.model.*;\n" + "global java.util.List list\n" + "\n" + "rule R when\n" + " Man( $toy: /wife/children#Man/toys )\n" + "then\n" + " list.add( $toy.getName() );\n" + "end\n";
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
final Results results = ks.newKieBuilder(kfs).buildAll().getResults();
assertTrue(results.hasMessages(Message.Level.ERROR));
}
use of org.kie.api.builder.Results in project drools by kiegroup.
the class Misc2Test method testExtendingDate.
@Test
public void testExtendingDate() {
// BZ-1072629
String str = "import " + MyDate.class.getCanonicalName() + " \n" + "rule 'sample rule' \n" + "when \n" + " $date: MyDate() \n" + "then \n" + "$date.setDescription(\"test\"); \n" + "end \n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
Results results = ks.newKieBuilder(kfs).buildAll().getResults();
assertEquals(0, results.getMessages().size());
}
Aggregations