private JGitFileSystem newFileSystem(Map<String, String> fullHostNames, Git git, String fsName, CredentialsProvider credential, JGitFileSystemsEventsManager fsEventsManager, Map<FileSystemHooks, ?> fsHooks) { fileSystemsLocks.putIfAbsent(fsName, createLock(git)); final JGitFileSystem fs = new JGitFileSystemImpl(jGitFileSystemProvider, fullHostNames, git, fileSystemsLocks.get(fsName), fsName, credential, fsEventsManager, fsHooks); fs.getGit().gc(); return fs; }
@Test public void testOnlyLocalRoot() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.getRootDirectories()).hasSize(1); final Path root = fileSystem.getRootDirectories().iterator().next(); assertThat(root.toString()).isEqualTo("/"); assertThat(root.getRoot().toString()).isEqualTo("/"); }
@Test public void testProvider() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.provider()).isEqualTo(fsProvider); }
@Test public void testOnlyLocalRoot() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.getRootDirectories()).hasSize(1); final Path root = fileSystem.getRootDirectories().iterator().next(); assertThat(root.toString()).isEqualTo("/"); assertThat(root.getRoot().toString()).isEqualTo("/"); }
@Test public void testProvider() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.provider()).isEqualTo(fsProvider); }
@Test public void testPathNonBranchNonRooted() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); when(fsProvider.isDefault()).thenReturn(false); when(fsProvider.getScheme()).thenReturn("git"); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); final Path path = fileSystem.getPath("path/to/some/place.txt"); AssertionsForClassTypes.assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isFalse(); assertThat(path.toString()).isEqualTo("path/to/some/place.txt"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-repo/:path/to/some/place.txt"); assertThat(path.getNameCount()).isEqualTo(4); assertThat(path.getName(0).toString()).isNotNull().isEqualTo("path"); assertThat(path.getRoot().toString()).isNotNull().isEqualTo(""); }
@Test public void testPathNonBranchRooted() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); when(fsProvider.isDefault()).thenReturn(false); when(fsProvider.getScheme()).thenReturn("git"); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); final Path path = fileSystem.getPath("/path/to/some/place.txt"); AssertionsForClassTypes.assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/path/to/some/place.txt"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-repo/path/to/some/place.txt"); assertThat(path.getNameCount()).isEqualTo(4); assertThat(path.getName(0).toString()).isNotNull().isEqualTo("path"); assertThat(path.getRoot().toString()).isNotNull().isEqualTo("/"); }
@Test public void testFileStore() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final File tempDir = createTempDirectory(); final Git git = setupGit(tempDir); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.getFileStores()).hasSize(1); final FileStore fileStore = fileSystem.getFileStores().iterator().next(); assertThat(fileStore).isNotNull(); assertThat(fileStore.getTotalSpace()).isEqualTo(tempDir.getTotalSpace()); assertThat(fileStore.getUsableSpace()).isEqualTo(tempDir.getUsableSpace()); }
@Test public void testFileStore() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final File tempDir = createTempDirectory(); final Git git = setupGit(tempDir); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.getFileStores()).hasSize(1); final FileStore fileStore = fileSystem.getFileStores().iterator().next(); assertThat(fileStore).isNotNull(); assertThat(fileStore.getTotalSpace()).isEqualTo(tempDir.getTotalSpace()); assertThat(fileStore.getUsableSpace()).isEqualTo(tempDir.getUsableSpace()); }
@Test public void testSupportedFileAttributeViews() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.supportedFileAttributeViews()).isNotEmpty().hasSize(2).contains("basic", "version"); }
@Test public void testSupportedFileAttributeViews() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.supportedFileAttributeViews()).isNotEmpty().hasSize(2).contains("basic", "version"); }
@Test(expected = UnsupportedOperationException.class) public void testGetPathMatcher() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); fileSystem.getPathMatcher("*"); }
@Test(expected = IllegalStateException.class) public void testClose() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.isOpen()).isTrue(); assertThat(fileSystem.getFileStores()).isNotNull(); fileSystem.close(); assertThat(fileSystem.isOpen()).isFalse(); assertThat(fileSystem.getFileStores()).isNotNull(); }
@Test(expected = UnsupportedOperationException.class) public void testGetUserPrincipalLookupService() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); fileSystem.getUserPrincipalLookupService(); }
@Test(expected = UnsupportedOperationException.class) public void testGetPathMatcher() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); fileSystem.getPathMatcher("*"); }
@Test(expected = UnsupportedOperationException.class) public void testGetUserPrincipalLookupService() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); fileSystem.getUserPrincipalLookupService(); }
@Test public void testRemoteRoot() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final File tempDir = createTempDirectory(); final Git git = new GitImpl(GitImpl._cloneRepository().setNoCheckout(false).setBare(true).setCloneAllBranches(true).setURI(setupGit().getRepository().getDirectory().toString()).setDirectory(tempDir).call()); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.getRootDirectories()).hasSize(1); final Path root = fileSystem.getRootDirectories().iterator().next(); assertThat(root.toString()).isEqualTo("/"); assertThat(root.getRoot().toString()).isEqualTo("/"); }
@Test(expected = UnsupportedOperationException.class) @Ignore public void testNewWatchService() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); fileSystem.newWatchService(); }
@Test(expected = UnsupportedOperationException.class) @Ignore public void testNewWatchService() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); fileSystem.newWatchService(); }
@Test public void lockShouldSupportMultipleInnerLocksForTheSameThreadTest() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final Git git = setupGit(); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); fileSystem.lock(); //inner locks fileSystem.lock(); fileSystem.lock(); fileSystem.unlock(); fileSystem.unlock(); fileSystem.unlock(); }