Search in sources :

Example 1 with ResourceProvider

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;
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) Field(java.lang.reflect.Field) KieRepository(org.kie.api.builder.KieRepository) ResourceProvider(org.drools.wiring.api.ResourceProvider) KieRepositoryImpl(org.drools.compiler.kie.builder.impl.KieRepositoryImpl) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) KieModuleKieProject(org.drools.compiler.kie.builder.impl.KieModuleKieProject) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 2 with ResourceProvider

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");
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) ResourceProvider(org.drools.wiring.api.ResourceProvider) MemoryKieModule(org.drools.compiler.kie.builder.impl.MemoryKieModule) MemoryFolder(org.drools.compiler.compiler.io.memory.MemoryFolder) Test(org.junit.Test)

Example 3 with ResourceProvider

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");
}
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) MemoryFolder(org.drools.compiler.compiler.io.memory.MemoryFolder) Test(org.junit.Test)

Example 4 with ResourceProvider

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");
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) ResourceProvider(org.drools.wiring.api.ResourceProvider) MemoryKieModule(org.drools.compiler.kie.builder.impl.MemoryKieModule) MemoryFolder(org.drools.compiler.compiler.io.memory.MemoryFolder) Test(org.junit.Test)

Example 5 with ResourceProvider

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();
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) ResourceProvider(org.drools.wiring.api.ResourceProvider) MemoryKieModule(org.drools.compiler.kie.builder.impl.MemoryKieModule) MemoryFolder(org.drools.compiler.compiler.io.memory.MemoryFolder) 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