Search in sources :

Example 1 with MemoryFolder

use of org.drools.compiler.compiler.io.memory.MemoryFolder 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)

Example 2 with MemoryFolder

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

the class MemoryKieModuleResourceProviderTest method testGetResourceForFolderWithFilesAndSubFolders.

@Test
public void testGetResourceForFolderWithFilesAndSubFolders() 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"));
    mfs.setFileContents(new MemoryFile(mfs, "my-file1", mfs.getFolder("src/main/java")), new byte[10]);
    mfs.setFileContents(new MemoryFile(mfs, "my-file2", mfs.getFolder("src/main/java")), new byte[10]);
    MemoryKieModule mkm = new MemoryKieModule(releaseId, kieModuleModel, mfs);
    ResourceProvider resourceProvider = mkm.createResourceProvider();
    String folderContents = IOUtils.toString(resourceProvider.getResource("src/main/java").openStream());
    Assertions.assertThat(folderContents).hasLineCount(4).contains("com", "org", "my-file1", "my-file2");
}
Also used : MemoryFile(org.drools.compiler.compiler.io.memory.MemoryFile) 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)

Example 3 with MemoryFolder

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

the class MemoryKieModuleResourceProviderTest method testGetResourceForFolderWithOnlySubFolders.

@Test
public void testGetResourceForFolderWithOnlySubFolders() 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.getResource("src/main/java").openStream());
    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)

Example 4 with MemoryFolder

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

the class MemoryKieModuleResourceProviderTest method testGetResourceForEmptyFolder.

@Test
public void testGetResourceForEmptyFolder() throws Exception {
    MemoryFileSystem mfs = new MemoryFileSystem();
    mfs.createFolder(new MemoryFolder(mfs, "src/main/java"));
    MemoryKieModule mkm = new MemoryKieModule(releaseId, kieModuleModel, mfs);
    ResourceProvider resourceProvider = mkm.createResourceProvider();
    String folderContents = IOUtils.toString(resourceProvider.getResource("src/main/java").openStream());
    Assertions.assertThat(folderContents).isEmpty();
}
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)

Example 5 with MemoryFolder

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

the class MemoryFolderTest method testGetParentWithLeadingAndTrailingSlash.

@Test
public void testGetParentWithLeadingAndTrailingSlash() {
    MemoryFileSystem mfs = new MemoryFileSystem();
    assertEquals("", new MemoryFolder(mfs, "/src").getParent().getPath().toPortableString());
    assertEquals("", new MemoryFolder(mfs, "src/").getParent().getPath().toPortableString());
    assertEquals("", new MemoryFolder(mfs, "/src/").getParent().getPath().toPortableString());
    assertEquals("src", new MemoryFolder(mfs, "/src/main").getParent().getPath().toPortableString());
    assertEquals("src", new MemoryFolder(mfs, "src/main/").getParent().getPath().toPortableString());
    assertEquals("src", new MemoryFolder(mfs, "/src/main/").getParent().getPath().toPortableString());
    assertEquals("src/main", new MemoryFolder(mfs, "/src/main/java").getParent().getPath().toPortableString());
    assertEquals("src/main", new MemoryFolder(mfs, "src/main/java/").getParent().getPath().toPortableString());
    assertEquals("src/main", new MemoryFolder(mfs, "/src/main/java/").getParent().getPath().toPortableString());
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) MemoryFolder(org.drools.compiler.compiler.io.memory.MemoryFolder) Test(org.junit.Test)

Aggregations

MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)5 MemoryFolder (org.drools.compiler.compiler.io.memory.MemoryFolder)5 Test (org.junit.Test)5 ResourceProvider (org.drools.core.common.ResourceProvider)4 MemoryFile (org.drools.compiler.compiler.io.memory.MemoryFile)1