Search in sources :

Example 1 with Log4JRepositoryImportLogger

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();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileInputStream(java.io.FileInputStream) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) File(java.io.File) Test(org.junit.Test)

Example 2 with Log4JRepositoryImportLogger

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);
}
Also used : HashMap(java.util.HashMap) IRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) FileInputStream(java.io.FileInputStream) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) File(java.io.File) Test(org.junit.Test)

Example 3 with Log4JRepositoryImportLogger

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);
}
Also used : MockUnifiedRepository(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) IRepositoryDefaultAclHandler(org.pentaho.platform.api.repository2.unified.IRepositoryDefaultAclHandler) ICurrentUserProvider(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository.ICurrentUserProvider) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) Converter(org.pentaho.platform.api.repository2.unified.Converter)

Example 4 with Log4JRepositoryImportLogger

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();
}
Also used : Log(org.apache.commons.logging.Log) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) IRepositoryContentConverterHandler(org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) Converter(org.pentaho.platform.api.repository2.unified.Converter) Before(org.junit.Before)

Example 5 with Log4JRepositoryImportLogger

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);
}
Also used : ArrayList(java.util.ArrayList) Mockery(org.jmock.Mockery) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) IPentahoMetadataDomainRepositoryImporter(org.pentaho.platform.plugin.services.metadata.IPentahoMetadataDomainRepositoryImporter) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) Converter(org.pentaho.platform.api.repository2.unified.Converter) Before(org.junit.Before)

Aggregations

Log4JRepositoryImportLogger (org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger)8 IMimeType (org.pentaho.platform.api.mimetype.IMimeType)7 MimeType (org.pentaho.platform.core.mimetype.MimeType)6 ArrayList (java.util.ArrayList)5 Converter (org.pentaho.platform.api.repository2.unified.Converter)5 File (java.io.File)4 Test (org.junit.Test)4 IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)4 FileInputStream (java.io.FileInputStream)3 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 IRepositoryContentConverterHandler (org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler)3 Log (org.apache.commons.logging.Log)2 IRepositoryImportLogger (org.pentaho.platform.plugin.services.importexport.IRepositoryImportLogger)2 MicroPlatform (org.pentaho.test.platform.engine.core.MicroPlatform)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Mockery (org.jmock.Mockery)1 Matchers.anyString (org.mockito.Matchers.anyString)1 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)1 IPlatformMimeResolver (org.pentaho.platform.api.mimetype.IPlatformMimeResolver)1