@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 ); try { PROVIDER.newFileSystem(path, EMPTY_ENV); failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); } catch (Exception e) { } }
@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(); try { PROVIDER.newAsynchronousFileChannel(path, options, null); failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); } catch (Exception e) { } }
@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(); try { PROVIDER.newFileChannel(path, options); failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); } catch (Exception e) { } }
@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")); try { PROVIDER.createLink(link, path); failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); } catch (Exception e) { } }
@Test public void testNewFileSystem() { final URI newRepo = URI.create( "git://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 ).isNotNull().hasSize( 0 ); try { PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); failBecauseExceptionWasNotThrown( FileSystemAlreadyExistsException.class ); } catch ( final Exception ex ) { } PROVIDER.newFileSystem( URI.create( "git://repo-name2" ), EMPTY_ENV ); }
@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 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")); try { PROVIDER.readSymbolicLink(link); failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); } catch (Exception e) { } } }
@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")); try { PROVIDER.createSymbolicLink(link, path); failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); } catch (Exception e) { } }
@Test public void testGetFileStore() throws Exception { final URI newRepo = URI.create( "git://filestore-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://master@filestore-test-repo/path/to/myfile1.txt" ) ); final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); final FileStore fileStore = PROVIDER.getFileStore( path ); assertThat( fileStore ).isNotNull(); assertThat( fileStore.getAttribute( "readOnly" ) ).isEqualTo( Boolean.FALSE ); }
@Test public void testCheckAccess() throws Exception { final URI newRepo = URI.create( "git://checkaccess-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://master@checkaccess-test-repo/path/to/myfile1.txt" ) ); final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); PROVIDER.checkAccess( path ); final Path path_to_dir = PROVIDER.getPath( URI.create( "git://master@checkaccess-test-repo/path/to" ) ); PROVIDER.checkAccess( path_to_dir ); final Path path_not_exists = PROVIDER.getPath( URI.create( "git://master@checkaccess-test-repo/path/to/some.txt" ) ); try { PROVIDER.checkAccess( path_not_exists ); failBecauseExceptionWasNotThrown( NoSuchFileException.class ); } catch ( NoSuchFileException e ) { } }
@Test @Ignore public void testUsingProvidedPath() throws IOException { final File dir = createTempDirectory(); System.setProperty("org.kie.nio.git.dir", dir.toString()); JGitFileSystemProvider.loadConfig(); final JGitFileSystemProvider provider = new JGitFileSystemProvider(); final URI newRepo = URI.create("git://repo-name"); provider.newFileSystem(newRepo, EMPTY_ENV); final String[] names = dir.list(); assertThat(names).isNotEmpty().contains(".niogit"); final String[] repos = new File(dir, ".niogit").list(); assertThat(repos).isNotEmpty().contains("repo-name.git"); System.setProperty("org.kie.nio.git.dir", ""); }
@Test public void testDeleteBranchIfExists() throws IOException { final URI newRepo = URI.create( "git://deletebranchifexists1-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://user_branch@deletebranchifexists1-test-repo/path/to/myfile.txt" ) ); final OutputStream outStream = PROVIDER.newOutputStream( path ); assertThat( outStream ).isNotNull(); outStream.write( "my cool content".getBytes() ); outStream.close(); PROVIDER.newInputStream( path ).close(); assertThat( PROVIDER.deleteIfExists( PROVIDER.getPath( URI.create( "git://user_branch@deletebranchifexists1-test-repo" ) ) ) ).isTrue(); assertThat( PROVIDER.deleteIfExists( PROVIDER.getPath( URI.create( "git://not_user_branch@deletebranchifexists1-test-repo" ) ) ) ).isFalse(); assertThat( PROVIDER.deleteIfExists( PROVIDER.getPath( URI.create( "git://user_branch@deletebranchifexists1-test-repo" ) ) ) ).isFalse(); }
@Test public void testGetComplexPath() { final URI newRepo = URI.create( "git://new-complex-get-repo-name" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://origin/master@new-complex-get-repo-name/home" ) ); assertThat( path ).isNotNull(); assertThat( path.getRoot().toString() ).isEqualTo( "/" ); assertThat( path.toString() ).isEqualTo( "/home" ); final Path pathRelative = PROVIDER.getPath( URI.create( "git://origin/master@new-complex-get-repo-name/:home" ) ); assertThat( pathRelative ).isNotNull(); assertThat( pathRelative.getRoot().toString() ).isEqualTo( "" ); assertThat( pathRelative.toString() ).isEqualTo( "home" ); }
@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 testGetPath() { final URI newRepo = URI.create("default://default-new-get-repo-name"); PROVIDER.newFileSystem(newRepo, EMPTY_ENV); final Path path = PROVIDER.getPath(URI.create("default://master@default-new-get-repo-name/home")); assertThat(path).isNotNull(); assertThat(path.getRoot().toString()).isEqualTo("/"); assertThat(path.toString()).isEqualTo("/home"); assertThat(path.toUri().getScheme()).isEqualTo("default"); final Path pathRelative = PROVIDER.getPath(URI.create("default://master@default-new-get-repo-name/:home")); assertThat(pathRelative).isNotNull(); assertThat(pathRelative.toUri().toString()).isEqualTo("default://master@default-new-get-repo-name/:home"); assertThat(pathRelative.getRoot().toString()).isEqualTo(""); assertThat(pathRelative.toString()).isEqualTo("home"); }
@Test(expected = NoSuchFileException.class) public void testInputStream3() throws IOException { final File parentFolder = createTempDirectory(); final File gitFolder = new File( parentFolder, "mytest.git" ); final Git origin = JGitUtil.newRepository( gitFolder, true ); commit( origin, "master", "user", "user@example.com", "commit message", null, null, false, new HashMap<String, File>() {{ put( "path/to/file/myfile.txt", tempFile( "temp\n.origin\n.content" ) ); }} ); final URI newRepo = URI.create( "git://xxinputstream-test-repo" ); final Map<String, Object> env = new HashMap<String, Object>() {{ put( JGitFileSystemProvider.GIT_DEFAULT_REMOTE_NAME, origin.getRepository().getDirectory().toString() ); }}; final FileSystem fs = PROVIDER.newFileSystem( newRepo, env ); assertThat( fs ).isNotNull(); final Path path = PROVIDER.getPath( URI.create( "git://origin/master@xxinputstream-test-repo/path/to" ) ); PROVIDER.newInputStream( path ); }
@Test(expected = NoSuchFileException.class) public void testInputStreamNoSuchFile() throws IOException { final File parentFolder = createTempDirectory(); final File gitFolder = new File( parentFolder, "mytest.git" ); final Git origin = JGitUtil.newRepository( gitFolder, true ); commit( origin, "master", "user1", "user1@example.com", "commitx", null, null, false, new HashMap<String, File>() {{ put( "file.txt", tempFile( "temp.origin.content.2" ) ); }} ); final URI newRepo = URI.create( "git://inputstream-not-exists-test-repo" ); final Map<String, Object> env = new HashMap<String, Object>() {{ put( JGitFileSystemProvider.GIT_DEFAULT_REMOTE_NAME, origin.getRepository().getDirectory().toString() ); }}; final FileSystem fs = PROVIDER.newFileSystem( newRepo, env ); assertThat( fs ).isNotNull(); final Path path = PROVIDER.getPath( URI.create( "git://origin/master@inputstream-not-exists-test-repo/temp.txt" ) ); PROVIDER.newInputStream( path ); }
@Test public void testGetComplexPath() { final URI newRepo = URI.create("default://default-new-complex-get-repo-name"); PROVIDER.newFileSystem(newRepo, EMPTY_ENV); final Path path = PROVIDER.getPath(URI.create("default://origin/master@default-new-complex-get-repo-name/home")); assertThat(path).isNotNull(); assertThat(path.getRoot().toString()).isEqualTo("/"); assertThat(path.toString()).isEqualTo("/home"); assertThat(path.toUri().getScheme()).isEqualTo("default"); final Path pathRelative = PROVIDER.getPath(URI.create("default://origin/master@default-new-complex-get-repo-name/:home")); assertThat(pathRelative).isNotNull(); assertThat(pathRelative.getRoot().toString()).isEqualTo(""); assertThat(pathRelative.getRoot().toUri().toString()).isEqualTo("default://origin/master@default-new-complex-get-repo-name"); assertThat(pathRelative.toString()).isEqualTo("home"); } }
@Test public void testGetPath() { final URI newRepo = URI.create( "git://new-get-repo-name" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://master@new-get-repo-name/home" ) ); assertThat( path ).isNotNull(); assertThat( path.getRoot().toString() ).isEqualTo( "/" ); assertThat( path.getRoot().toRealPath().toUri().toString() ).isEqualTo( "git://master@new-get-repo-name/" ); assertThat( path.toString() ).isEqualTo( "/home" ); final Path pathRelative = PROVIDER.getPath( URI.create( "git://master@new-get-repo-name/:home" ) ); assertThat( pathRelative ).isNotNull(); assertThat( pathRelative.toRealPath().toUri().toString() ).isEqualTo( "git://master@new-get-repo-name/:home" ); assertThat( pathRelative.getRoot().toString() ).isEqualTo( "" ); assertThat( pathRelative.toString() ).isEqualTo( "home" ); }
@Test public void testNewFileSystemInited() { final URI newRepo = URI.create( "git://init-repo-name" ); final Map<String, ?> env = new HashMap<String, Object>() {{ put( "init", Boolean.TRUE ); }}; final FileSystem fs = PROVIDER.newFileSystem( newRepo, env ); assertThat( fs ).isNotNull(); final DirectoryStream<Path> stream = PROVIDER.newDirectoryStream( PROVIDER.getPath( newRepo ), null ); assertThat( stream ).isNotNull().hasSize( 1 ); }