Search in sources :

Example 31 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.

the class KettleDatabaseRepository method readDatabases.

/**
 * Read all the databases defined in the repository
 *
 * @return a list of all the databases defined in the repository
 * @throws KettleException
 */
public List<DatabaseMeta> readDatabases() throws KettleException {
    List<DatabaseMeta> databases = new ArrayList<>();
    ObjectId[] ids = getDatabaseIDs(false);
    for (int i = 0; i < ids.length; i++) {
        // reads last
        DatabaseMeta databaseMeta = loadDatabaseMeta(ids[i], null);
        // versions
        databases.add(databaseMeta);
    }
    return databases;
}
Also used : LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ArrayList(java.util.ArrayList) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

Example 32 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.

the class ZipFileMetaTest method testReadRep.

@Test
public void testReadRep() throws Exception {
    ZipFileMeta zipFileMeta = new ZipFileMeta();
    Repository rep = mock(Repository.class);
    IMetaStore metastore = mock(IMetaStore.class);
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    StringObjectId oid = new StringObjectId("oid");
    when(rep.getStepAttributeString(oid, "sourcefilenamefield")).thenReturn(SOURCE_FILENAME);
    when(rep.getStepAttributeString(oid, "targetfilenamefield")).thenReturn(TARGET_FILENAME);
    when(rep.getStepAttributeString(oid, "baseFolderField")).thenReturn(BASE_FOLDER);
    when(rep.getStepAttributeString(oid, "operation_type")).thenReturn(OPERATION_TYPE);
    when(rep.getStepAttributeBoolean(oid, "addresultfilenames")).thenReturn(ADD_RESULT_FILENAME);
    when(rep.getStepAttributeBoolean(oid, "overwritezipentry")).thenReturn(OVERWRITE_ZIP_ENTRY);
    when(rep.getStepAttributeBoolean(oid, "createparentfolder")).thenReturn(CREATE_PARENT_FOLDER);
    when(rep.getStepAttributeBoolean(oid, "keepsourcefolder")).thenReturn(KEEP_SOURCE_FOLDER);
    when(rep.getStepAttributeString(oid, "movetofolderfield")).thenReturn(MOVE_TO_FOLDER_FIELD);
    zipFileMeta.readRep(rep, metastore, oid, Collections.singletonList(dbMeta));
    assertEquals(SOURCE_FILENAME, zipFileMeta.getDynamicSourceFileNameField());
    assertEquals(TARGET_FILENAME, zipFileMeta.getDynamicTargetFileNameField());
    assertEquals(BASE_FOLDER, zipFileMeta.getBaseFolderField());
    assertEquals(ZipFileMeta.getOperationTypeByDesc(OPERATION_TYPE), zipFileMeta.getOperationType());
    assertEquals(MOVE_TO_FOLDER_FIELD, zipFileMeta.getMoveToFolderField());
    assertTrue(zipFileMeta.isaddTargetFileNametoResult());
    assertTrue(zipFileMeta.isOverwriteZipEntry());
    assertTrue(zipFileMeta.isKeepSouceFolder());
    assertTrue(zipFileMeta.isCreateParentFolder());
    Mockito.reset(rep, metastore);
    StringObjectId transid = new StringObjectId("transid");
    zipFileMeta.saveRep(rep, metastore, transid, oid);
    verify(rep).saveStepAttribute(transid, oid, "sourcefilenamefield", SOURCE_FILENAME);
    verify(rep).saveStepAttribute(transid, oid, "targetfilenamefield", TARGET_FILENAME);
    verify(rep).saveStepAttribute(transid, oid, "baseFolderField", BASE_FOLDER);
    verify(rep).saveStepAttribute(transid, oid, "operation_type", OPERATION_TYPE);
    verify(rep).saveStepAttribute(transid, oid, "addresultfilenames", ADD_RESULT_FILENAME);
    verify(rep).saveStepAttribute(transid, oid, "overwritezipentry", OVERWRITE_ZIP_ENTRY);
    verify(rep).saveStepAttribute(transid, oid, "createparentfolder", CREATE_PARENT_FOLDER);
    verify(rep).saveStepAttribute(transid, oid, "keepsourcefolder", KEEP_SOURCE_FOLDER);
    verify(rep).saveStepAttribute(transid, oid, "movetofolderfield", MOVE_TO_FOLDER_FIELD);
    Mockito.verifyNoMoreInteractions(rep, metastore);
}
Also used : Repository(org.pentaho.di.repository.Repository) IMetaStore(org.pentaho.metastore.api.IMetaStore) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) Test(org.junit.Test)

Example 33 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.

the class UnivariateStatsMetaTest method testLegacyLoadXml.

