Search in sources :

Example 6 with ResourceProvider

use of org.drools.wiring.api.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.wiring.api.ResourceProvider) MemoryKieModule(org.drools.compiler.kie.builder.impl.MemoryKieModule) Test(org.junit.Test)

Example 7 with ResourceProvider

use of org.drools.wiring.api.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.wiring.api.ResourceProvider) MemoryKieModule(org.drools.compiler.kie.builder.impl.MemoryKieModule) Test(org.junit.Test)

Aggregations

ResourceProvider (org.drools.wiring.api.ResourceProvider)7 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)6 MemoryKieModule (org.drools.compiler.kie.builder.impl.MemoryKieModule)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 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)1 KieContainerImpl (org.drools.compiler.kie.builder.impl.KieContainerImpl)1 KieModuleKieProject (org.drools.compiler.kie.builder.impl.KieModuleKieProject)1 KieRepositoryImpl (org.drools.compiler.kie.builder.impl.KieRepositoryImpl)1 KieRepository (org.kie.api.builder.KieRepository)1 KieBaseModel (org.kie.api.builder.model.KieBaseModel)1