Search in sources :

Example 11 with MemoryKieModule

use of org.drools.compiler.kie.builder.impl.MemoryKieModule in project drools by kiegroup.

the class MemoryKieModuleResourceProviderTest method testGetResourceAsStreamForFile.

@Test
public void testGetResourceAsStreamForFile() throws Exception {
    MemoryFileSystem mfs = new MemoryFileSystem();
    mfs.setFileContents(new MemoryFile(mfs, "my-file1", mfs.getFolder("src/main/resources")), new byte[] { 65, 66 });
    MemoryKieModule mkm = new MemoryKieModule(releaseId, kieModuleModel, mfs);
    ResourceProvider resourceProvider = mkm.createResourceProvider();
    String folderContents = IOUtils.toString(resourceProvider.getResourceAsStream("src/main/resources/my-file1"));
    // "AB" == new byte[] {65, 66}
    Assertions.assertThat(folderContents).hasLineCount(1).contains("AB");
}
Also used : MemoryFile(org.drools.compiler.compiler.io.memory.MemoryFile) MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) ResourceProvider(org.drools.wiring.api.ResourceProvider) MemoryKieModule(org.drools.compiler.kie.builder.impl.MemoryKieModule) Test(org.junit.Test)

Example 12 with MemoryKieModule

use of org.drools.compiler.kie.builder.impl.MemoryKieModule 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");
    KieUtil.buildAndInstallKieModuleIntoRepo(kieBaseTestConfiguration, releaseId, KieModuleModelImpl.fromXML(kmodule), 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

MemoryKieModule (org.drools.compiler.kie.builder.impl.MemoryKieModule)12 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)11 Test (org.junit.Test)8 ResourceProvider (org.drools.wiring.api.ResourceProvider)6 KieServices (org.kie.api.KieServices)5 MemoryFile (org.drools.compiler.compiler.io.memory.MemoryFile)4 MemoryFolder (org.drools.compiler.compiler.io.memory.MemoryFolder)4 ReleaseId (org.kie.api.builder.ReleaseId)4 StringReader (java.io.StringReader)3 Folder (org.drools.compiler.compiler.io.Folder)3 Resource (org.kie.api.io.Resource)3 InternalKieContainer (org.drools.core.impl.InternalKieContainer)2 KieBuilder (org.kie.api.builder.KieBuilder)2 KieModule (org.kie.api.builder.KieModule)2 KieBaseModel (org.kie.api.builder.model.KieBaseModel)2 KieModuleModel (org.kie.api.builder.model.KieModuleModel)2 KieContainer (org.kie.api.runtime.KieContainer)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1