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