use of org.pentaho.platform.api.mimetype.IMimeType in project pentaho-platform by pentaho.
the class PlatformImporterTest method testUseDefaultHandler.
@Test
public void testUseDefaultHandler() throws Exception {
List<IMimeType> mimeList = Collections.singletonList((IMimeType) new MimeType("text/html", "html"));
IPlatformImportHandler mockImportHandler = mock(IPlatformImportHandler.class);
when(mockImportHandler.getMimeTypes()).thenReturn(mimeList);
List<IPlatformImportHandler> handlers = Collections.singletonList(mockImportHandler);
NameBaseMimeResolver nameResolver = new NameBaseMimeResolver();
PentahoSystem.registerObject(nameResolver);
// mock logger to prevent npe
IRepositoryImportLogger importLogger = new Log4JRepositoryImportLogger();
PentahoPlatformImporter importer = new PentahoPlatformImporter(handlers, new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>()));
IPlatformImportHandler mockDefaultImportHandler = mock(IPlatformImportHandler.class);
importer.setDefaultHandler(mockDefaultImportHandler);
importer.setRepositoryImportLogger(importLogger);
FileInputStream in = new FileInputStream(new File(TestResourceLocation.TEST_RESOURCES + "/ImportTest/steel-wheels.xmi"));
// With custom domain id
final IPlatformImportBundle bundle1 = (new RepositoryFileImportBundle.Builder().input(in).charSet("UTF-8").hidden(false).mime("text/xmi+xml").name("steel-wheels.xmi").comment("Test Metadata Import").withParam("domain-id", "parameterized-domain-id")).build();
importer.importFile(bundle1);
verify(mockDefaultImportHandler, times(1)).importFile(bundle1);
}
use of org.pentaho.platform.api.mimetype.IMimeType in project pentaho-platform by pentaho.
the class SolutionImportHandlerNamingIT method init.
@Before
public void init() throws IOException, PlatformInitializationException, PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException {
// repository
File repoDir = new File(tempDir.getAbsolutePath() + REPO_PATH);
FileUtils.forceMkdir(repoDir);
FileUtils.cleanDirectory(repoDir);
repoRoot = repoDir;
repo = new FileSystemBackedUnifiedRepository();
repo = Mockito.spy(repo);
repo.setRootDir(repoRoot);
// mimeResolver
final Converter defaultConverter = new StreamConverter();
final List<IMimeType> solutionMimeList = java.util.Collections.singletonList(MIME_SOLUTION);
final List<IMimeType> contentMimeList = java.util.Arrays.asList(new IMimeType[] { MIME_PRPT, MIME_XML });
final List<IMimeType> allMimeTypes = new ArrayList<IMimeType>(solutionMimeList.size() + contentMimeList.size());
{
allMimeTypes.addAll(solutionMimeList);
allMimeTypes.addAll(contentMimeList);
for (IMimeType mimeType : allMimeTypes) {
mimeType.setConverter(defaultConverter);
}
}
final IPlatformMimeResolver mimeResolver = new NameBaseMimeResolver();
for (IMimeType mimeType : allMimeTypes) {
mimeResolver.addMimeType(mimeType);
}
// platform, import handlers
PentahoSystem.clearObjectFactory();
microPlatform = new MicroPlatform(getSolutionPath());
microPlatform.defineInstance(IUnifiedRepository.class, repo);
microPlatform.defineInstance(IPlatformMimeResolver.class, mimeResolver);
microPlatform.defineInstance(ISolutionEngine.class, Mockito.mock(SolutionEngine.class));
microPlatform.defineInstance(IDatasourceMgmtService.class, Mockito.mock(IDatasourceMgmtService.class));
IRepositoryContentConverterHandler converterHandler = new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>());
RepositoryFileImportFileHandler contentImportFileHandler = new RepositoryFileImportFileHandler(contentMimeList);
contentImportFileHandler.setRepository(repo);
solutionImportHandler = new SolutionImportHandler(solutionMimeList);
List<IPlatformImportHandler> handlers = new ArrayList<IPlatformImportHandler>();
handlers.add(contentImportFileHandler);
handlers.add(solutionImportHandler);
PentahoPlatformImporter importer = new PentahoPlatformImporter(handlers, converterHandler);
importer.setDefaultHandler(contentImportFileHandler);
importer.setRepositoryImportLogger(new Log4JRepositoryImportLogger());
microPlatform.defineInstance(IPlatformImporter.class, importer);
microPlatform.start();
}
use of org.pentaho.platform.api.mimetype.IMimeType 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();
}
Aggregations