use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.
the class AbstractMetaTest method testGetSetImportMetaStore.
@Test(expected = KettlePluginException.class)
public void testGetSetImportMetaStore() throws Exception {
assertNull(meta.getMetaStore());
meta.importFromMetaStore();
IMetaStore metastore = mock(IMetaStore.class);
meta.setMetaStore(metastore);
assertEquals(metastore, meta.getMetaStore());
meta.importFromMetaStore();
IMetaStoreElementType elementType = mock(IMetaStoreElementType.class);
when(metastore.getElementTypeByName(PentahoDefaults.NAMESPACE, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME)).thenReturn(elementType);
when(metastore.getElements(PentahoDefaults.NAMESPACE, elementType)).thenReturn(new ArrayList<IMetaStoreElement>());
meta.importFromMetaStore();
IMetaStoreElement element = mock(IMetaStoreElement.class);
when(metastore.getElements(PentahoDefaults.NAMESPACE, elementType)).thenReturn(Arrays.asList(element));
meta.importFromMetaStore();
}
use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.
the class ReplaceStringMetaTest method testGetFields.
@Test
public void testGetFields() throws KettleStepException {
ReplaceStringMeta meta = new ReplaceStringMeta();
meta.setFieldInStream(new String[] { FIELD_NAME });
meta.setFieldOutStream(new String[] { FIELD_NAME });
ValueMetaInterface inputFieldMeta = mock(ValueMetaInterface.class);
when(inputFieldMeta.getStringEncoding()).thenReturn(ENCODING_NAME);
RowMetaInterface inputRowMeta = mock(RowMetaInterface.class);
when(inputRowMeta.searchValueMeta(anyString())).thenReturn(inputFieldMeta);
StepMeta nextStep = mock(StepMeta.class);
VariableSpace space = mock(VariableSpace.class);
Repository repository = mock(Repository.class);
IMetaStore metaStore = mock(IMetaStore.class);
meta.getFields(inputRowMeta, "test", null, nextStep, space, repository, metaStore);
ArgumentCaptor<ValueMetaInterface> argument = ArgumentCaptor.forClass(ValueMetaInterface.class);
verify(inputRowMeta).addValueMeta(argument.capture());
assertEquals(ENCODING_NAME, argument.getValue().getStringEncoding());
}
use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.
the class RowGeneratorMetaTest method testReadRowLimitAsStringFromRepository.
/**
* If we can read row limit as string from repository then we can run row generator.
* @see RowGeneratorTest
* @throws KettleException
*/
@Test
public void testReadRowLimitAsStringFromRepository() throws KettleException {
RowGeneratorMeta rowGeneratorMeta = new RowGeneratorMeta();
IMetaStore metaStore = Mockito.mock(IMetaStore.class);
DatabaseMeta dbMeta = Mockito.mock(DatabaseMeta.class);
rowGeneratorMeta.readRep(rep, metaStore, id_step, Collections.singletonList(dbMeta));
assertEquals(rowGeneratorMeta.getRowLimit(), launchVariable);
}
use of org.pentaho.metastore.api.IMetaStore in project pentaho-platform by pentaho.
the class PentahoPlatformExporterTest method testExportMetaStore.
@Test
public void testExportMetaStore() throws Exception {
exporterSpy.zos = mock(ZipOutputStream.class);
IMetaStore metastore = mock(IMetaStore.class);
exporterSpy.setRepoMetaStore(metastore);
ExportManifest manifest = mock(ExportManifest.class);
exporterSpy.setExportManifest(manifest);
exporterSpy.exportMetastore();
verify(exporterSpy.zos).putNextEntry(any(ZipEntry.class));
verify(manifest).setMetaStore(any(ExportManifestMetaStore.class));
}
use of org.pentaho.metastore.api.IMetaStore in project pentaho-platform by pentaho.
the class MetaStoreImportHandler method importFile.
@Override
public void importFile(IPlatformImportBundle bundle) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
InputStream inputStream = bundle.getInputStream();
Path path = Files.createTempDirectory(METASTORE);
path.toFile().deleteOnExit();
// get the zipped metastore from the export bundle
ZipInputStream zis = new ZipInputStream(inputStream);
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
try {
String filePath = path.toString() + File.separator + entry.getName();
if (entry.isDirectory()) {
File dir = new File(filePath);
dir.mkdir();
} else {
File file = new File(filePath);
file.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(filePath);
IOUtils.copy(zis, fos);
IOUtils.closeQuietly(fos);
}
} finally {
zis.closeEntry();
}
}
IOUtils.closeQuietly(zis);
// get a hold of the metastore to import into
IMetaStore metastore = getRepoMetaStore();
if (metastore != null) {
// copy the exported metastore to where it needs to go
try {
if (tmpXmlMetaStore == null) {
tmpXmlMetaStore = new XmlMetaStore(path.toString());
} else {
// we are re-using an existing object, make sure the root folder is pointed at the new location on disk
tmpXmlMetaStore.setRootFolder(path.toString() + File.separator + METASTORE);
}
tmpXmlMetaStore.setName(bundle.getName());
String desc = bundle.getProperty("description") == null ? null : bundle.getProperty("description").toString();
tmpXmlMetaStore.setDescription(desc);
MetaStoreUtil.copy(tmpXmlMetaStore, metastore, bundle.overwriteInRepository());
} catch (MetaStoreException e) {
log.error("Could not restore the MetaStore");
log.debug("Error restoring the MetaStore", e);
}
}
}
Aggregations