@Test public void testCopyFiles() throws IOException { final URI newRepo = URI.create( "git://copyasset-test-repo" ); PROVIDER.newFileSystem( newRepo, EMPTY_ENV ); final Path path = PROVIDER.getPath( URI.create( "git://master@copyasset-test-repo/myfile1.txt" ) ); { final OutputStream outStream = PROVIDER.newOutputStream( path ); outStream.write( "my cool content".getBytes() ); outStream.close(); } final Path path2 = PROVIDER.getPath( URI.create( "git://user_branch@copyasset-test-repo/other/path/myfile2.txt" ) ); { final OutputStream outStream2 = PROVIDER.newOutputStream( path2 ); outStream2.write( "my cool content".getBytes() ); outStream2.close(); } final Path path3 = PROVIDER.getPath( URI.create( "git://user_branch@copyasset-test-repo/myfile3.txt" ) ); { final OutputStream outStream3 = PROVIDER.newOutputStream( path3 ); outStream3.write( "my cool content".getBytes() ); outStream3.close(); } final Path target = PROVIDER.getPath( URI.create( "git://user_branch@copyasset-test-repo/myfile1.txt" ) ); PROVIDER.copy( path, target ); final DirectoryStream<Path> stream = PROVIDER.newDirectoryStream( PROVIDER.getPath( URI.create( "git://user_branch@copyasset-test-repo/" ) ), null ); for ( Path path1 : stream ) { System.out.println("content: " + path1.toUri()); } assertThat( stream ).isNotNull().hasSize( 3 ); }
assertThat( stream ).isNotNull().hasSize( 2 );
assertThat( stream3 ).isNotNull().hasSize( 4 );
assertThat( stream1 ).isNotNull().hasSize( 2 ).contains( path3, PROVIDER.getPath( URI.create( "git://user_branch@dirstream-test-repo/other" ) ) ); assertThat( stream2 ).isNotNull().hasSize( 1 ).contains( PROVIDER.getPath( URI.create( "git://user_branch@dirstream-test-repo/other/path" ) ) ); assertThat( stream3 ).isNotNull().hasSize( 1 ).contains( path2 ); assertThat( stream4 ).isNotNull().hasSize( 1 ).contains( path ); assertThat( PROVIDER.newDirectoryStream( crazyPath, null ) ).isNotNull().hasSize( 1 );
@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 ); }
@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 testFileStore() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class ); final File tempDir = createTempDirectory(); final Git git = setupGit( tempDir ); final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() ); 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 testOnlyLocalRoot() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class ); final Git git = setupGit(); final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() ); 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( "/" ); }
assertThat( fs.getRootDirectories() ).hasSize( 2 ); assertThat( fs.getRootDirectories() ).hasSize( 3 ); assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 2 ); } else if ( root.toAbsolutePath().toUri().toString().contains( "origin" ) ) { assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 1 ); } else { assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 2 ); assertThat( fs.getRootDirectories() ).hasSize( 3 ); assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 3 ); } else if ( root.toAbsolutePath().toUri().toString().contains( "origin" ) ) { assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 1 ); } else { assertThat( PROVIDER.newDirectoryStream( root, null ) ).isNotEmpty().hasSize( 3 );
@Test public void checkDeleteNonEmptyDir() throws IOException { final SimpleFileSystemProvider fsProvider = new SimpleFileSystemProvider(); final String userSourcePath = System.getProperty( "user.dir" ) + "/temp"; final Path dir = GeneralPathImpl.create( fsProvider.getFileSystem( URI.create( "file:///" ) ), userSourcePath, false ); FileUtils.deleteDirectory( dir.toFile() ); fsProvider.createDirectory( dir ); File.createTempFile( "foo", "bar", dir.toFile() ); File.createTempFile( "bar", "foo", dir.toFile() ); File.createTempFile( "bar", "foo", dir.toFile() ); fsProvider.createDirectory( dir.resolve( "other_dir" ) ); final DirectoryStream<Path> stream5 = fsProvider.newDirectoryStream( dir, new DirectoryStream.Filter<Path>() { @Override public boolean accept( final Path entry ) throws org.kie.commons.java.nio.IOException { return true; } } ); assertThat( stream5 ).hasSize( 4 ).contains( dir.resolve( "other_dir" ) ); try { fsProvider.delete( dir ); fail( "must throw error" ); } catch ( final DirectoryNotEmptyException expection ) { } fsProvider.delete( dir, NON_EMPTY_DIRECTORIES ); assertThat( dir.toFile().exists() ).isEqualTo( false ); }
@Test public void testRemoteRoot() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class ); final File tempDir = createTempDirectory(); final Git git = Git.cloneRepository().setNoCheckout( false ).setBare( true ).setCloneAllBranches( true ).setURI( setupGit().getRepository().getDirectory().toString() ).setDirectory( tempDir ).call(); final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() ); 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 simpleTests() { final FileSystem fileSystem = new SimpleUnixFileSystem( fsProvider, "/" ); assertThat( fileSystem.isOpen() ).isTrue(); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( System.getProperty( "file.separator" ) ); assertThat( fileSystem.provider() ).isEqualTo( fsProvider ); assertThat( fileSystem.supportedFileAttributeViews() ).isNotEmpty().hasSize( 1 ).contains( "basic" ); assertThat( fileSystem.getPath( "/path/to/file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "/path/to/file.txt", false ) ); assertThat( fileSystem.getPath( "/path/to/file.txt", null ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "/path/to/file.txt", false ) ); assertThat( fileSystem.getPath( "/path", "to", "file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "/path/to/file.txt", false ) ); try { fileSystem.close(); fail( "can't close this fileSystem" ); } catch ( UnsupportedOperationException ex ) { } assertThat( fileSystem.getFileStores() ).isNotNull().hasSize( 1 ); assertThat( fileSystem.getFileStores().iterator().next().name() ).isEqualTo( "/" ); assertThat( fileSystem.getRootDirectories() ).isNotNull().hasSize( 1 ); assertThat( fileSystem.getRootDirectories().iterator().next().toString() ).isEqualTo( "/" ); assertThat( fileSystem.getRootDirectories().iterator().next().isAbsolute() ).isTrue(); }
@Test public void simpleTests() { final FileSystem fileSystem = new SimpleWindowsFileSystem( roots, fsProvider, "c:\\" ); assertThat( fileSystem.isOpen() ).isTrue(); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( "\\" ); assertThat( fileSystem.provider() ).isEqualTo( fsProvider ); assertThat( fileSystem.supportedFileAttributeViews() ).isNotEmpty().hasSize( 1 ).contains( "basic" ); assertThat( fileSystem.getPath( "c:\\path\\to\\file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "c:\\path\\to\\file.txt", false ) ); assertThat( fileSystem.getPath( "c:\\path\\to\\file.txt", null ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "c:\\path\\to\\file.txt", false ) ); assertThat( fileSystem.getPath( "c:\\path", "to", "file.txt" ) ).isNotNull().isEqualTo( GeneralPathImpl.create( fileSystem, "c:\\path\\to\\file.txt", false ) ); try { fileSystem.close(); fail( "can't close this fileSystem" ); } catch ( UnsupportedOperationException ex ) { } assertThat( fileSystem.getFileStores() ).isNotNull().hasSize( 2 ); assertThat( fileSystem.getFileStores().iterator().next().name() ).isEqualTo( "c:\\" ); assertThat( fileSystem.getRootDirectories() ).isNotNull().hasSize( 2 ); assertThat( fileSystem.getRootDirectories().iterator().next().toString() ).isEqualTo( "c:\\" ); assertThat( fileSystem.getRootDirectories().iterator().next().isAbsolute() ).isTrue(); }
@Test public void testSupportedFileAttributeViews() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class ); final Git git = setupGit(); final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() ); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( "/" ); assertThat( fileSystem.getName() ).isEqualTo( "my-repo" ); assertThat( fileSystem.supportedFileAttributeViews() ).isNotEmpty().hasSize( 2 ).contains( "basic", "version" ); }