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());
}
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());
}
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);
}
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);
}
}
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();
}
Aggregations