@Test
public void testLegacyLoadXml() throws IOException, KettleXMLException {
    String legacyXml = IOUtils.toString(UnivariateStatsMetaTest.class.getClassLoader().getResourceAsStream("org/pentaho/di/trans/steps/univariatestats/legacyUnivariateStatsMetaTest.xml"));
    IMetaStore mockMetaStore = mock(IMetaStore.class);
    UnivariateStatsMeta meta = new UnivariateStatsMeta();
    meta.loadXML(XMLHandler.loadXMLString(legacyXml).getFirstChild(), new ArrayList<DatabaseMeta>(), mockMetaStore);
    assertEquals(2, meta.getNumFieldsToProcess());
    UnivariateStatsMetaFunction first = meta.getInputFieldMetaFunctions()[0];
    assertEquals("a", first.getSourceFieldName());
    assertEquals(true, first.getCalcN());
    assertEquals(true, first.getCalcMean());
    assertEquals(true, first.getCalcStdDev());
    assertEquals(true, first.getCalcMin());
    assertEquals(true, first.getCalcMax());
    assertEquals(true, first.getCalcMedian());
    assertEquals(.5, first.getCalcPercentile(), 0);
    assertEquals(true, first.getInterpolatePercentile());
    UnivariateStatsMetaFunction second = meta.getInputFieldMetaFunctions()[1];
    assertEquals("b", second.getSourceFieldName());
    assertEquals(false, second.getCalcN());
    assertEquals(false, second.getCalcMean());
    assertEquals(false, second.getCalcStdDev());
    assertEquals(false, second.getCalcMin());
    assertEquals(false, second.getCalcMax());
    assertEquals(false, second.getCalcMedian());
    assertEquals(-1.0, second.getCalcPercentile(), 0);
    assertEquals(false, second.getInterpolatePercentile());
}
Also used : IMetaStore(org.pentaho.metastore.api.IMetaStore) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 34 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.

the class WebServiceMetaTest method testGetFieldOut.

@Test
public void testGetFieldOut() throws Exception {
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    IMetaStore metastore = mock(IMetaStore.class);
    WebServiceMeta webServiceMeta = new WebServiceMeta(getTestNode(), Collections.singletonList(dbMeta), metastore);
    assertNull(webServiceMeta.getFieldOutFromWsName("", true));
    assertEquals("GetCurrentExchangeRateResult", webServiceMeta.getFieldOutFromWsName("GetCurrentExchangeRateResult", false).getName());
    assertEquals("GetCurrentExchangeRateResult", webServiceMeta.getFieldOutFromWsName("something:GetCurrentExchangeRateResult", true).getName());
}
Also used : DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 35 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.

the class WebServiceMetaTest method testReadRep.

