Search in sources :

Example 81 with IMetaStore

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();
}
Also used : IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 82 with IMetaStore

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());
}
Also used : Repository(org.pentaho.di.repository.Repository) VariableSpace(org.pentaho.di.core.variables.VariableSpace) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 83 with IMetaStore

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);
}
Also used : IMetaStore(org.pentaho.metastore.api.IMetaStore) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 84 with IMetaStore

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));
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) IMetaStore(org.pentaho.metastore.api.IMetaStore) ExportManifest(org.pentaho.platform.plugin.services.importexport.exportManifest.ExportManifest) ExportManifestMetaStore(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMetaStore) Test(org.junit.Test)

Example 85 with IMetaStore

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);
        }
    }
}
Also used : Path(java.nio.file.Path) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) FileOutputStream(java.io.FileOutputStream) XmlMetaStore(org.pentaho.metastore.stores.xml.XmlMetaStore) File(java.io.File) IMetaStore(org.pentaho.metastore.api.IMetaStore)

Aggregations

IMetaStore (org.pentaho.metastore.api.IMetaStore)86 Test (org.junit.Test)62 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)25 Repository (org.pentaho.di.repository.Repository)25 SQL (org.pentaho.di.core.sql.SQL)17 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)12 TransMeta (org.pentaho.di.trans.TransMeta)12 Matchers.anyString (org.mockito.Matchers.anyString)11 StepMeta (org.pentaho.di.trans.step.StepMeta)11 KettleException (org.pentaho.di.core.exception.KettleException)10 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)10 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)10 ArrayList (java.util.ArrayList)9 IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)9 Node (org.w3c.dom.Node)9 Variables (org.pentaho.di.core.variables.Variables)7 StringObjectId (org.pentaho.di.repository.StringObjectId)7 PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)7 CheckResultInterface (org.pentaho.di.core.CheckResultInterface)6 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)6