diff --git a/src/main/java/org/pentaho/di/dataset/TransUnitTest.java b/src/main/java/org/pentaho/di/dataset/TransUnitTest.java index 9631609..1cd1d02 100644 --- a/src/main/java/org/pentaho/di/dataset/TransUnitTest.java +++ b/src/main/java/org/pentaho/di/dataset/TransUnitTest.java @@ -31,6 +31,7 @@ import org.pentaho.di.core.row.RowMeta; import org.pentaho.di.core.row.RowMetaInterface; import org.pentaho.di.dataset.spoon.xtpoint.RowCollection; +import org.pentaho.di.dataset.util.DataSetConst; import org.pentaho.di.dataset.util.FactoriesHierarchy; import org.pentaho.metastore.persist.MetaStoreAttribute; import org.pentaho.metastore.persist.MetaStoreElementType; @@ -75,6 +76,9 @@ public class TransUnitTest { @MetaStoreAttribute( key = "persist_filename") protected String filename; + @MetaStoreAttribute + protected String basePath; + @MetaStoreAttribute( key = "database_replacements" ) protected List databaseReplacements; @@ -88,6 +92,7 @@ public TransUnitTest() { type = TestType.NONE; databaseReplacements = new ArrayList(); variableValues = new ArrayList<>(); + basePath = DataSetConst.VARIABLE_UNIT_TESTS_BASE_PATH; } public TransUnitTest( String name, String description, @@ -127,72 +132,8 @@ public boolean equals( Object obj ) { public int hashCode() { return name.hashCode(); } - - - public String getName() { - return name; - } - - public void setName( String name ) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription( String description ) { - this.description = description; - } - - public List getInputDataSets() { - return inputDataSets; - } - - public void setInputDataSets( List inputDataSets ) { - this.inputDataSets = inputDataSets; - } - - public String getTransObjectId() { - return transObjectId; - } - - public void setTransObjectId( String transObjectId ) { - this.transObjectId = transObjectId; - } - - public String getTransRepositoryPath() { - return transRepositoryPath; - } - - public void setTransRepositoryPath( String transRepositoryPath ) { - this.transRepositoryPath = transRepositoryPath; - } - - public String getTransFilename() { - return transFilename; - } - - public void setTransFilename( String transFilename ) { - this.transFilename = transFilename; - } - public List getGoldenDataSets() { - return goldenDataSets; - } - - public void setGoldenDataSets( List goldenDataSets ) { - this.goldenDataSets = goldenDataSets; - } - - public List getTweaks() { - return tweaks; - } - public void setTweaks(List tweaks) { - this.tweaks = tweaks; - } - public TransUnitTestSetLocation findGoldenLocation(String stepName) { for (TransUnitTestSetLocation location : goldenDataSets) { if (stepName.equalsIgnoreCase( location.getStepname() )) { @@ -201,7 +142,7 @@ public TransUnitTestSetLocation findGoldenLocation(String stepName) { } return null; } - + public TransUnitTestSetLocation findInputLocation(String stepName) { for (TransUnitTestSetLocation location : inputDataSets) { if (stepName.equalsIgnoreCase( location.getStepname() )) { @@ -210,7 +151,7 @@ public TransUnitTestSetLocation findInputLocation(String stepName) { } return null; } - + /** * Retrieve the golden data set for the specified location * @@ -218,7 +159,7 @@ public TransUnitTestSetLocation findInputLocation(String stepName) { * @param hierarchy The factories to load sets with * @param location the location where we want to check against golden rows * @return The golden data set - * + * * @throws KettleException */ public DataSet getGoldenDataSet(LogChannelInterface log, FactoriesHierarchy hierarchy, TransUnitTestSetLocation location) throws KettleException { @@ -232,7 +173,7 @@ public DataSet getGoldenDataSet(LogChannelInterface log, FactoriesHierarchy hier if (goldenDataSetName==null) { throw new KettleException("Unable to find golden data set for step '"+stepName+"'"); } - + DataSet goldenDataSet = hierarchy.getSetFactory().loadElement( goldenDataSetName ); if (goldenDataSet==null) { throw new KettleException("Unable to find golden data set '"+goldenDataSetName+"' for step '"+stepName+"'"); @@ -245,7 +186,7 @@ public DataSet getGoldenDataSet(LogChannelInterface log, FactoriesHierarchy hier } } - /** Find the first tweak for a certain step + /** Find the first tweak for a certain step * @param stepname the name of the step on which a tweak is put * @return the first tweak for a certain step or null if nothing was found */ @@ -258,27 +199,216 @@ public TransUnitTestTweak findTweak(String stepname) { return null; } + /** + * Remove all input and golden data sets on the step with the provided name + * @param stepname the name of the step for which we need to clear out all input and golden data sets + */ + public void removeInputAndGoldenDataSets(String stepname) { + + for (Iterator iterator = inputDataSets.iterator() ; iterator.hasNext() ; ) { + TransUnitTestSetLocation inputLocation = iterator.next(); + if (inputLocation.getStepname().equalsIgnoreCase(stepname)) { + iterator.remove(); + } + } + + for (Iterator iterator = goldenDataSets.iterator() ; iterator.hasNext() ; ) { + TransUnitTestSetLocation goldenLocation = iterator.next(); + if (goldenLocation.getStepname().equalsIgnoreCase(stepname)) { + iterator.remove(); + } + } + } + + /** + * Gets name + * + * @return value of name + */ + public String getName() { + return name; + } + + /** + * @param name The name to set + */ + public void setName( String name ) { + this.name = name; + } + + /** + * Gets description + * + * @return value of description + */ + public String getDescription() { + return description; + } + + /** + * @param description The description to set + */ + public void setDescription( String description ) { + this.description = description; + } + + /** + * Gets transObjectId + * + * @return value of transObjectId + */ + public String getTransObjectId() { + return transObjectId; + } + + /** + * @param transObjectId The transObjectId to set + */ + public void setTransObjectId( String transObjectId ) { + this.transObjectId = transObjectId; + } + + /** + * Gets transRepositoryPath + * + * @return value of transRepositoryPath + */ + public String getTransRepositoryPath() { + return transRepositoryPath; + } + + /** + * @param transRepositoryPath The transRepositoryPath to set + */ + public void setTransRepositoryPath( String transRepositoryPath ) { + this.transRepositoryPath = transRepositoryPath; + } + + /** + * Gets transFilename + * + * @return value of transFilename + */ + public String getTransFilename() { + return transFilename; + } + + /** + * @param transFilename The transFilename to set + */ + public void setTransFilename( String transFilename ) { + this.transFilename = transFilename; + } + + /** + * Gets inputDataSets + * + * @return value of inputDataSets + */ + public List getInputDataSets() { + return inputDataSets; + } + + /** + * @param inputDataSets The inputDataSets to set + */ + public void setInputDataSets( List inputDataSets ) { + this.inputDataSets = inputDataSets; + } + + /** + * Gets goldenDataSets + * + * @return value of goldenDataSets + */ + public List getGoldenDataSets() { + return goldenDataSets; + } + + /** + * @param goldenDataSets The goldenDataSets to set + */ + public void setGoldenDataSets( List goldenDataSets ) { + this.goldenDataSets = goldenDataSets; + } + + /** + * Gets tweaks + * + * @return value of tweaks + */ + public List getTweaks() { + return tweaks; + } + + /** + * @param tweaks The tweaks to set + */ + public void setTweaks( List tweaks ) { + this.tweaks = tweaks; + } + + /** + * Gets type + * + * @return value of type + */ public TestType getType() { return type; } - public void setType(TestType type) { + /** + * @param type The type to set + */ + public void setType( TestType type ) { this.type = type; } + /** + * Gets filename + * + * @return value of filename + */ public String getFilename() { return filename; } - public void setFilename(String filename) { + /** + * @param filename The filename to set + */ + public void setFilename( String filename ) { this.filename = filename; } + /** + * Gets basePath + * + * @return value of basePath + */ + public String getBasePath() { + return basePath; + } + + /** + * @param basePath The basePath to set + */ + public void setBasePath( String basePath ) { + this.basePath = basePath; + } + + /** + * Gets databaseReplacements + * + * @return value of databaseReplacements + */ public List getDatabaseReplacements() { return databaseReplacements; } - public void setDatabaseReplacements(List databaseReplacements) { + /** + * @param databaseReplacements The databaseReplacements to set + */ + public void setDatabaseReplacements( List databaseReplacements ) { this.databaseReplacements = databaseReplacements; } @@ -297,25 +427,4 @@ public List getVariableValues() { public void setVariableValues( List variableValues ) { this.variableValues = variableValues; } - - /** - * Remove all input and golden data sets on the step with the provided name - * @param stepname the name of the step for which we need to clear out all input and golden data sets - */ - public void removeInputAndGoldenDataSets(String stepname) { - - for (Iterator iterator = inputDataSets.iterator() ; iterator.hasNext() ; ) { - TransUnitTestSetLocation inputLocation = iterator.next(); - if (inputLocation.getStepname().equalsIgnoreCase(stepname)) { - iterator.remove(); - } - } - - for (Iterator iterator = goldenDataSets.iterator() ; iterator.hasNext() ; ) { - TransUnitTestSetLocation goldenLocation = iterator.next(); - if (goldenLocation.getStepname().equalsIgnoreCase(stepname)) { - iterator.remove(); - } - } - } } diff --git a/src/main/java/org/pentaho/di/dataset/spoon/DataSetHelper.java b/src/main/java/org/pentaho/di/dataset/spoon/DataSetHelper.java index 6925256..90887e7 100755 --- a/src/main/java/org/pentaho/di/dataset/spoon/DataSetHelper.java +++ b/src/main/java/org/pentaho/di/dataset/spoon/DataSetHelper.java @@ -26,9 +26,12 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.commons.lang.StringUtils; +import org.apache.commons.vfs2.FileObject; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.MessageBox; import org.pentaho.di.core.Const; @@ -37,6 +40,7 @@ import org.pentaho.di.core.database.DatabaseMeta; import org.pentaho.di.core.exception.KettleException; import org.pentaho.di.core.gui.SpoonFactory; +import org.pentaho.di.core.logging.LogChannel; import org.pentaho.di.core.row.RowDataUtil; import org.pentaho.di.core.row.RowMeta; import org.pentaho.di.core.row.RowMetaInterface; @@ -44,6 +48,7 @@ import org.pentaho.di.core.row.value.ValueMetaString; import org.pentaho.di.core.util.StringUtil; import org.pentaho.di.core.variables.Variables; +import org.pentaho.di.core.vfs.KettleVFS; import org.pentaho.di.dataset.DataSet; import org.pentaho.di.dataset.DataSetField; import org.pentaho.di.dataset.DataSetGroup; @@ -89,8 +94,11 @@ public class DataSetHelper extends AbstractXulEventHandler implements ISpoonMenu protected static Class PKG = DataSetHelper.class; // for i18n private static DataSetHelper instance = null; + + private Map activeTests; private DataSetHelper() { + activeTests = new HashMap<>(); } public static DataSetHelper getInstance() { @@ -371,12 +379,14 @@ public void setInputDataSet() { if ( transGraph == null || transMeta == null || stepMeta == null ) { return; } + IMetaStore metaStore = spoon.getMetaStore(); if (checkTestPresent(spoon, transMeta)) { return; } - + TransUnitTest unitTest = activeTests.get( transMeta ); + try { List databases = getAvailableDatabases( spoon.getRepository() ); @@ -389,10 +399,7 @@ public void setInputDataSet() { String setName = esd.open(); if ( setName != null ) { DataSet dataSet = setFactory.loadElement( setName ); - - stepMeta.setAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_DATASET_GOLDEN, null); - stepMeta.setAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_DATASET_INPUT, dataSet.getName() ); - + // Now we need to map the fields from the input data set to the step... // RowMetaInterface setFields = dataSet.getSetRowMeta( false ); @@ -429,19 +436,6 @@ public void setInputDataSet() { return; } - // What is the unit test we are using? - // - String testName = transMeta.getAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_TRANS_SELECTED_UNIT_TEST_NAME ); - if (StringUtil.isEmpty( testName )) { - return; - } - TransUnitTest unitTest = hierarchy.getTestFactory().loadElement( testName ); - if (unitTest==null) { - // Show a message box later - // - return; - } - // Modify the test // @@ -471,8 +465,8 @@ public void setInputDataSet() { // Save the unit test... // - hierarchy.getTestFactory().saveElement( unitTest ); - + saveUnitTest( getHierarchy().getTestFactory(), unitTest, transMeta ); + stepMeta.setChanged(); spoon.refreshGraph(); @@ -483,9 +477,9 @@ public void setInputDataSet() { } private boolean checkTestPresent(Spoon spoon, TransMeta transMeta) { - - String testName = transMeta.getAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_TRANS_SELECTED_UNIT_TEST_NAME ); - if (!StringUtil.isEmpty( testName )) { + + TransUnitTest activeTest = activeTests.get( transMeta ); + if (activeTest!=null) { return false; } @@ -516,6 +510,7 @@ public void setGoldenDataSet() { if (checkTestPresent(spoon, transMeta)) { return; } + TransUnitTest unitTest = activeTests.get( transMeta ); try { FactoriesHierarchy hierarchy = getHierarchy(); @@ -528,11 +523,6 @@ public void setGoldenDataSet() { if ( setName != null ) { DataSet dataSet = setFactory.loadElement( setName ); - // Clear possible input data set name - stepMeta.setAttribute(DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_DATASET_INPUT, null); - // Set golden data set name - stepMeta.setAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_DATASET_GOLDEN, dataSet.getName() ); - // Now we need to map the fields from the step to golden data set fields... // RowMetaInterface stepFields = transMeta.getPrevStepFields( stepMeta ); @@ -566,28 +556,15 @@ public void setGoldenDataSet() { return; } - // What is the unit test we are using? - // - String testName = transMeta.getAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_TRANS_SELECTED_UNIT_TEST_NAME ); - if (StringUtil.isEmpty( testName )) { - return; - } - TransUnitTest goldenTest = hierarchy.getTestFactory().loadElement( testName ); - if (goldenTest==null) { - // Show a message box later - // - return; - } - // Modify the test // // Remove golden locations and input locations on the step to avoid duplicates // - goldenTest.removeInputAndGoldenDataSets(stepMeta.getName()); + unitTest.removeInputAndGoldenDataSets(stepMeta.getName()); TransUnitTestSetLocation goldenLocation = new TransUnitTestSetLocation(); - goldenTest.getGoldenDataSets().add( goldenLocation ); + unitTest.getGoldenDataSets().add( goldenLocation ); goldenLocation.setStepname( stepMeta.getName() ); goldenLocation.setDataSetName( dataSet.getName() ); @@ -608,8 +585,8 @@ public void setGoldenDataSet() { // Save the unit test... // - hierarchy.getTestFactory().saveElement( goldenTest ); - + saveUnitTest( getHierarchy().getTestFactory(), unitTest, transMeta ); + stepMeta.setChanged(); spoon.refreshGraph(); @@ -628,6 +605,9 @@ public void clearInputDataSet() { if ( transGraph == null || transMeta == null || stepMeta == null ) { return; } + if (checkTestPresent(spoon, transMeta)) { + return; + } try { TransUnitTest currentUnitTest = getCurrentUnitTest( transMeta ); @@ -637,9 +617,7 @@ public void clearInputDataSet() { currentUnitTest.getInputDataSets().remove( inputLocation ); } - stepMeta.setAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_DATASET_INPUT, null ); - - getHierarchy().getTestFactory().saveElement( currentUnitTest ); + saveUnitTest( getHierarchy().getTestFactory(), currentUnitTest, transMeta ); transGraph.redraw(); } catch(Exception e) { @@ -655,6 +633,9 @@ public void clearGoldenDataSet() { if ( transGraph == null || transMeta == null || stepMeta == null ) { return; } + if (checkTestPresent(spoon, transMeta)) { + return; + } try { TransUnitTest currentUnitTest = getCurrentUnitTest( transMeta ); @@ -664,9 +645,7 @@ public void clearGoldenDataSet() { currentUnitTest.getGoldenDataSets().remove( goldenLocation ); } - stepMeta.setAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_DATASET_GOLDEN, null ); - - getHierarchy().getTestFactory().saveElement( currentUnitTest ); + saveUnitTest( getHierarchy().getTestFactory(), currentUnitTest, transMeta ); } catch(Exception e) { new ErrorDialog(spoon.getShell(), "Error", "Error saving unit test", e); } @@ -848,12 +827,9 @@ public void createUnitTest(Spoon spoon, TransMeta transMeta) { TransUnitTestDialog dialog = new TransUnitTestDialog(spoon.getShell(), transMeta, spoon.getMetaStore(), unitTest); if (dialog.open()) { - hierarchy.getTestFactory().saveElement(unitTest); - transMeta.setAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_TRANS_SELECTED_UNIT_TEST_NAME, unitTest.getName() ); + saveUnitTest(hierarchy.getTestFactory(), unitTest, transMeta); - // Don't carry on old indicators... - // - DataSetConst.clearStepDataSetIndicators( transMeta ); + activeTests.put( transMeta, unitTest ); spoon.refreshGraph(); } @@ -863,6 +839,62 @@ public void createUnitTest(Spoon spoon, TransMeta transMeta) { } } + private void saveUnitTest( MetaStoreFactory testFactory, TransUnitTest unitTest, TransMeta transMeta ) throws MetaStoreException { + + // Build relative path whenever a transformation is saved + // + if (StringUtils.isNotEmpty( transMeta.getFilename() )) { + // Set the filename to be safe + // + unitTest.setTransFilename( transMeta.getFilename() ); + + String basePath = unitTest.getBasePath(); + if (StringUtils.isEmpty( basePath )) { + basePath = DataSetConst.VARIABLE_UNIT_TESTS_BASE_PATH; + } + basePath = transMeta.environmentSubstitute( basePath ); + if (StringUtils.isNotEmpty( basePath )) { + // See if the basePath is present in the filename + // Then replace the filename + // + try { + FileObject baseFolder = KettleVFS.getFileObject( basePath ); + FileObject transFile = KettleVFS.getFileObject( transMeta.getFilename() ); + FileObject parent = transFile.getParent(); + while (parent!=null) { + if (parent.equals( baseFolder)) { + // Here we are, we found the base folder in the transformation file + // + String transFilename = transFile.toString(); + String baseFoldername = parent.toString(); + + // Final validation & unit test filename correction + // + if (transFilename.startsWith( baseFoldername )) { + String relativeFile = transFilename.substring( baseFoldername.length() ); + String filename; + if (relativeFile.startsWith( "/" )) { + filename= "."+relativeFile; + } else { + filename = "./"+relativeFile; + } + // Set the transformation filename to the relative path + // + unitTest.setTransFilename( filename ); + LogChannel.GENERAL.logBasic( "Unit test '"+unitTest.getName()+"' : Saved relative path to transformation: "+filename ); + } + } + parent = parent.getParent(); + } + } catch ( Exception e ) { + throw new MetaStoreException( "Error calculating relative unit test file path", e ); + } + } + } + + testFactory.saveElement(unitTest); + } + public void editUnitTest(Spoon spoon, TransMeta transMeta, String unitTestName) { IMetaStore metaStore = spoon.getMetaStore(); @@ -875,7 +907,7 @@ public void editUnitTest(Spoon spoon, TransMeta transMeta, String unitTestName) } TransUnitTestDialog dialog = new TransUnitTestDialog(spoon.getShell(), transMeta, metaStore, unitTest); if (dialog.open()) { - hierarchy.getTestFactory().saveElement(unitTest); + saveUnitTest( hierarchy.getTestFactory(), unitTest, transMeta ); } } catch(Exception exception) { new ErrorDialog(Spoon.getInstance().getShell(), @@ -898,11 +930,11 @@ public void detachUnitTest() { return; } - transMeta.setAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_TRANS_SELECTED_UNIT_TEST_NAME, null ); - transMeta.setChanged(); - - DataSetConst.clearStepDataSetIndicators( transMeta ); - + + // Remove + // + activeTests.remove( transMeta ); + spoon.refreshGraph(); } catch ( Exception e ) { new ErrorDialog( spoon.getShell(), "Error", "Error detaching unit test", e ); @@ -944,25 +976,13 @@ public void selectUnitTest() { new ErrorDialog( spoon.getShell(), "Error", "Error selecting a new transformation unit test", e ); } } - - public static final void selectUnitTest(TransMeta transMeta, TransUnitTest unitTest) throws KettleException { - transMeta.setAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_TRANS_SELECTED_UNIT_TEST_NAME, unitTest.getName() ); - - DataSetConst.loadStepDataSetIndicators( transMeta, unitTest); - transMeta.setChanged(); + public static final void selectUnitTest(TransMeta transMeta, TransUnitTest unitTest) { + getInstance().getActiveTests().put(transMeta, unitTest); } - public TransUnitTest getCurrentUnitTest(TransMeta transMeta) throws MetaStoreException, KettleException { - // What is the unit test we are using? - // - String testName = transMeta.getAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_TRANS_SELECTED_UNIT_TEST_NAME ); - if (StringUtil.isEmpty( testName )) { - return null; - } - Spoon spoon = Spoon.getInstance(); - TransUnitTest unitTest = getHierarchy().getTestFactory().loadElement( testName ); - return unitTest; + public static final TransUnitTest getCurrentUnitTest(TransMeta transMeta) { + return getInstance().getActiveTests().get( transMeta ); } public void enableTweakRemoveStepInUnitTest() { @@ -987,24 +1007,22 @@ private void tweakUnitTestStep(TransTweak stepTweak, boolean enable) { if ( stepMeta == null || transMeta == null ) { return; } + if (checkTestPresent(spoon, transMeta)) { + return; + } try { TransUnitTest unitTest = getCurrentUnitTest(transMeta); - if (unitTest==null) { - return; - } TransUnitTestTweak unitTestTweak = unitTest.findTweak(stepMeta.getName()); if (unitTestTweak!=null) { unitTest.getTweaks().remove(unitTestTweak); - stepMeta.setAttribute(DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_TWEAK, null); } if (enable) { unitTest.getTweaks().add(new TransUnitTestTweak(stepTweak, stepMeta.getName())); - stepMeta.setAttribute(DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_TWEAK, stepTweak.name()); } - getHierarchy().getTestFactory().saveElement(unitTest); - + saveUnitTest( getHierarchy().getTestFactory(), unitTest, transMeta ); + spoon.refreshGraph(); } catch(Exception exception) { @@ -1144,4 +1162,19 @@ public void switchUnitTest(TransUnitTest targetTest, TransMeta transMeta) { Spoon.getInstance().refreshGraph(); } + /** + * Gets activeTests + * + * @return value of activeTests + */ + public Map getActiveTests() { + return activeTests; + } + + /** + * @param activeTests The activeTests to set + */ + public void setActiveTests( Map activeTests ) { + this.activeTests = activeTests; + } } diff --git a/src/main/java/org/pentaho/di/dataset/spoon/dialog/TransUnitTestDialog.java b/src/main/java/org/pentaho/di/dataset/spoon/dialog/TransUnitTestDialog.java index 12b6c07..aea01a9 100644 --- a/src/main/java/org/pentaho/di/dataset/spoon/dialog/TransUnitTestDialog.java +++ b/src/main/java/org/pentaho/di/dataset/spoon/dialog/TransUnitTestDialog.java @@ -22,9 +22,6 @@ package org.pentaho.di.dataset.spoon.dialog; -import java.util.Arrays; - -import org.apache.commons.validator.Var; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CCombo; import org.eclipse.swt.events.SelectionAdapter; @@ -64,7 +61,8 @@ import org.pentaho.metastore.api.exceptions.MetaStoreException; import org.pentaho.metastore.persist.MetaStoreFactory; import org.pentaho.metastore.util.PentahoDefaults; -import org.snmp4j.smi.Variable; + +import java.util.Arrays; public class TransUnitTestDialog extends Dialog { private static Class PKG = TransUnitTestDialog.class; // for i18n purposes, needed by Translator2!! @@ -78,6 +76,7 @@ public class TransUnitTestDialog extends Dialog { private Text wDescription; private CCombo wTestType; private TextVar wFilename; + private TextVar wBasePath; private TableView wDbReplacements; private TableView wVariableValues; @@ -95,23 +94,23 @@ public class TransUnitTestDialog extends Dialog { protected IMetaStore metaStore; MetaStoreFactory setFactory; - - public TransUnitTestDialog(Shell parent, TransMeta transMeta, IMetaStore metaStore, TransUnitTest transUnitTest) throws KettleException, MetaStoreException { - super(parent, SWT.NONE); + + public TransUnitTestDialog( Shell parent, TransMeta transMeta, IMetaStore metaStore, TransUnitTest transUnitTest ) throws KettleException, MetaStoreException { + super( parent, SWT.NONE ); this.transMeta = transMeta; this.metaStore = metaStore; this.transUnitTest = transUnitTest; props = PropsUI.getInstance(); ok = false; - setFactory = new MetaStoreFactory(TransUnitTest.class, metaStore, PentahoDefaults.NAMESPACE); + setFactory = new MetaStoreFactory( TransUnitTest.class, metaStore, PentahoDefaults.NAMESPACE ); } public boolean open() { Shell parent = getParent(); - shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN); - props.setLook(shell); - shell.setImage(GUIResource.getInstance().getImageTable()); + shell = new Shell( parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN ); + props.setLook( shell ); + shell.setImage( GUIResource.getInstance().getImageTable() ); middle = props.getMiddlePct(); margin = Const.MARGIN; @@ -120,197 +119,216 @@ public boolean open() { formLayout.marginWidth = Const.FORM_MARGIN; formLayout.marginHeight = Const.FORM_MARGIN; - shell.setText(BaseMessages.getString(PKG, "TransUnitTestDialog.Shell.Title")); - shell.setLayout(formLayout); + shell.setText( BaseMessages.getString( PKG, "TransUnitTestDialog.Shell.Title" ) ); + shell.setLayout( formLayout ); // The name of the unit test... // - Label wlName = new Label(shell, SWT.RIGHT); - props.setLook(wlName); - wlName.setText(BaseMessages.getString(PKG, "TransUnitTestDialog.Name.Label")); + Label wlName = new Label( shell, SWT.RIGHT ); + props.setLook( wlName ); + wlName.setText( BaseMessages.getString( PKG, "TransUnitTestDialog.Name.Label" ) ); FormData fdlName = new FormData(); - fdlName.top = new FormAttachment(0, 0); - fdlName.left = new FormAttachment(0, 0); - fdlName.right = new FormAttachment(middle, -margin); - wlName.setLayoutData(fdlName); - wName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); - props.setLook(wName); + fdlName.top = new FormAttachment( 0, 0 ); + fdlName.left = new FormAttachment( 0, 0 ); + fdlName.right = new FormAttachment( middle, -margin ); + wlName.setLayoutData( fdlName ); + wName = new Text( shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER ); + props.setLook( wName ); FormData fdName = new FormData(); - fdName.top = new FormAttachment(0, 0); - fdName.left = new FormAttachment(middle, 0); - fdName.right = new FormAttachment(100, 0); - wName.setLayoutData(fdName); + fdName.top = new FormAttachment( 0, 0 ); + fdName.left = new FormAttachment( middle, 0 ); + fdName.right = new FormAttachment( 100, 0 ); + wName.setLayoutData( fdName ); Control lastControl = wName; // The description of the test... // - Label wlDescription = new Label(shell, SWT.RIGHT); - props.setLook(wlDescription); - wlDescription.setText(BaseMessages.getString(PKG, "TransUnitTestDialog.Description.Label")); + Label wlDescription = new Label( shell, SWT.RIGHT ); + props.setLook( wlDescription ); + wlDescription.setText( BaseMessages.getString( PKG, "TransUnitTestDialog.Description.Label" ) ); FormData fdlDescription = new FormData(); - fdlDescription.top = new FormAttachment(lastControl, margin); - fdlDescription.left = new FormAttachment(0, 0); - fdlDescription.right = new FormAttachment(middle, -margin); - wlDescription.setLayoutData(fdlDescription); - wDescription = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); - props.setLook(wDescription); + fdlDescription.top = new FormAttachment( lastControl, margin ); + fdlDescription.left = new FormAttachment( 0, 0 ); + fdlDescription.right = new FormAttachment( middle, -margin ); + wlDescription.setLayoutData( fdlDescription ); + wDescription = new Text( shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER ); + props.setLook( wDescription ); FormData fdDescription = new FormData(); - fdDescription.top = new FormAttachment(lastControl, margin); - fdDescription.left = new FormAttachment(middle, 0); - fdDescription.right = new FormAttachment(100, 0); - wDescription.setLayoutData(fdDescription); + fdDescription.top = new FormAttachment( lastControl, margin ); + fdDescription.left = new FormAttachment( middle, 0 ); + fdDescription.right = new FormAttachment( 100, 0 ); + wDescription.setLayoutData( fdDescription ); lastControl = wDescription; // The type of test... // - Label wlTestType = new Label(shell, SWT.RIGHT); - props.setLook(wlTestType); - wlTestType.setText(BaseMessages.getString(PKG, "TransUnitTestDialog.TestType.Label")); + Label wlTestType = new Label( shell, SWT.RIGHT ); + props.setLook( wlTestType ); + wlTestType.setText( BaseMessages.getString( PKG, "TransUnitTestDialog.TestType.Label" ) ); FormData fdlTestType = new FormData(); - fdlTestType.top = new FormAttachment(lastControl, margin); - fdlTestType.left = new FormAttachment(0, 0); - fdlTestType.right = new FormAttachment(middle, -margin); - wlTestType.setLayoutData(fdlTestType); - wTestType = new CCombo(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); - props.setLook(wTestType); + fdlTestType.top = new FormAttachment( lastControl, margin ); + fdlTestType.left = new FormAttachment( 0, 0 ); + fdlTestType.right = new FormAttachment( middle, -margin ); + wlTestType.setLayoutData( fdlTestType ); + wTestType = new CCombo( shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER ); + props.setLook( wTestType ); FormData fdTestType = new FormData(); - fdTestType.top = new FormAttachment(lastControl, margin); - fdTestType.left = new FormAttachment(middle, 0); - fdTestType.right = new FormAttachment(100, 0); - wTestType.setLayoutData(fdTestType); - wTestType.setItems(DataSetConst.getTestTypeDescriptions()); + fdTestType.top = new FormAttachment( lastControl, margin ); + fdTestType.left = new FormAttachment( middle, 0 ); + fdTestType.right = new FormAttachment( 100, 0 ); + wTestType.setLayoutData( fdTestType ); + wTestType.setItems( DataSetConst.getTestTypeDescriptions() ); lastControl = wTestType; - + // The optional filename of the test result... // - Label wlFilename = new Label(shell, SWT.RIGHT); - props.setLook(wlFilename); - wlFilename.setText(BaseMessages.getString(PKG, "TransUnitTestDialog.Filename.Label")); + Label wlFilename = new Label( shell, SWT.RIGHT ); + props.setLook( wlFilename ); + wlFilename.setText( BaseMessages.getString( PKG, "TransUnitTestDialog.Filename.Label" ) ); FormData fdlFilename = new FormData(); - fdlFilename.top = new FormAttachment(lastControl, margin); - fdlFilename.left = new FormAttachment(0, 0); - fdlFilename.right = new FormAttachment(middle, -margin); - wlFilename.setLayoutData(fdlFilename); - wFilename = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); - props.setLook(wFilename); + fdlFilename.top = new FormAttachment( lastControl, margin ); + fdlFilename.left = new FormAttachment( 0, 0 ); + fdlFilename.right = new FormAttachment( middle, -margin ); + wlFilename.setLayoutData( fdlFilename ); + wFilename = new TextVar( transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER ); + props.setLook( wFilename ); FormData fdFilename = new FormData(); - fdFilename.top = new FormAttachment(lastControl, margin); - fdFilename.left = new FormAttachment(middle, 0); - fdFilename.right = new FormAttachment(100, 0); - wFilename.setLayoutData(fdFilename); + fdFilename.top = new FormAttachment( lastControl, margin ); + fdFilename.left = new FormAttachment( middle, 0 ); + fdFilename.right = new FormAttachment( 100, 0 ); + wFilename.setLayoutData( fdFilename ); lastControl = wFilename; + // The base path for relative test path resolution + // + Label wlBasePath = new Label( shell, SWT.RIGHT ); + props.setLook( wlBasePath ); + wlBasePath.setText( BaseMessages.getString( PKG, "TransUnitTestDialog.BasePath.Label" ) ); + FormData fdlBasePath = new FormData(); + fdlBasePath.top = new FormAttachment( lastControl, margin ); + fdlBasePath.left = new FormAttachment( 0, 0 ); + fdlBasePath.right = new FormAttachment( middle, -margin ); + wlBasePath.setLayoutData( fdlBasePath ); + wBasePath = new TextVar( transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER ); + props.setLook( wBasePath ); + FormData fdBasePath = new FormData(); + fdBasePath.top = new FormAttachment( lastControl, margin ); + fdBasePath.left = new FormAttachment( middle, 0 ); + fdBasePath.right = new FormAttachment( 100, 0 ); + wBasePath.setLayoutData( fdBasePath ); + lastControl = wBasePath; // The list of database replacements in the unit test transformation // - Label wlFieldMapping = new Label(shell, SWT.NONE); - wlFieldMapping.setText(BaseMessages.getString(PKG, "TransUnitTestDialog.DbReplacements.Label")); - props.setLook(wlFieldMapping); + Label wlFieldMapping = new Label( shell, SWT.NONE ); + wlFieldMapping.setText( BaseMessages.getString( PKG, "TransUnitTestDialog.DbReplacements.Label" ) ); + props.setLook( wlFieldMapping ); FormData fdlUpIns = new FormData(); - fdlUpIns.left = new FormAttachment(0, 0); - fdlUpIns.top = new FormAttachment(lastControl, margin); - wlFieldMapping.setLayoutData(fdlUpIns); + fdlUpIns.left = new FormAttachment( 0, 0 ); + fdlUpIns.top = new FormAttachment( lastControl, margin ); + wlFieldMapping.setLayoutData( fdlUpIns ); lastControl = wlFieldMapping; // Buttons at the bottom... // - wOK = new Button(shell, SWT.PUSH); - wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); + wOK = new Button( shell, SWT.PUSH ); + wOK.setText( BaseMessages.getString( PKG, "System.Button.OK" ) ); - wCancel = new Button(shell, SWT.PUSH); - wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + wCancel = new Button( shell, SWT.PUSH ); + wCancel.setText( BaseMessages.getString( PKG, "System.Button.Cancel" ) ); Button[] buttons = new Button[] { wOK, wCancel }; - BaseStepDialog.positionBottomButtons(shell, buttons, margin, null); + BaseStepDialog.positionBottomButtons( shell, buttons, margin, null ); // the database replacements // String[] dbNames = transMeta.getDatabaseNames(); - Arrays.sort(dbNames); + Arrays.sort( dbNames ); ColumnInfo[] columns = new ColumnInfo[] { - new ColumnInfo(BaseMessages.getString(PKG, "TransUnitTestDialog.DbReplacement.ColumnInfo.OriginalDb"), - ColumnInfo.COLUMN_TYPE_CCOMBO, dbNames, false), - new ColumnInfo(BaseMessages.getString(PKG, "TransUnitTestDialog.DbReplacement.ColumnInfo.ReplacementDb"), - ColumnInfo.COLUMN_TYPE_CCOMBO, dbNames, false), }; - columns[0].setUsingVariables(true); - columns[1].setUsingVariables(true); - - wDbReplacements = new TableView(new Variables(), shell, - SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, columns, - transUnitTest.getTweaks().size(), null, props); + new ColumnInfo( BaseMessages.getString( PKG, "TransUnitTestDialog.DbReplacement.ColumnInfo.OriginalDb" ), + ColumnInfo.COLUMN_TYPE_CCOMBO, dbNames, false ), + new ColumnInfo( BaseMessages.getString( PKG, "TransUnitTestDialog.DbReplacement.ColumnInfo.ReplacementDb" ), + ColumnInfo.COLUMN_TYPE_CCOMBO, dbNames, false ), }; + columns[ 0 ].setUsingVariables( true ); + columns[ 1 ].setUsingVariables( true ); + + wDbReplacements = new TableView( new Variables(), shell, + SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, columns, + transUnitTest.getTweaks().size(), null, props ); FormData fdDbReplacements = new FormData(); - fdDbReplacements.left = new FormAttachment(0, 0); - fdDbReplacements.top = new FormAttachment(lastControl, margin); - fdDbReplacements.right = new FormAttachment(100, 0); - fdDbReplacements.bottom = new FormAttachment(lastControl, 150); - wDbReplacements.setLayoutData(fdDbReplacements); + fdDbReplacements.left = new FormAttachment( 0, 0 ); + fdDbReplacements.top = new FormAttachment( lastControl, margin ); + fdDbReplacements.right = new FormAttachment( 100, 0 ); + fdDbReplacements.bottom = new FormAttachment( lastControl, 250 ); + wDbReplacements.setLayoutData( fdDbReplacements ); lastControl = wDbReplacements; - Label wlVariableValues = new Label(shell, SWT.NONE); - wlVariableValues.setText(BaseMessages.getString(PKG, "TransUnitTestDialog.VariableValues.Label")); - props.setLook(wlVariableValues); + Label wlVariableValues = new Label( shell, SWT.NONE ); + wlVariableValues.setText( BaseMessages.getString( PKG, "TransUnitTestDialog.VariableValues.Label" ) ); + props.setLook( wlVariableValues ); FormData fdlVariableValues = new FormData(); - fdlVariableValues.left = new FormAttachment(0, 0); - fdlVariableValues.top = new FormAttachment(lastControl, margin); - wlVariableValues.setLayoutData(fdlVariableValues); + fdlVariableValues.left = new FormAttachment( 0, 0 ); + fdlVariableValues.top = new FormAttachment( lastControl, margin ); + wlVariableValues.setLayoutData( fdlVariableValues ); lastControl = wlVariableValues; ColumnInfo[] varValColumns = new ColumnInfo[] { - new ColumnInfo(BaseMessages.getString(PKG, "TransUnitTestDialog.VariableValues.ColumnInfo.VariableName"), ColumnInfo.COLUMN_TYPE_TEXT, false), - new ColumnInfo(BaseMessages.getString(PKG, "TransUnitTestDialog.VariableValues.ColumnInfo.VariableValue"), ColumnInfo.COLUMN_TYPE_TEXT, false), + new ColumnInfo( BaseMessages.getString( PKG, "TransUnitTestDialog.VariableValues.ColumnInfo.VariableName" ), ColumnInfo.COLUMN_TYPE_TEXT, false ), + new ColumnInfo( BaseMessages.getString( PKG, "TransUnitTestDialog.VariableValues.ColumnInfo.VariableValue" ), ColumnInfo.COLUMN_TYPE_TEXT, false ), }; - varValColumns[0].setUsingVariables(true); - varValColumns[1].setUsingVariables(true); + varValColumns[ 0 ].setUsingVariables( true ); + varValColumns[ 1 ].setUsingVariables( true ); - wVariableValues = new TableView(new Variables(), shell, + wVariableValues = new TableView( new Variables(), shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, varValColumns, - transUnitTest.getVariableValues().size(), null, props); + transUnitTest.getVariableValues().size(), null, props ); FormData fdVariableValues = new FormData(); - fdVariableValues.left = new FormAttachment(0, 0); - fdVariableValues.top = new FormAttachment(lastControl, margin); - fdVariableValues.right = new FormAttachment(100, 0); - fdVariableValues.bottom = new FormAttachment(wOK, -2 * margin); - wVariableValues.setLayoutData(fdVariableValues); + fdVariableValues.left = new FormAttachment( 0, 0 ); + fdVariableValues.top = new FormAttachment( lastControl, margin ); + fdVariableValues.right = new FormAttachment( 100, 0 ); + fdVariableValues.bottom = new FormAttachment( wOK, -2 * margin ); + wVariableValues.setLayoutData( fdVariableValues ); // Add listeners - wOK.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { + wOK.addListener( SWT.Selection, new Listener() { + public void handleEvent( Event e ) { ok(); } - }); - wCancel.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event e) { + } ); + wCancel.addListener( SWT.Selection, new Listener() { + public void handleEvent( Event e ) { cancel(); } - }); + } ); SelectionAdapter selAdapter = new SelectionAdapter() { - public void widgetDefaultSelected(SelectionEvent e) { + public void widgetDefaultSelected( SelectionEvent e ) { ok(); } }; - wName.addSelectionListener(selAdapter); - wDescription.addSelectionListener(selAdapter); - wTestType.addSelectionListener(selAdapter); - wFilename.addSelectionListener(selAdapter); + wName.addSelectionListener( selAdapter ); + wDescription.addSelectionListener( selAdapter ); + wTestType.addSelectionListener( selAdapter ); + wFilename.addSelectionListener( selAdapter ); + wBasePath.addSelectionListener( selAdapter ); // Detect X or ALT-F4 or something that kills this window... - shell.addShellListener(new ShellAdapter() { - public void shellClosed(ShellEvent e) { + shell.addShellListener( new ShellAdapter() { + public void shellClosed( ShellEvent e ) { cancel(); } - }); + } ); getData(); - BaseStepDialog.setSize(shell); + BaseStepDialog.setSize( shell ); shell.open(); Display display = parent.getDisplay(); - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { + while ( !shell.isDisposed() ) { + if ( !display.readAndDispatch() ) { display.sleep(); } } @@ -318,7 +336,7 @@ public void shellClosed(ShellEvent e) { } public void dispose() { - props.setScreen(new WindowProperty(shell)); + props.setScreen( new WindowProperty( shell ) ); shell.dispose(); } @@ -326,19 +344,20 @@ public void getData() { wName.setText( Const.NVL( transUnitTest.getName(), "" ) ); wDescription.setText( Const.NVL( transUnitTest.getDescription(), "" ) ); - wTestType.setText( Const.NVL( DataSetConst.getTestTypeDescription(transUnitTest.getType()), "") ); - wFilename.setText( Const.NVL( transUnitTest.getFilename(), "")); - + wTestType.setText( Const.NVL( DataSetConst.getTestTypeDescription( transUnitTest.getType() ), "" ) ); + wFilename.setText( Const.NVL( transUnitTest.getFilename(), "" ) ); + wBasePath.setText( Const.NVL( transUnitTest.getBasePath(), "" ) ); + for ( int i = 0; i < transUnitTest.getDatabaseReplacements().size(); i++ ) { TransUnitTestDatabaseReplacement dbReplacement = transUnitTest.getDatabaseReplacements().get( i ); - wDbReplacements.setText( Const.NVL( dbReplacement.getOriginalDatabaseName(), ""), 1, i ); + wDbReplacements.setText( Const.NVL( dbReplacement.getOriginalDatabaseName(), "" ), 1, i ); wDbReplacements.setText( Const.NVL( dbReplacement.getReplacementDatabaseName(), "" ), 2, i ); } - for (int i = 0 ; i < transUnitTest.getVariableValues().size() ; i++) { + for ( int i = 0; i < transUnitTest.getVariableValues().size(); i++ ) { VariableValue variableValue = transUnitTest.getVariableValues().get( i ); - wVariableValues.setText(Const.NVL(variableValue.getKey(), ""), 1, i); - wVariableValues.setText(Const.NVL(variableValue.getValue(), ""), 2, i); + wVariableValues.setText( Const.NVL( variableValue.getKey(), "" ), 1, i ); + wVariableValues.setText( Const.NVL( variableValue.getValue(), "" ), 2, i ); } wDbReplacements.removeEmptyRows(); @@ -353,44 +372,44 @@ private void cancel() { } /** - * @param test - * The trans unit test to load the dialog information into + * @param test The trans unit test to load the dialog information into */ - public void getInfo(TransUnitTest test) { + public void getInfo( TransUnitTest test ) { + + test.setName( wName.getText() ); + test.setDescription( wDescription.getText() ); + test.setType( DataSetConst.getTestTypeForDescription( wTestType.getText() ) ); + test.setFilename( wFilename.getText() ); + test.setBasePath( wBasePath.getText() ); - test.setName(wName.getText()); - test.setDescription(wDescription.getText()); - test.setType(DataSetConst.getTestTypeForDescription(wTestType.getText())); - test.setFilename(wFilename.getText()); - test.getDatabaseReplacements().clear(); int nrFields = wDbReplacements.nrNonEmpty(); - for (int i=0;i steps = transMeta.getSteps(); for (StepMeta step : steps) { StepMeta stepMeta = copyTransMeta.findStep(step.getName()); - String inputSetName = stepMeta.getAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_DATASET_INPUT ); - String goldenSetName = stepMeta.getAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_DATASET_GOLDEN ); - String tweakName = stepMeta.getAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_TWEAK ); - + TransUnitTestSetLocation inputLocation = unitTest.findInputLocation( stepMeta.getName() ); + TransUnitTestSetLocation goldenLocation = unitTest.findGoldenLocation( stepMeta.getName() ); + TransUnitTestTweak stepTweak = unitTest.findTweak( stepMeta.getName() ); + // See if there's a unit test if the step isn't flagged... // - if ( !StringUtil.isEmpty( inputSetName ) ) { - handleInputDataSet(log, inputSetName, unitTest, transMeta, stepMeta, factoriesHierarchy); + if ( inputLocation!=null ) { + handleInputDataSet(log, inputLocation, unitTest, transMeta, stepMeta, factoriesHierarchy); } // Capture golden data in a dummy step instead of the regular one? // - if ( !StringUtil.isEmpty( goldenSetName )) { - handleGoldenDataSet(log, goldenSetName, stepMeta); + if ( goldenLocation!=null) { + handleGoldenDataSet(log, goldenLocation, stepMeta); } - if ( !StringUtil.isEmpty(tweakName)) { - TransTweak tweak; - try { - tweak = TransTweak.valueOf(tweakName); - } catch(Exception e) { - throw new KettleException("Unrecognized tweak '"+tweakName+"-", e); - } - switch(tweak) { + if ( stepTweak!=null && stepTweak.getTweak()!=null) { + switch(stepTweak.getTweak()) { case NONE : break; case REMOVE_STEP: handleTweakRemoveStep(log, copyTransMeta, stepMeta); break; case BYPASS_STEP: handleTweakBypassStep(log, stepMeta); break; default: break; } } - } @@ -272,7 +266,7 @@ private void handleTweakRemoveStep(LogChannelInterface log, TransMeta copyTransM } } - private void handleGoldenDataSet(LogChannelInterface log, String goldenSetName, StepMeta stepMeta) { + private void handleGoldenDataSet( LogChannelInterface log, TransUnitTestSetLocation goldenSetName, StepMeta stepMeta) { if (log.isDetailed()) { log.logDetailed("Replacing step '"+stepMeta.getName()+"' with an Dummy for golden dataset '"+goldenSetName+"'"); @@ -287,11 +281,9 @@ private void replaceStepWithDummy(LogChannelInterface log, StepMeta stepMeta) { stepMeta.setStepID( PluginRegistry.getInstance().getPluginId( StepPluginType.class, dummyTransMeta) ); } - private void handleInputDataSet(LogChannelInterface log, String inputSetName, TransUnitTest unitTest, TransMeta transMeta, StepMeta stepMeta, FactoriesHierarchy factoriesHierarchy) throws KettleException { - TransUnitTestSetLocation inputLocation = unitTest.findInputLocation( stepMeta.getName() ); - if (inputLocation!=null) { - inputSetName = inputLocation.getDataSetName(); - } + private void handleInputDataSet( LogChannelInterface log, TransUnitTestSetLocation inputLocation, TransUnitTest unitTest, TransMeta transMeta, StepMeta stepMeta, FactoriesHierarchy factoriesHierarchy) throws KettleException { + + String inputSetName = inputLocation.getDataSetName(); if (log.isDetailed()) { log.logDetailed("Replacing step '"+stepMeta.getName()+"' with an Injector for dataset '"+inputSetName+"'"); diff --git a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawGoldenDataSetOnStepExtensionPoint.java b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawGoldenDataSetOnStepExtensionPoint.java index 5493473..1b1b311 100644 --- a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawGoldenDataSetOnStepExtensionPoint.java +++ b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawGoldenDataSetOnStepExtensionPoint.java @@ -32,7 +32,11 @@ import org.pentaho.di.core.gui.PrimitiveGCInterface.EFont; import org.pentaho.di.core.logging.LogChannelInterface; import org.pentaho.di.core.util.StringUtil; +import org.pentaho.di.dataset.TransUnitTest; +import org.pentaho.di.dataset.TransUnitTestSetLocation; +import org.pentaho.di.dataset.spoon.DataSetHelper; import org.pentaho.di.dataset.util.DataSetConst; +import org.pentaho.di.trans.TransMeta; import org.pentaho.di.trans.TransPainterExtension; import org.pentaho.di.trans.step.StepMeta; @@ -50,13 +54,21 @@ public void callExtensionPoint( LogChannelInterface log, Object object ) throws TransPainterExtension ext = (TransPainterExtension) object; StepMeta stepMeta = ext.stepMeta; - String dataSetName = stepMeta.getAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_DATASET_GOLDEN ); - if ( !StringUtil.isEmpty( dataSetName ) ) { - drawGoldenSetMarker( ext, stepMeta, dataSetName ); + TransMeta transMeta = ext.transMeta; + TransUnitTest unitTest = DataSetHelper.getInstance().getActiveTests().get( transMeta ); + if (unitTest!=null) { + drawGoldenSetMarker( ext, stepMeta, unitTest ); } } - protected void drawGoldenSetMarker( TransPainterExtension ext, StepMeta stepMeta, String testName ) { + protected void drawGoldenSetMarker( TransPainterExtension ext, StepMeta stepMeta, TransUnitTest unitTest ) { + + TransUnitTestSetLocation location = unitTest.findGoldenLocation( stepMeta.getName() ); + if (location==null) { + return; + } + String dataSetName = Const.NVL(location.getDataSetName(), ""); + // Now we're here, draw a marker and indicate the name of the unit test // GCInterface gc = ext.gc; @@ -68,7 +80,7 @@ protected void drawGoldenSetMarker( TransPainterExtension ext, StepMeta stepMeta gc.setForeground( EColor.CRYSTAL ); gc.setBackground( EColor.LIGHTGRAY ); gc.setFont( EFont.GRAPH ); - Point textExtent = gc.textExtent( testName ); + Point textExtent = gc.textExtent( dataSetName ); textExtent.x += 6; // add a tiny bit of a margin textExtent.y += 6; @@ -87,7 +99,7 @@ protected void drawGoldenSetMarker( TransPainterExtension ext, StepMeta stepMeta gc.fillPolygon( arrow ); gc.drawPolygon( arrow ); - gc.drawText( testName, point.x + arrowSize + 3, point.y + 3 ); + gc.drawText( dataSetName, point.x + arrowSize + 3, point.y + 3 ); } } diff --git a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawInputDataSetOnStepExtensionPoint.java b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawInputDataSetOnStepExtensionPoint.java index b1c5897..a6a641e 100644 --- a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawInputDataSetOnStepExtensionPoint.java +++ b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawInputDataSetOnStepExtensionPoint.java @@ -32,7 +32,11 @@ import org.pentaho.di.core.gui.PrimitiveGCInterface.EFont; import org.pentaho.di.core.logging.LogChannelInterface; import org.pentaho.di.core.util.StringUtil; +import org.pentaho.di.dataset.TransUnitTest; +import org.pentaho.di.dataset.TransUnitTestSetLocation; +import org.pentaho.di.dataset.spoon.DataSetHelper; import org.pentaho.di.dataset.util.DataSetConst; +import org.pentaho.di.trans.TransMeta; import org.pentaho.di.trans.TransPainterExtension; import org.pentaho.di.trans.step.StepMeta; @@ -50,15 +54,22 @@ public void callExtensionPoint( LogChannelInterface log, Object object ) throws TransPainterExtension ext = (TransPainterExtension) object; StepMeta stepMeta = ext.stepMeta; - String dataSetName = stepMeta.getAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_DATASET_INPUT ); - if ( !StringUtil.isEmpty( dataSetName ) ) { - drawInputDataSetMarker( ext, stepMeta, dataSetName ); + TransMeta transMeta = ext.transMeta; + TransUnitTest unitTest = DataSetHelper.getInstance().getActiveTests().get( transMeta ); + if (unitTest!=null) { + drawInputDataSetMarker( ext, stepMeta, unitTest ); } } - private void drawInputDataSetMarker( TransPainterExtension ext, StepMeta stepMeta, String dataSetName ) { + private void drawInputDataSetMarker( TransPainterExtension ext, StepMeta stepMeta, TransUnitTest unitTest ) { // Now we're here, draw a marker and indicate the name of the data set name // + TransUnitTestSetLocation location = unitTest.findInputLocation( stepMeta.getName() ); + if (location==null) { + return; + } + String dataSetName = Const.NVL(location.getDataSetName(), ""); + GCInterface gc = ext.gc; int iconsize = ext.iconsize; int x = ext.x1; diff --git a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawTweakOnStepExtensionPoint.java b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawTweakOnStepExtensionPoint.java index 2c0eb81..8157e2d 100644 --- a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawTweakOnStepExtensionPoint.java +++ b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawTweakOnStepExtensionPoint.java @@ -30,6 +30,9 @@ import org.pentaho.di.core.gui.PrimitiveGCInterface.EFont; import org.pentaho.di.core.logging.LogChannelInterface; import org.pentaho.di.dataset.TransTweak; +import org.pentaho.di.dataset.TransUnitTest; +import org.pentaho.di.dataset.TransUnitTestTweak; +import org.pentaho.di.dataset.spoon.DataSetHelper; import org.pentaho.di.dataset.util.DataSetConst; import org.pentaho.di.trans.TransPainterExtension; import org.pentaho.di.trans.step.StepMeta; @@ -48,10 +51,17 @@ public void callExtensionPoint(LogChannelInterface log, Object object) throws Ke TransPainterExtension ext = (TransPainterExtension) object; StepMeta stepMeta = ext.stepMeta; - String tweakDesc = stepMeta.getAttribute(DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_TWEAK); + TransUnitTest unitTest = DataSetHelper.getCurrentUnitTest( ext.transMeta ); + if (unitTest==null) { + return; + } + TransUnitTestTweak tweak = unitTest.findTweak( stepMeta.getName() ); + if (tweak==null || tweak.getTweak()==null) { + return; + } + try { - TransTweak tweak = TransTweak.valueOf(tweakDesc); - switch(tweak) { + switch(tweak.getTweak()) { case NONE: break; case REMOVE_STEP: drawRemovedTweak(ext, stepMeta); break; case BYPASS_STEP: drawBypassedTweak(ext, stepMeta); break; diff --git a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawUnitTestOnTransExtentionPoint.java b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawUnitTestOnTransExtensionPoint.java similarity index 88% rename from src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawUnitTestOnTransExtentionPoint.java rename to src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawUnitTestOnTransExtensionPoint.java index 0e00085..ac64169 100644 --- a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawUnitTestOnTransExtentionPoint.java +++ b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/DrawUnitTestOnTransExtensionPoint.java @@ -32,15 +32,17 @@ import org.pentaho.di.core.gui.Point; import org.pentaho.di.core.gui.PrimitiveGCInterface.EColor; import org.pentaho.di.core.logging.LogChannelInterface; +import org.pentaho.di.dataset.TransUnitTest; +import org.pentaho.di.dataset.spoon.DataSetHelper; import org.pentaho.di.dataset.util.DataSetConst; import org.pentaho.di.trans.TransMeta; import org.pentaho.di.trans.TransPainter; @ExtensionPoint( - id = "DrawUnitTestOnTransExtentionPoint", + id = "DrawUnitTestOnTransExtensionPoint", description = "Indicates graphically which unit test is currently selected.", extensionPointId = "TransPainterEnd" ) -public class DrawUnitTestOnTransExtentionPoint implements ExtensionPointInterface { +public class DrawUnitTestOnTransExtensionPoint implements ExtensionPointInterface { @Override public void callExtensionPoint( LogChannelInterface log, Object object ) throws KettleException { @@ -50,13 +52,14 @@ public void callExtensionPoint( LogChannelInterface log, Object object ) throws TransPainter painter = (TransPainter) object; TransMeta transMeta = painter.getTransMeta(); - String testName = transMeta.getAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_TRANS_SELECTED_UNIT_TEST_NAME); - // System.out.println("Drawing unit test usage/editing : '"+testName+"'"); - drawUnitTestName( painter, transMeta, testName ); + TransUnitTest unitTest = DataSetHelper.getCurrentUnitTest( transMeta ); + drawUnitTestName( painter, transMeta, unitTest ); } - private void drawUnitTestName( TransPainter painter, TransMeta transMeta, String unitTestName ) { - + private void drawUnitTestName( TransPainter painter, TransMeta transMeta, TransUnitTest test ) { + + String unitTestName = test!=null ? test.getName() : null; + GCInterface gc = painter.getGc(); EColor color = EColor.CRYSTAL; @@ -120,8 +123,8 @@ private void drawUnitTestName( TransPainter painter, TransMeta transMeta, String // Let the world know where the flask is... // - painter.getAreaOwners().add(new AreaOwner( AreaType.CUSTOM, x, y, w, h, painter.getOffset(), - DataSetConst.AREA_DRAWN_UNIT_ICON, unitTestName)); + painter.getAreaOwners().add(new AreaOwner( AreaType.CUSTOM, x, y, w, h, painter.getOffset(), + DataSetConst.AREA_DRAWN_UNIT_TEST_ICON, "Flask")); // Write the name of the unit test to the right... // @@ -134,7 +137,7 @@ private void drawUnitTestName( TransPainter painter, TransMeta transMeta, String int ty = y+h/2-te.y/2; gc.drawText(unitTestName, tx, ty, true); painter.getAreaOwners().add(new AreaOwner( AreaType.CUSTOM, tx, ty, te.x, te.y, painter.getOffset(), - DataSetConst.AREA_DRAWN_UNIT_ICON, unitTestName)); + DataSetConst.AREA_DRAWN_UNIT_TEST_NAME, unitTestName)); } } diff --git a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/InjectDataSetIntoTransExtensionPoint.java b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/InjectDataSetIntoTransExtensionPoint.java index 66300f1..8ba2c73 100644 --- a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/InjectDataSetIntoTransExtensionPoint.java +++ b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/InjectDataSetIntoTransExtensionPoint.java @@ -88,7 +88,7 @@ public void callExtensionPoint( LogChannelInterface log, Object object ) throws return; } - String unitTestName = transMeta.getAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_TRANS_SELECTED_UNIT_TEST_NAME ); + String unitTestName = trans.getVariable( DataSetConst.VAR_UNIT_TEST_NAME ); log.logBasic("Unit test name: "+unitTestName); try { @@ -119,26 +119,14 @@ public void callExtensionPoint( LogChannelInterface log, Object object ) throws // for ( final StepMeta stepMeta : trans.getTransMeta().getSteps() ) { String stepname = stepMeta.getName(); - String inputDataSetName = stepMeta.getAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_DATASET_INPUT ); - if (StringUtils.isNotEmpty(inputDataSetName)) { - // See if there's a unit test if the step isn't flagged... + TransUnitTestSetLocation inputLocation = unitTest.findInputLocation( stepname ); + if (inputLocation!=null && StringUtils.isNotEmpty(inputLocation.getDataSetName())) { + String inputDataSetName = inputLocation.getDataSetName(); + log.logDetailed("Data Set location found for step '"+stepname+"' and data set "+inputDataSetName); + + // We need to inject data from the data set with the specified name into the step // - TransUnitTestSetLocation inputLocation = null; - if ( unitTest!=null ) { - inputLocation = unitTest.findInputLocation( stepname ); - if (inputLocation!=null) { - log.logBasic("Data Set location found for step '"+stepname+"' and data set "+inputDataSetName); - } else { - log.logBasic("NO data set location found for step '"+stepname+"' and data set "+inputDataSetName); - } - } - - if ( !StringUtil.isEmpty( inputDataSetName ) && inputLocation!=null ) { - - // We need to inject data from the data set with the specified name into the step - // - injectDataSetIntoStep( trans, transMeta, inputDataSetName, factoriesHierarchy.getSetFactory(), repository, metaStore, stepMeta, inputLocation ); - } + injectDataSetIntoStep( trans, transMeta, inputDataSetName, factoriesHierarchy.getSetFactory(), repository, metaStore, stepMeta, inputLocation ); } // How about capturing rows for golden data review? diff --git a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/ShowUnitTestMenuExtensionPoint.java b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/ShowUnitTestMenuExtensionPoint.java index c9997a2..2f26e3f 100644 --- a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/ShowUnitTestMenuExtensionPoint.java +++ b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/ShowUnitTestMenuExtensionPoint.java @@ -28,18 +28,13 @@ import org.apache.commons.lang.StringUtils; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.swt.widgets.MessageBox; import org.pentaho.di.core.exception.KettleException; import org.pentaho.di.core.extension.ExtensionPoint; import org.pentaho.di.core.extension.ExtensionPointInterface; @@ -47,7 +42,6 @@ import org.pentaho.di.core.logging.LogChannelInterface; import org.pentaho.di.dataset.TransUnitTest; import org.pentaho.di.dataset.spoon.DataSetHelper; -import org.pentaho.di.dataset.spoon.dialog.TransUnitTestDialog; import org.pentaho.di.dataset.util.DataSetConst; import org.pentaho.di.i18n.BaseMessages; import org.pentaho.di.trans.TransMeta; @@ -74,6 +68,7 @@ public void callExtensionPoint(LogChannelInterface log, Object object) throws Ke TransGraphExtension tge = (TransGraphExtension) object; final TransMeta transMeta = tge.getTransGraph().getTransMeta(); + final TransUnitTest unitTest = DataSetHelper.getCurrentUnitTest( transMeta ); Spoon spoon = Spoon.getInstance(); MouseEvent e = tge.getEvent(); @@ -82,8 +77,8 @@ public void callExtensionPoint(LogChannelInterface log, Object object) throws Ke if ( areaOwner != null && areaOwner.getAreaType() != null ) { // Check if this is the flask... // - if (DataSetConst.AREA_DRAWN_UNIT_ICON.equals(areaOwner.getParent())) { - final String unitTestName = (String) areaOwner.getOwner(); + if (DataSetConst.AREA_DRAWN_UNIT_TEST_ICON.equals(areaOwner.getParent())) { + final String unitTestName = unitTest!=null ? unitTest.getName() : null; Canvas canvas = findCanvas(tge.getTransGraph()); if (canvas!=null) { diff --git a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/SpoonFlagUnitTestExtensionPoint.java b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/SpoonFlagUnitTestExtensionPoint.java index 6044a37..2b3fb35 100644 --- a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/SpoonFlagUnitTestExtensionPoint.java +++ b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/SpoonFlagUnitTestExtensionPoint.java @@ -28,6 +28,8 @@ import org.pentaho.di.core.extension.ExtensionPointInterface; import org.pentaho.di.core.logging.LogChannelInterface; import org.pentaho.di.core.util.StringUtil; +import org.pentaho.di.dataset.TransUnitTest; +import org.pentaho.di.dataset.spoon.DataSetHelper; import org.pentaho.di.dataset.util.DataSetConst; import org.pentaho.di.trans.TransMeta; @@ -44,14 +46,20 @@ public void callExtensionPoint( LogChannelInterface log, Object object ) throws } TransMeta transMeta = (TransMeta) object; - - String unitTestName = transMeta.getAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_TRANS_SELECTED_UNIT_TEST_NAME ); + + TransUnitTest unitTest = DataSetHelper.getCurrentUnitTest( transMeta ); + if (unitTest==null) { + return; + } + + String unitTestName = unitTest.getName(); if (!StringUtil.isEmpty( unitTestName )) { // We're running in Spoon and there's a unit test selected : test it // System.out.println( "==== Running unit test on this transformation ====" ); transMeta.setVariable( DataSetConst.VAR_RUN_UNIT_TEST, "Y" ); + transMeta.setVariable( DataSetConst.VAR_UNIT_TEST_NAME, unitTestName ); } } diff --git a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/SpoonTransAfterClose.java b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/SpoonTransAfterClose.java new file mode 100644 index 0000000..ff82f52 --- /dev/null +++ b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/SpoonTransAfterClose.java @@ -0,0 +1,23 @@ +package org.pentaho.di.dataset.spoon.xtpoint; + +import org.pentaho.di.core.exception.KettleException; +import org.pentaho.di.core.extension.ExtensionPoint; +import org.pentaho.di.core.extension.ExtensionPointInterface; +import org.pentaho.di.core.logging.LogChannelInterface; +import org.pentaho.di.dataset.spoon.DataSetHelper; +import org.pentaho.di.trans.TransMeta; + +@ExtensionPoint( + extensionPointId = "TransAfterClose", + id = "SpoonTransAfterClose", + description = "Cleanup the active unit test for the closed transformation" +) +public class SpoonTransAfterClose implements ExtensionPointInterface { + + @Override public void callExtensionPoint( LogChannelInterface log, Object object ) throws KettleException { + if (!(object instanceof TransMeta )) { + return; + } + DataSetHelper.getInstance().getActiveTests().remove( (TransMeta)object ); + } +} diff --git a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/ValidateTransUnitTestExtensionPoint.java b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/ValidateTransUnitTestExtensionPoint.java index dd864d4..4f64d4c 100644 --- a/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/ValidateTransUnitTestExtensionPoint.java +++ b/src/main/java/org/pentaho/di/dataset/spoon/xtpoint/ValidateTransUnitTestExtensionPoint.java @@ -64,13 +64,12 @@ public void callExtensionPoint( LogChannelInterface log, Object object ) throws final Trans trans = (Trans) object; final TransMeta transMeta = trans.getTransMeta(); boolean runUnitTest = "Y".equalsIgnoreCase( transMeta.getVariable( DataSetConst.VAR_RUN_UNIT_TEST ) ); - if ( !runUnitTest ) { return; } // We should always have a unit test name here... - String unitTestName = transMeta.getAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_TRANS_SELECTED_UNIT_TEST_NAME ); + String unitTestName = transMeta.getVariable( DataSetConst.VAR_UNIT_TEST_NAME ); if (StringUtil.isEmpty( unitTestName )) { return; } diff --git a/src/main/java/org/pentaho/di/dataset/steps/exectests/ExecuteTests.java b/src/main/java/org/pentaho/di/dataset/steps/exectests/ExecuteTests.java index 8b8e1cc..42e8378 100644 --- a/src/main/java/org/pentaho/di/dataset/steps/exectests/ExecuteTests.java +++ b/src/main/java/org/pentaho/di/dataset/steps/exectests/ExecuteTests.java @@ -26,11 +26,14 @@ import java.util.List; import org.apache.commons.lang.StringUtils; +import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemException; import org.pentaho.di.core.Const; import org.pentaho.di.core.Result; import org.pentaho.di.core.exception.KettleException; import org.pentaho.di.core.row.RowDataUtil; import org.pentaho.di.core.row.RowMeta; +import org.pentaho.di.core.vfs.KettleVFS; import org.pentaho.di.dataset.TransUnitTest; import org.pentaho.di.dataset.UnitTestResult; import org.pentaho.di.dataset.spoon.DataSetHelper; @@ -183,8 +186,33 @@ public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws K private TransMeta loadTestTransformation(TransUnitTest test) throws KettleException { TransMeta unitTestTransMeta = null; + // Environment substitution is not yet supported in the UI + // String filename = getTrans().environmentSubstitute(test.getTransFilename()); if (StringUtils.isNotEmpty(filename)) { + + // Do we need a relative path resolution? + // + String basePathString = environmentSubstitute(test.getBasePath()); + if (StringUtils.isEmpty( basePathString )) { + // Check global variable + // + basePathString = getVariable( DataSetConst.VARIABLE_UNIT_TESTS_BASE_PATH ); + } + + if (StringUtils.isNotEmpty( basePathString )) { + + FileObject basePath = KettleVFS.getFileObject( basePathString ); + + // Try to resolve the relative path stored in the test... + // + try { + filename = basePath.resolveFile( filename ).toString(); + } catch(Exception e) { + throw new KettleException( "Unable to resolve relative path of "+filename+" against base path "+basePathString, e ); + } + } + unitTestTransMeta = new TransMeta(filename, repository, true, getTrans()); } else { if (StringUtils.isNotEmpty(test.getTransObjectId())) { diff --git a/src/main/java/org/pentaho/di/dataset/util/DataSetConst.java b/src/main/java/org/pentaho/di/dataset/util/DataSetConst.java index f4f1158..3e67085 100755 --- a/src/main/java/org/pentaho/di/dataset/util/DataSetConst.java +++ b/src/main/java/org/pentaho/di/dataset/util/DataSetConst.java @@ -73,21 +73,21 @@ public class DataSetConst { public static final String GROUP_LIST_KEY = "DataSetGroups"; public static final String SET_LIST_KEY = "DataSets"; - public static final String ATTR_GROUP_DATASET = "DataSet"; - public static final String ATTR_STEP_DATASET_INPUT = "InputDataSet"; - public static final String ATTR_STEP_DATASET_GOLDEN = "GoldenDataSet"; - public static final String ATTR_STEP_TWEAK= "UnitTestStepTweak"; - public static final String ATTR_STEP_TARGET_DATASET = "TargetDataSet"; - - public static final String VAR_RUN_UNIT_TEST = "__UnitTest__"; - public static final String VAR_WRITE_TO_DATASET = "__WriteDataSet__"; - public static final String VAR_DO_NOT_SHOW_UNIT_TEST_ERRORS = "__DontShowUnitTestErrors__"; - public static final String ATTR_TRANS_SELECTED_UNIT_TEST_NAME = "SelectedUnitTest"; - - public static final String AREA_DRAWN_UNIT_ICON = "DrawnUnitTestIcon"; + // Variables during execution to indicate the selected test to run + // + public static final String VAR_RUN_UNIT_TEST = "__UnitTest_Run__"; + public static final String VAR_UNIT_TEST_NAME = "__UnitTest_Name__"; + public static final String VAR_WRITE_TO_DATASET = "__UnitTest_WriteDataSet__"; + public static final String VAR_DO_NOT_SHOW_UNIT_TEST_ERRORS = "__UnitTest_DontShowUnitTestErrors__"; + + public static final String AREA_DRAWN_UNIT_TEST_ICON = "Drawn_UnitTestIcon"; + public static final String AREA_DRAWN_UNIT_TEST_NAME = "Drawn_UnitTestName"; + public static final String ROW_COLLECTION_MAP = "RowCollectionMap"; public static final String UNIT_TEST_RESULTS = "UnitTestResults"; + public static final String VARIABLE_UNIT_TESTS_BASE_PATH = "UNIT_TESTS_BASE_PATH"; + private static final String[] tweakDesc = new String[] { BaseMessages.getString(PKG, "DataSetConst.Tweak.NONE.Desc"), BaseMessages.getString(PKG, "DataSetConst.Tweak.BYPASS_STEP.Desc"), @@ -193,75 +193,7 @@ public static final DataSet writeDataSet(String name, String description, DataSe return dataSet; } - - public static final void clearStepDataSetIndicators(TransMeta transMeta) { - for (StepMeta stepMeta : transMeta.getSteps()) { - Map attributes = stepMeta.getAttributesMap().remove( DataSetConst.ATTR_GROUP_DATASET ); - } - transMeta.setChanged(); - } - - - public static final void loadStepDataSetIndicators(TransMeta transMeta, TransUnitTest test) throws KettleException { - - // First clear 'm all - // - clearStepDataSetIndicators( transMeta ); - // Set links to the input data sets (for the extension point) - // - List inputNotFound = new ArrayList<>(); - for (TransUnitTestSetLocation location : test.getInputDataSets()) { - StepMeta stepMeta = transMeta.findStep( location.getStepname() ); - if (stepMeta!=null) { - stepMeta.setAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_DATASET_INPUT, location.getDataSetName()); - } else { - inputNotFound.add(location.getStepname()); - } - } - // Remove the input locations that were not found... - // It's fine to have metadata from removed steps in the test but not during execution - // - for (String stepName : inputNotFound) { - TransUnitTestSetLocation location = test.findInputLocation( stepName ); - if (location!=null) { - test.getInputDataSets().remove(location); - } - } - - - // Set links to the golden data sets (for the extension point) - // - List goldenNotFound = new ArrayList<>(); - for (TransUnitTestSetLocation location : test.getGoldenDataSets()) { - StepMeta stepMeta = transMeta.findStep( location.getStepname() ); - if (stepMeta!=null) { - stepMeta.setAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_DATASET_GOLDEN, location.getDataSetName()); - } else { - goldenNotFound.add(location.getStepname()); - } - } - // Remove the golden locations that were not found... - // It's fine to have metadata from removed steps in the test but not during execution - // - for (String stepName : goldenNotFound) { - TransUnitTestSetLocation location = test.findGoldenLocation( stepName ); - if (location!=null) { - test.getGoldenDataSets().remove(location); - } - } - - // Load the tweak indicators? - // - List tweaks = test.getTweaks(); - for (TransUnitTestTweak tweak : tweaks) { - StepMeta stepMeta = transMeta.findStep(tweak.getStepName()); - if (stepMeta!=null && tweak.getTweak()!=null) { - stepMeta.setAttribute(DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_TWEAK, tweak.getTweak().name()); - } - } - } - /** * Validate the execution results of a transformation against the golden data sets of a unit test. * @param trans The transformation after execution diff --git a/src/test/java/org/pentaho/di/dataset/TransUnitTestExecutionTest.java b/src/test/java/org/pentaho/di/dataset/TransUnitTestExecutionTest.java index 8063c34..da97914 100644 --- a/src/test/java/org/pentaho/di/dataset/TransUnitTestExecutionTest.java +++ b/src/test/java/org/pentaho/di/dataset/TransUnitTestExecutionTest.java @@ -222,14 +222,7 @@ public void testExecution() throws Exception { // Enable unit test validation // transMeta.setVariable( DataSetConst.VAR_RUN_UNIT_TEST, "Y" ); - - // Pass indicators for the transformation (might be existing stuff the user is working on) - // - DataSetConst.loadStepDataSetIndicators( transMeta, unitTest ); - - // This will cause the transformation to be a unit test... - // - transMeta.setAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_TRANS_SELECTED_UNIT_TEST_NAME, unitTest.getName() ); + transMeta.setVariable( DataSetConst.VAR_UNIT_TEST_NAME, unitTest.getName() ); // pass our metastore reference // @@ -238,7 +231,6 @@ public void testExecution() throws Exception { // Create an in-memory data-set group and data sets to test with... // StepMeta stepMeta = transMeta.findStep( INPUT_STEP_NAME ); - stepMeta.setAttribute( DataSetConst.ATTR_GROUP_DATASET, DataSetConst.ATTR_STEP_DATASET_INPUT, inputDataSet.getName() ); Trans trans = new Trans( transMeta ); trans.setPreview( true ); // data set only works in preview right now