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());
}
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());
}
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());
}
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;
}
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());
}
Aggregations