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