use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.
the class RowGeneratorUnitTest method setUp.
@Before
public void setUp() throws KettleException {
// add variable to row generator step
StepMetaInterface stepMetaInterface = spy(new RowGeneratorMeta());
((RowGeneratorMeta) stepMetaInterface).setRowLimit("${ROW_LIMIT}");
String[] strings = {};
when(((RowGeneratorMeta) stepMetaInterface).getFieldName()).thenReturn(strings);
StepMeta stepMeta = new StepMeta();
stepMeta.setStepMetaInterface(stepMetaInterface);
stepMeta.setName("ROW_STEP_META");
StepDataInterface stepDataInterface = stepMeta.getStepMetaInterface().getStepData();
// add variable to transformation variable space
Map<String, String> map = new HashMap<String, String>();
map.put("ROW_LIMIT", "1440");
TransMeta transMeta = spy(new TransMeta());
transMeta.injectVariables(map);
when(transMeta.findStep(anyString())).thenReturn(stepMeta);
Trans trans = spy(new Trans(transMeta, null));
when(trans.getSocketRepository()).thenReturn(null);
when(trans.getLogChannelId()).thenReturn("ROW_LIMIT");
// prepare row generator, substitutes variable by value from transformation variable space
rowGenerator = spy(new RowGenerator(stepMeta, stepDataInterface, 0, transMeta, trans));
rowGenerator.initializeVariablesFrom(trans);
rowGenerator.init(stepMetaInterface, stepDataInterface);
}
use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.
the class RunTransServletTest method setup.
@Before
public void setup() throws Exception {
runTransServlet = new RunTransServlet();
outData = new ByteArrayOutputStream();
out = new PrintWriter(outData);
stepList = new ArrayList<>();
for (int i = 0; i < 5; i++) {
StepMetaDataCombi stepMetaDataCombi = new StepMetaDataCombi();
StepMetaInterface stepMeta = mock(StepMetaInterface.class);
when(stepMeta.passDataToServletOutput()).thenReturn(false);
stepMetaDataCombi.meta = stepMeta;
stepList.add(stepMetaDataCombi);
}
when(trans.getSteps()).thenReturn(stepList);
when(trans.getContainerObjectId()).thenReturn(transId);
}
use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.
the class SpoonTest method testDelHop.
@Test
public void testDelHop() throws Exception {
StepMetaInterface stepMetaInterface = Mockito.mock(StepMetaInterface.class);
StepMeta step = new StepMeta();
step.setStepMetaInterface(stepMetaInterface);
TransHopMeta transHopMeta = new TransHopMeta();
transHopMeta.setFromStep(step);
TransMeta transMeta = Mockito.mock(TransMeta.class);
spoon.delHop(transMeta, transHopMeta);
Mockito.verify(stepMetaInterface, times(1)).cleanAfterHopFromRemove();
}
use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.
the class SpoonStepsDelegateTest method testGetStepDialogClass.
@Test
public void testGetStepDialogClass() throws Exception {
PluginMockInterface plugin = mock(PluginMockInterface.class);
when(plugin.getIds()).thenReturn(new String[] { "mockPlugin" });
when(plugin.matches("mockPlugin")).thenReturn(true);
when(plugin.getName()).thenReturn("mockPlugin");
StepMetaInterface meta = mock(StepMetaInterface.class);
when(meta.getDialogClassName()).thenReturn(String.class.getName());
when(plugin.getClassMap()).thenReturn(new HashMap<Class<?>, String>() {
{
put(StepMetaInterface.class, meta.getClass().getName());
put(StepDialogInterface.class, StepDialogInterface.class.getName());
}
});
PluginRegistry.getInstance().registerPlugin(StepPluginType.class, plugin);
SpoonStepsDelegate delegate = mock(SpoonStepsDelegate.class);
Spoon spoon = mock(Spoon.class);
delegate.spoon = spoon;
delegate.log = mock(LogChannelInterface.class);
when(spoon.getShell()).thenReturn(mock(Shell.class));
doCallRealMethod().when(delegate).getStepDialog(any(StepMetaInterface.class), any(TransMeta.class), any(String.class));
TransMeta trans = mock(TransMeta.class);
// verify that dialog class is requested from plugin
try {
// exception is expected here
delegate.getStepDialog(meta, trans, "");
} catch (Throwable ignore) {
verify(meta, never()).getDialogClassName();
}
// verify that the deprecated way is still valid
when(plugin.getClassMap()).thenReturn(new HashMap<Class<?>, String>() {
{
put(StepMetaInterface.class, meta.getClass().getName());
}
});
try {
// exception is expected here
delegate.getStepDialog(meta, trans, "");
} catch (Throwable ignore) {
verify(meta, times(1)).getDialogClassName();
}
// cleanup
PluginRegistry.getInstance().removePlugin(StepPluginType.class, plugin);
}
use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.
the class Spoon method pasteXML.
public void pasteXML(TransMeta transMeta, String clipcontent, Point loc) {
if (RepositorySecurityUI.verifyOperations(shell, rep, RepositoryOperation.MODIFY_TRANSFORMATION, RepositoryOperation.EXECUTE_TRANSFORMATION)) {
return;
}
try {
Document doc = XMLHandler.loadXMLString(clipcontent);
Node transNode = XMLHandler.getSubNode(doc, Spoon.XML_TAG_TRANSFORMATION_STEPS);
// De-select all, re-select pasted steps...
transMeta.unselectAll();
Node stepsNode = XMLHandler.getSubNode(transNode, "steps");
int nr = XMLHandler.countNodes(stepsNode, "step");
if (getLog().isDebug()) {
// "I found "+nr+" steps to paste on location: "
getLog().logDebug(BaseMessages.getString(PKG, "Spoon.Log.FoundSteps", "" + nr) + loc);
}
StepMeta[] steps = new StepMeta[nr];
ArrayList<String> stepOldNames = new ArrayList<>(nr);
// Point min = new Point(loc.x, loc.y);
Point min = new Point(99999999, 99999999);
// Load the steps...
for (int i = 0; i < nr; i++) {
Node stepNode = XMLHandler.getSubNodeByNr(stepsNode, "step", i);
steps[i] = new StepMeta(stepNode, transMeta.getDatabases(), metaStore);
if (loc != null) {
Point p = steps[i].getLocation();
if (min.x > p.x) {
min.x = p.x;
}
if (min.y > p.y) {
min.y = p.y;
}
}
}
// Load the hops...
Node hopsNode = XMLHandler.getSubNode(transNode, "order");
nr = XMLHandler.countNodes(hopsNode, "hop");
if (getLog().isDebug()) {
// "I found "+nr+" hops to paste."
getLog().logDebug(BaseMessages.getString(PKG, "Spoon.Log.FoundHops", "" + nr));
}
TransHopMeta[] hops = new TransHopMeta[nr];
for (int i = 0; i < nr; i++) {
Node hopNode = XMLHandler.getSubNodeByNr(hopsNode, "hop", i);
hops[i] = new TransHopMeta(hopNode, Arrays.asList(steps));
}
// This is the offset:
Point offset = new Point(loc.x - min.x, loc.y - min.y);
// Undo/redo object positions...
int[] position = new int[steps.length];
for (int i = 0; i < steps.length; i++) {
Point p = steps[i].getLocation();
String name = steps[i].getName();
steps[i].setLocation(p.x + offset.x, p.y + offset.y);
steps[i].setDraw(true);
// Check the name, find alternative...
stepOldNames.add(name);
steps[i].setName(transMeta.getAlternativeStepname(name));
transMeta.addStep(steps[i]);
position[i] = transMeta.indexOfStep(steps[i]);
steps[i].setSelected(true);
}
// Add the hops too...
for (TransHopMeta hop : hops) {
transMeta.addTransHop(hop);
}
// Load the notes...
Node notesNode = XMLHandler.getSubNode(transNode, "notepads");
nr = XMLHandler.countNodes(notesNode, "notepad");
if (getLog().isDebug()) {
// "I found "+nr+" notepads to paste."
getLog().logDebug(BaseMessages.getString(PKG, "Spoon.Log.FoundNotepads", "" + nr));
}
NotePadMeta[] notes = new NotePadMeta[nr];
for (int i = 0; i < notes.length; i++) {
Node noteNode = XMLHandler.getSubNodeByNr(notesNode, "notepad", i);
notes[i] = new NotePadMeta(noteNode);
Point p = notes[i].getLocation();
notes[i].setLocation(p.x + offset.x, p.y + offset.y);
transMeta.addNote(notes[i]);
notes[i].setSelected(true);
}
// Set the source and target steps ...
for (StepMeta step : steps) {
StepMetaInterface smi = step.getStepMetaInterface();
smi.searchInfoAndTargetSteps(transMeta.getSteps());
}
// Set the error handling hops
Node errorHandlingNode = XMLHandler.getSubNode(transNode, TransMeta.XML_TAG_STEP_ERROR_HANDLING);
int nrErrorHandlers = XMLHandler.countNodes(errorHandlingNode, StepErrorMeta.XML_ERROR_TAG);
for (int i = 0; i < nrErrorHandlers; i++) {
Node stepErrorMetaNode = XMLHandler.getSubNodeByNr(errorHandlingNode, StepErrorMeta.XML_ERROR_TAG, i);
StepErrorMeta stepErrorMeta = new StepErrorMeta(transMeta.getParentVariableSpace(), stepErrorMetaNode, transMeta.getSteps());
// Handle pasting multiple times, need to update source and target step names
int srcStepPos = stepOldNames.indexOf(stepErrorMeta.getSourceStep().getName());
int tgtStepPos = stepOldNames.indexOf(stepErrorMeta.getTargetStep().getName());
StepMeta sourceStep = transMeta.findStep(steps[srcStepPos].getName());
if (sourceStep != null) {
sourceStep.setStepErrorMeta(stepErrorMeta);
}
sourceStep.setStepErrorMeta(null);
if (tgtStepPos >= 0) {
sourceStep.setStepErrorMeta(stepErrorMeta);
StepMeta targetStep = transMeta.findStep(steps[tgtStepPos].getName());
stepErrorMeta.setSourceStep(sourceStep);
stepErrorMeta.setTargetStep(targetStep);
}
}
// Save undo information too...
addUndoNew(transMeta, steps, position, false);
int[] hopPos = new int[hops.length];
for (int i = 0; i < hops.length; i++) {
hopPos[i] = transMeta.indexOfTransHop(hops[i]);
}
addUndoNew(transMeta, hops, hopPos, true);
int[] notePos = new int[notes.length];
for (int i = 0; i < notes.length; i++) {
notePos[i] = transMeta.indexOfNote(notes[i]);
}
addUndoNew(transMeta, notes, notePos, true);
if (transMeta.haveStepsChanged()) {
refreshTree();
refreshGraph();
}
} catch (KettleException e) {
// "Error pasting steps...",
// "I was unable to paste steps to this transformation"
new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.UnablePasteSteps.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.UnablePasteSteps.Message"), e);
}
}
Aggregations