Search in sources :

Example 1 with MondrianImportHandler

use of org.pentaho.platform.plugin.services.importer.MondrianImportHandler in project data-access by pentaho.

the class DatasourceResourceIT method testMondrianImportExport.

@Test
public void testMondrianImportExport() throws Exception {
    final String domainName = "SalesData";
    List<IMimeType> mimeTypeList = new ArrayList<IMimeType>();
    mimeTypeList.add(new MimeType("Mondrian", "mondrian.xml"));
    // $NON-NLS-1$ //$NON-NLS-2$
    System.setProperty("org.osjava.sj.root", "target/test-classes/solution1/system/simple-jndi");
    File mondrian = new File("target/test-classes/dsw/testData/SalesData.mondrian.xml");
    RepositoryFile repoMondrianFile = new RepositoryFile.Builder(mondrian.getName()).folder(false).hidden(false).build();
    RepositoryFileImportBundle bundle1 = new RepositoryFileImportBundle.Builder().file(repoMondrianFile).charSet("UTF-8").input(new FileInputStream(mondrian)).mime("mondrian.xml").withParam("parameters", "Datasource=Pentaho;overwrite=true").withParam("domain-id", "SalesData").build();
    MondrianImportHandler mondrianImportHandler = new MondrianImportHandler(mimeTypeList, PentahoSystem.get(IMondrianCatalogService.class));
    mondrianImportHandler.importFile(bundle1);
    try {
        KettleEnvironment.init();
        Props.init(Props.TYPE_PROPERTIES_EMPTY);
    } catch (Exception e) {
    // may already be initialized by another test
    }
    Domain domain = generateModel();
    ModelerWorkspace model = new ModelerWorkspace(new GwtModelerWorkspaceHelper());
    model.setModelName("ORDERS");
    model.setDomain(domain);
    model.getWorkspaceHelper().populateDomain(model);
    new ModelerService().serializeModels(domain, domainName);
    final Response salesData = new DataSourceWizardResource().doGetDSWFilesAsDownload(domainName + ".xmi");
    Assert.assertEquals(salesData.getStatus(), Response.Status.OK.getStatusCode());
    Assert.assertNotNull(salesData.getMetadata());
    Assert.assertNotNull(salesData.getMetadata().getFirst("Content-Disposition"));
    Assert.assertEquals(salesData.getMetadata().getFirst("Content-Disposition").getClass(), String.class);
    Assert.assertTrue(((String) salesData.getMetadata().getFirst("Content-Disposition")).endsWith(domainName + ".zip\""));
    File file = File.createTempFile(domainName, ".zip");
    final FileOutputStream fileOutputStream = new FileOutputStream(file);
    ((StreamingOutput) salesData.getEntity()).write(fileOutputStream);
    fileOutputStream.close();
    final ZipFile zipFile = new ZipFile(file);
    final Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        final ZipEntry zipEntry = entries.nextElement();
        Assert.assertTrue(zipEntry.getName().equals(domainName + ".xmi") || zipEntry.getName().equals(domainName + ".mondrian.xml"));
    }
    zipFile.close();
    file.delete();
}
Also used : ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) StreamingOutput(javax.ws.rs.core.StreamingOutput) Matchers.anyString(org.mockito.Matchers.anyString) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileImportBundle(org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle) MondrianImportHandler(org.pentaho.platform.plugin.services.importer.MondrianImportHandler) IMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService) FileInputStream(java.io.FileInputStream) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) PlatformInitializationException(org.pentaho.platform.engine.core.system.boot.PlatformInitializationException) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) DataAccessException(org.springframework.dao.DataAccessException) DuplicateDatasourceException(org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException) IOException(java.io.IOException) NonExistingDatasourceException(org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException) GwtModelerWorkspaceHelper(org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper) Response(javax.ws.rs.core.Response) DataSourceWizardResource(org.pentaho.platform.dataaccess.datasource.api.resources.DataSourceWizardResource) ZipFile(java.util.zip.ZipFile) FileOutputStream(java.io.FileOutputStream) Domain(org.pentaho.metadata.model.Domain) ZipFile(java.util.zip.ZipFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) Test(org.junit.Test)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 Response (javax.ws.rs.core.Response)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)1 GwtModelerWorkspaceHelper (org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper)1 Domain (org.pentaho.metadata.model.Domain)1 IMimeType (org.pentaho.platform.api.mimetype.IMimeType)1 DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)1 DuplicateDatasourceException (org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException)1 NonExistingDatasourceException (org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 MimeType (org.pentaho.platform.core.mimetype.MimeType)1