Search in sources :

Example 26 with IPlatformImportBundle

use of org.pentaho.platform.api.repository2.unified.IPlatformImportBundle 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 27 with IPlatformImportBundle

use of org.pentaho.platform.api.repository2.unified.IPlatformImportBundle in project pentaho-platform by pentaho.

the class MetaStoreImportHandlerTest method testImportFile.

@Test
public void testImportFile() throws Exception {
    IPlatformImportBundle bundle = mock(IPlatformImportBundle.class);
    InputStream ios = mock(InputStream.class);
    byte[] bytes = new byte[] {};
    when(ios.read(any(bytes.getClass()), anyInt(), anyInt())).thenReturn(-1);
    when(bundle.getInputStream()).thenReturn(ios);
    when(bundle.getName()).thenReturn("metastore");
    when(bundle.getProperty("description")).thenReturn("bundle description");
    handler.tmpXmlMetaStore = fromMetaStore;
    handler.importFile(bundle);
    // not going to test all of the internals of the MetaStoreUtil.copy, just enough to make sure it was called.
    verify(metastore).createNamespace("pentaho");
    verify(metastore).createNamespace("hitachi");
    verify(fromMetaStore).setRootFolder(anyString());
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 28 with IPlatformImportBundle

use of org.pentaho.platform.api.repository2.unified.IPlatformImportBundle 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 29 with IPlatformImportBundle

use of org.pentaho.platform.api.repository2.unified.IPlatformImportBundle in project pentaho-platform by pentaho.

the class MetadataImportHandlerIT method testPreserveDsw.

@Test
public void testPreserveDsw() throws Exception {
    final String domainId = "AModel.xmi";
    final InputStream fileIn = new FileInputStream(new File(TestResourceLocation.TEST_RESOURCES + "/ImportTest/AModel.xmi"));
    try {
        final IPlatformImportBundle bundle = getMetadataImport(domainId, fileIn).preserveDsw(true).build();
        context.checking(new Expectations() {

            {
                oneOf(metadataImporter).storeDomain(with(xmiInputStreamHasOlap(true)), with(equal(domainId)), with(equal(true)));
            }
        });
        importer.importFile(bundle);
        context.assertIsSatisfied();
    } finally {
        IOUtils.closeQuietly(fileIn);
    }
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) Expectations(org.jmock.Expectations) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 30 with IPlatformImportBundle

use of org.pentaho.platform.api.repository2.unified.IPlatformImportBundle in project pentaho-platform by pentaho.

the class MetadataImportHandlerIT method testDomainOnlyImport.

@Test
public void testDomainOnlyImport() throws Exception {
    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").mime("text/xmi+xml").hidden(false).overwriteFile(true).name("steel-wheels.xmi").comment("Test Metadata Import").withParam("domain-id", "parameterized-domain-id")).build();
    context.checking(new Expectations() {

        {
            oneOf(metadataImporter).storeDomain(with(any(InputStream.class)), with(equal("parameterized-domain-id")), with(equal(true)));
        }
    });
    importer.importFile(bundle1);
    context.assertIsSatisfied();
}
Also used : IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) Expectations(org.jmock.Expectations) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

IPlatformImportBundle (org.pentaho.platform.api.repository2.unified.IPlatformImportBundle)34 Test (org.junit.Test)21 InputStream (java.io.InputStream)15 FileInputStream (java.io.FileInputStream)14 IPlatformImporter (org.pentaho.platform.plugin.services.importer.IPlatformImporter)13 File (java.io.File)12 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)10 RepositoryFileImportBundle (org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle)8 ArrayList (java.util.ArrayList)7 Expectations (org.jmock.Expectations)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IOException (java.io.IOException)5 Response (javax.ws.rs.core.Response)5 Matchers.anyString (org.mockito.Matchers.anyString)5 FileResource (org.pentaho.platform.web.http.api.resources.FileResource)5 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)4 Domain (org.pentaho.metadata.model.Domain)4 XmiParser (org.pentaho.metadata.util.XmiParser)4