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