Search in sources :

Example 21 with FileContent

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);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream)

Example 22 with FileContent

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());
}
Also used : FileContent(org.apache.commons.vfs2.FileContent) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) ByteArrayInputStream(java.io.ByteArrayInputStream) IAclNodeHelper(org.pentaho.platform.api.repository2.unified.IAclNodeHelper) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Test(org.junit.Test)

Aggregations

FileContent (org.apache.commons.vfs2.FileContent)20 FileObject (org.apache.commons.vfs2.FileObject)16 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 File (java.io.File)4 FileSystemException (org.apache.commons.vfs2.FileSystemException)4 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)4 Test (org.junit.Test)4 FileOutputStream (java.io.FileOutputStream)3 OutputStream (java.io.OutputStream)3 URL (java.net.URL)2 FileName (org.apache.commons.vfs2.FileName)2 KettleFileException (org.pentaho.di.core.exception.KettleFileException)2 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Connection (com.trilead.ssh2.Connection)1 HTTPProxyData (com.trilead.ssh2.HTTPProxyData)1 CharArrayWriter (java.io.CharArrayWriter)1