Search in sources :

Example 1 with MemoryFileSystem

use of org.drools.compiler.compiler.io.memory.MemoryFileSystem in project drools by kiegroup.

the class KieFileSystemImplTest method testClone.

@Test
public void testClone() throws Exception {
    KieFileSystem clonedKieFileSystem = kieFileSystem.clone();
    MemoryFileSystem clonedMfs = ((KieFileSystemImpl) clonedKieFileSystem).getMfs();
    Collection<String> clonedFileNames = clonedMfs.getFileNames();
    assertTrue(kieFileSystem != clonedKieFileSystem);
    assertTrue(kieFileSystem.getMfs() != clonedMfs);
    assertEquals(kieFileSystem.getMfs().getFileNames(), clonedFileNames);
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) KieFileSystem(org.kie.api.builder.KieFileSystem) Test(org.junit.Test)

Example 2 with MemoryFileSystem

use of org.drools.compiler.compiler.io.memory.MemoryFileSystem in project drools by kiegroup.

the class MemoryFileTest method testFileRemoval.

@Test
public void testFileRemoval() throws IOException {
    FileSystem fs = new MemoryFileSystem();
    Folder mres = fs.getFolder("src/main/java/org/domain");
    mres.create();
    File f1 = mres.getFile("MyClass.java");
    f1.create(new ByteArrayInputStream("ABC".getBytes()));
    assertTrue(f1.exists());
    assertEquals("ABC", StringUtils.toString(f1.getContents()));
    fs.remove(f1);
    f1 = mres.getFile("MyClass.java");
    assertFalse(f1.exists());
    try {
        f1.getContents();
        fail("Should throw IOException");
    } catch (IOException e) {
    }
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) ByteArrayInputStream(java.io.ByteArrayInputStream) FileSystem(org.drools.compiler.compiler.io.FileSystem) MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) IOException(java.io.IOException) Folder(org.drools.compiler.compiler.io.Folder) File(org.drools.compiler.compiler.io.File) Test(org.junit.Test)

Example 3 with MemoryFileSystem

use of org.drools.compiler.compiler.io.memory.MemoryFileSystem in project drools by kiegroup.

the class MemoryFileTest method testRelativeToBranchFilePath.

@Test
public void testRelativeToBranchFilePath() {
    FileSystem fs = new MemoryFileSystem();
    Folder mres = fs.getFolder("src/main/java/org/domain");
    Folder f2 = fs.getFolder("src/main/resources/org/domain/");
    File f1 = mres.getFile("MyClass.java");
    assertEquals("../../../java/org/domain/MyClass.java", f1.getPath().toRelativePortableString(f2.getPath()));
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) FileSystem(org.drools.compiler.compiler.io.FileSystem) MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) Folder(org.drools.compiler.compiler.io.Folder) File(org.drools.compiler.compiler.io.File) Test(org.junit.Test)

Example 4 with MemoryFileSystem

use of org.drools.compiler.compiler.io.memory.MemoryFileSystem 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.core.common.ResourceProvider) Test(org.junit.Test)

Example 5 with MemoryFileSystem

use of org.drools.compiler.compiler.io.memory.MemoryFileSystem in project drools by kiegroup.

the class MemoryKieModuleResourceProviderTest method testGetResourceAsStreamFolderWithOnlySubFolders.

@Test
public void testGetResourceAsStreamFolderWithOnlySubFolders() throws Exception {
    MemoryFileSystem mfs = new MemoryFileSystem();
    mfs.createFolder(new MemoryFolder(mfs, "src/main/java"));
    mfs.createFolder(new MemoryFolder(mfs, "src/main/java/org"));
    mfs.createFolder(new MemoryFolder(mfs, "src/main/java/com"));
    MemoryKieModule mkm = new MemoryKieModule(releaseId, kieModuleModel, mfs);
    ResourceProvider resourceProvider = mkm.createResourceProvider();
    String folderContents = IOUtils.toString(resourceProvider.getResourceAsStream("src/main/java"));
    Assertions.assertThat(folderContents).hasLineCount(2).contains("com", "org");
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) ResourceProvider(org.drools.core.common.ResourceProvider) MemoryFolder(org.drools.compiler.compiler.io.memory.MemoryFolder) 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