Search in sources :

Example 31 with Message

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

the class DeleteTest method setUp.

@Before
public void setUp() {
    KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
    kfs.write(KieServices.Factory.get().getResources().newClassPathResource(DELETE_TEST_DRL, DeleteTest.class));
    KieBuilder kbuilder = KieServices.Factory.get().newKieBuilder(kfs);
    kbuilder.buildAll();
    List<Message> res = kbuilder.getResults().getMessages(Level.ERROR);
    Assertions.assertThat(res).isEmpty();
    KieBase kbase = KieServices.Factory.get().newKieContainer(kbuilder.getKieModule().getReleaseId()).getKieBase();
    ksession = kbase.newKieSession();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieBase(org.kie.api.KieBase) KieBuilder(org.kie.api.builder.KieBuilder) Before(org.junit.Before)

Example 32 with Message

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

the class KieModuleMetaDataTest method testKieModuleMetaDataInMemoryWithJavaClassDefaultPackage.

@Test
public void testKieModuleMetaDataInMemoryWithJavaClassDefaultPackage() throws Exception {
    final KieServices ks = KieServices.Factory.get();
    final ReleaseId releaseId = ks.newReleaseId("org.kie", "javaDefaultPackage", "1.0-SNAPSHOT");
    final KieModuleModel kproj = ks.newKieModuleModel();
    final KieFileSystem kfs = ks.newKieFileSystem();
    kfs.writeKModuleXML(kproj.toXML()).writePomXML(generatePomXml(releaseId)).write("src/main/java/test/Bean.java", createJavaSource());
    final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    final List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
    assertTrue(messages.isEmpty());
    final KieModule kieModule = kieBuilder.getKieModule();
    final KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(kieModule);
    // The call to kieModuleMetaData.getClass() assumes a Java file has an explicit package
    final Class<?> beanClass = kieModuleMetaData.getClass("", "test.Bean");
    assertNotNull(beanClass);
    final TypeMetaInfo beanMetaInfo = kieModuleMetaData.getTypeMetaInfo(beanClass);
    assertNotNull(beanMetaInfo);
}
Also used : TypeMetaInfo(org.drools.core.rule.TypeMetaInfo) KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 33 with Message

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

the class KieModuleMetaDataTest method testGetRuleNames.

@Test
public void testGetRuleNames() {
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write("src/main/resources/test1.drl", "package org.test\n" + "rule A\n" + " when\n" + "then\n" + "end\n" + "rule B\n" + " when\n" + "then\n" + "end\n");
    kfs.write("src/main/resources/test2.drl", "package org.test\n" + "rule C\n" + " when\n" + "then\n" + "end\n");
    final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    final List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
    assertTrue(messages.isEmpty());
    final KieModule kieModule = kieBuilder.getKieModule();
    final KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(kieModule);
    Collection<String> rules = kieModuleMetaData.getRuleNamesInPackage("org.test");
    assertEquals(3, rules.size());
    assertTrue(rules.containsAll(asList("A", "B", "C")));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) 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