use of org.drools.wiring.api.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.wiring.api.ResourceProvider 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, KiePath.of("src/main/java")));
mfs.createFolder(new MemoryFolder(mfs, KiePath.of("src/main/java/org")));
mfs.createFolder(new MemoryFolder(mfs, KiePath.of("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");
}
use of org.drools.wiring.api.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, KiePath.of("src/main/java")));
mfs.createFolder(new MemoryFolder(mfs, KiePath.of("src/main/java/org")));
mfs.createFolder(new MemoryFolder(mfs, KiePath.of("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");
}
use of org.drools.wiring.api.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, KiePath.of("src/main/java")));
mfs.createFolder(new MemoryFolder(mfs, KiePath.of("src/main/java/org")));
mfs.createFolder(new MemoryFolder(mfs, KiePath.of("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.wiring.api.ResourceProvider 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, KiePath.of("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();
}
Aggregations