public static FileSystem convert(final org.uberfire.java.nio.file.FileSystem fs) { if (!cache.containsKey(fs)) { final Map<String, String> roots = new HashMap<>(); for (final org.uberfire.java.nio.file.Path root : fs.getRootDirectories()) { roots.put(root.toUri().toString(), root.getFileName() == null ? "/" : root.getFileName().toString()); } cache.put(fs, FileSystemFactory.newFS(roots, fs.supportedFileAttributeViews())); } return cache.get(fs); }
@Before public void setup() throws Exception { rootUri = new URI(ROOT_URI); when(fileSystem.supportedFileAttributeViews()).thenReturn(FS_ATTRIBUTES); when(rootPath.toUri()).thenReturn(rootUri); when(rootPath.getFileSystem()).thenReturn(fileSystem); doAnswer((Answer<org.uberfire.java.nio.file.Path>) invocationOnMock -> { final URI arg = (URI) invocationOnMock.getArguments()[0]; return arg.toURL().toString().equals(ROOT_URI) ? rootPath : null; }).when(ioService).get(any(URI.class)); tested = new VFSServicesServerImpl(ioService); }
public static Path convert(final org.uberfire.java.nio.file.Path path) { if (path == null) { return null; } if (path.getFileName() == null) { return newPath("/", path.toUri().toString(), new HashMap<String, Object>(1) {{ put(PathFactory.VERSION_PROPERTY, path.getFileSystem().supportedFileAttributeViews().contains("version")); }}); } return newPath(path.getFileName().toString(), path.toUri().toString(), new HashMap<String, Object>(1) {{ put(PathFactory.VERSION_PROPERTY, path.getFileSystem().supportedFileAttributeViews().contains("version")); }}); }
@Before public void setup() throws Exception { rootUri = new URI(ROOT_URI); when(fileSystem.supportedFileAttributeViews()).thenReturn(FS_ATTRIBUTES); when(rootPath.toUri()).thenReturn(rootUri); when(rootPath.getFileSystem()).thenReturn(fileSystem); doAnswer((Answer<org.uberfire.java.nio.file.Path>) invocationOnMock -> { final URI arg = (URI) invocationOnMock.getArguments()[0]; return arg.toURL().toString().equals(ROOT_URI) ? rootPath : null; }).when(ioService).get(any(URI.class)); tested = new VFSServicesServerImpl(ioService); }
public IOService getIOService() throws Exception { if (ioService == null) { ioService = mock(IOService.class); FileSystem fileSystem = mock(FileSystem.class); Iterable iterable = mock(Iterable.class); Iterator iterator = mock(Iterator.class); Path path = mock(Path.class); when(ioService.newFileSystem(any(URI.class), any(Map.class))).thenReturn(fileSystem); when(ioService.getFileSystem(any(URI.class))).thenReturn(fileSystem); when(fileSystem.getRootDirectories()).thenReturn(iterable); when(fileSystem.supportedFileAttributeViews()).thenReturn(new HashSet<String>()); when(iterable.iterator()).thenReturn(iterator); when(iterator.next()).thenReturn(path); when(path.resolve(anyString())).thenReturn(path); when(path.resolve(any(Path.class))).thenReturn(path); when(path.toUri()).thenReturn(new URI("uri")); when(path.getFileName()).thenReturn(path); when(path.getFileSystem()).thenReturn(fileSystem); } return ioService; } }
public IOService getIOService() throws Exception { if (ioService == null) { ioService = mock(IOService.class); FileSystem fileSystem = mock(FileSystem.class); Iterable iterable = mock(Iterable.class); Iterator iterator = mock(Iterator.class); Path path = mock(Path.class); when(ioService.newFileSystem(any(URI.class), any(Map.class))).thenReturn(fileSystem); when(ioService.getFileSystem(any(URI.class))).thenReturn(fileSystem); when(fileSystem.getRootDirectories()).thenReturn(iterable); when(fileSystem.supportedFileAttributeViews()).thenReturn(new HashSet<String>()); when(iterable.iterator()).thenReturn(iterator); when(iterator.next()).thenReturn(path); when(path.resolve(anyString())).thenReturn(path); when(path.resolve(any(Path.class))).thenReturn(path); when(path.toUri()).thenReturn(new URI("uri")); when(path.getFileName()).thenReturn(path); when(path.getFileSystem()).thenReturn(fileSystem); } return ioService; } }
@Before public void setup() { // attach test logging appender final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); logger.addAppender(mockAppender); // configure project and kmodule paths when(kmodulePath.toURI()).thenReturn("default://p0/Evaluation/src/main/resources/META-INF/kmodule.xml"); when(projectPath.toURI()).thenReturn("default://p0/Evaluation"); // configure deployment descriptor path when(ddPath.toUri()).thenReturn(URI.create("default://p0/Evaluation/src/main/resources/META-INF/kie-deployment-descriptor.xml")); when(ddPath.getParent()).thenReturn(Mockito.mock(Path.class)); FileSystem fileSystem = Mockito.mock(FileSystem.class); when(fileSystem.supportedFileAttributeViews()).thenReturn(new HashSet<String>()); when(ddPath.getFileSystem()).thenReturn(fileSystem); // configure services when(ioService.get(any(URI.class))).thenReturn(ddPath); when(ddEditorService.load(any())).thenReturn(new DeploymentDescriptorModel()); // configure the project when(kieModule.getKModuleXMLPath()).thenReturn(kmodulePath); when(kieModule.getRootPath()).thenReturn(projectPath); caseProjectService = new CaseProjectServiceImpl(ddEditorService, ioService); }
@Before public void setup() { // attach test logging appender final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); logger.addAppender(mockAppender); // configure project and kmodule paths when(kmodulePath.toURI()).thenReturn("default://p0/Evaluation/src/main/resources/META-INF/kmodule.xml"); when(projectPath.toURI()).thenReturn("default://p0/Evaluation"); // configure deployment descriptor path when(ddPath.toUri()).thenReturn(URI.create("default://p0/Evaluation/src/main/resources/META-INF/kie-deployment-descriptor.xml")); when(ddPath.getParent()).thenReturn(Mockito.mock(Path.class)); FileSystem fileSystem = Mockito.mock(FileSystem.class); when(fileSystem.supportedFileAttributeViews()).thenReturn(new HashSet<String>()); when(ddPath.getFileSystem()).thenReturn(fileSystem); // configure services when(ioService.get(any(URI.class))).thenReturn(ddPath); when(ddEditorService.load(any())).thenReturn(new DeploymentDescriptorModel()); // configure the project when(kieModule.getKModuleXMLPath()).thenReturn(kmodulePath); when(kieModule.getRootPath()).thenReturn(projectPath); caseProjectService = new CaseProjectServiceImpl(ddEditorService, ioService); }
@SuppressWarnings("unchecked") private WatchEvent<?> mockWatchEvent(WatchEvent.Kind kind, String originalPathURI, String newPathURI, String sessionId, String userId, String commitMessage) throws URISyntaxException { WatchEvent<?> event = mock(WatchEvent.class); when(event.kind()).thenReturn(kind); FileSystem fileSystem = mock(FileSystem.class); Set<String> supportedViews = new HashSet<>(); when(fileSystem.supportedFileAttributeViews()).thenReturn(supportedViews); WatchContext context = mock(WatchContext.class); when(context.getSessionId()).thenReturn(sessionId); when(context.getUser()).thenReturn(userId); when(context.getMessage()).thenReturn(commitMessage); Path oldPath = mock(Path.class); URI oldPathUri = new URI(originalPathURI); when(oldPath.toUri()).thenReturn(oldPathUri); when(oldPath.getFileSystem()).thenReturn(fileSystem); Path path = mock(Path.class); URI pathUri = new URI(newPathURI); when(path.toUri()).thenReturn(pathUri); when(path.getFileSystem()).thenReturn(fileSystem); when(context.getOldPath()).thenReturn(oldPath); when(context.getPath()).thenReturn(path); when(event.context()).thenReturn(context); return event; }
@SuppressWarnings("unchecked") private WatchEvent<?> mockWatchEvent(WatchEvent.Kind kind, String originalPathURI, String newPathURI, String sessionId, String userId, String commitMessage) throws URISyntaxException { WatchEvent<?> event = mock(WatchEvent.class); when(event.kind()).thenReturn(kind); FileSystem fileSystem = mock(FileSystem.class); Set<String> supportedViews = new HashSet<>(); when(fileSystem.supportedFileAttributeViews()).thenReturn(supportedViews); WatchContext context = mock(WatchContext.class); when(context.getSessionId()).thenReturn(sessionId); when(context.getUser()).thenReturn(userId); when(context.getMessage()).thenReturn(commitMessage); Path oldPath = mock(Path.class); URI oldPathUri = new URI(originalPathURI); when(oldPath.toUri()).thenReturn(oldPathUri); when(oldPath.getFileSystem()).thenReturn(fileSystem); Path path = mock(Path.class); URI pathUri = new URI(newPathURI); when(path.toUri()).thenReturn(pathUri); when(path.getFileSystem()).thenReturn(fileSystem); when(context.getOldPath()).thenReturn(oldPath); when(context.getPath()).thenReturn(path); when(event.context()).thenReturn(context); return event; }
when(discoveryService.discoverFiles(any(), any())).thenReturn(new ArrayList<Path>()); when(fileSystem.supportedFileAttributeViews()).thenReturn(new HashSet<String>()); when(path.getFileSystem()).thenReturn(fileSystem); when(path.toString()).thenReturn("/");
when(discoveryService.discoverFiles(any(), any())).thenReturn(new ArrayList<Path>()); when(fileSystem.supportedFileAttributeViews()).thenReturn(new HashSet<String>()); when(path.getFileSystem()).thenReturn(fileSystem); when(path.toString()).thenReturn("/");
assertThat(fileSystem.getSeparator()).isEqualTo(System.getProperty("file.separator")); assertThat(fileSystem.provider()).isEqualTo(fsProvider); Assertions.assertThat(fileSystem.supportedFileAttributeViews()).hasSize(1).contains("basic");
assertThat(fileSystem.getSeparator()).isEqualTo(System.getProperty("file.separator")); assertThat(fileSystem.provider()).isEqualTo(fsProvider); Assertions.assertThat(fileSystem.supportedFileAttributeViews()).hasSize(1).contains("basic");
assertThat(fileSystem.getSeparator()).isEqualTo("\\"); assertThat(fileSystem.provider()).isEqualTo(fsProvider); Assertions.assertThat(fileSystem.supportedFileAttributeViews()).hasSize(1).contains("basic");
assertThat(fileSystem.getSeparator()).isEqualTo("\\"); assertThat(fileSystem.provider()).isEqualTo(fsProvider); Assertions.assertThat(fileSystem.supportedFileAttributeViews()).hasSize(1).contains("basic");