Search in sources :

Example 66 with Results

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);
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) IncrementalResults(org.kie.internal.builder.IncrementalResults) Results(org.kie.api.builder.Results) StringReader(java.io.StringReader) KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 67 with Results

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());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KnowledgeBuilderResults(org.kie.internal.builder.KnowledgeBuilderResults) KieServices(org.kie.api.KieServices) Test(org.junit.Test)

Example 68 with Results

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());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) Test(org.junit.Test)

Example 69 with Results

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());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) Test(org.junit.Test)

Example 70 with Results

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());
}
Also used : QueryResults(org.kie.api.runtime.rule.QueryResults) FlatQueryResults(org.drools.core.runtime.rule.impl.FlatQueryResults) Results(org.kie.api.builder.Results) KieHelper(org.kie.internal.utils.KieHelper) Test(org.junit.Test)

Aggregations

Results (org.kie.api.builder.Results)92 Test (org.junit.Test)81 KieServices (org.kie.api.KieServices)72 KieFileSystem (org.kie.api.builder.KieFileSystem)60 KieContainer (org.kie.api.runtime.KieContainer)36 KieBuilder (org.kie.api.builder.KieBuilder)32 KieSession (org.kie.api.runtime.KieSession)25 IncrementalResults (org.kie.internal.builder.IncrementalResults)20 ReleaseId (org.kie.api.builder.ReleaseId)19 QueryResults (org.kie.api.runtime.rule.QueryResults)17 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)15 KieBase (org.kie.api.KieBase)14 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)13 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)11 KieHelper (org.kie.internal.utils.KieHelper)11 KieModuleModel (org.kie.api.builder.model.KieModuleModel)10 FactType (org.kie.api.definition.type.FactType)10 ArrayList (java.util.ArrayList)9 FlatQueryResults (org.drools.core.runtime.rule.impl.FlatQueryResults)9 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)7