Search in sources :

Example 46 with Repository

use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.

the class BaseStepMetaCloningTest method testClone.

@Test
public void testClone() throws Exception {
    final Database db1 = mock(Database.class);
    final Database db2 = mock(Database.class);
    final Repository repository = mock(Repository.class);
    final StepMeta stepMeta = mock(StepMeta.class);
    BaseStepMeta meta = new BaseStepMeta();
    meta.setChanged(true);
    meta.databases = new Database[] { db1, db2 };
    meta.ioMeta = new StepIOMeta(true, false, false, false, false, false);
    meta.repository = repository;
    meta.parentStepMeta = stepMeta;
    BaseStepMeta clone = (BaseStepMeta) meta.clone();
    assertTrue(clone.hasChanged());
    // is it OK ?
    assertTrue(clone.databases == meta.databases);
    assertArrayEquals(meta.databases, clone.databases);
    assertEquals(meta.repository, clone.repository);
    assertEquals(meta.parentStepMeta, clone.parentStepMeta);
    assertNotNull(clone.ioMeta);
    assertEquals(meta.ioMeta.isInputAcceptor(), clone.ioMeta.isInputAcceptor());
    assertEquals(meta.ioMeta.isInputDynamic(), clone.ioMeta.isInputDynamic());
    assertEquals(meta.ioMeta.isInputOptional(), clone.ioMeta.isInputOptional());
    assertEquals(meta.ioMeta.isOutputDynamic(), clone.ioMeta.isOutputDynamic());
    assertEquals(meta.ioMeta.isOutputProducer(), clone.ioMeta.isOutputProducer());
    assertEquals(meta.ioMeta.isSortedDataRequired(), clone.ioMeta.isSortedDataRequired());
    assertNotNull(clone.ioMeta.getInfoStreams());
    assertEquals(0, clone.ioMeta.getInfoStreams().size());
}
Also used : Repository(org.pentaho.di.repository.Repository) Database(org.pentaho.di.core.database.Database) Test(org.junit.Test)

Example 47 with Repository

use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.

the class BaseStepMetaCloningTest method testCloneWithInfoSteps.

@Test
public void testCloneWithInfoSteps() throws Exception {
    final Database db1 = mock(Database.class);
    final Database db2 = mock(Database.class);
    final Repository repository = mock(Repository.class);
    final StepMeta stepMeta = mock(StepMeta.class);
    BaseStepMeta meta = new BaseStepMeta();
    meta.setChanged(true);
    meta.databases = new Database[] { db1, db2 };
    meta.ioMeta = new StepIOMeta(true, false, false, false, false, false);
    final String refStepName = "referenced step";
    final StepMeta refStepMeta = mock(StepMeta.class);
    doReturn(refStepName).when(refStepMeta).getName();
    StreamInterface stream = new Stream(StreamInterface.StreamType.INFO, refStepMeta, null, null, refStepName);
    meta.ioMeta.addStream(stream);
    meta.repository = repository;
    meta.parentStepMeta = stepMeta;
    BaseStepMeta clone = (BaseStepMeta) meta.clone();
    assertTrue(clone.hasChanged());
    // is it OK ?
    assertTrue(clone.databases == meta.databases);
    assertArrayEquals(meta.databases, clone.databases);
    assertEquals(meta.repository, clone.repository);
    assertEquals(meta.parentStepMeta, clone.parentStepMeta);
    assertNotNull(clone.ioMeta);
    assertEquals(meta.ioMeta.isInputAcceptor(), clone.ioMeta.isInputAcceptor());
    assertEquals(meta.ioMeta.isInputDynamic(), clone.ioMeta.isInputDynamic());
    assertEquals(meta.ioMeta.isInputOptional(), clone.ioMeta.isInputOptional());
    assertEquals(meta.ioMeta.isOutputDynamic(), clone.ioMeta.isOutputDynamic());
    assertEquals(meta.ioMeta.isOutputProducer(), clone.ioMeta.isOutputProducer());
    assertEquals(meta.ioMeta.isSortedDataRequired(), clone.ioMeta.isSortedDataRequired());
    final List<StreamInterface> clonedInfoStreams = clone.ioMeta.getInfoStreams();
    assertNotNull(clonedInfoStreams);
    assertEquals(1, clonedInfoStreams.size());
    final StreamInterface clonedStream = clonedInfoStreams.get(0);
    assertNotSame(stream, clonedStream);
    assertEquals(stream.getStreamType(), clonedStream.getStreamType());
    assertEquals(refStepName, clonedStream.getStepname());
    // PDI-15799
    assertSame(refStepMeta, clonedStream.getStepMeta());
}
Also used : Repository(org.pentaho.di.repository.Repository) Database(org.pentaho.di.core.database.Database) Stream(org.pentaho.di.trans.step.errorhandling.Stream) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface) Test(org.junit.Test)

