use of org.apache.commons.vfs2.FileContent in project pentaho-platform by pentaho.
the class ApacheVFSOutputHandlerTest method setupMockObjectsDefaults.
private void setupMockObjectsDefaults(String contentName, boolean isWritable, boolean hasContent) {
try {
when(mockFileContent.getOutputStream()).thenReturn(new ByteArrayOutputStream());
when(mockFileObject.isWriteable()).thenReturn(isWritable);
when(mockFileObject.getContent()).thenReturn(hasContent ? mockFileContent : null);
when(mockedFSM.resolveFile("1:filecontent")).thenReturn(mockFileObject);
doReturn(mockedFSM).when(apacheVFSOutputHandler).getFileSystemManager();
doReturn(contentName).when(apacheVFSOutputHandler).getContentRef();
} catch (FileSystemException e) {
assertTrue("Shouldn't have thrown exception here", false);
}
}
use of org.apache.commons.vfs2.FileContent in project pentaho-platform by pentaho.
the class SolutionRepositoryVfsFileObjectTest method testContentRelatedMethods.
@Test
public void testContentRelatedMethods() throws FileSystemException {
String fileRef = "/etc/mondrian/SteelWheels/schema.xml";
RepositoryFile mockRepoFile = mock(RepositoryFile.class);
IAclNodeHelper mockAclHelper = mock(IAclNodeHelper.class);
SimpleRepositoryFileData mockFileData = mock(SimpleRepositoryFileData.class);
when(mockUnifiedRepository.getFile(nullable(String.class))).thenReturn(mockRepoFile);
when(mockAclHelper.canAccess(mockRepoFile, EnumSet.of(RepositoryFilePermission.READ))).thenReturn(true);
when(mockUnifiedRepository.getDataForRead(any(), any())).thenReturn(mockFileData);
when(mockFileData.getStream()).thenReturn(new ByteArrayInputStream("some string".getBytes()));
SolutionRepositoryVfsFileObject solutionRepositoryVfsFileObject = new SolutionRepositoryVfsFileObject(fileRef);
SolutionRepositoryVfsFileObject.setTestAclHelper(mockAclHelper);
FileContent someFileContent = solutionRepositoryVfsFileObject.getContent();
assertNotNull(someFileContent);
assertFalse(solutionRepositoryVfsFileObject.isContentOpen());
someFileContent.getInputStream();
assertTrue(solutionRepositoryVfsFileObject.isContentOpen());
someFileContent.close();
assertFalse(solutionRepositoryVfsFileObject.isContentOpen());
someFileContent = solutionRepositoryVfsFileObject.getContent();
someFileContent.getInputStream();
assertTrue(solutionRepositoryVfsFileObject.isContentOpen());
solutionRepositoryVfsFileObject.close();
assertFalse(solutionRepositoryVfsFileObject.isContentOpen());
}
Aggregations