use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class JavaBeansEventRoleTest method testBeanAndDeclarativeTypeInSamePackage.
@Test
public void testBeanAndDeclarativeTypeInSamePackage() throws Exception {
String declaration = "package org.drools.compiler;\n" + "public class Bean {}";
String drl = "package org.drools.compiler;\n" + "declare Bean\n" + " @role(event)\n" + "end";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/java/org/drools/compiler/Bean.java", declaration).write("src/main/resources/bean1.drl", drl);
final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
final KieModule kieModule = kieBuilder.buildAll().getKieModule();
final KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(kieModule);
final String packageName = "org.drools.compiler";
final String className = "Bean";
final Class clazz = kieModuleMetaData.getClass(packageName, className);
final TypeMetaInfo typeMetaInfo = kieModuleMetaData.getTypeMetaInfo(clazz);
assertTrue(typeMetaInfo.isEvent());
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class AbstractKieCiTest method createKieJarWithDependencies.
protected InternalKieModule createKieJarWithDependencies(KieServices ks, ReleaseId releaseId, boolean isdefault, String rule, Dependency... dependencies) {
KieFileSystem kfs = createKieFileSystemWithKProject(ks, isdefault);
kfs.writePomXML(pomWithMvnDeps(dependencyWithScope(releaseId.getGroupId(), releaseId.getArtifactId(), releaseId.getVersion(), ""), dependencies));
String file = "org/test/" + rule + ".drl";
kfs.write("src/main/resources/KBase1/" + file, createDRL(rule));
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
assertTrue(kieBuilder.buildAll().getResults().getMessages().isEmpty());
return (InternalKieModule) kieBuilder.getKieModule();
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieModuleBuilderTest method testKieModuleUsingPOMMissingKBaseDefinition.
@Test
public void testKieModuleUsingPOMMissingKBaseDefinition() throws Exception {
KieServices ks = KieServices.Factory.get();
// Build a KieModule jar, deploy it into local Maven repository
ReleaseId releaseId = ks.newReleaseId("org.kie", "metadata-test2", "1.0-SNAPSHOT");
String pomText = getPom(releaseId);
File pomFile = new File(System.getProperty("java.io.tmpdir"), MavenRepository.toFileName(releaseId, null) + ".pom");
try {
FileOutputStream fos = new FileOutputStream(pomFile);
fos.write(pomText.getBytes());
fos.flush();
fos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writePomXML(getPom(releaseId));
kfs.write("src/main/java/org/kie/test/Bean.java", createJavaSourceInPackage());
KieBuilder kieBuilder1 = ks.newKieBuilder(kfs);
Assert.assertTrue(kieBuilder1.buildAll().getResults().getMessages().isEmpty());
InternalKieModule kieModule = (InternalKieModule) kieBuilder1.getKieModule();
KieMavenRepository.getKieMavenRepository().installArtifact(releaseId, kieModule, pomFile);
// Build a second KieModule, depends on the first KieModule jar which we have deployed into Maven
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "metadata-test-using-pom", "1.0-SNAPSHOT");
String pomText2 = getPom(releaseId2, releaseId);
File pomFile2 = new File(System.getProperty("java.io.tmpdir"), MavenRepository.toFileName(releaseId2, null) + ".pom");
try {
FileOutputStream fos = new FileOutputStream(pomFile2);
fos.write(pomText2.getBytes());
fos.flush();
fos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
// Try building the second KieModule
KieServices kieServices = KieServices.Factory.get();
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
InputStream is = new FileInputStream(pomFile2);
KieModuleModel kproj2 = ks.newKieModuleModel();
kieFileSystem.write("pom.xml", KieServices.Factory.get().getResources().newInputStreamResource(is));
kieFileSystem.writeKModuleXML(kproj2.toXML());
kieFileSystem.write("src/main/resources/rule.drl", createDRLWithImport("rule1"));
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
kieBuilder.buildAll();
assertTrue(kieBuilder.getResults().getMessages().isEmpty());
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieModuleIncrementalCompilationTest method testCheckMetaDataAfterIncrementalDelete.
@Test
public void testCheckMetaDataAfterIncrementalDelete() throws Exception {
String drl1 = "package org.kie.scanner\n" + "rule R1 when\n" + " String()\n" + "then\n" + "end\n";
String drl2 = "package org.kie.scanner\n" + "rule R2_2 when\n" + " String( )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl1).write("src/main/resources/r2.drl", drl2);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(2, getRuleNames(kieBuilder).get("org.kie.scanner").size());
kfs.delete("src/main/resources/r2.drl");
IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(1, getRuleNames(kieBuilder).get("org.kie.scanner").size());
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieModuleIncrementalCompilationTest method checkIncrementalCompilationWithRuleThenFunction.
@Test
public void checkIncrementalCompilationWithRuleThenFunction() throws Exception {
String rule = "package org.kie.scanner\n" + "rule R1 when\n" + " String()\n" + "then\n" + " System.out.println(MyFunction());\n" + "end\n";
String function = "package org.kie.scanner\n" + "function int MyFunction() {\n" + " return 1;\n" + "}\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/org/kie/scanner/rule.drl", rule);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(1, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
kfs.write("src/main/resources/org/kie/scanner/function.drl", function);
IncrementalResults addResults1 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/org/kie/scanner/function.drl").build();
assertEquals(0, addResults1.getAddedMessages().size());
assertEquals(1, addResults1.getRemovedMessages().size());
}
Aggregations