Search in sources :

Example 6 with Log4JRepositoryImportLogger

use of org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger in project pentaho-platform by pentaho.

the class LocaleFilesProcessorTest method testProcessLocaleFilesTwoLocaleFiles.

@Test
public void testProcessLocaleFilesTwoLocaleFiles() throws Exception {
    IRepositoryContentConverterHandler converterHandler = new DefaultRepositoryContentConverterHandler(new HashMap<String, Converter>());
    List<IMimeType> localeMimeList = new ArrayList<IMimeType>();
    localeMimeList.add(new MimeType("text/locale", "locale"));
    LocaleImportHandler localeImportHandler = new LocaleImportHandler(localeMimeList, null);
    LocaleImportHandler localeImportHandlerSpy = spy(localeImportHandler);
    Log log = mock(Log.class);
    doReturn(log).when(localeImportHandlerSpy).getLogger();
    String localeFileName = "SampleTransformationWithParameters";
    List<IPlatformImportHandler> handlers = new ArrayList<IPlatformImportHandler>();
    handlers.add(localeImportHandlerSpy);
    importer = new PentahoPlatformImporter(handlers, converterHandler);
    importer.setRepositoryImportLogger(new Log4JRepositoryImportLogger());
    localeFilesProcessor = new LocaleFilesProcessor();
    StringBuffer localePropertiesContent = new StringBuffer();
    localePropertiesContent.append("description=This runs a simple Kettle transformation filtering records from the Quandrant_Actuals sample data " + "table, and sending a Hello message to each position.\n");
    localePropertiesContent.append("name=1. Hello ETL");
    assertTrue(processIsLocalFile("SampleTransformation.properties", localePropertiesContent));
    StringBuffer localeContent = new StringBuffer();
    localeContent.append("file.title=" + localeFileName + "\n");
    localeContent.append("title=SampleTransformation\n");
    localeContent.append("file.description=");
    assertTrue(processIsLocalFile("SampleTransformation.xaction.locale", localeContent));
    localeFilesProcessor.processLocaleFiles(importer);
    // verify that in case of both .properties and .locale files are at input the only one proceeded is .locale
    Mockito.verify(localeImportHandlerSpy, times(1)).importFile(any(IPlatformImportBundle.class));
    ArgumentCaptor<IPlatformImportBundle> argument = ArgumentCaptor.forClass(IPlatformImportBundle.class);
    Mockito.verify(localeImportHandlerSpy).importFile(argument.capture());
    assertEquals(localeFileName, argument.getValue().getName());
}
Also used : Log(org.apache.commons.logging.Log) ArrayList(java.util.ArrayList) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MimeType(org.pentaho.platform.core.mimetype.MimeType) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) 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) Test(org.junit.Test)

Example 7 with Log4JRepositoryImportLogger

use of org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger 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);
}
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 8 with Log4JRepositoryImportLogger

use of org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger 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();
}
Also used : ArrayList(java.util.ArrayList) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) SolutionEngine(org.pentaho.platform.engine.services.solution.SolutionEngine) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) IRepositoryContentConverterHandler(org.pentaho.platform.api.repository2.unified.IRepositoryContentConverterHandler) IPlatformMimeResolver(org.pentaho.platform.api.mimetype.IPlatformMimeResolver) Log4JRepositoryImportLogger(org.pentaho.platform.plugin.services.importexport.Log4JRepositoryImportLogger) StreamConverter(org.pentaho.platform.plugin.services.importexport.StreamConverter) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) Converter(org.pentaho.platform.api.repository2.unified.Converter) StreamConverter(org.pentaho.platform.plugin.services.importexport.StreamConverter) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) FileSystemBackedUnifiedRepository(org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository) 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