use of org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger in project pentaho-platform by pentaho.
the class PlatformImporterTest method testNoMatchingMime.
@Test
public void testNoMatchingMime() throws Exception {
IPlatformImportHandler mockImportHandler = mock(IPlatformImportHandler.class);
when(mockImportHandler.getMimeTypes()).thenReturn(Collections.<IMimeType>emptyList());
List<IPlatformImportHandler> handlers = new ArrayList<IPlatformImportHandler>();
handlers.add(mockImportHandler);
NameBaseMimeResolver nameResolver = new NameBaseMimeResolver();
PentahoSystem.registerObject(nameResolver);
PentahoPlatformImporter importer = new PentahoPlatformImporter(handlers, new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>()));
importer.setDefaultHandler(mockImportHandler);
FileInputStream in = new FileInputStream(new File(TestResourceLocation.TEST_RESOURCES + "/ImportTest/steel-wheels.xmi"));
Log4JRepositoryImportLogger importLogger = new Log4JRepositoryImportLogger();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
importLogger.startJob(outputStream, "", Level.DEBUG);
// With custom domain id
final IPlatformImportBundle bundle1 = (new RepositoryFileImportBundle.Builder().input(in).charSet("UTF-8").hidden(false).overwriteFile(true).name("steel-wheels.xmi").comment("Test Metadata Import").withParam("domain-id", "parameterized-domain-id")).build();
try {
importer.setRepositoryImportLogger(importLogger);
importer.importFile(bundle1);
String result = new String(outputStream.toByteArray());
assertTrue(result.contains("Error computing or retrieving mime-type"));
} catch (PlatformImportException e) {
e.printStackTrace();
return;
}
importLogger.endJob();
}
use of org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger in project pentaho-platform by pentaho.
the class PlatformImporterTest method testMatchingMimeAndHandler.
@Test
public void testMatchingMimeAndHandler() throws Exception {
List<IMimeType> mimeList = Collections.singletonList((IMimeType) new MimeType("text/xmi+xml", "xmi"));
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>()));
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(mockImportHandler, times(1)).importFile(bundle1);
}
use of org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger 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 = Arrays.asList(extension);
IMimeType mimeType = new MimeType(mimeTypeName, extensions);
mimeType.setConverter(mock(Converter.class));
List<IMimeType> mimeTypeList = Arrays.asList(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(Arrays.asList("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.plugin.services.importexport.Log4JRepositoryImportLogger in project pentaho-platform by pentaho.
the class LocaleImportHandlerTest method setUp.
@Before
public void setUp() throws Exception {
NameBaseMimeResolver nameResolver = new NameBaseMimeResolver();
PentahoSystem.registerObject(nameResolver);
IRepositoryContentConverterHandler converterHandler = new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>());
List<IMimeType> localeMimeList = new ArrayList<IMimeType>();
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);
List<String> allowedArtifacts = new ArrayList<String>();
allowedArtifacts.add("xaction");
allowedArtifacts.add("url");
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<IPlatformImportHandler>();
handlers.add(spylocaleImportHandler);
importer = new PentahoPlatformImporter(handlers, converterHandler);
importer.setRepositoryImportLogger(new Log4JRepositoryImportLogger());
localeFilesProcessor = new LocaleFilesProcessor();
}
use of org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger 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);
}
Aggregations