@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 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 testInvalidURIGetFileSystem() { final URI newRepo = URI.create( "git:///new-repo-name" ); try { PROVIDER.getFileSystem( newRepo ); failBecauseExceptionWasNotThrown( IllegalArgumentException.class ); } catch ( final IllegalArgumentException ex ) { assertThat( ex.getMessage() ).isEqualTo( "Parameter named 'uri' is invalid, missing host repository!" ); } }
@Test public void testInvalidURIGetPath() { final URI uri = URI.create( "git:///master@new-get-repo-name/home" ); try { PROVIDER.getPath( uri ); failBecauseExceptionWasNotThrown( IllegalArgumentException.class ); } catch ( final IllegalArgumentException ex ) { assertThat( ex.getMessage() ).isEqualTo( "Parameter named 'uri' is invalid, missing host repository!" ); } }
@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 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 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 public void testDeleteBranch() throws IOException { final URI newRepo = URI.create( "git://delete-branch-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://user_branch@delete-branch-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(); PROVIDER.delete( PROVIDER.getPath( URI.create( "git://user_branch@delete-branch-test-repo" ) ) ); try { PROVIDER.delete( PROVIDER.getPath( URI.create( "git://user_branch@delete-branch-test-repo" ) ) ); failBecauseExceptionWasNotThrown( NoSuchFileException.class ); } catch ( NoSuchFileException ex ) { } try { PROVIDER.delete( PROVIDER.getPath( URI.create( "git://some_user_branch@delete-branch-test-repo" ) ) ); failBecauseExceptionWasNotThrown( NoSuchFileException.class ); } catch ( NoSuchFileException ex ) { } }
failBecauseExceptionWasNotThrown( FileAlreadyExistsException.class ); } catch ( FileAlreadyExistsException e ) { failBecauseExceptionWasNotThrown( NoSuchFileException.class ); } catch ( NoSuchFileException e ) {
@Test public void testDeleteIfExists() throws IOException { final URI newRepo = URI.create( "git://deleteifexists1-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://user_branch@deleteifexists1-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@deleteifexists1-test-repo/non_existent_path" ) ) ) ).isFalse(); try { PROVIDER.deleteIfExists( PROVIDER.getPath( URI.create( "git://user_branch@deleteifexists1-test-repo/path/to/" ) ) ); failBecauseExceptionWasNotThrown( DirectoryNotEmptyException.class ); } catch ( DirectoryNotEmptyException ex ) { } assertThat( PROVIDER.deleteIfExists( path ) ).isTrue(); }
@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 ); }
failBecauseExceptionWasNotThrown( NoSuchFileException.class ); } catch ( NoSuchFileException ex ) { failBecauseExceptionWasNotThrown( DirectoryNotEmptyException.class ); } catch ( DirectoryNotEmptyException ex ) { failBecauseExceptionWasNotThrown( FileSystemAlreadyExistsException.class ); } catch ( FileSystemAlreadyExistsException e ) {
failBecauseExceptionWasNotThrown( org.kie.commons.java.nio.IOException.class ); } catch ( Exception e ) {
failBecauseExceptionWasNotThrown( NotDirectoryException.class ); } catch ( NotDirectoryException ex ) { try { PROVIDER.newDirectoryStream( crazyPath, null ); failBecauseExceptionWasNotThrown( NotDirectoryException.class ); } catch ( NotDirectoryException ex ) {
@Test public void testSimpleImplicitBranchGitRoot() { when(fs.getSeparator()).thenReturn("/"); final Path path = JGitPathImpl.create(fs, "/", "my-host", false); assertThat(path).isNotNull(); assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/"); assertThat(path.getRoot().toString()).isEqualTo("/"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/"); assertThat(path.getNameCount()).isEqualTo(0); assertThat(path.getRoot().toString()).isNotNull().isEqualTo("/"); try { assertThat(path.getName(0).toString()).isNotNull().isEqualTo(""); failBecauseExceptionWasNotThrown(IllegalArgumentException.class); } catch (IllegalArgumentException ex) { } }
failBecauseExceptionWasNotThrown( NoSuchFileException.class ); } catch ( NoSuchFileException e ) {
@Test public void testCreateDirectory() throws Exception { final URI newRepo = URI.create( "git://xcreatedir-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final JGitPathImpl path = (JGitPathImpl) PROVIDER.getPath( URI.create( "git://master@xcreatedir-test-repo/some/path/to/" ) ); final Pair<PathType, ObjectId> result = JGitUtil.checkPath( path.getFileSystem().gitRepo(), path.getRefTree(), path.getPath() ); assertThat( result.getK1() ).isEqualTo( PathType.NOT_FOUND ); PROVIDER.createDirectory( path ); final Pair<PathType, ObjectId> resultAfter = JGitUtil.checkPath( path.getFileSystem().gitRepo(), path.getRefTree(), path.getPath() ); assertThat( resultAfter.getK1() ).isEqualTo( PathType.DIRECTORY ); try { PROVIDER.createDirectory( path ); failBecauseExceptionWasNotThrown( FileAlreadyExistsException.class ); } catch ( FileAlreadyExistsException e ) { } }