Search in sources :

Example 61 with KieModule

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

the class KieModuleMetaDataTest method testExcludeTestDeps.

@Test
public void testExcludeTestDeps() {
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    kfs.writePomXML(getPomWithTestDependency());
    final KieModule kieModule = ks.newKieBuilder(kfs).getKieModule();
    final KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(kieModule, new DependencyFilter.ExcludeScopeFilter("test"));
    assertFalse(("" + kieModuleMetaData.getPackages()).contains("junit"));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) DependencyFilter(org.appformer.maven.support.DependencyFilter) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 62 with KieModule

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

the class KieModuleMetaDataTest method testGetPackageNames.

@Test
public void testGetPackageNames() {
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write("src/main/resources/test.drl", "package org.test declare Bean end");
    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);
    assertFalse(kieModuleMetaData.getPackages().isEmpty());
    assertTrue(kieModuleMetaData.getPackages().contains("org.test"));
}
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)

Example 63 with KieModule

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

the class KieModuleMetaDataTest method testIncludeAllDeps.

@Test
public void testIncludeAllDeps() {
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    kfs.writePomXML(getPomWithTestDependency());
    final KieModule kieModule = ks.newKieBuilder(kfs).getKieModule();
    final KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(kieModule);
    assertTrue(("" + kieModuleMetaData.getPackages()).contains("junit"));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 64 with KieModule

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

the class KieModuleMetaDataTest method testKieMavenPluginEmptyProject.

@Test
public void testKieMavenPluginEmptyProject() {
    // According to https://bugzilla.redhat.com/show_bug.cgi?id=1049674#c2 the below is the minimal POM required to use KieMavenPlugin.
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write("pom.xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "  <modelVersion>4.0.0</modelVersion>" + "  <groupId>org.kie</groupId>" + "  <artifactId>plugin-test</artifactId>" + "  <version>1.0</version>" + "  <packaging>kjar</packaging>" + "  <build>" + "    <plugins>" + "      <plugin>" + "        <groupId>org.kie</groupId>" + "        <artifactId>kie-maven-plugin</artifactId>" + "        <version>the-test-does-not-need-proper-version-here</version>" + "        <extensions>true</extensions>" + "      </plugin>" + "    </plugins>" + "  </build>" + "</project>");
    kfs.write("/src/main/resources/META-INF/kmodule.xml", "<kmodule xmlns=\"http://www.drools.org/xsd/kmodule\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>");
    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);
    boolean fail = false;
    for (final String packageName : kieModuleMetaData.getPackages()) {
        for (final String className : kieModuleMetaData.getClasses(packageName)) {
            try {
                kieModuleMetaData.getClass(packageName, className);
            } catch (Throwable e) {
                fail = true;
                System.out.println(e);
            }
        }
    }
    if (fail) {
        fail("See console for details.");
    }
}
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)

Example 65 with KieModule

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

the class KieBuilderTest method testDeclarativeChannelRegistration.

@Test
public void testDeclarativeChannelRegistration() {
    final String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + "   $m : Message()\n" + "then\n" + "end\n";
    final String kmodule = "<kmodule xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" + "         xmlns=\"http://www.drools.org/xsd/kmodule\">\n" + "  <kbase name=\"kbase1\">\n" + "    <ksession name=\"ksession1\" default=\"true\">\n" + "       <channels>\n" + "         <channel name=\"testChannel\" type=\"org.drools.compiler.integrationtests.KieBuilderTest$MockChannel\" />\n" + "       </channels>\n" + "    </ksession>" + "  </kbase>\n" + "</kmodule>";
    final KieServices ks = KieServices.Factory.get();
    final ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-kie-builder", "1.0.0");
    final Resource r1 = ResourceFactory.newByteArrayResource(drl1.getBytes()).setResourceType(ResourceType.DRL).setSourcePath("kbase1/drl1.drl");
    final KieModule km = createAndDeployJar(ks, kmodule, releaseId1, r1);
    KieContainer kieContainer = ks.newKieContainer(km.getReleaseId());
    KieSession kieSession = kieContainer.newKieSession();
    assertEquals(1, kieSession.getChannels().size());
    assertTrue(kieSession.getChannels().keySet().contains("testChannel"));
}
Also used : Resource(org.kie.api.io.Resource) KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

KieModule (org.kie.api.builder.KieModule)124 KieServices (org.kie.api.KieServices)104 Test (org.junit.Test)94 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)84 ReleaseId (org.kie.api.builder.ReleaseId)84 KieContainer (org.kie.api.runtime.KieContainer)75 KieSession (org.kie.api.runtime.KieSession)64 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)53 Message (org.drools.compiler.Message)25 KieFileSystem (org.kie.api.builder.KieFileSystem)23 Resource (org.kie.api.io.Resource)20 ArrayList (java.util.ArrayList)15 KieModuleModel (org.kie.api.builder.model.KieModuleModel)15 KieBuilder (org.kie.api.builder.KieBuilder)13 KieRepository (org.kie.api.builder.KieRepository)10 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)7 KieBaseModel (org.kie.api.builder.model.KieBaseModel)7 KieBase (org.kie.api.KieBase)6 List (java.util.List)5 Results (org.kie.api.builder.Results)5