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