@Test
public void testReadRep() throws Exception {
    Repository rep = mock(Repository.class);
    IMetaStore metastore = mock(IMetaStore.class);
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    StringObjectId id_step = new StringObjectId("oid");
    when(rep.getStepAttributeString(id_step, "wsOperation")).thenReturn("GetCurrentExchangeRate");
    when(rep.getStepAttributeString(id_step, "wsOperationRequest")).thenReturn("opRequest");
    when(rep.getStepAttributeString(id_step, "wsOperationNamespace")).thenReturn("opNamespace");
    when(rep.getStepAttributeString(id_step, "wsInFieldContainer")).thenReturn("ifc");
    when(rep.getStepAttributeString(id_step, "wsInFieldArgument")).thenReturn("ifa");
    when(rep.getStepAttributeString(id_step, "wsOutFieldContainer")).thenReturn("ofc");
    when(rep.getStepAttributeString(id_step, "wsOutFieldArgument")).thenReturn("ofa");
    when(rep.getStepAttributeString(id_step, "proxyHost")).thenReturn("phost");
    when(rep.getStepAttributeString(id_step, "proxyPort")).thenReturn("1234");
    when(rep.getStepAttributeString(id_step, "httpLogin")).thenReturn("user");
    when(rep.getStepAttributeString(id_step, "httpPassword")).thenReturn("password");
    when(rep.getStepAttributeInteger(id_step, "callStep")).thenReturn(2L);
    when(rep.getStepAttributeBoolean(id_step, "passingInputData")).thenReturn(true);
    when(rep.getStepAttributeBoolean(id_step, 0, "compatible", true)).thenReturn(false);
    when(rep.getStepAttributeString(id_step, "repeating_element")).thenReturn("repeat");
    when(rep.getStepAttributeBoolean(id_step, 0, "reply_as_string")).thenReturn(true);
    when(rep.countNrStepAttributes(id_step, "fieldIn_ws_name")).thenReturn(2);
    when(rep.getStepAttributeString(id_step, 0, "fieldIn_name")).thenReturn("bank");
    when(rep.getStepAttributeString(id_step, 0, "fieldIn_ws_name")).thenReturn("inBank");
    when(rep.getStepAttributeString(id_step, 0, "fieldIn_xsd_type")).thenReturn("string");
    when(rep.getStepAttributeString(id_step, 1, "fieldIn_name")).thenReturn("branch");
    when(rep.getStepAttributeString(id_step, 1, "fieldIn_ws_name")).thenReturn("inBranch");
    when(rep.getStepAttributeString(id_step, 1, "fieldIn_xsd_type")).thenReturn("string");
    when(rep.countNrStepAttributes(id_step, "fieldOut_ws_name")).thenReturn(2);
    when(rep.getStepAttributeString(id_step, 0, "fieldOut_name")).thenReturn("balance");
    when(rep.getStepAttributeString(id_step, 0, "fieldOut_ws_name")).thenReturn("outBalance");
    when(rep.getStepAttributeString(id_step, 0, "fieldOut_xsd_type")).thenReturn("int");
    when(rep.getStepAttributeString(id_step, 1, "fieldOut_name")).thenReturn("transactions");
    when(rep.getStepAttributeString(id_step, 1, "fieldOut_ws_name")).thenReturn("outTransactions");
    when(rep.getStepAttributeString(id_step, 1, "fieldOut_xsd_type")).thenReturn("int");
    WebServiceMeta webServiceMeta = new WebServiceMeta(rep, metastore, id_step, Collections.singletonList(dbMeta));
    String expectedXml = "" + "    <wsURL/>\n" + "    <wsOperation>GetCurrentExchangeRate</wsOperation>\n" + "    <wsOperationRequest>opRequest</wsOperationRequest>\n" + "    <wsOperationNamespace>opNamespace</wsOperationNamespace>\n" + "    <wsInFieldContainer>ifc</wsInFieldContainer>\n" + "    <wsInFieldArgument>ifa</wsInFieldArgument>\n" + "    <wsOutFieldContainer>ofc</wsOutFieldContainer>\n" + "    <wsOutFieldArgument>ofa</wsOutFieldArgument>\n" + "    <proxyHost>phost</proxyHost>\n" + "    <proxyPort>1234</proxyPort>\n" + "    <httpLogin>user</httpLogin>\n" + "    <httpPassword>password</httpPassword>\n" + "    <callStep>2</callStep>\n" + "    <passingInputData>Y</passingInputData>\n" + "    <compatible>N</compatible>\n" + "    <repeating_element>repeat</repeating_element>\n" + "    <reply_as_string>Y</reply_as_string>\n" + "    <fieldsIn>\n" + "    <field>\n" + "        <name>bank</name>\n" + "        <wsName>inBank</wsName>\n" + "        <xsdType>string</xsdType>\n" + "    </field>\n" + "    <field>\n" + "        <name>branch</name>\n" + "        <wsName>inBranch</wsName>\n" + "        <xsdType>string</xsdType>\n" + "    </field>\n" + "      </fieldsIn>\n" + "    <fieldsOut>\n" + "    <field>\n" + "        <name>balance</name>\n" + "        <wsName>outBalance</wsName>\n" + "        <xsdType>int</xsdType>\n" + "    </field>\n" + "    <field>\n" + "        <name>transactions</name>\n" + "        <wsName>outTransactions</wsName>\n" + "        <xsdType>int</xsdType>\n" + "    </field>\n" + "      </fieldsOut>\n";
    String actualXml = TestUtils.toUnixLineSeparators(webServiceMeta.getXML());
    assertEquals(expectedXml, actualXml);
}
Also used : Repository(org.pentaho.di.repository.Repository) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) IMetaStore(org.pentaho.metastore.api.IMetaStore) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) Test(org.junit.Test)

Aggregations

DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)522 Test (org.junit.Test)133 KettleException (org.pentaho.di.core.exception.KettleException)131 Database (org.pentaho.di.core.database.Database)88 MessageBox (org.eclipse.swt.widgets.MessageBox)66 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)63 TransMeta (org.pentaho.di.trans.TransMeta)57 StepMeta (org.pentaho.di.trans.step.StepMeta)54 ArrayList (java.util.ArrayList)53 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)48 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)44 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)42 SlaveServer (org.pentaho.di.cluster.SlaveServer)33 IMetaStore (org.pentaho.metastore.api.IMetaStore)30 ObjectId (org.pentaho.di.repository.ObjectId)29 DatabaseExplorerDialog (org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog)29 JobMeta (org.pentaho.di.job.JobMeta)26 TransHopMeta (org.pentaho.di.trans.TransHopMeta)26 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)24 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)24