Search in sources :

Example 31 with IPlatformImportBundle

use of org.pentaho.platform.api.repository2.unified.IPlatformImportBundle in project pentaho-platform by pentaho.

the class SolutionImportHandlerNamingIT method testImportFileWithManifest.

@Test
public void testImportFileWithManifest() throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException, PlatformInitializationException, InterruptedException {
    ZipBuilder zipBuilder = new ZipBuilder();
    zipBuilder.addFile(solutionDir + SRC_EXPORTMANIFEST, ZIPENTRY_EXPORTMANIFEST);
    zipBuilder.addFile(solutionDir + SRC_CONTENT_FILE, ZIPENTRY_CONTENT_FILE);
    ByteArrayOutputStream out = zipBuilder.build();
    ByteArrayInputStream solutionInputStream = new ByteArrayInputStream(out.toByteArray());
    final IPlatformImportBundle bundle = buildBundle(solutionInputStream);
    runImport(solutionImportHandler, bundle);
    {
        // files with correct names do exist
        RepositoryFile dir = repo.getFile(IMPORT_REPO_DIR + "/two words%25");
        assertNotNull(dir);
        assertTrue(dir.isFolder());
        RepositoryFile file = repo.getFile(IMPORT_REPO_DIR + "/two words%25/eval (+)%25.prpt");
        assertNotNull(file);
        assertFalse(file.isFolder());
        assertFileContentEquals(new File(solutionDir + SRC_CONTENT_FILE), file);
    }
    {
        // exportManifest.xml does not exist
        assertNull(repo.getFile(IMPORT_REPO_DIR + "/exportManifest.xml"));
    }
    {
        // files with incorrect names do not exist
        assertNull(repo.getFile(IMPORT_REPO_DIR + "/two+words%2525"));
        assertNull(repo.getFile(IMPORT_REPO_DIR + "/two+words%25"));
        assertNull(repo.getFile(IMPORT_REPO_DIR + "/two+words%"));
        assertNull(repo.getFile(IMPORT_REPO_DIR + "/two words%2525"));
        assertNull(repo.getFile(IMPORT_REPO_DIR + "/two words%"));
        assertNull(repo.getFile(IMPORT_REPO_DIR + "/two words%25/eval+%28%2B%29%2525.prpt"));
        assertNull(repo.getFile(IMPORT_REPO_DIR + "/two words%25/eval (+)%.prpt"));
    }
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Test(org.junit.Test)

Example 32 with IPlatformImportBundle

use of org.pentaho.platform.api.repository2.unified.IPlatformImportBundle in project pentaho-platform by pentaho.

the class SolutionImportHandlerNamingIT method importFile.

private RepositoryFile importFile(String manifest) throws IOException, InterruptedException {
    ZipBuilder zipBuilder = new ZipBuilder();
    zipBuilder.addFile(solutionDir + SRC_ROOT + manifest, "exportManifest.xml");
    zipBuilder.addFile(solutionDir + SRC_CONTENT_FILE, SRC_CONTENT_FILE);
    ByteArrayOutputStream out = zipBuilder.build();
    ByteArrayInputStream solutionInputStream = new ByteArrayInputStream(out.toByteArray());
    IPlatformImportBundle bundle = buildBundle(solutionInputStream);
    runImport(solutionImportHandler, bundle);
    return answer != null ? answer.getObj() : null;
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 33 with IPlatformImportBundle

use of org.pentaho.platform.api.repository2.unified.IPlatformImportBundle in project pentaho-platform by pentaho.

the class SolutionImportHandlerNamingIT method testImportFileWithoutManifest.

@Test
public void testImportFileWithoutManifest() throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException, PlatformInitializationException, InterruptedException {
    ByteArrayInputStream solutionInputStream = null;
    final File srcContentFile = new File(solutionDir + SRC_CONTENT_FILE);
    ByteArrayOutputStream tmpOS = null;
    try {
        tmpOS = new ByteArrayOutputStream();
        ZipOutputStream zipOS = new ZipOutputStream(tmpOS);
        zipOS.putNextEntry(new ZipEntry(ZIPENTRY_CONTENT_FILE_NOMANIFEST));
        FileUtils.copyFile(srcContentFile, zipOS);
        zipOS.closeEntry();
        zipOS.close();
        solutionInputStream = new ByteArrayInputStream(tmpOS.toByteArray());
    } finally {
        if (tmpOS != null) {
            tmpOS.close();
        }
    }
    final IPlatformImportBundle bundle = buildBundle(solutionInputStream);
    runImport(solutionImportHandler, bundle);
    {
        // files with correct names do exist
        RepositoryFile dir = repo.getFile(IMPORT_REPO_DIR + "/two words%25");
        assertNotNull(dir);
        assertTrue(dir.isFolder());
        RepositoryFile file = repo.getFile(IMPORT_REPO_DIR + "/two words%25/eval (+)%25.prpt");
        assertNotNull(file);
        assertFalse(file.isFolder());
        assertFileContentEquals(srcContentFile, file);
    }
    {
        // files with incorrect names do not exist
        assertNull(repo.getFile(IMPORT_REPO_DIR + "/two+words%2525"));
        assertNull(repo.getFile(IMPORT_REPO_DIR + "/two+words%25"));
        assertNull(repo.getFile(IMPORT_REPO_DIR + "/two+words%"));
        assertNull(repo.getFile(IMPORT_REPO_DIR + "/two words%2525"));
        assertNull(repo.getFile(IMPORT_REPO_DIR + "/two words%"));
        assertNull(repo.getFile(IMPORT_REPO_DIR + "/two words%25/eval+%28%2B%29%2525.prpt"));
        assertNull(repo.getFile(IMPORT_REPO_DIR + "/two words%25/eval (+)%.prpt"));
    }
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Test(org.junit.Test)

Example 34 with IPlatformImportBundle

use of org.pentaho.platform.api.repository2.unified.IPlatformImportBundle in project data-access by pentaho.

the class DatasourceResourceIT method testPublishDsw.

@Test
public void testPublishDsw() throws Exception {
    DataSourceWizardResource service = new DataSourceWizardResource();
    Mockery mockery = new Mockery();
    final IPlatformImporter mockImporter = mockery.mock(IPlatformImporter.class);
    mp.defineInstance(IPlatformImporter.class, mockImporter);
    mockery.checking(new Expectations() {

        {
            oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {

                public boolean matchesSafely(IPlatformImportBundle bundle) {
                    return bundle.isPreserveDsw() && bundle.getProperty("domain-id").equals("AModel.xmi") && bundle.getMimeType().equals("text/xmi+xml");
                }

                public void describeTo(Description description) {
                    description.appendText("bundle with xmi");
                }
            })));
            oneOf(mockImporter).importFile(with(match(new TypeSafeMatcher<IPlatformImportBundle>() {

                public boolean matchesSafely(IPlatformImportBundle bundle) {
                    return bundle.getProperty("domain-id").equals("AModel") && bundle.getMimeType().equals("application/vnd.pentaho.mondrian+xml");
                }

                public void describeTo(Description description) {
                    description.appendText("bundle with mondrian schema");
                }
            })));
        }
    });
    FileInputStream in = new FileInputStream(new File(new File("target/test-classes"), "SampleDataOlap.xmi"));
    try {
        Response resp = service.publishDsw("AModel.xmi", in, true, false, null);
        Assert.assertEquals(Response.Status.Family.SUCCESSFUL, Response.Status.fromStatusCode(resp.getStatus()).getFamily());
        mockery.assertIsSatisfied();
    } finally {
        IOUtils.closeQuietly(in);
    }
}
Also used : Expectations(org.jmock.Expectations) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) Response(javax.ws.rs.core.Response) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) DataSourceWizardResource(org.pentaho.platform.dataaccess.datasource.api.resources.DataSourceWizardResource) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) Mockery(org.jmock.Mockery) ZipFile(java.util.zip.ZipFile) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 35 with IPlatformImportBundle

