SolutionRepositoryVfsFileObject implements FileObject { private void initFile() { String fileUrl = fileRef; try { final Charset urlCharset = Charset.forName( "UTF-8" ); fileUrl = URLDecoder.decode( fileUrl, urlCharset.name() ); } catch ( UnsupportedEncodingException e ) { fileUrl = fileRef; } String dsPath = fileUrl; if ( fileUrl.matches( "^(/etc/mondrian/)(.*)(/schema.xml)" ) ) { dsPath = fileUrl.substring( 0, fileUrl.indexOf( "/schema.xml" ) ); } repositoryFile = getRepository().getFile( fileUrl ); if ( !getAclHelper().canAccess( getRepository().getFile( dsPath ), EnumSet.of( RepositoryFilePermission.READ ) ) ) { repositoryFile = null; } } SolutionRepositoryVfsFileObject( final String fileRef ); IUnifiedRepository getRepository(); IRepositoryContentConverterHandler getConverterHandler(); String getFileRef(); FileName getName(); URL getURL(); boolean exists(); boolean isHidden(); boolean isReadable(); boolean isWriteable(); FileType getType(); FileObject getParent(); @Override String getPublicURIString(); FileSystem getFileSystem(); FileObject[] getChildren(); FileObject getChild( final String arg0 ); FileObject resolveFile( final String arg0, final NameScope arg1 ); @Override boolean setExecutable( boolean executable, boolean ownerOnly ); @Override boolean setReadable( boolean readable, boolean ownerOnly ); @Override boolean setWritable( boolean writable, boolean ownerOnly ); FileObject resolveFile( final String arg0 ); FileObject[] findFiles( final FileSelector arg0 ); void findFiles( final FileSelector arg0, final boolean arg1, final List arg2 ); boolean delete(); int delete( final FileSelector arg0 ); @Override int deleteAll(); void createFolder(); void createFile(); void copyFrom( final FileObject arg0, final FileSelector arg1 ); void moveTo( final FileObject arg0 ); boolean canRenameTo( final FileObject arg0 ); FileContent getContent(); void close(); void refresh(); boolean isAttached(); boolean isContentOpen(); @Override boolean isExecutable(); @Override boolean isFile(); @Override boolean isFolder(); FileOperations getFileOperations(); InputStream getInputStream(); @VisibleForTesting static void setTestAclHelper( IAclNodeHelper helper ); @Override int compareTo( FileObject file ); @Override Iterator<FileObject> iterator();  }
@Test public void initFileTest() throws Exception { String fileRef = "/etc/mondrian/SteelWheels/schema.xml"; String dsRef = "/etc/mondrian/SteelWheels"; SolutionRepositoryVfsFileObject fileObject = new SolutionRepositoryVfsFileObject( fileRef ); SolutionRepositoryVfsFileObject fileObjectSpy = spy( fileObject ); IAclNodeHelper aclNodeHelper = mock( IAclNodeHelper.class ); doReturn( aclNodeHelper ).when( fileObjectSpy ).getAclHelper(); RepositoryFile file = mock( RepositoryFile.class ); doReturn( true ).when( aclNodeHelper ).canAccess( file, EnumSet.of( RepositoryFilePermission.READ ) ); IUnifiedRepository repository = mock( IUnifiedRepository.class ); doReturn( file ).when( repository ).getFile( fileRef ); doReturn( repository ).when( fileObjectSpy ).getRepository(); fileObjectSpy.getName(); verify( repository, times( 1 ) ).getFile( eq( dsRef ) ); verify( repository, times( 1 ) ).getFile( eq( fileRef ) ); verify( aclNodeHelper, times( 1 ) ).canAccess( any( RepositoryFile.class ), eq( EnumSet.of( RepositoryFilePermission.READ ) ) ); fileRef = "/etca/mondriana/SteelWheels/schema.xml"; fileObject = new SolutionRepositoryVfsFileObject( fileRef ); fileObjectSpy = spy( fileObject ); doReturn( aclNodeHelper ).when( fileObjectSpy ).getAclHelper(); doReturn( false ).when( aclNodeHelper ).canAccess( file, EnumSet.of( RepositoryFilePermission.READ ) ); doReturn( repository ).when( fileObjectSpy ).getRepository(); fileObjectSpy.getName(); verify( repository, times( 2 ) ).getFile( eq( fileRef ) ); verify( aclNodeHelper, times( 2 ) ).canAccess( any( RepositoryFile.class ), eq( EnumSet.of( RepositoryFilePermission.READ ) ) ); }