@Test public void testNewFileSystemUnsupportedOp() { final URI newRepo = URI.create("git://someunsup-repo-name"); final FileSystem fs = provider.newFileSystem(newRepo, EMPTY_ENV); final Path path = JGitPathImpl.create((JGitFileSystem) fs, "", "repo2-name", false); assertThatThrownBy(() -> provider.newFileSystem(path, EMPTY_ENV)) .isInstanceOf(UnsupportedOperationException.class); }
@Test public void testNewFileSystemUnsupportedOp() { final URI newRepo = URI.create("git://someunsup-repo-name"); final FileSystem fs = provider.newFileSystem(newRepo, EMPTY_ENV); final Path path = JGitPathImpl.create((JGitFileSystem) fs, "", "repo2-name", false); assertThatThrownBy(() -> provider.newFileSystem(path, EMPTY_ENV)) .isInstanceOf(UnsupportedOperationException.class); }
@Before public void init() { final URI newRepo = URI.create(GIT + REPO_NAME); final Map<String, Object> env = new HashMap<>(); env.put(FileSystemHooks.PostCommit.name(), postCommitHook); fs = (JGitFileSystem) provider.newFileSystem(newRepo, env); assertThat(fs).isNotNull(); }
@Test public void testComplexExtractPath() { final URI newRepo = URI.create("git://test/repo"); final FileSystem fs = provider.newFileSystem(newRepo, EMPTY_ENV); String path = "git://origin/master@test/repo/readme.md"; final URI uri = URI.create(path); final String extracted = provider.extractPath(uri); assertThat(extracted).isEqualTo("/readme.md"); }
@Test public void testInvalidURINewFileSystem() { final URI newRepo = URI.create("git:///repo-name"); try { provider.newFileSystem(newRepo, EMPTY_ENV); failBecauseExceptionWasNotThrown(IllegalArgumentException.class); } catch (final IllegalArgumentException ex) { assertThat(ex.getMessage()).isEqualTo("Parameter named 'uri' is invalid, missing host repository!"); } }
@Test public void testGetFileSystem() { final URI newRepo = URI.create("git://new-repo-name"); final FileSystem fs = provider.newFileSystem(newRepo, EMPTY_ENV); assertThat(fs).isNotNull(); assertThat(provider.getFileSystem(newRepo)).isEqualTo(fs); assertThat(provider.getFileSystem(URI.create("git://master@new-repo-name"))).isEqualTo(fs); assertThat(provider.getFileSystem(URI.create("git://branch@new-repo-name"))).isEqualTo(fs); assertThat(provider.getFileSystem(URI.create("git://branch@new-repo-name?_fetch"))).isEqualTo(fs); }
@Test public void testNewFileChannelUnsupportedOp() { final URI newRepo = URI.create("git://newfcrepo-name"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path path = provider.getPath(URI.create("git://newfcrepo-name/file.txt")); final Set<? extends OpenOption> options = emptySet(); assertThatThrownBy(() -> provider.newFileChannel(path, options)) .isInstanceOf(UnsupportedOperationException.class); }
@Test public void testNewAsynchronousFileChannelUnsupportedOp() { final URI newRepo = URI.create("git://newasyncrepo-name"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path path = provider.getPath(URI.create("git://newasyncrepo-name/file.txt")); final Set<? extends OpenOption> options = emptySet(); assertThatThrownBy(() -> provider.newAsynchronousFileChannel(path, options, null)) .isInstanceOf(UnsupportedOperationException.class); }
@Test public void testReadSymbolicLinkUnsupportedOp() { final URI newRepo = URI.create("git://read-link-repo-name"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path link = provider.getPath(URI.create("git://read-link-repo-name/link.lnk")); assertThatThrownBy(() -> provider.readSymbolicLink(link)) .isInstanceOf(UnsupportedOperationException.class); } }
@Test public void extractPathTest() { URI composedName = URI.create("git://user1/dora"); FileSystem fsComposedName1 = provider.newFileSystem(composedName, EMPTY_ENV); URI composedFileName1 = URI.create("git://user1/dora/file.txt"); Path path1 = provider.getPath(composedFileName1); assertEquals(path1.toString(), provider.extractPath(composedFileName1)); }
@Test public void testExtractPathWithAuthority() { provider.newFileSystem(URI.create("git://test/repo"), new HashMap<String, Object>() {{ put("init", Boolean.TRUE); }}); String path = "git://master@test/repo/readme.md"; final URI uri = URI.create(path); final String extracted = provider.extractPath(uri); assertThat(extracted).isEqualTo("/readme.md"); }
@Test public void testExtractComplexRepoName() { provider.newFileSystem(URI.create("default://test/repo"), new HashMap<String, Object>() {{ put("init", Boolean.TRUE); }}); String path = "git://origin/master@test/repo/readme.md"; final URI uri = URI.create(path); final String extracted = provider.extractFSNameWithPath(uri); assertThat(extracted).isEqualTo("test/repo/readme.md"); }
@Test public void testExtractPathWithAuthority() { provider.newFileSystem(URI.create("git://test/repo"), new HashMap<String, Object>() {{ put("init", Boolean.TRUE); }}); String path = "git://master@test/repo/readme.md"; final URI uri = URI.create(path); final String extracted = provider.extractPath(uri); assertThat(extracted).isEqualTo("/readme.md"); }
@Test public void testExtractComplexRepoName() { provider.newFileSystem(URI.create("default://test/repo"), new HashMap<String, Object>() {{ put("init", Boolean.TRUE); }}); String path = "git://origin/master@test/repo/readme.md"; final URI uri = URI.create(path); final String extracted = provider.extractFSNameWithPath(uri); assertThat(extracted).isEqualTo("test/repo/readme.md"); }
@Test public void testCreateSymbolicLinkUnsupportedOp() { final URI newRepo = URI.create("git://symbolic-repo-name"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path link = provider.getPath(URI.create("git://symbolic-repo-name/link.lnk")); final Path path = provider.getPath(URI.create("git://symbolic-repo-name/file.txt")); assertThatThrownBy(() -> provider.createSymbolicLink(link, path)) .isInstanceOf(UnsupportedOperationException.class); }
@Test public void testCreateLinkUnsupportedOp() { final URI newRepo = URI.create("git://link-repo-name"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path link = provider.getPath(URI.create("git://link-repo-name/link.lnk")); final Path path = provider.getPath(URI.create("git://link-repo-name/file.txt")); assertThatThrownBy(() -> provider.createLink(link, path)) .isInstanceOf(UnsupportedOperationException.class); }
@Test public void testCreateLinkUnsupportedOp() { final URI newRepo = URI.create("git://link-repo-name"); provider.newFileSystem(newRepo, EMPTY_ENV); final Path link = provider.getPath(URI.create("git://link-repo-name/link.lnk")); final Path path = provider.getPath(URI.create("git://link-repo-name/file.txt")); assertThatThrownBy(() -> provider.createLink(link, path)) .isInstanceOf(UnsupportedOperationException.class); }
@Test public void testNewFileSystemWithSubfolder() { final URI newRepo = URI.create("git://test/sub-repo-name"); final FileSystem fs = provider.newFileSystem(newRepo, EMPTY_ENV); assertThat(fs).isNotNull(); final DirectoryStream<Path> stream = provider.newDirectoryStream(provider.getPath(newRepo), null); assertThat(stream).isEmpty(); }
@Test public void checkRootPath() { URI composedName = URI.create("git://dora-repo/subdir1"); FileSystem fsComposedName = provider.newFileSystem(composedName, EMPTY_ENV); Path path = provider.getPath(URI.create("git://dora-repo/subdir1/file.txt")); Path path1 = provider.getPath(URI.create("git://origin/bla@dora-repo/subdir1/file2.txt")); assertEquals(fsComposedName, path.getRoot().getFileSystem()); assertEquals(fsComposedName, path1.getRoot().getFileSystem()); }
@Test public void resolveByRepositoryTest() { JGitFileSystem fsSimpleName = ((JGitFileSystemProxy) provider.newFileSystem(URI.create("git://repo"), EMPTY_ENV)).getRealJGitFileSystem(); JGitFileSystemProvider.RepositoryResolverImpl<Object> objectRepositoryResolver = provider.new RepositoryResolverImpl<>(); assertEquals(fsSimpleName, objectRepositoryResolver.resolveFileSystem(fsSimpleName.getGit().getRepository())); JGitFileSystem fsComposedName1 = ((JGitFileSystemProxy) provider.newFileSystem(URI.create("git://user1/dora"), EMPTY_ENV)).getRealJGitFileSystem(); assertEquals(fsComposedName1, objectRepositoryResolver.resolveFileSystem(fsComposedName1.getGit().getRepository())); }