use of org.pentaho.platform.api.repository2.unified.IPlatformImportBundle in project data-access by pentaho.

the class DataSourceWizardServiceTest method testPublishDswError.

@Test
public void testPublishDswError() throws Exception {
    String domainId = "domainId";
    InputStream metadataFile = mock(InputStream.class);
    boolean overwrite = true;
    boolean checkConnection = false;
    XmiParser mockXmiParser = mock(XmiParser.class);
    Domain mockDomain = mock(Domain.class);
    InputStream mockInputStream = mock(InputStream.class);
    IPlatformImportBundle mockMetadataBundle = mock(IPlatformImportBundle.class);
    IPlatformImportBundle mockMondrianBundle = mock(IPlatformImportBundle.class);
    IPlatformImporter mockIPlatformImporter = mock(IPlatformImporter.class);
    IPentahoSession mockIPentahoSession = mock(IPentahoSession.class);
    String mockObject = "not null";
    String dswId = "dswId";
    // Test 1
    doReturn(false).when(dataSourceWizardService).hasManageAccessCheck();
    try {
        dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
        fail();
    } catch (PentahoAccessControlException e) {
    // expected
    }
    // Test 2
    doReturn(true).when(dataSourceWizardService).hasManageAccessCheck();
    doReturn(false).when(dataSourceWizardService).endsWith(anyString(), anyString());
    try {
        dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
        fail();
    } catch (IllegalArgumentException e) {
    // expected
    }
    // Test 3
    doReturn(true).when(dataSourceWizardService).endsWith(anyString(), anyString());
    try {
        dataSourceWizardService.publishDsw(domainId, null, overwrite, checkConnection, null);
        fail();
    } catch (IllegalArgumentException e) {
    // expected
    }
    // Test 4
    List<String> mockList = new ArrayList<String>();
    mockList.add("string1");
    doReturn(mockList).when(dataSourceWizardService).getOverwrittenDomains(domainId);
    try {
        dataSourceWizardService.publishDsw(domainId, metadataFile, false, checkConnection, null);
        fail();
    } catch (Exception e) {
    // expected
    }
    // Test 5
    doReturn(mockXmiParser).when(dataSourceWizardService).createXmiParser();
    RuntimeException mockException = mock(RuntimeException.class);
    doThrow(mockException).when(mockXmiParser).parseXmi(metadataFile);
    try {
        dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
        fail();
    } catch (Exception e) {
    // expected
    }
    // Test 6
    doReturn(mockDomain).when(mockXmiParser).parseXmi(metadataFile);
    doReturn(null).when(dataSourceWizardService).getMondrianDatasourceWrapper(mockDomain);
    try {
        dataSourceWizardService.publishDsw(domainId, metadataFile, overwrite, true, null);
        fail();
    } catch (Exception e) {
    // expected
    }
    verify(dataSourceWizardService, times(3)).publishDsw(domainId, metadataFile, overwrite, checkConnection, null);
    verify(dataSourceWizardService, times(1)).publishDsw(domainId, null, overwrite, checkConnection, null);
    verify(dataSourceWizardService, times(1)).publishDsw(domainId, metadataFile, false, checkConnection, null);
    verify(dataSourceWizardService, times(1)).publishDsw(domainId, metadataFile, overwrite, true, null);
}
Also used : InputStream(java.io.InputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) XmiParser(org.pentaho.metadata.util.XmiParser) IPlatformImporter(org.pentaho.platform.plugin.services.importer.IPlatformImporter) Domain(org.pentaho.metadata.model.Domain) Test(org.junit.Test)

Aggregations

IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)34 Test (org.junit.Test)21 InputStream (java.io.InputStream)15 FileInputStream (java.io.FileInputStream)14 IPlatformImporter (org.pentaho.platform.plugin.services.importer.IPlatformImporter)13 File (java.io.File)12 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)10 RepositoryFileImportBundle (org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle)8 ArrayList (java.util.ArrayList)7 Expectations (org.jmock.Expectations)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IOException (java.io.IOException)5 Response (javax.ws.rs.core.Response)5 Matchers.anyString (org.mockito.Matchers.anyString)5 FileResource (org.pentaho.platform.web.http.api.resources.FileResource)5 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)4 Domain (org.pentaho.metadata.model.Domain)4 XmiParser (org.pentaho.metadata.util.XmiParser)4