Search in sources :

Example 1 with DefaultExportHandler

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

the class FileResourceIT method testBrowserDownload.

// This is testing the Rest end points, we should instead be testing the underlying functionality in unit tests
@Test
public void testBrowserDownload() {
    final String text = "abcdefg";
    // mock converters map
    StreamConverter streamConverter = new StreamConverter(repo);
    Map<String, Converter> converterMap = new HashMap<String, Converter>();
    converterMap.put("txt", streamConverter);
    // stub DefaultExportProcessor
    DefaultExportHandler defaultExportHandler = new DefaultExportHandler();
    defaultExportHandler.setConverters(converterMap);
    defaultExportHandler.setRepository(repo);
    loginAsRepositoryAdmin();
    ITenant systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminAuthorityName, authenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminAuthorityName });
    login(sysAdminUserName, systemTenant, new String[] { adminAuthorityName, authenticatedAuthorityName });
    ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminAuthorityName, authenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(mainTenant_1, "admin", "password", "", new String[] { adminAuthorityName });
    try {
        login("admin", mainTenant_1, new String[] { authenticatedAuthorityName, adminAuthorityName });
        mp.defineInstance(IUnifiedRepository.class, repo);
        mp.defineInstance(DefaultExportHandler.class, defaultExportHandler);
        final String fileName = "file.txt";
        createTestFile("/public".replaceAll("/", ":") + ":" + fileName, text);
        // test download of file
        WebResource webResource = resource();
        webResource.path("repo/files/public:file.txt/download").get(ClientResponse.class);
        // test download of dir as a zip file
        ClientResponse r2 = webResource.path("repo/files/public:file.txt/download").get(ClientResponse.class);
        assertResponse(r2, Status.OK);
        JerseyTestUtil.assertResponseIsZip(r2);
    } catch (Throwable ex) {
        TestCase.fail();
    } finally {
        cleanupUserAndRoles(mainTenant_1);
        cleanupUserAndRoles(systemTenant);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ITenant(org.pentaho.platform.api.mt.ITenant) HashMap(java.util.HashMap) StreamConverter(org.pentaho.platform.plugin.services.importexport.StreamConverter) StreamConverter(org.pentaho.platform.plugin.services.importexport.StreamConverter) Converter(org.pentaho.platform.api.repository2.unified.Converter) WebResource(com.sun.jersey.api.client.WebResource) DefaultExportHandler(org.pentaho.platform.plugin.services.importexport.DefaultExportHandler) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Aggregations

ClientResponse (com.sun.jersey.api.client.ClientResponse)1 WebResource (com.sun.jersey.api.client.WebResource)1 JerseyTest (com.sun.jersey.test.framework.JerseyTest)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 ITenant (org.pentaho.platform.api.mt.ITenant)1 Converter (org.pentaho.platform.api.repository2.unified.Converter)1 DefaultExportHandler (org.pentaho.platform.plugin.services.importexport.DefaultExportHandler)1 StreamConverter (org.pentaho.platform.plugin.services.importexport.StreamConverter)1