Search in sources :

Example 1 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 2 with FileSystem

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

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

the class MemoryFolderTest method testNestedRelativeDifferentPath.

@Test
public void testNestedRelativeDifferentPath() {
    FileSystem fs = new MemoryFileSystem();
    Folder f1 = fs.getFolder("src/main/java");
    Folder f2 = fs.getFolder("src/main/resources");
    f1.create();
    f2.create();
    assertEquals("../resources", f2.getPath().toRelativePortableString(f1.getPath()));
    fs = new MemoryFileSystem();
    f1 = fs.getFolder("src/main/java/org/drools");
    f2 = fs.getFolder("src/main/resources/org/drools/reteoo");
    f1.create();
    f2.create();
    assertEquals("../../../resources/org/drools/reteoo", 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 4 with FileSystem

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

the class MemoryFolderTest method testFolderRemoval.

@Test
public void testFolderRemoval() throws IOException {
    FileSystem fs = new MemoryFileSystem();
    Folder fld = fs.getFolder("src/main/resources/org/domain");
    fld.create();
    fld = fs.getFolder("src/main");
    File file = fld.getFile("MyClass1.java");
    file.create(new ByteArrayInputStream("ABC1".getBytes()));
    file = fld.getFile("MyClass2.java");
    file.create(new ByteArrayInputStream("ABC2".getBytes()));
    fld = fs.getFolder("src/main/resources/org");
    file = fld.getFile("MyClass3.java");
    file.create(new ByteArrayInputStream("ABC3".getBytes()));
    file = fld.getFile("MyClass4.java");
    file.create(new ByteArrayInputStream("ABC4".getBytes()));
    fld = fs.getFolder("src/main/resources/org/domain");
    file = fld.getFile("MyClass4.java");
    file.create(new ByteArrayInputStream("ABC5".getBytes()));
    assertTrue(fs.getFolder("src/main").exists());
    assertTrue(fs.getFile("src/main/MyClass1.java").exists());
    assertTrue(fs.getFile("src/main/MyClass2.java").exists());
    assertTrue(fs.getFile("src/main/resources/org/MyClass3.java").exists());
    assertTrue(fs.getFile("src/main/resources/org/MyClass4.java").exists());
    assertTrue(fs.getFile("src/main/resources/org/domain/MyClass4.java").exists());
    fs.remove(fs.getFolder("src/main"));
    assertFalse(fs.getFolder("src/main").exists());
    assertFalse(fs.getFile("src/main/MyClass1.java").exists());
    assertFalse(fs.getFile("src/main/MyClass2.java").exists());
    assertFalse(fs.getFile("src/main/resources/org/MyClass3.java").exists());
    assertFalse(fs.getFile("src/main/resources/org/MyClass4.java").exists());
    assertFalse(fs.getFile("src/main/resources/org/domain/MyClass4.java").exists());
}
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) MemoryFolder(org.drools.compiler.compiler.io.memory.MemoryFolder) File(org.drools.compiler.compiler.io.File) Test(org.junit.Test)

Example 5 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