Search in sources :

Example 21 with Message

use of org.kie.api.builder.Message in project drools by kiegroup.

the class DroolsGcCausesNPETest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    final KieModuleModel module = SERVICES.newKieModuleModel();
    final KieBaseModel base = module.newKieBaseModel(KIE_BASE_NAME);
    base.setEventProcessingMode(EventProcessingOption.STREAM);
    final KieFileSystem fs = SERVICES.newKieFileSystem();
    fs.generateAndWritePomXML(RELEASE_ID);
    fs.write(SERVICES.getResources().newClassPathResource(DRL_FILE_NAME, DroolsGcCausesNPETest.class));
    fs.writeKModuleXML(module.toXML());
    final KieBuilder builder = SERVICES.newKieBuilder(fs);
    final List<Message> errors = builder.buildAll().getResults().getMessages(Message.Level.ERROR);
    Assertions.assertThat(errors).as("Unexpected errors building drl: " + errors).isEmpty();
    SERVICES.getRepository().addKieModule(builder.getKieModule());
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieBuilder(org.kie.api.builder.KieBuilder) BeforeClass(org.junit.BeforeClass)

Example 22 with Message

use of org.kie.api.builder.Message in project drools by kiegroup.

the class RuleTemplateModelIncrementalCompilationTests method testRuleTemplateInvalidFullBuild.

