Search in sources :

Example 1 with ExportHandler

use of org.pentaho.platform.plugin.services.importexport.ExportHandler in project pentaho-platform by pentaho.

the class FileServiceTest method assertDoGetFileOrDirAsDownload.

/**
 * @param fileName
 * @param withManifest
 * @param expectedEncodedFileName
 * @param expectedFileName
 * @throws Throwable
 */
public void assertDoGetFileOrDirAsDownload(final String fileName, final String withManifest, final String expectedEncodedFileName, final String expectedFileName) throws Throwable {
    IAuthorizationPolicy mockAuthPolicy = mock(IAuthorizationPolicy.class);
    when(mockAuthPolicy.isAllowed(anyString())).thenReturn(true);
    BaseExportProcessor mockExportProcessor = mock(BaseExportProcessor.class);
    File mockExportFile = mock(File.class);
    ExportHandler mockExportHandler = mock(ExportHandler.class);
    StreamingOutput mockStream = mock(StreamingOutput.class);
    RepositoryFile mockRepoFile = mock(RepositoryFile.class);
    doReturn(fileName).when(mockRepoFile).getName();
    doReturn(mockExportFile).when(mockExportProcessor).performExport(mockRepoFile);
    doReturn(mockRepoFile).when(fileService.repository).getFile(anyString());
    doReturn(mockAuthPolicy).when(fileService).getPolicy();
    doReturn(mockExportProcessor).when(fileService).getDownloadExportProcessor(anyString(), anyBoolean(), anyBoolean());
    doReturn(mockExportHandler).when(fileService).getDownloadExportHandler();
    doReturn(mockStream).when(fileService).getDownloadStream(mockRepoFile, mockExportProcessor);
    FileService.DownloadFileWrapper wrapper = fileService.doGetFileOrDirAsDownload("", "mock:path:" + fileName, withManifest);
    verify(fileService.repository, times(1)).getFile(anyString());
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(mockAuthPolicy, times(3)).isAllowed(captor.capture());
    assertTrue(captor.getAllValues().contains(RepositoryReadAction.NAME));
    assertTrue(captor.getAllValues().contains(RepositoryCreateAction.NAME));
    assertEquals(mockStream, wrapper.getOutputStream());
    assertEquals(expectedEncodedFileName, wrapper.getEncodedFileName());
    assertEquals("attachment; filename=\"" + expectedFileName + "\"", wrapper.getAttachment());
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) ExportHandler(org.pentaho.platform.plugin.services.importexport.ExportHandler) StreamingOutput(javax.ws.rs.core.StreamingOutput) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) BaseExportProcessor(org.pentaho.platform.plugin.services.importexport.BaseExportProcessor)

Aggregations

File (java.io.File)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 Matchers.anyString (org.mockito.Matchers.anyString)1 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 BaseExportProcessor (org.pentaho.platform.plugin.services.importexport.BaseExportProcessor)1 ExportHandler (org.pentaho.platform.plugin.services.importexport.ExportHandler)1