use of org.uberfire.backend.vfs.Path in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsHelperStandaloneImplTest method testGetImportXML.
@Test
public void testGetImportXML() throws java.io.IOException {
final String xml1 = "<some xml/>";
final String xml2 = "<some other xml/>";
final Metadata metadata = mock(Metadata.class);
final Import import1 = mock(Import.class);
final Path path1 = makePath("../file1.dmn");
final Path path2 = makePath("../file2.dmn");
// Mock loading of XML files in Project
final InputStream inputStream1 = mock(InputStream.class);
final InputStream inputStream2 = mock(InputStream.class);
final InputStreamReader inputStreamReader1 = mock(InputStreamReader.class);
final InputStreamReader inputStreamReader2 = mock(InputStreamReader.class);
final List<Path> paths = asList(path1, path2);
when(pathsHelper.getDMNModelsPaths(any())).thenReturn(paths);
when(dmnIOHelper.isAsString(inputStream1)).thenReturn(xml1);
when(dmnIOHelper.isAsString(inputStream2)).thenReturn(xml2);
doReturn(Optional.of(inputStream1)).when(helper).loadPath(path1);
doReturn(Optional.of(inputStream2)).when(helper).loadPath(path2);
doReturn(inputStreamReader1).when(helper).toInputStreamReader(inputStream1);
doReturn(inputStreamReader2).when(helper).toInputStreamReader(inputStream2);
// Mock retrieval of Definitions from XML files in Project
final StringReader stringReader1 = mock(StringReader.class);
final StringReader stringReader2 = mock(StringReader.class);
final Definitions definitions1 = mock(Definitions.class);
final Definitions definitions2 = mock(Definitions.class);
doReturn(stringReader1).when(helper).toStringReader(xml1);
doReturn(stringReader2).when(helper).toStringReader(xml2);
when(marshaller.unmarshal(stringReader1)).thenReturn(definitions1);
when(marshaller.unmarshal(stringReader2)).thenReturn(definitions2);
when(import1.getNamespace()).thenReturn("://namespace1");
when(definitions1.getNamespace()).thenReturn("://namespace1");
when(definitions2.getNamespace()).thenReturn("://namespace2-not-imported");
final List<Import> imports = Collections.singletonList(import1);
final Map<Import, String> importXML = helper.getImportXML(metadata, imports);
assertEquals(1, importXML.size());
assertEquals(xml1, importXML.get(import1));
}
use of org.uberfire.backend.vfs.Path in project kie-wb-common by kiegroup.
the class DMNPathsHelperImplTest method doTestGetPathsWhenWorkspaceProjectIsNotNull.
private void doTestGetPathsWhenWorkspaceProjectIsNotNull(final Function<WorkspaceProject, List<Path>> paths) {
final Path rootPath = mock(Path.class);
final String uri = "/src/path//project/root";
final RefactoringPageRow row1 = mock(RefactoringPageRow.class);
final RefactoringPageRow row2 = mock(RefactoringPageRow.class);
final RefactoringPageRow row3 = mock(RefactoringPageRow.class);
final List<RefactoringPageRow> rows = asList(row1, row2, row3);
final Path path1 = mock(Path.class);
final Path path2 = mock(Path.class);
final Path path3 = mock(Path.class);
when(workspaceProject.getRootPath()).thenReturn(rootPath);
when(rootPath.toURI()).thenReturn(uri);
when(refactoringQueryService.query(any(RefactoringPageRequest.class))).thenReturn(pageResponse);
when(pageResponse.getPageRowList()).thenReturn(rows);
when(row1.getValue()).thenReturn(path1);
when(row2.getValue()).thenReturn(path2);
when(row3.getValue()).thenReturn(path3);
final List<Path> result = paths.apply(workspaceProject);
assertEquals(3, result.size());
assertEquals(path1, result.get(0));
assertEquals(path2, result.get(1));
assertEquals(path3, result.get(2));
}
use of org.uberfire.backend.vfs.Path in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsHelperStandaloneImplTest method testGetOtherDMNDiagramsDefinitionsWhenProjectCannotBeFound.
@Test
public void testGetOtherDMNDiagramsDefinitionsWhenProjectCannotBeFound() {
final Metadata metadata = mock(Metadata.class);
final Path path1 = makePath("../file1.dmn");
final Path path2 = makePath("../file2.dmn");
final Path path3 = makePath("../file3.dmn");
final InputStream inputStream1 = mock(InputStream.class);
final InputStream inputStream2 = mock(InputStream.class);
final InputStream inputStream3 = mock(InputStream.class);
final InputStreamReader inputStreamReader1 = mock(InputStreamReader.class);
final InputStreamReader inputStreamReader2 = mock(InputStreamReader.class);
final InputStreamReader inputStreamReader3 = mock(InputStreamReader.class);
final Definitions definitions1 = mock(Definitions.class);
final Definitions definitions2 = mock(Definitions.class);
final Definitions definitions3 = mock(Definitions.class);
final List<Path> paths = asList(path1, path2, path3);
when(projectService.resolveProject(any(Path.class))).thenThrow(new NullPointerException());
when(pathsHelper.getDMNModelsPaths(any())).thenReturn(paths);
when(metadata.getPath()).thenReturn(path2);
doReturn(Optional.of(inputStream1)).when(helper).loadPath(path1);
doReturn(Optional.of(inputStream2)).when(helper).loadPath(path2);
doReturn(Optional.of(inputStream3)).when(helper).loadPath(path3);
doReturn(inputStreamReader1).when(helper).toInputStreamReader(inputStream1);
doReturn(inputStreamReader2).when(helper).toInputStreamReader(inputStream2);
doReturn(inputStreamReader3).when(helper).toInputStreamReader(inputStream3);
when(marshaller.unmarshal(inputStreamReader1)).thenReturn(definitions1);
when(marshaller.unmarshal(inputStreamReader2)).thenReturn(definitions2);
when(marshaller.unmarshal(inputStreamReader3)).thenReturn(definitions3);
final List<Definitions> actualDefinitions = helper.getOtherDMNDiagramsDefinitions(metadata);
final List<Definitions> expectedDefinitions = asList(definitions1, definitions3);
assertEquals(expectedDefinitions, actualDefinitions);
}
use of org.uberfire.backend.vfs.Path in project kie-wb-common by kiegroup.
the class FormGenerationIntegrationTest method init.
@Before
public void init() {
formModelHandlerManager = new TestFormModelHandlerManager(moduleService, moduleClassLoaderHelper, fieldManager, finderService);
when(pathModelReaderService.getModelReader(any())).thenReturn(new RuntimeDMOModelReader(moduleClassLoader, new RawMVELEvaluator()));
when(formFinderService.findFormsForType(anyString(), any())).then((Answer<List<FormDefinition>>) invocationOnMock -> {
String type = invocationOnMock.getArguments()[0].toString();
return Collections.singletonList(readFormDefinitionForType(type));
});
service = new BPMNVFSFormDefinitionGeneratorService(fieldManager, pathModelReaderService, formModelHandlerManager, formFinderService, formSerializer, ioService, commentedOptionFactory, formModelSynchronizationUtil);
when(moduleService.resolveModule(any())).thenReturn(module);
when(moduleClassLoaderHelper.getModuleClassLoader(any())).thenReturn(moduleClassLoader);
generator = new BPMNFormModelGeneratorImpl(moduleService, moduleClassLoaderHelper);
final Path rootPathWithNestedForms = PathFactory.newPath(DATA_OBJECTS_FOLDER, getUriOfResource(PREPARED_NESTED_FORMS_FOLDER));
;
processFormModel = generator.generateProcessFormModel(formGenerationProcessDefinitions, rootPathWithNestedForms);
taskFormModels = generator.generateTaskFormModels(formGenerationProcessDefinitions, rootPathWithNestedForms);
}
use of org.uberfire.backend.vfs.Path in project kie-wb-common by kiegroup.
the class DataSourceServicesHelper method getModuleDataSourcesContext.
/**
* Returns the path where data sources and drivers are located for a given module.
*/
public Path getModuleDataSourcesContext(final Module module) {
Path rootPath = module.getRootPath();
org.uberfire.java.nio.file.Path dataSourcesNioPath = Paths.convert(rootPath).resolve("src/main/resources/META-INF");
return Paths.convert(dataSourcesNioPath);
}
Aggregations