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());
}
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());
}
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));
}
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());
}
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")));
}
Aggregations