Search in sources :

Example 1 with PosixPermissions

use of org.apache.commons.vfs2.util.PosixPermissions in project pentaho-kettle by pentaho.

the class SftpFileObjectWithWindowsSupportTest method getLinuxFileObject.

private static FileObject getLinuxFileObject(boolean posixReadable, boolean posixWritable) throws Exception {
    GenericFileName fileName = mock(GenericFileName.class);
    doReturn(PATH).when(fileName).getPath();
    Session session = mock(Session.class);
    SftpFileSystemWindows sftpFileSystem = spy(new SftpFileSystemWindows(fileName, session, null));
    doReturn(false).when(sftpFileSystem).isRemoteHostWindows();
    int permissions = 0;
    if (posixReadable) {
        permissions += 256;
    }
    if (posixWritable) {
        permissions += 128;
    }
    PosixPermissions posixPermissions = new PosixPermissions(permissions, true, true);
    return new SftpFileObjectWithWindowsSupport(fileName, sftpFileSystem) {

        @Override
        public PosixPermissions getPermissions(boolean checkIds) {
            return posixPermissions;
        }

        @Override
        public FileType getType() {
            return FileType.FILE;
        }
    };
}
Also used : GenericFileName(org.apache.commons.vfs2.provider.GenericFileName) PosixPermissions(org.apache.commons.vfs2.util.PosixPermissions) Session(com.jcraft.jsch.Session)

Example 2 with PosixPermissions

use of org.apache.commons.vfs2.util.PosixPermissions in project pentaho-kettle by pentaho.

the class SftpFileObjectWithWindowsSupportTest method getWindowsFileObject.

private static FileObject getWindowsFileObject(boolean windowsReadable, boolean windowsWritable) throws Exception {
    GenericFileName fileName = mock(GenericFileName.class);
    Session session = mock(Session.class);
    doReturn(PATH).when(fileName).getPath();
    SftpFileSystemWindows sftpFileSystem = spy(new SftpFileSystemWindows(fileName, session, null));
    doReturn(true).when(sftpFileSystem).isRemoteHostWindows();
    List<String> groups = new ArrayList<>();
    groups.add(USERS);
    doReturn(groups).when(sftpFileSystem).getUserGroups();
    HashMap<String, String> permissions = new HashMap<>();
    doReturn(permissions).when(sftpFileSystem).getFilePermission(PATH);
    if (windowsReadable) {
        permissions.put(USERS, PERMISSION_READ);
    }
    if (windowsWritable) {
        permissions.put(USERS, PERMISSION_WRITE);
    }
    PosixPermissions posixPermissions = new PosixPermissions(0, true, true);
    return new SftpFileObjectWithWindowsSupport(fileName, sftpFileSystem) {

        @Override
        public PosixPermissions getPermissions(boolean checkIds) {
            return posixPermissions;
        }

        @Override
        public FileType getType() {
            return FileType.FILE;
        }
    };
}
Also used : GenericFileName(org.apache.commons.vfs2.provider.GenericFileName) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PosixPermissions(org.apache.commons.vfs2.util.PosixPermissions) Session(com.jcraft.jsch.Session)

Aggregations

Session (com.jcraft.jsch.Session)2 GenericFileName (org.apache.commons.vfs2.provider.GenericFileName)2 PosixPermissions (org.apache.commons.vfs2.util.PosixPermissions)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1