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"));
}
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"));
}
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"));
}
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.");
}
}
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"));
}
Aggregations