Search in sources :

Example 1 with Exporter

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

the class ExporterTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    // set up mock repository
    unifiedRepository = mock(IUnifiedRepository.class);
    repositoryFile = mock(RepositoryFile.class);
    // handle method calls
    when(unifiedRepository.getFile(REPO_PATH)).thenReturn(repositoryFile);
    // instantiate exporter here to reuse for each test
    exporter = new Exporter(unifiedRepository);
    exporter.setRepoPath(REPO_PATH);
    exporter.setFilePath(FILE_PATH);
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Exporter(org.pentaho.platform.plugin.services.importexport.Exporter) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 2 with Exporter

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

the class ExporterTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    // set up mock repository
    unifiedRepository = mock(IUnifiedRepository.class);
    repositoryFile = mock(RepositoryFile.class);
    // handle method calls
    when(unifiedRepository.getFile(REPO_PATH)).thenReturn(repositoryFile);
    // instantiate exporter here to reuse for each test
    exporter = new Exporter(unifiedRepository);
    exporter.setRepoPath(REPO_PATH);
    exporter.setFilePath(FILE_PATH);
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Exporter(org.pentaho.platform.plugin.services.importexport.Exporter) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 3 with Exporter

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

the class FileResource method doGetDirAsZip.

/**
 * @param repositoryFile
 * @return
 */
public Response doGetDirAsZip(RepositoryFile repositoryFile) {
    String path = repositoryFile.getPath();
    final InputStream is;
    try {
        Exporter exporter = getExporter();
        exporter.setRepoPath(path);
        exporter.setRepoWs(repoWs);
        File zipFile = exporter.doExportAsZip(repositoryFile);
        is = getFileInputStream(zipFile);
    } catch (Exception e) {
        return buildServerErrorResponse(e.toString());
    }
    StreamingOutput streamingOutput = getStreamingOutput(is);
    return buildOkResponse(streamingOutput, APPLICATION_ZIP);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) Exporter(org.pentaho.platform.plugin.services.importexport.Exporter) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) GeneralSecurityException(java.security.GeneralSecurityException) InvalidParameterException(java.security.InvalidParameterException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) WebApplicationException(javax.ws.rs.WebApplicationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExportException(org.pentaho.platform.plugin.services.importexport.ExportException) DocumentException(org.dom4j.DocumentException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 4 with Exporter

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

the class FileResourceTest method testDoGetDirAsZipWithFile.

@Test
public void testDoGetDirAsZipWithFile() throws Exception {
    RepositoryFile mockRepositoryFile = mock(RepositoryFile.class);
    String path = "path";
    doReturn(path).when(mockRepositoryFile).getPath();
    Exporter mockExporter = mock(Exporter.class);
    doReturn(mockExporter).when(fileResource).getExporter();
    File mockFile = mock(File.class);
    doReturn(mockFile).when(mockExporter).doExportAsZip(mockRepositoryFile);
    InputStream mockInputStream = mock(FileInputStream.class);
    doReturn(mockInputStream).when(fileResource).getFileInputStream(mockFile);
    StreamingOutput mockOutput = mock(StreamingOutput.class);
    doReturn(mockOutput).when(fileResource).getStreamingOutput(mockInputStream);
    Response mockResponse = mock(Response.class);
    doReturn(mockResponse).when(fileResource).buildOkResponse(mockOutput, FileResource.APPLICATION_ZIP);
    Response testResponse = fileResource.doGetDirAsZip(mockRepositoryFile);
    assertEquals(mockResponse, testResponse);
    verify(mockRepositoryFile, times(1)).getPath();
    verify(fileResource, times(1)).getExporter();
    verify(mockExporter, times(1)).setRepoPath(path);
    verify(mockExporter, times(1)).setRepoWs(fileResource.repoWs);
    verify(mockExporter, times(1)).doExportAsZip(mockRepositoryFile);
    verify(fileResource, times(1)).getFileInputStream(mockFile);
    verify(fileResource, times(1)).getStreamingOutput(mockInputStream);
    verify(fileResource, times(1)).buildOkResponse(mockOutput, FileResource.APPLICATION_ZIP);
}
Also used : Response(javax.ws.rs.core.Response) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) StreamingOutput(javax.ws.rs.core.StreamingOutput) Exporter(org.pentaho.platform.plugin.services.importexport.Exporter) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) Test(org.junit.Test)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)4 Exporter (org.pentaho.platform.plugin.services.importexport.Exporter)4 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 StreamingOutput (javax.ws.rs.core.StreamingOutput)2 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 IllegalSelectorException (java.nio.channels.IllegalSelectorException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 InvalidParameterException (java.security.InvalidParameterException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Response (javax.ws.rs.core.Response)1 DocumentException (org.dom4j.DocumentException)1 Test (org.junit.Test)1 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)1 UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)1 PlatformImportException (org.pentaho.platform.plugin.services.importer.PlatformImportException)1