use of org.pentaho.platform.dataaccess.datasource.api.resources.DataSourceWizardResource in project data-access by pentaho.
the class DatasourceResourceIT method testMetadataImportExport.
@Test
public void testMetadataImportExport() throws PlatformInitializationException, IOException, PlatformImportException {
List<IMimeType> mimeTypeList = new ArrayList<IMimeType>();
mimeTypeList.add(new MimeType("Metadata", ".xmi"));
File metadata = new File("target/test-classes/dsw/testData/metadata.xmi");
RepositoryFile repoMetadataFile = new RepositoryFile.Builder(metadata.getName()).folder(false).hidden(false).build();
MetadataImportHandler metadataImportHandler = new MetadataImportHandler(mimeTypeList, (IPentahoMetadataDomainRepositoryImporter) PentahoSystem.get(IMetadataDomainRepository.class));
RepositoryFileImportBundle bundle1 = new RepositoryFileImportBundle.Builder().file(repoMetadataFile).charSet("UTF-8").input(new FileInputStream(metadata)).mime(".xmi").withParam("domain-id", "SalesData").build();
metadataImportHandler.importFile(bundle1);
final Response salesData = new DataSourceWizardResource().doGetDSWFilesAsDownload("SalesData");
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(".xmi\""));
}
use of org.pentaho.platform.dataaccess.datasource.api.resources.DataSourceWizardResource 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();
}
use of org.pentaho.platform.dataaccess.datasource.api.resources.DataSourceWizardResource 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);
}
}
Aggregations