Search in sources :

Example 1 with ResourceProvider

use of org.drools.core.common.ResourceProvider 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 2 with ResourceProvider

use of org.drools.core.common.ResourceProvider 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 3 with ResourceProvider

use of org.drools.core.common.ResourceProvider in project drools by kiegroup.

the class MemoryKieModuleResourceProviderTest method testGetResourceTrailingSlashIgnored.

@Test
public void testGetResourceTrailingSlashIgnored() 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 noTrailingSlashContents = IOUtils.toString(resourceProvider.getResourceAsStream("src/main/resources/my-file1"));
    // "AB" == new byte[] {65, 66}
    Assertions.assertThat(noTrailingSlashContents).hasLineCount(1).contains("AB");
    String withTrailingSlashContents = IOUtils.toString(resourceProvider.getResourceAsStream("src/main/resources/my-file1/"));
    // "AB" == new byte[] {65, 66}
    Assertions.assertThat(withTrailingSlashContents).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 4 with ResourceProvider

use of org.drools.core.common.ResourceProvider in project drools by kiegroup.

the class KieModuleRepoTest method createMockKieContainer.

private static KieContainerImpl createMockKieContainer(final ReleaseId projectReleaseId, final KieModuleRepo kieModuleRepo) throws Exception {
    // kie module
    final InternalKieModule mockKieProjectKieModule = mock(InternalKieModule.class);
    final ResourceProvider mockKieProjectKieModuleResourceProvider = mock(ResourceProvider.class);
    when(mockKieProjectKieModule.createResourceProvider()).thenReturn(mockKieProjectKieModuleResourceProvider);
    // kie project
    final KieModuleKieProject kieProject = new KieModuleKieProject(mockKieProjectKieModule);
    final KieModuleKieProject mockKieProject = spy(kieProject);
    doNothing().when(mockKieProject).init();
    doReturn(projectReleaseId).when(mockKieProject).getGAV();
    doReturn(new HashMap<String, KieBaseModel>()).when(mockKieProject).updateToModule(any(InternalKieModule.class));
    // kie repository
    final KieRepository kieRepository = new KieRepositoryImpl();
    final Field kieModuleRepoField = KieRepositoryImpl.class.getDeclaredField("kieModuleRepo");
    kieModuleRepoField.setAccessible(true);
    kieModuleRepoField.set(kieRepository, kieModuleRepo);
    kieModuleRepoField.setAccessible(false);
    // kie container
    final KieContainerImpl kieContainerImpl = new KieContainerImpl(mockKieProject, kieRepository);
    return kieContainerImpl;
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) Field(java.lang.reflect.Field) KieRepository(org.kie.api.builder.KieRepository) ResourceProvider(org.drools.core.common.ResourceProvider)

Example 5 with ResourceProvider

use of org.drools.core.common.ResourceProvider 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)

Aggregations

ResourceProvider (org.drools.core.common.ResourceProvider)7 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)6 Test (org.junit.Test)6 MemoryFolder (org.drools.compiler.compiler.io.memory.MemoryFolder)4 MemoryFile (org.drools.compiler.compiler.io.memory.MemoryFile)3 Field (java.lang.reflect.Field)1 KieRepository (org.kie.api.builder.KieRepository)1 KieBaseModel (org.kie.api.builder.model.KieBaseModel)1