Search in sources :

Example 16 with MemoryFileSystem

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);
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) KieFileSystem(org.kie.api.builder.KieFileSystem) KieFileSystemImpl(org.drools.compiler.kie.builder.impl.KieFileSystemImpl) KieModuleModel(org.kie.api.builder.model.KieModuleModel) ReleaseId(org.kie.api.builder.ReleaseId) Test(org.junit.Test)

Example 17 with MemoryFileSystem

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);
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) KieFileSystem(org.kie.api.builder.KieFileSystem) KieFileSystemImpl(org.drools.compiler.kie.builder.impl.KieFileSystemImpl) ReleaseId(org.kie.api.builder.ReleaseId) Test(org.junit.Test)

Example 18 with MemoryFileSystem

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);
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) KieFileSystem(org.kie.api.builder.KieFileSystem) KieFileSystemImpl(org.drools.compiler.kie.builder.impl.KieFileSystemImpl) ReleaseId(org.kie.api.builder.ReleaseId) Test(org.junit.Test)

Example 19 with MemoryFileSystem

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);
}
Also used : FactField(org.kie.api.definition.type.FactField) KieFileSystem(org.kie.api.builder.KieFileSystem) Resource(org.kie.api.io.Resource) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) FactType(org.kie.api.definition.type.FactType) MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) File(org.drools.compiler.compiler.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 20 with MemoryFileSystem

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());
}
Also used : Resource(org.kie.api.io.Resource) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) Folder(org.drools.compiler.compiler.io.Folder) MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) StringReader(java.io.StringReader) MemoryKieModule(org.drools.compiler.kie.builder.impl.MemoryKieModule) InternalKieContainer(org.drools.core.impl.InternalKieContainer) MemoryKieModule(org.drools.compiler.kie.builder.impl.MemoryKieModule) KieModule(org.kie.api.builder.KieModule) InternalKieContainer(org.drools.core.impl.InternalKieContainer) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)35 Test (org.junit.Test)30 ReleaseId (org.kie.api.builder.ReleaseId)14 Folder (org.drools.compiler.compiler.io.Folder)12 FileSystem (org.drools.compiler.compiler.io.FileSystem)11 MemoryFolder (org.drools.compiler.compiler.io.memory.MemoryFolder)11 File (org.drools.compiler.compiler.io.File)10 KieFileSystem (org.kie.api.builder.KieFileSystem)10 KieFileSystemImpl (org.drools.compiler.kie.builder.impl.KieFileSystemImpl)7 KieServices (org.kie.api.KieServices)7 KieModule (org.kie.api.builder.KieModule)7 ResourceProvider (org.drools.core.common.ResourceProvider)6 KieModuleModel (org.kie.api.builder.model.KieModuleModel)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 MemoryFile (org.drools.compiler.compiler.io.memory.MemoryFile)4 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)4 Resource (org.kie.api.io.Resource)4 KieSession (org.kie.api.runtime.KieSession)4 KieContainer (org.kie.api.runtime.KieContainer)3 IOException (java.io.IOException)2