Search in sources :

Example 11 with IOService

use of org.uberfire.io.IOService in project kie-wb-common by kiegroup.

the class BPMFinderServiceImplTest method initialize.

@Before
public void initialize() throws URISyntaxException, ClassNotFoundException {
    when(ioService.newDirectoryStream(any(), any())).thenAnswer(invocationOnMock -> Files.newDirectoryStream((Path) invocationOnMock.getArguments()[0], (DirectoryStream.Filter<Path>) invocationOnMock.getArguments()[1]));
    when(ioService.newInputStream(any())).thenAnswer(invocationOnMock -> new FileInputStream(((Path) invocationOnMock.getArguments()[0]).toFile()));
    simpleFileSystemProvider = new SimpleFileSystemProvider();
    simpleFileSystemProvider.forceAsDefault();
    rootPath = simpleFileSystemProvider.getPath(this.getClass().getResource(RESOURCES_PATH).toURI());
    when(moduleService.resolveModule(any())).thenReturn(module);
    when(module.getRootPath()).thenReturn(Paths.convert(rootPath));
    when(classLoader.loadClass(any())).thenAnswer((Answer<Class>) invocation -> String.class);
    when(moduleClassLoaderHelper.getModuleClassLoader(any())).thenReturn(classLoader);
    bpmnFormModelGenerator = new BPMNFormModelGeneratorImpl(moduleService, moduleClassLoaderHelper);
    finderService = new BPMFinderServiceImpl(ioService, moduleService, bpmnFormModelGenerator);
    finderService.init();
}
Also used : Path(org.uberfire.java.nio.file.Path) SimpleFileSystemProvider(org.uberfire.java.nio.fs.file.SimpleFileSystemProvider) ModuleClassLoaderHelper(org.kie.workbench.common.services.backend.project.ModuleClassLoaderHelper) Mock(org.mockito.Mock) Path(org.uberfire.java.nio.file.Path) Assert.assertNotNull(org.junit.Assert.assertNotNull) URISyntaxException(java.net.URISyntaxException) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) KieModule(org.kie.workbench.common.services.shared.project.KieModule) FileInputStream(java.io.FileInputStream) Mockito.when(org.mockito.Mockito.when) JBPMProcessModel(org.kie.workbench.common.forms.jbpm.model.authoring.JBPMProcessModel) Files(org.uberfire.java.nio.file.Files) Paths(org.uberfire.backend.server.util.Paths) Matchers.any(org.mockito.Matchers.any) Answer(org.mockito.stubbing.Answer) List(java.util.List) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) SimpleFileSystemProvider(org.uberfire.java.nio.fs.file.SimpleFileSystemProvider) IOService(org.uberfire.io.IOService) DirectoryStream(org.uberfire.java.nio.file.DirectoryStream) Assert.fail(org.junit.Assert.fail) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 12 with IOService

use of org.uberfire.io.IOService in project kie-wb-common by kiegroup.

the class FormsMigrationTool method systemMigrationWasExecuted.

private boolean systemMigrationWasExecuted() {
    final IOService systemIoService = migrationServicesCDIWrapper.getSystemIoService();
    final Repository systemRepository = migrationServicesCDIWrapper.getSystemRepository();
    if (!systemIoService.exists(systemIoService.get(systemRepository.getUri()).resolve("spaces"))) {
        system.err().println(String.format("The SYSTEM CONFIGURATION DIRECTORY STRUCTURE MIGRATION must be ran before this one."));
        return false;
    }
    return true;
}
Also used : Repository(org.guvnor.structure.repositories.Repository) IOService(org.uberfire.io.IOService)

Example 13 with IOService

use of org.uberfire.io.IOService in project kie-wb-common by kiegroup.

the class ConfigGroupsMigrationServiceTest method mockIoService.

private IOService mockIoService() {
    final IOService ioService = spy(fileSystemTestingUtils.getIoService());
    doNothing().when(ioService).startBatch(any(FileSystem.class));
    doNothing().when(ioService).endBatch();
    return ioService;
}
Also used : IOService(org.uberfire.io.IOService) FileSystem(org.uberfire.java.nio.file.FileSystem)

Example 14 with IOService

use of org.uberfire.io.IOService in project kie-wb-common by kiegroup.

the class ModuleFormFinderServiceImpl method findForms.

private List<FormDefinition> findForms(final Path path, final Predicate<FormDefinition> predicate) {
    KieModule module = moduleService.resolveModule(path);
    org.uberfire.java.nio.file.Path nioPath = Paths.convert(module.getRootPath());
    List<FormDefinition> moduleForms = VFSScanner.scan(ioService, nioPath, Collections.singleton(FormResourceTypeDefinition.EXTENSION), this::convert, predicate).stream().map(VFSScanner.ScanResult::getResource).filter(Objects::nonNull).collect(Collectors.toList());
    List<String> moduleFormsIds = moduleForms.stream().map(FormDefinition::getId).collect(Collectors.toList());
    Map<String, String> dependenciesForms = buildInfoService.getBuildInfo(module).getKieModuleMetaDataIgnoringErrors().getForms();
    return dependenciesForms.values().stream().map(serializer::deserialize).filter(predicate).filter(formDefinition -> !moduleFormsIds.contains(formDefinition)).collect(Collectors.toCollection(() -> moduleForms));
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) FormDefinitionSerializer(org.kie.workbench.common.forms.services.backend.serialization.FormDefinitionSerializer) JavaFormModel(org.kie.workbench.common.forms.model.JavaFormModel) Paths(org.uberfire.backend.server.util.Paths) Inject(javax.inject.Inject) Charset(java.nio.charset.Charset) KieModuleService(org.kie.workbench.common.services.shared.project.KieModuleService) Map(java.util.Map) Service(org.jboss.errai.bus.server.annotations.Service) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) Named(javax.inject.Named) Path(org.uberfire.backend.vfs.Path) BuildInfoService(org.kie.workbench.common.services.backend.builder.service.BuildInfoService) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) ModuleFormFinderService(org.kie.workbench.common.forms.editor.service.shared.ModuleFormFinderService) IOException(java.io.IOException) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) VFSScanner(org.kie.workbench.common.forms.services.backend.util.VFSScanner) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) FormResourceTypeDefinition(org.kie.workbench.common.forms.editor.type.FormResourceTypeDefinition) Dependent(javax.enterprise.context.Dependent) IOService(org.uberfire.io.IOService) Collections(java.util.Collections) InputStream(java.io.InputStream) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) KieModule(org.kie.workbench.common.services.shared.project.KieModule)