Example 48 with Repository

use of org.pentaho.di.repository.Repository 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 49 with Repository

use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.

the class UnivariateStatsMetaFunctionTest method testRepoConstructor.

@Test
public void testRepoConstructor() throws ParseException, KettleException, IOException {
    String jsString = IOUtils.toString(UnivariateStatsMetaTest.class.getClassLoader().getResourceAsStream("org/pentaho/di/trans/steps/univariatestats/trueValuesUnivariateStatsMetaFunctionNode.json"));
    Repository repo = new MemoryRepository(jsString);
    UnivariateStatsMetaFunction function = new UnivariateStatsMetaFunction(repo, new StringObjectId("test"), 0);
    assertEquals("test", function.getSourceFieldName());
    assertTrue(function.getCalcN());
    assertTrue(function.getCalcMean());
    assertTrue(function.getCalcStdDev());
    assertTrue(function.getCalcMin());
    assertTrue(function.getCalcMax());
    assertTrue(function.getCalcMedian());
    assertEquals(0.5, function.getCalcPercentile(), 0);
    assertTrue(function.getInterpolatePercentile());
    jsString = IOUtils.toString(UnivariateStatsMetaTest.class.getClassLoader().getResourceAsStream("org/pentaho/di/trans/steps/univariatestats/falseValuesUnivariateStatsMetaFunctionNode.json"));
    repo = new MemoryRepository(jsString);
    function = new UnivariateStatsMetaFunction(repo, new StringObjectId("test"), 0);
    assertTrue(Utils.isEmpty(function.getSourceFieldName()));
    assertFalse(function.getCalcN());
    assertFalse(function.getCalcMean());
    assertFalse(function.getCalcStdDev());
    assertFalse(function.getCalcMin());
    assertFalse(function.getCalcMax());
    assertFalse(function.getCalcMedian());
    assertEquals(-1.0, function.getCalcPercentile(), 0);
    assertFalse(function.getInterpolatePercentile());
}
Also used : Repository(org.pentaho.di.repository.Repository) MemoryRepository(org.pentaho.di.trans.steps.loadsave.MemoryRepository) MemoryRepository(org.pentaho.di.trans.steps.loadsave.MemoryRepository) StringObjectId(org.pentaho.di.repository.StringObjectId) Test(org.junit.Test)

Example 50 with Repository

use of org.pentaho.di.repository.Repository 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

Repository (org.pentaho.di.repository.Repository)143 Test (org.junit.Test)69 KettleException (org.pentaho.di.core.exception.KettleException)54 TransMeta (org.pentaho.di.trans.TransMeta)39 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)21 IMetaStore (org.pentaho.metastore.api.IMetaStore)20 RepositoryMeta (org.pentaho.di.repository.RepositoryMeta)19 JobMeta (org.pentaho.di.job.JobMeta)18 ObjectId (org.pentaho.di.repository.ObjectId)14 StepMeta (org.pentaho.di.trans.step.StepMeta)14 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)14 StringObjectId (org.pentaho.di.repository.StringObjectId)13 Variables (org.pentaho.di.core.variables.Variables)12 ArrayList (java.util.ArrayList)11 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)11 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)11 VariableSpace (org.pentaho.di.core.variables.VariableSpace)11 RepositoriesMeta (org.pentaho.di.repository.RepositoriesMeta)11 RepositoryPluginType (org.pentaho.di.core.plugins.RepositoryPluginType)10 IOException (java.io.IOException)9