Search in sources :

Example 6 with FileSystem

use of org.drools.compiler.compiler.io.FileSystem in project drools by kiegroup.

the class MemoryFolderTest method testFolderGetParent.

@Test
public void testFolderGetParent() {
    FileSystem fs = new MemoryFileSystem();
    Folder mres = fs.getFolder("src/main/resources");
    mres.create();
    assertEquals("src/main", mres.getParent().getPath().toPortableString());
    assertEquals("src", mres.getParent().getParent().getPath().toPortableString());
}
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) MemoryFolder(org.drools.compiler.compiler.io.memory.MemoryFolder) Test(org.junit.Test)

Example 7 with FileSystem

use of org.drools.compiler.compiler.io.FileSystem in project drools by kiegroup.

the class MemoryFolderTest method testNestedRelativePathReverseArguments.

@Test
public void testNestedRelativePathReverseArguments() {
    FileSystem fs = new MemoryFileSystem();
    Folder f1 = fs.getFolder("src/main/java/org");
    Folder f2 = fs.getFolder("src/main/java/");
    f1.create();
    f2.create();
    assertEquals("..", f2.getPath().toRelativePortableString(f1.getPath()));
    fs = new MemoryFileSystem();
    f1 = fs.getFolder("src/main/java/org/drools/reteoo");
    f2 = fs.getFolder("src/main/java");
    f1.create();
    f2.create();
    assertEquals("../../..", f2.getPath().toRelativePortableString(f1.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) MemoryFolder(org.drools.compiler.compiler.io.memory.MemoryFolder) Test(org.junit.Test)

Example 8 with FileSystem

use of org.drools.compiler.compiler.io.FileSystem 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 9 with FileSystem

use of org.drools.compiler.compiler.io.FileSystem in project drools by kiegroup.

the class MemoryFileTest method testFileCreation.

@Test
public void testFileCreation() throws IOException {
    FileSystem fs = new MemoryFileSystem();
    Folder mres = fs.getFolder("src/main/java/org/domain");
    File f1 = mres.getFile("MyClass.java");
    f1.create(new ByteArrayInputStream("ABC".getBytes()));
    mres.create();
    f1 = mres.getFile("MyClass.java");
    assertTrue(f1.exists());
    f1.create(new ByteArrayInputStream("ABC".getBytes()));
    f1 = mres.getFile("MyClass.java");
    assertTrue(f1.exists());
    assertEquals("ABC", StringUtils.toString(f1.getContents()));
    f1.create(new ByteArrayInputStream("ABC".getBytes()));
    f1.setContents(new ByteArrayInputStream("DEF".getBytes()));
    assertEquals("DEF", StringUtils.toString(f1.getContents()));
}
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) Folder(org.drools.compiler.compiler.io.Folder) File(org.drools.compiler.compiler.io.File) Test(org.junit.Test)

Example 10 with FileSystem

use of org.drools.compiler.compiler.io.FileSystem in project drools by kiegroup.

the class MemoryFolderTest method testRecursiveFolderCreation.

@Test
public void testRecursiveFolderCreation() {
    FileSystem fs = new MemoryFileSystem();
    Folder mres = fs.getFolder("src/main/resources");
    assertFalse(mres.exists());
    mres.create();
    assertTrue(mres.exists());
    Folder fld = fs.getFolder("src/main");
    assertTrue(fld.exists());
    Folder src = fs.getFolder("src");
    assertTrue(src.exists());
}
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) MemoryFolder(org.drools.compiler.compiler.io.memory.MemoryFolder) Test(org.junit.Test)

Aggregations

FileSystem (org.drools.compiler.compiler.io.FileSystem)17 Folder (org.drools.compiler.compiler.io.Folder)17 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)17 Test (org.junit.Test)17 File (org.drools.compiler.compiler.io.File)10 MemoryFolder (org.drools.compiler.compiler.io.memory.MemoryFolder)9 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IOException (java.io.IOException)2