Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,11 @@ private void tweakUnitTestTransform(
TransformMeta transformMeta = context.getTransformMeta();
IVariables variables = context.getPipelineGraph().getVariables();

if (transformMeta == null || pipelineMeta == null) {
if (pipelineMeta == null) {
return;
}
List<TransformMeta> targets = resolveTweakTargetTransforms(pipelineMeta, transformMeta);
if (targets.isEmpty()) {
return;
}
if (checkTestPresent(hopGui, context)) {
Expand All @@ -1419,12 +1423,10 @@ private void tweakUnitTestTransform(
if (unitTest == null) {
return;
}
PipelineUnitTestTweak unitTestTweak = unitTest.findTweak(transformMeta.getName());
if (unitTestTweak != null) {
unitTest.getTweaks().remove(unitTestTweak);
}
if (enable) {
unitTest.getTweaks().add(new PipelineUnitTestTweak(tweak, transformMeta.getName()));

// Apply to all selected transforms (issue #2742), not only the one right-clicked
for (TransformMeta target : targets) {
applyTweakToTransform(unitTest, target.getName(), tweak, enable);
}

saveUnitTest(variables, metadataProvider, unitTest, pipelineMeta);
Expand All @@ -1439,12 +1441,56 @@ private void tweakUnitTestTransform(
BaseMessages.getString(
PKG,
"TestingGuiPlugin.TweakUnitTestTransform.Error.Message",
transformMeta.getName(),
targets.get(0).getName(),
tweak.name()),
exception);
}
}

/**
* Resolve which transforms a unit-test tweak action should affect. Prefer the current selection;
* if nothing is selected, fall back to the transform that was right-clicked.
*
* @param pipelineMeta the pipeline containing the selection
* @param clickedTransform the transform under the context menu, may be null
* @return the transforms to tweak (never null)
*/
static List<TransformMeta> resolveTweakTargetTransforms(
PipelineMeta pipelineMeta, TransformMeta clickedTransform) {
List<TransformMeta> selected = pipelineMeta.getSelectedTransforms();
if (selected != null && !selected.isEmpty()) {
return selected;
}
if (clickedTransform == null) {
return Collections.emptyList();
}
return Collections.singletonList(clickedTransform);
}

/**
* Apply or clear a unit-test tweak on a single transform. When enabling, any existing tweak on
* the transform is replaced. When disabling, only a tweak of the requested type is removed so a
* multi-select action does not wipe unrelated tweaks.
*
* @param unitTest the active unit test
* @param transformName name of the transform to tweak
* @param tweak the tweak type
* @param enable true to set the tweak, false to clear a matching tweak
*/
static void applyTweakToTransform(
PipelineUnitTest unitTest, String transformName, PipelineTweak tweak, boolean enable) {
PipelineUnitTestTweak existing = unitTest.findTweak(transformName);
if (existing != null) {
if (!enable && existing.getTweak() != tweak) {
return;
}
unitTest.getTweaks().remove(existing);
}
if (enable) {
unitTest.getTweaks().add(new PipelineUnitTestTweak(tweak, transformName));
}
}

/** List all unit tests which are defined And allow the user to select one */
public RowMetaAndData selectUnitTestFromAllTests() {
HopGui hopGui = HopGui.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.hop.pipeline.PipelineMeta;
import org.apache.hop.pipeline.engine.IPipelineEngine;
import org.apache.hop.testing.DataSet;
import org.apache.hop.testing.PipelineTweak;
import org.apache.hop.testing.PipelineUnitTest;
import org.apache.hop.testing.PipelineUnitTestFieldMapping;
import org.apache.hop.testing.PipelineUnitTestSetLocation;
Expand Down Expand Up @@ -522,4 +523,45 @@ public static TestType getTestTypeForDescription(String testTypeDescription) {
public static String[] getTestTypeDescriptions() {
return testTypeDesc;
}

/**
* Get the localized description for a pipeline unit-test tweak.
*
* @param tweak the tweak type
* @return description for dialogs/editors
*/
public static String getTweakDescription(PipelineTweak tweak) {
int index = 0; // NONE
if (tweak != null) {
PipelineTweak[] tweaks = PipelineTweak.values();
for (int i = 0; i < tweaks.length; i++) {
if (tweaks[i] == tweak) {
index = i;
break;
}
}
}
return tweakDesc[index];
}

/**
* Get the PipelineTweak for a description (from the dialog).
*
* @param tweakDescription the description to look for
* @return the tweak type or NONE if nothing matched
*/
public static PipelineTweak getTweakForDescription(String tweakDescription) {
if (StringUtils.isEmpty(tweakDescription)) {
return PipelineTweak.NONE;
}
int index = Const.indexOfString(tweakDescription, tweakDesc);
if (index < 0) {
return PipelineTweak.NONE;
}
return PipelineTweak.values()[index];
}

public static String[] getTweakDescriptions() {
return tweakDesc;
}
}
Loading
Loading