@Test
public void testRuleTemplateInvalidFullBuild() throws Exception {
    // Smurf is unknown
    // package org.mortgages;
    // rule "t1_0"
    // when
    // Applicant( age == 22 )
    // Smurf()
    // then
    // end
    String drl = "<rule>\n" + "  <name>t1</name>\n" + "  <modelVersion>1.0</modelVersion>\n" + "  <attributes/>\n" + "  <metadataList/>\n" + "  <lhs>\n" + "    <fact>\n" + "      <constraintList>\n" + "        <constraints>\n" + "          <fieldConstraint>\n" + "            <value>$default</value>\n" + "            <operator>==</operator>\n" + "            <constraintValueType>7</constraintValueType>\n" + "            <expression>\n" + "              <parts/>\n" + "            </expression>\n" + "            <parameters/>\n" + "            <factType>Applicant</factType>\n" + "            <fieldName>age</fieldName>\n" + "            <fieldType>Integer</fieldType>\n" + "          </fieldConstraint>\n" + "        </constraints>\n" + "      </constraintList>\n" + "      <factType>Applicant</factType>\n" + "      <isNegated>false</isNegated>\n" + "      <window>\n" + "        <parameters/>\n" + "      </window>\n" + "    </fact>\n" + "    <freeForm>\n" + "      <text>Smurf()</text>\n" + "    </freeForm>\n" + "  </lhs>\n" + "  <rhs/>\n" + "  <imports>\n" + "    <imports/>\n" + "  </imports>\n" + "  <packageName>org.drools.workbench.models.guided.template.backend</packageName>\n" + "  <isNegated>false</isNegated>\n" + "  <table>\n" + "    <entry>\n" + "      <string>__ID_KOL_NAME__</string>\n" + "      <list>\n" + "        <string>1</string>\n" + "      </list>\n" + "    </entry>\n" + "    <entry>\n" + "      <string>$default</string>\n" + "      <list>\n" + "        <string>22</string>\n" + "      </list>\n" + "    </entry>\n" + "  </table>\n" + "  <idCol>1</idCol>\n" + "  <rowsCount>1</rowsCount>\n" + "</rule>";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.template", drl);
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    List<Message> messages = kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR);
    assertEquals(1, messages.size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieServices(org.kie.api.KieServices) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Example 23 with Message

use of org.kie.api.builder.Message in project drools by kiegroup.

the class RuleTemplateModelIncrementalCompilationTests method testRuleTemplateIncrementalCompilationAddValidUpdateWithInvalid.

@Test
public void testRuleTemplateIncrementalCompilationAddValidUpdateWithInvalid() throws Exception {
    // DROOLS-360
    // Valid
    // package org.mortgages;
    // rule "t1_0"
    // when
    // Applicant( age == 22 )
    // then
    // end
    String drl1_1 = "<rule>\n" + "  <name>t1</name>\n" + "  <modelVersion>1.0</modelVersion>\n" + "  <attributes/>\n" + "  <metadataList/>\n" + "  <lhs>\n" + "    <fact>\n" + "      <constraintList>\n" + "        <constraints>\n" + "          <fieldConstraint>\n" + "            <value>$default</value>\n" + "            <operator>==</operator>\n" + "            <constraintValueType>7</constraintValueType>\n" + "            <expression>\n" + "              <parts/>\n" + "            </expression>\n" + "            <parameters/>\n" + "            <factType>Applicant</factType>\n" + "            <fieldName>age</fieldName>\n" + "            <fieldType>Integer</fieldType>\n" + "          </fieldConstraint>\n" + "        </constraints>\n" + "      </constraintList>\n" + "      <factType>Applicant</factType>\n" + "      <isNegated>false</isNegated>\n" + "      <window>\n" + "        <parameters/>\n" + "      </window>\n" + "    </fact>\n" + "  </lhs>\n" + "  <rhs/>\n" + "  <imports>\n" + "    <imports/>\n" + "  </imports>\n" + "  <packageName>org.drools.workbench.models.guided.template.backend</packageName>\n" + "  <isNegated>false</isNegated>\n" + "  <table>\n" + "    <entry>\n" + "      <string>__ID_KOL_NAME__</string>\n" + "      <list>\n" + "        <string>1</string>\n" + "      </list>\n" + "    </entry>\n" + "    <entry>\n" + "      <string>$default</string>\n" + "      <list>\n" + "        <string>22</string>\n" + "      </list>\n" + "    </entry>\n" + "  </table>\n" + "  <idCol>1</idCol>\n" + "  <rowsCount>1</rowsCount>\n" + "</rule>";
    // Smurf is unknown
    // package org.mortgages;
    // rule "t1_0"
    // when
    // Applicant( age == 22 )
    // Smurf()
    // then
    // end
    String drl1_2 = "<rule>\n" + "  <name>t1</name>\n" + "  <modelVersion>1.0</modelVersion>\n" + "  <attributes/>\n" + "  <metadataList/>\n" + "  <lhs>\n" + "    <fact>\n" + "      <constraintList>\n" + "        <constraints>\n" + "          <fieldConstraint>\n" + "            <value>$default</value>\n" + "            <operator>==</operator>\n" + "            <constraintValueType>7</constraintValueType>\n" + "            <expression>\n" + "              <parts/>\n" + "            </expression>\n" + "            <parameters/>\n" + "            <factType>Applicant</factType>\n" + "            <fieldName>age</fieldName>\n" + "            <fieldType>Integer</fieldType>\n" + "          </fieldConstraint>\n" + "        </constraints>\n" + "      </constraintList>\n" + "      <factType>Applicant</factType>\n" + "      <isNegated>false</isNegated>\n" + "      <window>\n" + "        <parameters/>\n" + "      </window>\n" + "    </fact>\n" + "    <freeForm>\n" + "      <text>Smurf()</text>\n" + "    </freeForm>\n" + "  </lhs>\n" + "  <rhs/>\n" + "  <imports>\n" + "    <imports/>\n" + "  </imports>\n" + "  <packageName>org.drools.workbench.models.guided.template.backend</packageName>\n" + "  <isNegated>false</isNegated>\n" + "  <table>\n" + "    <entry>\n" + "      <string>__ID_KOL_NAME__</string>\n" + "      <list>\n" + "        <string>1</string>\n" + "      </list>\n" + "    </entry>\n" + "    <entry>\n" + "      <string>$default</string>\n" + "      <list>\n" + "        <string>22</string>\n" + "      </list>\n" + "    </entry>\n" + "  </table>\n" + "  <idCol>1</idCol>\n" + "  <rowsCount>1</rowsCount>\n" + "</rule>";
    KieServices ks = KieServices.Factory.get();
    // Add valid definition
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.template", drl1_1);
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    List<Message> messages = kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR);
    assertEquals(0, messages.size());
    // Update with invalid definition - expect 1 "added" error message
    kfs.write("src/main/resources/r1.template", drl1_2);
    IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r1.template").build();
    assertEquals(1, addResults.getAddedMessages().size());
    assertEquals(0, addResults.getRemovedMessages().size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieServices(org.kie.api.KieServices) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 24 with Message

use of org.kie.api.builder.Message in project drools by kiegroup.

the class RuleUnit method getKieSession.

/**
 * Return a wm ready to go based on the rules in a drl at the specified uri (in the classpath).
 */
public KieSession getKieSession(String uri) throws DroolsParserException, IOException, Exception {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write(ResourceFactory.newClassPathResource(uri, getClass())).writeKModuleXML(createKieProjectWithPackages(ks).toXML());
    KieBuilder builder = ks.newKieBuilder(kfs).buildAll();
    List<Message> results = builder.getResults().getMessages();
    assertTrue(results.toString(), results.isEmpty());
    KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
    return ksession;
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) KieBuilder(org.kie.api.builder.KieBuilder)

Example 25 with Message

use of org.kie.api.builder.Message in project drools by kiegroup.

the class GuidedScoreCardIntegrationJavaClassesOnClassPathTest method testEmptyScoreCardCompilation.

@Test
public void testEmptyScoreCardCompilation() throws Exception {
    String xml1 = Helper.createEmptyGuidedScoreCardXML();
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write("pom.xml", Helper.getPom());
    kfs.write("src/main/resources/META-INF/kmodule.xml", Helper.getKModule());
    kfs.write("src/main/resources/sc1.scgd", xml1);
    // Add complete Score Card
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    final List<Message> messages = kieBuilder.getResults().getMessages();
    Helper.dumpMessages(messages);
    assertEquals(0, messages.size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieServices(org.kie.api.KieServices) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Aggregations

Message (org.kie.api.builder.Message)33 KieBuilder (org.kie.api.builder.KieBuilder)30 KieFileSystem (org.kie.api.builder.KieFileSystem)26 Test (org.junit.Test)21 KieServices (org.kie.api.KieServices)19 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)10 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)7 KieBase (org.kie.api.KieBase)6 ReleaseId (org.kie.api.builder.ReleaseId)5 KieModule (org.kie.api.builder.KieModule)4 KieModuleModel (org.kie.api.builder.model.KieModuleModel)4 IncrementalResults (org.kie.internal.builder.IncrementalResults)4 Before (org.junit.Before)3 Resource (org.kie.api.io.Resource)3 KieSession (org.kie.api.runtime.KieSession)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)1 MavenRepository (org.appformer.maven.integration.MavenRepository)1 MavenRepository.getMavenRepository (org.appformer.maven.integration.MavenRepository.getMavenRepository)1