Example 15 with IOService

use of org.uberfire.io.IOService in project kie-wb-common by kiegroup.

the class AbstractFormDefinitionHelperTest method init.

@Before
public void init() throws IOException {
    simpleFileSystemProvider = new SimpleFileSystemProvider();
    simpleFileSystemProvider.forceAsDefault();
    serializer = spy(new FormDefinitionSerializerImpl(new FieldSerializer(), new FormModelSerializer(), new TestMetaDataEntryManager()));
    when(originalPath.getFileName()).thenReturn(ORIGNAL_FORM_ASSET_NAME);
    when(destinationPath.getFileName()).thenReturn(DESTINATION_FORM_ASSET_NAME);
    when(destinationPath.toURI()).thenReturn(DESTINATION_FORM_PATH);
    when(ioService.readAllString(any())).thenReturn(IOUtils.toString(new InputStreamReader(this.getClass().getResourceAsStream(ORIGINAL_FORM_PATH))));
    doAnswer((Answer<FormDefinition>) invocationOnMock -> {
        FormDefinition formDefinition = (FormDefinition) invocationOnMock.callRealMethod();
        beforeProcess(formDefinition);
        return formDefinition;
    }).when(serializer).deserialize(Mockito.<String>any());
    helper = getHelper(ioService, serializer, commentedOptionFactory);
}
Also used : SimpleFileSystemProvider(org.uberfire.java.nio.fs.file.SimpleFileSystemProvider) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) FormDefinitionSerializer(org.kie.workbench.common.forms.services.backend.serialization.FormDefinitionSerializer) Mockito.spy(org.mockito.Mockito.spy) Answer(org.mockito.stubbing.Answer) CommentedOptionFactory(org.guvnor.common.services.backend.util.CommentedOptionFactory) FormDefinitionSerializerImpl(org.kie.workbench.common.forms.services.backend.serialization.impl.FormDefinitionSerializerImpl) SimpleFileSystemProvider(org.uberfire.java.nio.fs.file.SimpleFileSystemProvider) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Assertions(org.assertj.core.api.Assertions) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) FormModelSerializer(org.kie.workbench.common.forms.services.backend.serialization.impl.FormModelSerializer) FieldSerializer(org.kie.workbench.common.forms.services.backend.serialization.impl.FieldSerializer) Path(org.uberfire.backend.vfs.Path) Before(org.junit.Before) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) InputStreamReader(java.io.InputStreamReader) Mockito.verify(org.mockito.Mockito.verify) IOUtils(org.apache.commons.io.IOUtils) Mockito(org.mockito.Mockito) FormResourceTypeDefinition(org.kie.workbench.common.forms.editor.type.FormResourceTypeDefinition) IOService(org.uberfire.io.IOService) TestMetaDataEntryManager(org.kie.workbench.common.forms.fields.test.TestMetaDataEntryManager) Mockito.mock(org.mockito.Mockito.mock) FieldSerializer(org.kie.workbench.common.forms.services.backend.serialization.impl.FieldSerializer) InputStreamReader(java.io.InputStreamReader) FormDefinitionSerializerImpl(org.kie.workbench.common.forms.services.backend.serialization.impl.FormDefinitionSerializerImpl) FormModelSerializer(org.kie.workbench.common.forms.services.backend.serialization.impl.FormModelSerializer) FormDefinition(org.kie.workbench.common.forms.model.FormDefinition) TestMetaDataEntryManager(org.kie.workbench.common.forms.fields.test.TestMetaDataEntryManager) Before(org.junit.Before)

Aggregations

IOService (org.uberfire.io.IOService)25 Before (org.junit.Before)18 Test (org.junit.Test)15 IOException (java.io.IOException)14 Mock (org.mockito.Mock)14 RunWith (org.junit.runner.RunWith)13 List (java.util.List)12 Paths (org.uberfire.backend.server.util.Paths)12 Mockito (org.mockito.Mockito)11 Path (org.uberfire.backend.vfs.Path)11 File (java.io.File)10 InputStream (java.io.InputStream)10 ArrayList (java.util.ArrayList)10 Collections (java.util.Collections)10 URI (java.net.URI)9 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)9 Logger (org.slf4j.Logger)9 Path (org.uberfire.java.nio.file.Path)9 Arrays (java.util.Arrays)8 LoggerFactory (org.slf4j.LoggerFactory)8