use of org.drools.compiler.compiler.io.memory.MemoryFileSystem in project drools by kiegroup.
the class KieBuilderTest method testNoPomXml.
@Test
public void testNoPomXml() throws ClassNotFoundException, InterruptedException, IOException {
String namespace = "org.kie.test";
KieModuleModel kProj = createKieProject(namespace);
ReleaseId releaseId = KieServices.Factory.get().getRepository().getDefaultReleaseId();
KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
generateKProjectXML(kfs, namespace, kProj);
generateMessageClass(kfs, namespace);
generateRule(kfs, namespace);
MemoryFileSystem mfs = ((KieFileSystemImpl) kfs).asMemoryFileSystem();
createAndTestKieContainer(releaseId, createKieBuilder(kfs), namespace);
}
use of org.drools.compiler.compiler.io.memory.MemoryFileSystem in project drools by kiegroup.
the class KieBuilderTest method testNoProjectXml.
@Test
public void testNoProjectXml() throws ClassNotFoundException, InterruptedException, IOException {
String namespace = "org.kie.test";
ReleaseId releaseId = KieServices.Factory.get().newReleaseId(namespace, "memory", "1.0-SNAPSHOT");
KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
generatePomXML(kfs, releaseId);
generateMessageClass(kfs, namespace);
generateRule(kfs, namespace);
MemoryFileSystem mfs = ((KieFileSystemImpl) kfs).asMemoryFileSystem();
createAndTestKieContainer(releaseId, createKieBuilder(kfs), null);
}
use of org.drools.compiler.compiler.io.memory.MemoryFileSystem in project drools by kiegroup.
the class KieBuilderTest method testNoPomAndProjectXml.
@Test
public void testNoPomAndProjectXml() throws ClassNotFoundException, InterruptedException, IOException {
String namespace = "org.kie.test";
ReleaseId releaseId = KieServices.Factory.get().getRepository().getDefaultReleaseId();
KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
generateMessageClass(kfs, namespace);
generateRule(kfs, namespace);
MemoryFileSystem mfs = ((KieFileSystemImpl) kfs).asMemoryFileSystem();
createAndTestKieContainer(releaseId, createKieBuilder(kfs), null);
}
use of org.drools.compiler.compiler.io.memory.MemoryFileSystem in project drools by kiegroup.
the class KieCompilationCacheTest method testCompilationCache.
@Test
public void testCompilationCache() throws Exception {
String drl = "package org.drools.compiler\n" + "declare type X\n" + " foo : String\n" + "end\n" + "rule R1 when\n" + " $m : X( foo == \"Hello World\" )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
ks.newKieBuilder(kfs).buildAll();
ReleaseId releaseId = ks.getRepository().getDefaultReleaseId();
InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
byte[] jar = kieModule.getBytes();
MemoryFileSystem mfs = MemoryFileSystem.readFromJar(jar);
File file = mfs.getFile(KieBuilderImpl.getCompilationCachePath(releaseId, "KBase1"));
assertNotNull(file);
Resource jarRes = ks.getResources().newByteArrayResource(jar);
KieModule km = ks.getRepository().addKieModule(jarRes);
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieBase kbase = kc.getKieBase();
FactType type = kbase.getFactType("org.drools.compiler", "X");
FactField foo = type.getField("foo");
Object x = type.newInstance();
foo.set(x, "Hello World");
KieSession ksession = kc.newKieSession();
ksession.insert(x);
int count = ksession.fireAllRules();
assertEquals(1, count);
}
use of org.drools.compiler.compiler.io.memory.MemoryFileSystem in project drools by kiegroup.
the class KieContainerTest method testMemoryFileSystemFolderUniqueness.
@Test
public void testMemoryFileSystemFolderUniqueness() {
KieServices kieServices = KieServices.Factory.get();
String drl = "package org.drools.test\n" + "rule R1 when\n" + " $m : Object()\n" + "then\n" + "end\n";
Resource resource = kieServices.getResources().newReaderResource(new StringReader(drl), "UTF-8");
resource.setTargetPath("org/drools/test/rules.drl");
String kmodule = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kmodule xmlns=\"http://www.drools.org/xsd/kmodule\">\n" + " <kbase name=\"testKbase\" packages=\"org.drools.test\">\n" + " <ksession name=\"testKsession\"/>\n" + " </kbase>\n" + "</kmodule>";
// Create an in-memory jar for version 1.0.0
ReleaseId releaseId = kieServices.newReleaseId("org.kie", "test-delete", "1.0.0");
createAndDeployJar(kieServices, kmodule, releaseId, resource);
KieContainer kieContainer = kieServices.newKieContainer(releaseId);
KieModule kieModule = ((InternalKieContainer) kieContainer).getMainKieModule();
MemoryFileSystem memoryFileSystem = ((MemoryKieModule) kieModule).getMemoryFileSystem();
Folder rootFolder = memoryFileSystem.getFolder("");
Object[] members = rootFolder.getMembers().toArray();
assertEquals(2, members.length);
Folder firstFolder = (Folder) members[0];
Folder secondFolder = (Folder) members[1];
assertEquals(firstFolder.getParent(), secondFolder.getParent());
}
Aggregations