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());
}
Aggregations