use of org.kie.api.builder.Message in project drools by kiegroup.
the class GuidedScoreCardIntegrationJavaClassesOnClassPathTest method testCompletedScoreCardCompilation.
@Test
public void testCompletedScoreCardCompilation() throws Exception {
String xml1 = Helper.createGuidedScoreCardXML();
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());
}
use of org.kie.api.builder.Message in project drools by kiegroup.
the class GuidedScoreCardIntegrationJavaClassesAddedToKieFileSystemTest method testIncrementalCompilation.
@Test
public void testIncrementalCompilation() throws Exception {
String xml1_1 = Helper.createEmptyGuidedScoreCardXML();
String xml1_2 = Helper.createGuidedScoreCardXML();
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/java/org/drools/workbench/models/guided/scorecard/backend/test2/Applicant.java", Helper.getApplicant());
kfs.write("src/main/java/org/drools/workbench/models/guided/scorecard/backend/test2/ApplicantAttribute.java", Helper.getApplicantAttribute());
kfs.write("src/main/resources/org/drools/workbench/models/guided/scorecard/backend/test2/sc1.scgd", xml1_1);
// Add empty Score Card
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
final List<Message> messages = kieBuilder.getResults().getMessages();
Helper.dumpMessages(messages);
assertEquals(0, messages.size());
// Update with complete Score Card
kfs.write("src/main/resources/sc1.scgd", xml1_2);
IncrementalResults results = ((InternalKieBuilder) kieBuilder).incrementalBuild();
final List<Message> addedMessages = results.getAddedMessages();
final List<Message> removedMessages = results.getRemovedMessages();
Helper.dumpMessages(addedMessages);
assertEquals(0, addedMessages.size());
Helper.dumpMessages(removedMessages);
assertEquals(0, removedMessages.size());
}
use of org.kie.api.builder.Message in project drools by kiegroup.
the class BuildtimeUtil method getKieBuilderFromResources.
public static KieBuilder getKieBuilderFromResources(final KieFileSystem kfs, final boolean useCanonicalModel, final Resource... resources) {
for (final Resource res : resources) {
kfs.write(res);
}
kfs.writeKModuleXML(getDefaultKieModuleModel(KieServices.get()).toXML());
KieBuilder kbuilder = KieServices.Factory.get().newKieBuilder(kfs);
kbuilder.buildAll(useCanonicalModel ? ExecutableModelFlowProject.class : DrlProject.class);
final List<Message> msgs = kbuilder.getResults().getMessages(Message.Level.ERROR);
if (msgs.size() > 0) {
throw new IllegalArgumentException("KieBuilder errors: {\n" + msgs.toString() + "\n}");
}
return kbuilder;
}
use of org.kie.api.builder.Message in project drools by kiegroup.
the class MultipleSheetsLoadingTest method test.
@Test
public void test() {
final KieBuilder kbuilder = this.buildResources();
final Collection<Message> results = kbuilder.getResults().getMessages(Level.ERROR, Level.WARNING);
if (results.size() > 0) {
LOGGER.error(results.toString());
}
Assertions.assertThat(results).as("Some errors/warnings found").isEmpty();
final KieBase kbase = KieBaseUtil.getDefaultKieBaseFromKieBuilder(kieBaseTestConfiguration, kbuilder);
final StatelessKieSession ksession = kbase.newStatelessKieSession();
final Set<String> resultSet = new HashSet<String>();
ksession.execute((Object) resultSet);
Assertions.assertThat(resultSet.size()).as("Wrong number of rules was fired").isEqualTo(2);
for (String ruleName : new String[] { "rule1", "rule2" }) {
Assertions.assertThat(resultSet.contains(ruleName)).as("Rule " + ruleName + " was not fired!").isTrue();
}
}
use of org.kie.api.builder.Message in project drools by kiegroup.
the class AbstractCompositeRestrictionTest method test.
@Test
public void test() {
final KieBuilder builder = KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, false, KieServices.Factory.get().getResources().newClassPathResource("abstractCompositeRestrictionTest.drl", getClass()));
final List<Message> msgs = builder.getResults().getMessages();
Assertions.assertThat(msgs.size()).isEqualTo(1);
final String[] lines = msgs.get(0).getText().split("\n");
final String unable = "Unable to Analyse Expression valueType == Field.INT || valueType == Field.DOUBLE:";
Assertions.assertThat(lines[0]).isEqualTo(unable);
}
Aggregations