use of org.pentaho.platform.core.mimetype.MimeType 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.core.mimetype.MimeType in project pentaho-platform by pentaho.
the class MimeTypeListFactoryIT method testGetMimeTypeList.
@Test
public void testGetMimeTypeList() throws Exception {
MicroPlatform microPlatform = new MicroPlatform();
StandaloneSpringPentahoObjectFactory objectFactory = new StandaloneSpringPentahoObjectFactory();
objectFactory.init(TestResourceLocation.TEST_RESOURCES + "/MimeTypeFactoryTest/MimeTypeFactoryTest.spring.xml", null);
PentahoSystem.registerObjectFactory(objectFactory);
MimeTypeListFactory factory = new MimeTypeListFactory(TestResourceLocation.TEST_RESOURCES + "/MimeTypeFactoryTest/ImportHandlerMimeTypeDefinitions.xml");
List<IMimeType> list1 = factory.createMimeTypeList("org.pentaho.platform.plugin.services.importer.RepositoryFileImportFileHandler");
assertNotNull(list1);
list1 = factory.createMimeTypeList("this.one.is.not.present");
assertNotNull(list1);
assertEquals(0, list1.size());
list1 = factory.createMimeTypeList("org.pentaho.platform.plugin.services.importer.SolutionImportHandler");
assertNotNull(list1);
assertTrue(list1.size() > 0);
list1 = factory.createMimeTypeList("com.pentaho.repository.importexport.PDIImportFileHandler");
assertNotNull(list1);
assert (list1.contains(new MimeType("application/vnd.pentaho.job", "ktr")));
}
use of org.pentaho.platform.core.mimetype.MimeType in project pentaho-platform by pentaho.
the class MetadataImportHandlerIT method setUp.
@Before
public void setUp() throws Exception {
// mock logger to prevent npe
importLogger = new Log4JRepositoryImportLogger();
context = new Mockery();
metadataImporter = context.mock(IPentahoMetadataDomainRepositoryImporter.class);
MicroPlatform microPlatform = new MicroPlatform();
NameBaseMimeResolver nameResolver = new NameBaseMimeResolver();
microPlatform.defineInstance(IPlatformMimeResolver.class, nameResolver);
List<IMimeType> mimeList = new ArrayList<IMimeType>();
mimeList.add(new MimeType("text/xmi+xml", "xmi"));
metadataHandler = new MetadataImportHandler(mimeList, metadataImporter);
handlers.add(metadataHandler);
importer = new PentahoPlatformImporter(handlers, new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>()));
importer.setRepositoryImportLogger(importLogger);
}
use of org.pentaho.platform.core.mimetype.MimeType in project pentaho-platform by pentaho.
the class RepositoryFileImportFileHandlerTest method setup.
private void setup(String mimeTypeName, String extension, String path, String fileName, boolean folder) {
List<String> extensions = Collections.singletonList(extension);
IMimeType mimeType = new MimeType(mimeTypeName, extensions);
mimeType.setConverter(mock(Converter.class));
List<IMimeType> mimeTypeList = Collections.singletonList(mimeType);
NameBaseMimeResolver mimeResolver = new NameBaseMimeResolver();
mimeResolver.addMimeType(mimeType);
SolutionFileImportHelper.testMimeResolver = mimeResolver;
userProvider = new UserProvider();
mockRepository = new MockUnifiedRepository(userProvider);
fileHandler = new RepositoryFileImportFileHandler(mimeTypeList);
fileHandler.setRepository(mockRepository);
fileHandler.setDefaultAclHandler(new DefaultAclHandler());
fileHandler.setKnownExtensions(Collections.singletonList("prpt"));
IPlatformImporter mockPlatformImporter = mock(IPlatformImporter.class);
when(mockPlatformImporter.getRepositoryImportLogger()).thenReturn(new Log4JRepositoryImportLogger());
ImportSession.iPlatformImporter = mockPlatformImporter;
importSession = fileHandler.getImportSession();
importSession.initialize();
mockBundle = mock(RepositoryFileImportBundle.class);
when(mockBundle.getPath()).thenReturn(path);
when(mockBundle.getName()).thenReturn(fileName);
when(mockBundle.getMimeType()).thenReturn(mimeTypeName);
when(mockBundle.isFolder()).thenReturn(folder);
}
use of org.pentaho.platform.core.mimetype.MimeType in project pentaho-platform by pentaho.
the class LocaleImportHandlerTest method setUp.
@Before
public void setUp() throws Exception {
mockUnifiedRepository = mock(IUnifiedRepository.class);
pentahoSystemMock.when(() -> PentahoSystem.get(IUnifiedRepository.class)).thenReturn(mockUnifiedRepository);
NameBaseMimeResolver nameResolver = new NameBaseMimeResolver();
PentahoSystem.registerObject(nameResolver);
IRepositoryContentConverterHandler converterHandler = new DefaultRepositoryContentConverterHandler(new HashMap<>());
List<IMimeType> localeMimeList = new ArrayList<>();
localeMimeList.add(new MimeType("text/locale", "locale"));
nameResolver.addMimeType(new MimeType("text/prptMimeType", "prpt"));
nameResolver.addMimeType(new MimeType("text/xactionMimeType", "xaction"));
MimeType mimeType = new MimeType("text/xml", "xml");
mimeType.setHidden(true);
nameResolver.addMimeType(mimeType);
mimeType = new MimeType("image/png", "png");
mimeType.setHidden(true);
nameResolver.addMimeType(mimeType);
pentahoSystemMock.when(() -> PentahoSystem.get(IPlatformMimeResolver.class)).thenReturn(nameResolver);
List<String> allowedArtifacts = new ArrayList<>();
allowedArtifacts.add("xaction");
allowedArtifacts.add("url");
allowedArtifacts.add("properties");
LocaleImportHandler localeImportHandler = new LocaleImportHandler(localeMimeList, allowedArtifacts);
LocaleImportHandler spylocaleImportHandler = spy(localeImportHandler);
Log log = mock(Log.class);
doReturn(log).when(spylocaleImportHandler).getLogger();
List<IPlatformImportHandler> handlers = new ArrayList<>();
handlers.add(spylocaleImportHandler);
importer = new PentahoPlatformImporter(handlers, converterHandler);
importer.setRepositoryImportLogger(new Log4JRepositoryImportLogger());
localeFilesProcessor = new LocaleFilesProcessor();
this.localeImportHandler = new LocaleImportHandler(localeMimeList, allowedArtifacts);
}
Aggregations