Search in sources :

Example 16 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class LoadFileInputMetaTest method testLoadXML.

@Test
public void testLoadXML() throws Exception {
    LoadFileInputMeta origMeta = createMeta();
    LoadFileInputMeta testMeta = new LoadFileInputMeta();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(new InputSource(new StringReader("<step>" + xmlOrig + "</step>")));
    IMetaStore metaStore = null;
    testMeta.loadXML(doc.getFirstChild(), null, metaStore);
    assertEquals(origMeta, testMeta);
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 17 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class TransMetaTest method testDatabaseNotOverridden.

@Test
public void testDatabaseNotOverridden() throws Exception {
    final String name = "db meta";
    DatabaseMeta dbMetaShared = new DatabaseMeta();
    dbMetaShared.setName(name);
    dbMetaShared.setHostname("host");
    DatabaseMeta dbMetaStore = new DatabaseMeta();
    dbMetaStore.setName(name);
    dbMetaStore.setHostname("anotherhost");
    IMetaStore mstore = new MemoryMetaStore();
    DatabaseMetaStoreUtil.createDatabaseElement(mstore, dbMetaStore);
    TransMeta trans = new TransMeta();
    trans.addOrReplaceDatabase(dbMetaShared);
    trans.setMetaStore(mstore);
    trans.importFromMetaStore();
    DatabaseMeta dbMeta = trans.findDatabase(name);
    assertEquals(dbMetaShared.getHostname(), dbMeta.getHostname());
}
Also used : MemoryMetaStore(org.pentaho.metastore.stores.memory.MemoryMetaStore) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 18 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class DimensionLookupMetaTest method testUseDefaultSchemaName.

@Test
public void testUseDefaultSchemaName() throws Exception {
    String schemaName = "";
    String tableName = "tableName";
    String schemaTable = "default.tableName";
    String keyField = "keyField";
    DatabaseMeta databaseMeta = spy(new DatabaseMeta(databaseXML) {

        @Override
        public String getFieldDefinition(ValueMetaInterface v, String tk, String pk, boolean use_autoinc) {
            return "someValue";
        }
    });
    when(databaseMeta.getQuotedSchemaTableCombination(schemaName, tableName)).thenReturn(schemaTable);
    DimensionLookupMeta dlm = new DimensionLookupMeta();
    dlm.setUpdate(true);
    dlm.setDatabaseMeta(databaseMeta);
    dlm.setTableName(tableName);
    dlm.setSchemaName(schemaName);
    dlm.setKeyLookup(new String[] { "keyLookup1", "keyLookup2" });
    dlm.setKeyStream(new String[] { "keyStream1", "keyStream2" });
    dlm.setFieldLookup(new String[] { "fieldLookup1", "fieldLookup2" });
    dlm.setFieldStream(new String[] { "FieldStream1", "FieldStream2" });
    dlm.setFieldUpdate(new int[] { 1, 2 });
    dlm.setKeyField(keyField);
    StepMeta stepMeta = mock(StepMeta.class);
    RowMetaInterface rowMetaInterface = mock(RowMetaInterface.class);
    when(rowMetaInterface.size()).thenReturn(1);
    Repository repository = mock(Repository.class);
    IMetaStore metaStore = mock(IMetaStore.class);
    SQLStatement sqlStatement = dlm.getSQLStatements(new TransMeta(), stepMeta, rowMetaInterface, repository, metaStore);
    String sql = sqlStatement.getSQL();
    assertEquals(3, StringUtils.countMatches(sql, schemaTable));
}
Also used : Repository(org.pentaho.di.repository.Repository) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Matchers.anyString(org.mockito.Matchers.anyString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) SQLStatement(org.pentaho.di.core.SQLStatement) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 19 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore 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 20 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class WebServiceMetaTest method testGetFields.

@Test
public void testGetFields() throws Exception {
    WebServiceMeta webServiceMeta = new WebServiceMeta();
    webServiceMeta.setDefault();
    RowMetaInterface rmi = mock(RowMetaInterface.class);
    RowMetaInterface rmi2 = mock(RowMetaInterface.class);
    StepMeta nextStep = mock(StepMeta.class);
    IMetaStore metastore = mock(IMetaStore.class);
    Repository rep = mock(Repository.class);
    WebServiceField field1 = new WebServiceField();
    field1.setName("field1");
    field1.setWsName("field1WS");
    field1.setXsdType("string");
    WebServiceField field2 = new WebServiceField();
    field2.setName("field2");
    field2.setWsName("field2WS");
    field2.setXsdType("string");
    WebServiceField field3 = new WebServiceField();
    field3.setName("field3");
    field3.setWsName("field3WS");
    field3.setXsdType("string");
    webServiceMeta.setFieldsOut(Arrays.asList(field1, field2, field3));
    webServiceMeta.getFields(rmi, "idk", new RowMetaInterface[] { rmi2 }, nextStep, new Variables(), rep, metastore);
    verify(rmi).addValueMeta(argThat(matchValueMetaString("field1")));
    verify(rmi).addValueMeta(argThat(matchValueMetaString("field2")));
    verify(rmi).addValueMeta(argThat(matchValueMetaString("field3")));
}
Also used : Variables(org.pentaho.di.core.variables.Variables) Repository(org.pentaho.di.repository.Repository) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Aggregations

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