use of org.kie.api.builder.Results in project drools by kiegroup.
the class IncrementalCompilationTest method testJavaClassRedefinitionJoined.
@Test
public void testJavaClassRedefinitionJoined() {
// DROOLS-1402
String JAVA1 = "package org.test;" + " public class MyBean {\n" + " private String firstName;\n" + " public MyBean() { /* empty constructor */ }\n" + " public MyBean(String firstName) { this.firstName = firstName; }\n" + " public String getFirstName() { return firstName; }\n" + " public void setFirstName(String firstName) { this.firstName = firstName; }\n" + " }";
String DRL1 = "package org.test;\n" + "\n" + "//from row number: 1\n" + "rule \"Row 1 HelloRules\"\n" + " when\n" + " $b : MyBean( firstName == null )\n" + " $s : String()\n" + " then\n" + " System.out.println($s + \" \" + $b);" + "end";
String INIT_DRL = "package org.test; rule RINIT when eval(true) then insert(new MyBean()); end";
String INIT_DRL_2 = "package org.test; rule RINIT when eval(1==1) then insert(new MyBean()); end";
String JAVA2 = "package org.test;" + " public class MyBean {\n" + " private String firstName;\n" + " private String lastName;\n" + " public MyBean() { /* empty constructor */ }\n" + " public MyBean(String firstName) { this.firstName = firstName; }\n" + " public MyBean(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; }\n" + " public String getFirstName() { return firstName; }\n" + " public void setFirstName(String firstName) { this.firstName = firstName; }\n" + " public String getLastName() { return lastName; }\n" + " public void setLastName(String lastName) { this.lastName = lastName; }\n" + " }";
String DRL2 = "package org.test;\n" + "\n" + "//from row number: 1\n" + "rule \"Row 1 HelloRules\"\n" + " when\n" + " $b : MyBean( firstName == null , lastName == null )\n" + " $s : String()\n" + " then\n" + " System.out.println($s + \" \" + $b);" + "end";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
ReleaseId id = ks.newReleaseId("org.test", "myTest", "1.0.0");
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
kfs.generateAndWritePomXML(id);
kfs.write("src/main/java/org/test/MyBean.java", ks.getResources().newReaderResource(new StringReader(JAVA1)));
kfs.write(ks.getResources().newReaderResource(new StringReader(DRL1)).setResourceType(ResourceType.DRL).setSourcePath("rules.drl"));
kfs.write(ks.getResources().newReaderResource(new StringReader(INIT_DRL)).setResourceType(ResourceType.DRL).setSourcePath("INIT_DRL.drl"));
kieBuilder.buildAll();
KieContainer kc = ks.newKieContainer(id);
KieSession ksession = kc.newKieSession();
ksession.insert("This string joins with");
int fired = ksession.fireAllRules();
assertEquals(2, fired);
ReleaseId id2 = ks.newReleaseId("org.test", "myTest", "2.0.0");
KieFileSystem kfs2 = ks.newKieFileSystem();
KieBuilder kieBuilder2 = ks.newKieBuilder(kfs2);
kfs2.generateAndWritePomXML(id2);
kfs2.write("src/main/java/org/test/MyBean.java", ks.getResources().newReaderResource(new StringReader(JAVA2)));
kfs2.write(ks.getResources().newReaderResource(new StringReader(DRL2)).setResourceType(ResourceType.DRL).setSourcePath("rules.drl"));
kfs2.write(ks.getResources().newReaderResource(new StringReader(INIT_DRL_2)).setResourceType(ResourceType.DRL).setSourcePath("INIT_DRL.drl"));
kieBuilder2.buildAll();
Results updateResults = kc.updateToVersion(id2);
assertFalse(updateResults.hasMessages(Level.ERROR));
fired = ksession.fireAllRules();
assertEquals(2, fired);
}
use of org.kie.api.builder.Results in project drools by kiegroup.
the class Misc2Test method testFieldNameStartingWithUnderscore.
@Test
public void testFieldNameStartingWithUnderscore() throws Exception {
// DROOLS-554
String str = "import " + Underscore.class.getCanonicalName() + ";\n" + "rule R when\n" + " Underscore( _id == \"test\" )\n" + "then\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());
}
use of org.kie.api.builder.Results in project drools by kiegroup.
the class StrictAnnotationTest method testUnknownAnnotation.
@Test
public void testUnknownAnnotation() throws Exception {
String str = "package org.simple \n" + "@Xyz rule yyy \n" + "when \n" + " $s : String()\n" + "then \n" + "end \n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str).writeKModuleXML(ks.newKieModuleModel().setConfigurationProperty(LanguageLevelOption.PROPERTY_NAME, LanguageLevelOption.DRL6_STRICT.toString()).toXML());
Results results = ks.newKieBuilder(kfs).buildAll().getResults();
assertEquals(1, results.getMessages().size());
}
use of org.kie.api.builder.Results in project drools by kiegroup.
the class StrictAnnotationTest method testStirctWatchWithoutQuotes.
@Test
public void testStirctWatchWithoutQuotes() throws Exception {
String str = "package com.sample;\n" + "import " + MyClass.class.getCanonicalName() + ";\n" + "rule R1 when\n" + " @Watch( !value ) $m : MyClass( value < 10 )\n" + "then \n" + " modify( $m ) { setValue( $m.getValue()+1 ) };\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str).writeKModuleXML(ks.newKieModuleModel().setConfigurationProperty(LanguageLevelOption.PROPERTY_NAME, LanguageLevelOption.DRL6_STRICT.toString()).toXML());
Results results = ks.newKieBuilder(kfs).buildAll().getResults();
assertEquals(1, results.getMessages().size());
}
use of org.kie.api.builder.Results in project drools by kiegroup.
the class QueryTest method testQueryWithWrongParamNumber.
@Test
public void testQueryWithWrongParamNumber() {
String drl = "global java.util.List list; " + "" + "query foo( Integer $i ) end " + "" + "rule React \n" + "when\n" + " $i : Integer() " + " $j : Integer() " + " foo( $i, $j ; ) " + "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());
}
Aggregations