use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.
the class SwitchCaseMetaTest method testsearchInfoAndTargetStepsTwice.
// Note - cloneTest removed because it's now covered by the load/save tester
@Test
public void testsearchInfoAndTargetStepsTwice() {
StepMetaInterface defStep = new DummyTransMeta();
StepMeta stepMeta = new StepMeta("id", "default", defStep);
SwitchCaseMeta meta = new SwitchCaseMeta();
meta.allocate();
meta.setDefaultTargetStepname(stepMeta.getName());
meta.searchInfoAndTargetSteps(Collections.singletonList(stepMeta));
// would throw npe
meta.searchInfoAndTargetSteps(Collections.singletonList(stepMeta));
}
use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.
the class SwitchCaseTest method testCreateOutputValueMappingWithBinaryType.
@Test
public void testCreateOutputValueMappingWithBinaryType() throws KettleException, URISyntaxException, ParserConfigurationException, SAXException, IOException {
SwitchCaseCustom krasavez = new SwitchCaseCustom(mockHelper);
// load step info value-case mapping from xml.
List<DatabaseMeta> emptyList = new ArrayList<DatabaseMeta>();
krasavez.meta.loadXML(loadStepXmlMetadata("SwitchCaseBinaryTest.xml"), emptyList, mock(IMetaStore.class));
KeyToRowSetMap expectedNN = new KeyToRowSetMap();
Set<RowSet> nulls = new HashSet<RowSet>();
// create real steps for all targets
List<SwitchCaseTarget> list = krasavez.meta.getCaseTargets();
for (SwitchCaseTarget item : list) {
StepMetaInterface smInt = new DummyTransMeta();
StepMeta stepMeta = new StepMeta(item.caseTargetStepname, smInt);
item.caseTargetStep = stepMeta;
// create and put row set for this
RowSet rw = new QueueRowSet();
krasavez.map.put(item.caseTargetStepname, rw);
// null values goes to null rowset
if (item.caseValue != null) {
expectedNN.put(item.caseValue, rw);
} else {
nulls.add(rw);
}
}
// create default step
StepMetaInterface smInt = new DummyTransMeta();
StepMeta stepMeta = new StepMeta(krasavez.meta.getDefaultTargetStepname(), smInt);
krasavez.meta.setDefaultTargetStep(stepMeta);
RowSet rw = new QueueRowSet();
krasavez.map.put(krasavez.meta.getDefaultTargetStepname(), rw);
krasavez.createOutputValueMapping();
// inspect step output data:
Set<RowSet> ones = krasavez.data.outputMap.get("1");
assertEquals("Output map for 1 values contains 2 row sets", 2, ones.size());
Set<RowSet> zeros = krasavez.data.outputMap.get("0");
assertEquals("Output map for 0 values contains 1 row sets", 1, zeros.size());
assertEquals("Null row set contains 0 items: ", 2, krasavez.data.nullRowSetSet.size());
assertEquals("We have at least one default rowset", 1, krasavez.data.defaultRowSetSet.size());
// check that rowsets data is correct:
Set<RowSet> rowsets = expectedNN.get("1");
for (RowSet rowset : rowsets) {
assertTrue("Output map for 1 values contains expected row set", ones.contains(rowset));
}
rowsets = expectedNN.get("0");
for (RowSet rowset : rowsets) {
assertTrue("Output map for 0 values contains expected row set", zeros.contains(rowset));
}
for (RowSet rowset : krasavez.data.nullRowSetSet) {
assertTrue("Output map for null values contains expected row set", nulls.contains(rowset));
}
// we have already check that there is only one item.
for (RowSet rowset : krasavez.data.defaultRowSetSet) {
assertTrue("Output map for default case contains expected row set", rowset.equals(rw));
}
}
use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.
the class SwitchCaseTest method processRow_NullsArePutIntoDefaultWhenNotSpecified.
@Test
public void processRow_NullsArePutIntoDefaultWhenNotSpecified() throws Exception {
SwitchCaseCustom step = new SwitchCaseCustom(mockHelper);
step.meta.loadXML(loadStepXmlMetadata("SwitchCaseTest_PDI-12671.xml"), Collections.<DatabaseMeta>emptyList(), mock(IMetaStore.class));
List<RowSet> outputRowSets = new LinkedList<RowSet>();
for (SwitchCaseTarget item : step.meta.getCaseTargets()) {
StepMetaInterface smInt = new DummyTransMeta();
item.caseTargetStep = new StepMeta(item.caseTargetStepname, smInt);
RowSet rw = new QueueRowSet();
step.map.put(item.caseTargetStepname, rw);
outputRowSets.add(rw);
}
// create a default step
StepMetaInterface smInt = new DummyTransMeta();
StepMeta stepMeta = new StepMeta(step.meta.getDefaultTargetStepname(), smInt);
step.meta.setDefaultTargetStep(stepMeta);
RowSet defaultRowSet = new QueueRowSet();
step.map.put(step.meta.getDefaultTargetStepname(), defaultRowSet);
step.input.add(new Object[] { null });
step.processRow();
assertEquals(1, defaultRowSet.size());
for (RowSet rowSet : outputRowSets) {
assertEquals(0, rowSet.size());
}
assertNull(defaultRowSet.getRow()[0]);
}
use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.
the class SynchronizeAfterMergeIT method setUp.
@Before
public void setUp() throws KettleDatabaseException, SQLException {
connection = DriverManager.getConnection("jdbc:h2:mem:PERSON;");
connection.setAutoCommit(false);
PreparedStatement stmt = connection.prepareStatement("CREATE TABLE PERSON (ID INT PRIMARY KEY, personName VARCHAR(64) )");
stmt.execute();
stmt.close();
stmt = connection.prepareStatement("INSERT INTO PERSON (ID, personName) VALUES (?, ?)");
for (int i = 0; i < ROW_FOR_UPDATE + ROW_FOR_DELETE; i++) {
stmt.setInt(1, i);
stmt.setString(2, "personName" + i);
stmt.addBatch();
}
stmt.executeBatch();
stmt.close();
connection.commit();
PluginRegistry pluginRegistry = PluginRegistry.getInstance();
transMeta = new TransMeta();
transMeta.setName("SynchronizeAfterMerge");
InjectorMeta injectorMeta = new InjectorMeta();
String injectorPid = pluginRegistry.getPluginId(StepPluginType.class, injectorMeta);
StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, injectorMeta);
transMeta.addStep(injectorStep);
DatabaseMeta dbMeta = spy(new DatabaseMeta());
dbMeta.setDatabaseType("H2");
when(dbMeta.getURL()).thenReturn("jdbc:h2:mem:PERSON;");
when(dbMeta.supportsErrorHandlingOnBatchUpdates()).thenReturn(false);
SynchronizeAfterMergeMeta synchronizeAfterMergeMeta = new SynchronizeAfterMergeMeta();
// set commit size
synchronizeAfterMergeMeta.setCommitSize(COMMIT_SIZE);
synchronizeAfterMergeMeta.setDatabaseMeta(dbMeta);
synchronizeAfterMergeMeta.setKeyCondition(new String[] { "=" });
synchronizeAfterMergeMeta.setKeyLookup(new String[] { "ID" });
synchronizeAfterMergeMeta.setKeyStream(new String[] { "personName" });
synchronizeAfterMergeMeta.setKeyStream2(new String[] { null });
synchronizeAfterMergeMeta.setUpdate(new Boolean[] { Boolean.TRUE });
synchronizeAfterMergeMeta.setOperationOrderField("flag");
synchronizeAfterMergeMeta.setOrderDelete(DELETE_FLAG);
synchronizeAfterMergeMeta.setOrderInsert(INSERT_FLAG);
synchronizeAfterMergeMeta.setOrderUpdate(UPDATE_FLAG);
synchronizeAfterMergeMeta.setPerformLookup(true);
synchronizeAfterMergeMeta.setTableName("PERSON");
synchronizeAfterMergeMeta.settablenameInField(false);
synchronizeAfterMergeMeta.settablenameField(null);
synchronizeAfterMergeMeta.setUseBatchUpdate(true);
synchronizeAfterMergeMeta.setUpdateLookup(new String[] { "ID" });
synchronizeAfterMergeMeta.setUpdateStream(new String[] { "personName" });
String synchronizeAfterMergePid = pluginRegistry.getPluginId(StepPluginType.class, synchronizeAfterMergeStepname);
StepMeta synchronizeAfterMerge = new StepMeta(synchronizeAfterMergePid, synchronizeAfterMergeStepname, synchronizeAfterMergeMeta);
transMeta.addStep(synchronizeAfterMerge);
String dummyResultStepName = "dummyResultStepName";
DummyTransMeta dummyResultTransMeta = new DummyTransMeta();
String dummyResultPid = pluginRegistry.getPluginId(StepPluginType.class, dummyResultTransMeta);
StepMeta dummyResultStep = new StepMeta(dummyResultPid, dummyResultStepName, dummyResultTransMeta);
transMeta.addStep(dummyResultStep);
String dummyErrorStepName = "dummyErrorStepName";
DummyTransMeta dummyErrorTransMeta = new DummyTransMeta();
String dummyErrorPid = pluginRegistry.getPluginId(StepPluginType.class, dummyErrorTransMeta);
StepMeta dummyErrorStep = new StepMeta(dummyErrorPid, dummyErrorStepName, dummyErrorTransMeta);
transMeta.addStep(dummyErrorStep);
StepErrorMeta stepErrorMeta = new StepErrorMeta(transMeta, synchronizeAfterMerge, dummyErrorStep);
stepErrorMeta.setEnabled(true);
synchronizeAfterMerge.setStepErrorMeta(stepErrorMeta);
TransHopMeta injSynch = new TransHopMeta(injectorStep, synchronizeAfterMerge);
transMeta.addTransHop(injSynch);
TransHopMeta synchDummyResult = new TransHopMeta(synchronizeAfterMerge, dummyResultStep);
transMeta.addTransHop(synchDummyResult);
TransHopMeta synchDummyError = new TransHopMeta(synchronizeAfterMerge, dummyErrorStep);
transMeta.addTransHop(synchDummyError);
}
use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.
the class StringSearcherTest method testSearchConditionCase.
@Test
public void testSearchConditionCase() {
String dummyStepname = "Output";
DummyTransMeta dummyMeta = new DummyTransMeta();
String dummyStepPid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, dummyMeta);
StepMeta dummyStep = new StepMeta(dummyStepPid, dummyStepname, dummyMeta);
List<StringSearchResult> stringList = new ArrayList<StringSearchResult>();
StringSearcher.findMetaData(dummyStep, 0, stringList, dummyMeta, 0);
int checkCount = 0;
String aResult = null;
// Check that it found a couple of fields and emits the values properly
for (int i = 0; i < stringList.size(); i++) {
aResult = stringList.get(i).toString();
if (aResult.endsWith("Dummy (stepid)")) {
checkCount++;
} else if (aResult.endsWith("Output (name)")) {
checkCount++;
}
if (checkCount == 2) {
break;
}
}
assertEquals(2, checkCount);
FilterRowsMeta filterRowsMeta = new FilterRowsMeta();
Condition condition = new Condition();
condition.setNegated(false);
condition.setLeftValuename("wibble_t");
condition.setRightValuename("wobble_s");
condition.setFunction(org.pentaho.di.core.Condition.FUNC_EQUAL);
filterRowsMeta.setDefault();
filterRowsMeta.setCondition(condition);
String filterRowsPluginPid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, filterRowsMeta);
StepMeta filterRowsStep = new StepMeta(filterRowsPluginPid, "Filter Rows", filterRowsMeta);
stringList.clear();
StringSearcher.findMetaData(filterRowsStep, 0, stringList, filterRowsMeta, 0);
checkCount = 0;
for (int i = 0; i < stringList.size(); i++) {
aResult = stringList.get(i).toString();
if (aResult.endsWith("FilterRows (stepid)")) {
checkCount++;
} else if (aResult.endsWith("Filter Rows (name)")) {
checkCount++;
}
if (checkCount == 2) {
break;
}
}
assertEquals(2, checkCount);
}
Aggregations