Search in sources :

Example 1 with MessageImpl

use of org.drools.compiler.kie.builder.impl.MessageImpl in project drools by kiegroup.

the class KieModuleIncrementalCompilationTest method checkIncrementalCompilationWithMultipleKieBases.

@Test
public void checkIncrementalCompilationWithMultipleKieBases() throws Exception {
    String rule = "package org.kie.scanner\n" + "rule R1 when\n" + "then\n" + "end\n";
    String invalidRule = "package org.kie.scanner\n" + "rule R2 when\n" + // missing import
    "   Cheese()\n" + "then\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = createKieFileSystemWithTwoKBases(ks);
    kfs.write("src/main/resources/org/kie/scanner/rule.drl", rule);
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    assertEquals(0, kieBuilder.getResults().getMessages().size());
    kfs.write("src/main/resources/org/kie/scanner/invalidRule.drl", invalidRule);
    IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/org/kie/scanner/invalidRule.drl").build();
    assertEquals(2, addResults.getAddedMessages().size());
    addResults.getAddedMessages().stream().map(m -> (MessageImpl) m).forEach(m -> assertNotNull(m.getKieBaseName()));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieBuilder(org.kie.api.builder.KieBuilder) EventProcessingOption(org.kie.api.conf.EventProcessingOption) MessageImpl(org.drools.compiler.kie.builder.impl.MessageImpl) Collection(java.util.Collection) EqualityBehaviorOption(org.kie.api.conf.EqualityBehaviorOption) HashMap(java.util.HashMap) Test(org.junit.Test) IncrementalResults(org.kie.internal.builder.IncrementalResults) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieServices(org.kie.api.KieServices) Assert(org.junit.Assert) KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) MessageImpl(org.drools.compiler.kie.builder.impl.MessageImpl) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 2 with MessageImpl

use of org.drools.compiler.kie.builder.impl.MessageImpl in project kie-wb-common by kiegroup.

the class MessageConverterTest method checkMessageWithKieBase.

@Test
public void checkMessageWithKieBase() {
    final MessageImpl m = new MessageImpl(ID, Message.Level.ERROR, FILE, TEXT);
    m.setKieBaseName(KIE_BASE_NAME);
    final BuildMessage bm = MessageConverter.convertMessage(m, handles);
    assertConversion(bm, () -> "[KBase: " + KIE_BASE_NAME + "]: " + TEXT);
}
Also used : BuildMessage(org.guvnor.common.services.project.builder.model.BuildMessage) MessageImpl(org.drools.compiler.kie.builder.impl.MessageImpl) Test(org.junit.Test)

Example 3 with MessageImpl

use of org.drools.compiler.kie.builder.impl.MessageImpl in project kie-wb-common by kiegroup.

the class MessageConverter method convertMessageText.

private static String convertMessageText(final Message message) {
    final StringBuilder sb = new StringBuilder();
    if (message instanceof MessageImpl) {
        final MessageImpl impl = (MessageImpl) message;
        final String kieBaseName = impl.getKieBaseName();
        if (!(kieBaseName == null || kieBaseName.isEmpty())) {
            sb.append("[KBase: ").append(kieBaseName).append("]: ");
        }
    }
    sb.append(message.getText());
    return sb.toString();
}
Also used : MessageImpl(org.drools.compiler.kie.builder.impl.MessageImpl)

Example 4 with MessageImpl

use of org.drools.compiler.kie.builder.impl.MessageImpl in project kie-wb-common by kiegroup.

the class MessageConverterTest method checkMessageWithoutKieBase.

@Test
public void checkMessageWithoutKieBase() {
    final Message m = new MessageImpl(ID, Message.Level.ERROR, FILE, TEXT);
    final BuildMessage bm = MessageConverter.convertMessage(m, handles);
    assertConversion(bm, () -> TEXT);
}
Also used : BuildMessage(org.guvnor.common.services.project.builder.model.BuildMessage) BuildMessage(org.guvnor.common.services.project.builder.model.BuildMessage) Message(org.kie.api.builder.Message) MessageImpl(org.drools.compiler.kie.builder.impl.MessageImpl) Test(org.junit.Test)

Aggregations

MessageImpl (org.drools.compiler.kie.builder.impl.MessageImpl)4 Test (org.junit.Test)3 BuildMessage (org.guvnor.common.services.project.builder.model.BuildMessage)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Assert (org.junit.Assert)1 KieServices (org.kie.api.KieServices)1 KieBuilder (org.kie.api.builder.KieBuilder)1 KieFileSystem (org.kie.api.builder.KieFileSystem)1 Message (org.kie.api.builder.Message)1 ReleaseId (org.kie.api.builder.ReleaseId)1 KieModuleModel (org.kie.api.builder.model.KieModuleModel)1 EqualityBehaviorOption (org.kie.api.conf.EqualityBehaviorOption)1 EventProcessingOption (org.kie.api.conf.EventProcessingOption)1 IncrementalResults (org.kie.internal.builder.IncrementalResults)1 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)1