Search in sources :

Example 16 with Message

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());
}
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 17 with Message

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());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) 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 18 with Message

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;
}
Also used : Message(org.kie.api.builder.Message) ExecutableModelFlowProject(org.drools.modelcompiler.ExecutableModelFlowProject) Resource(org.kie.api.io.Resource) DrlProject(org.drools.compiler.kie.builder.impl.DrlProject) KieBuilder(org.kie.api.builder.KieBuilder)

Example 19 with Message

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();
    }
}
Also used : Message(org.kie.api.builder.Message) KieBase(org.kie.api.KieBase) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieBuilder(org.kie.api.builder.KieBuilder) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with Message

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);
}
Also used : Message(org.kie.api.builder.Message) 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