Skip to content

Commit ff74172

Browse files
authored
Fix for issue #7355 (#7357)
1 parent d4343a7 commit ff74172

8 files changed

Lines changed: 320 additions & 13 deletions

File tree

plugins/misc/testing/src/main/java/org/apache/hop/testing/DataSet.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ public IRowMeta getMappedDataSetFieldsRowMeta(PipelineUnitTestSetLocation locati
141141
IRowMeta rowMeta = new RowMeta();
142142
for (PipelineUnitTestFieldMapping fieldMapping : location.getFieldMappings()) {
143143
IValueMeta valueMeta = setRowMeta.searchValueMeta(fieldMapping.getDataSetFieldName());
144+
if (valueMeta == null) {
145+
valueMeta =
146+
new org.apache.hop.core.row.value.ValueMetaString(fieldMapping.getDataSetFieldName());
147+
}
144148
rowMeta.addValueMeta(valueMeta);
145149
}
146150
return rowMeta;

plugins/misc/testing/src/main/java/org/apache/hop/testing/DataSetCsvUtil.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,14 @@ public static final List<Object[]> getAllRows(
170170
for (int i = 0; i < dataSetFieldIndexes.length; i++) {
171171
int index = dataSetFieldIndexes[i];
172172

173-
IValueMeta valueMeta = setRowMeta.getValueMeta(index);
174-
constantValueMeta.setConversionMetadata(valueMeta);
175-
String value = csvRecord.get(index);
176-
row[i] = valueMeta.convertData(constantValueMeta, value);
173+
if (index >= 0 && index < setRowMeta.size() && index < csvRecord.size()) {
174+
IValueMeta valueMeta = setRowMeta.getValueMeta(index);
175+
constantValueMeta.setConversionMetadata(valueMeta);
176+
String value = csvRecord.get(index);
177+
row[i] = valueMeta.convertData(constantValueMeta, value);
178+
} else {
179+
row[i] = null;
180+
}
177181
}
178182
rows.add(row);
179183
}

plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,26 @@ public IHasFilename loadReferencedObject(
167167
if (test == null) {
168168
throw new HopException("Unit test '" + testName + "' could not be found");
169169
}
170+
171+
variables.setVariable(
172+
org.apache.hop.testing.util.DataSetConst.VAR_UNIT_TEST_NAME, test.getName());
173+
try {
174+
if ("GUI".equalsIgnoreCase(org.apache.hop.core.Const.getHopPlatformRuntime())) {
175+
Class<?> hopGuiClass = Class.forName("org.apache.hop.ui.hopgui.HopGui");
176+
Object hopGuiInstance = hopGuiClass.getMethod("getInstance").invoke(null);
177+
if (hopGuiInstance != null) {
178+
IVariables guiVariables =
179+
(IVariables) hopGuiClass.getMethod("getVariables").invoke(hopGuiInstance);
180+
if (guiVariables != null) {
181+
guiVariables.setVariable(
182+
org.apache.hop.testing.util.DataSetConst.VAR_UNIT_TEST_NAME, test.getName());
183+
}
184+
}
185+
}
186+
} catch (Throwable e) {
187+
// Ignore
188+
}
189+
170190
return UnitTestUtil.loadTestPipeline(test, metadataProvider, variables);
171191
}
172192

plugins/misc/testing/src/main/java/org/apache/hop/testing/xp/AutoOpenTestExtensionPoint.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ public void callExtensionPoint(ILogChannel log, IVariables variables, PipelineMe
5555
TestingGuiPlugin.findPipelineUnitTest(
5656
variables, pipelineMeta, hopGui.getMetadataProvider());
5757

58+
// See if a specific unit test was requested
59+
//
60+
String unitTestName =
61+
variables.getVariable(org.apache.hop.testing.util.DataSetConst.VAR_UNIT_TEST_NAME);
62+
if (unitTestName != null && !unitTestName.isEmpty()) {
63+
for (PipelineUnitTest test : tests) {
64+
if (unitTestName.equalsIgnoreCase(test.getName())) {
65+
TestingGuiPlugin.selectUnitTest(pipelineMeta, test);
66+
variables.setVariable(org.apache.hop.testing.util.DataSetConst.VAR_UNIT_TEST_NAME, null);
67+
return;
68+
}
69+
}
70+
}
71+
5872
// See which ones are auto opening...
5973
//
6074
List<PipelineUnitTest> openTests = new ArrayList<>();
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hop.testing.xp;
19+
20+
import org.apache.hop.core.exception.HopException;
21+
import org.apache.hop.core.extension.ExtensionPoint;
22+
import org.apache.hop.core.extension.IExtensionPoint;
23+
import org.apache.hop.core.gui.AreaOwner;
24+
import org.apache.hop.core.gui.Point;
25+
import org.apache.hop.core.logging.ILogChannel;
26+
import org.apache.hop.core.variables.IVariables;
27+
import org.apache.hop.pipeline.PipelineMeta;
28+
import org.apache.hop.testing.gui.TestingGuiPlugin;
29+
import org.apache.hop.testing.util.DataSetConst;
30+
import org.apache.hop.ui.hopgui.file.pipeline.HopGuiPipelineGraph;
31+
import org.apache.hop.ui.hopgui.file.pipeline.extension.HopGuiPipelineGraphExtension;
32+
33+
@ExtensionPoint(
34+
extensionPointId = "PipelineGraphMouseUp",
35+
id = "LocationMouseUpExtensionPoint",
36+
description = "Prevent showing context menu when clicking on a data set")
37+
public class LocationMouseUpExtensionPoint
38+
implements IExtensionPoint<HopGuiPipelineGraphExtension> {
39+
40+
@Override
41+
public void callExtensionPoint(
42+
ILogChannel log, IVariables variables, HopGuiPipelineGraphExtension pipelineGraphExtension)
43+
throws HopException {
44+
HopGuiPipelineGraph pipelineGraph = pipelineGraphExtension.getPipelineGraph();
45+
PipelineMeta pipelineMeta = pipelineGraph.getPipelineMeta();
46+
47+
if (TestingGuiPlugin.getCurrentUnitTest(pipelineMeta) == null) {
48+
return;
49+
}
50+
51+
Point point = pipelineGraphExtension.getPoint();
52+
AreaOwner areaOwner = pipelineGraph.getVisibleAreaOwner(point.x, point.y);
53+
if (areaOwner != null && areaOwner.getAreaType() != null) {
54+
if (DataSetConst.AREA_DRAWN_INPUT_DATA_SET.equals(areaOwner.getParent())
55+
|| DataSetConst.AREA_DRAWN_GOLDEN_DATA_SET.equals(areaOwner.getParent())
56+
|| DataSetConst.AREA_DRAWN_GOLDEN_DATA_RESULT.equals(areaOwner.getParent())) {
57+
pipelineGraphExtension.setPreventingDefault(true);
58+
}
59+
}
60+
}
61+
}

plugins/misc/testing/src/main/java/org/apache/hop/ui/testing/PipelineUnitTestSetLocationDialog.java

Lines changed: 198 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import java.util.List;
2222
import java.util.Map;
2323
import org.apache.commons.lang3.StringUtils;
24+
import org.apache.hop.core.CheckResult;
2425
import org.apache.hop.core.Const;
26+
import org.apache.hop.core.ICheckResult;
2527
import org.apache.hop.core.SourceToTargetMapping;
2628
import org.apache.hop.core.exception.HopException;
2729
import org.apache.hop.core.row.IRowMeta;
@@ -34,6 +36,7 @@
3436
import org.apache.hop.testing.PipelineUnitTestSetLocation;
3537
import org.apache.hop.ui.core.PropsUi;
3638
import org.apache.hop.ui.core.dialog.BaseDialog;
39+
import org.apache.hop.ui.core.dialog.CheckResultDialog;
3740
import org.apache.hop.ui.core.dialog.EnterMappingDialog;
3841
import org.apache.hop.ui.core.dialog.ErrorDialog;
3942
import org.apache.hop.ui.core.gui.GuiResource;
@@ -190,11 +193,15 @@ public boolean open() {
190193
wGetSortFields.setText(
191194
BaseMessages.getString(PKG, "PipelineUnitTestSetLocationDialog.GetSortFields.Button"));
192195
wGetSortFields.addListener(SWT.Selection, e -> getSortFields());
196+
Button wValidate = new Button(shell, SWT.PUSH);
197+
wValidate.setText(
198+
BaseMessages.getString(PKG, "PipelineUnitTestSetLocationDialog.Validate.Button"));
199+
wValidate.addListener(SWT.Selection, e -> validate());
193200
Button wCancel = new Button(shell, SWT.PUSH);
194201
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
195202
wCancel.addListener(SWT.Selection, e -> cancel());
196203
BaseTransformDialog.positionBottomButtons(
197-
shell, new Button[] {wOk, wMapFields, wGetSortFields, wCancel}, margin, null);
204+
shell, new Button[] {wOk, wMapFields, wGetSortFields, wValidate, wCancel}, margin, null);
198205

199206
// the field mapping grid in between on the left
200207
//
@@ -428,6 +435,196 @@ public void getInfo(PipelineUnitTestSetLocation loc) {
428435
}
429436
}
430437

438+
protected void validate() {
439+
List<ICheckResult> remarks = new ArrayList<>();
440+
441+
String transformName = wTransformName.getText();
442+
String datasetName = wDataset.getText();
443+
444+
if (StringUtils.isEmpty(datasetName)) {
445+
remarks.add(
446+
new CheckResult(
447+
ICheckResult.TYPE_RESULT_ERROR,
448+
BaseMessages.getString(
449+
PKG, "PipelineUnitTestSetLocationDialog.Validate.Result.DatasetNotSelected"),
450+
null));
451+
}
452+
if (StringUtils.isEmpty(transformName)) {
453+
remarks.add(
454+
new CheckResult(
455+
ICheckResult.TYPE_RESULT_ERROR,
456+
BaseMessages.getString(
457+
PKG, "PipelineUnitTestSetLocationDialog.Validate.Result.TransformNotSelected"),
458+
null));
459+
}
460+
461+
DataSet dataSet = null;
462+
if (StringUtils.isNotEmpty(datasetName)) {
463+
try {
464+
dataSet = findDataSet(datasetName);
465+
remarks.add(
466+
new CheckResult(
467+
ICheckResult.TYPE_RESULT_OK,
468+
"Dataset '" + datasetName + "' exists in metadata.",
469+
null));
470+
} catch (Exception e) {
471+
remarks.add(
472+
new CheckResult(
473+
ICheckResult.TYPE_RESULT_ERROR,
474+
BaseMessages.getString(
475+
PKG,
476+
"PipelineUnitTestSetLocationDialog.Validate.Result.DatasetNotExist",
477+
datasetName),
478+
null));
479+
}
480+
}
481+
482+
// Check fields of the transform if selected
483+
IRowMeta transformRowMeta = null;
484+
if (StringUtils.isNotEmpty(transformName)) {
485+
transformRowMeta = transformFieldsMap.get(transformName);
486+
if (transformRowMeta == null) {
487+
remarks.add(
488+
new CheckResult(
489+
ICheckResult.TYPE_RESULT_ERROR,
490+
"Unable to find fields for transform " + transformName,
491+
null));
492+
}
493+
}
494+
495+
IRowMeta setRowMeta = null;
496+
if (dataSet != null) {
497+
try {
498+
setRowMeta = dataSet.getSetRowMeta();
499+
} catch (Exception e) {
500+
remarks.add(
501+
new CheckResult(
502+
ICheckResult.TYPE_RESULT_ERROR,
503+
"Error reading fields metadata for dataset '"
504+
+ datasetName
505+
+ "': "
506+
+ e.getMessage(),
507+
null));
508+
}
509+
}
510+
511+
// Verify field mappings
512+
PipelineUnitTestSetLocation loc = new PipelineUnitTestSetLocation();
513+
getInfo(loc);
514+
515+
if (loc.getFieldMappings().isEmpty()) {
516+
remarks.add(
517+
new CheckResult(
518+
ICheckResult.TYPE_RESULT_WARNING,
519+
BaseMessages.getString(
520+
PKG, "PipelineUnitTestSetLocationDialog.Validate.Result.FieldMappingEmpty"),
521+
null));
522+
} else {
523+
for (PipelineUnitTestFieldMapping mapping : loc.getFieldMappings()) {
524+
String tField = mapping.getTransformFieldName();
525+
String dField = mapping.getDataSetFieldName();
526+
527+
if (transformRowMeta != null && StringUtils.isNotEmpty(tField)) {
528+
if (transformRowMeta.indexOfValue(tField) < 0) {
529+
remarks.add(
530+
new CheckResult(
531+
ICheckResult.TYPE_RESULT_ERROR,
532+
BaseMessages.getString(
533+
PKG,
534+
"PipelineUnitTestSetLocationDialog.Validate.Result.TransformFieldNotExist",
535+
tField,
536+
transformName),
537+
null));
538+
}
539+
}
540+
if (setRowMeta != null && StringUtils.isNotEmpty(dField)) {
541+
if (setRowMeta.indexOfValue(dField) < 0) {
542+
remarks.add(
543+
new CheckResult(
544+
ICheckResult.TYPE_RESULT_ERROR,
545+
BaseMessages.getString(
546+
PKG,
547+
"PipelineUnitTestSetLocationDialog.Validate.Result.DatasetFieldNotExist",
548+
dField,
549+
datasetName),
550+
null));
551+
}
552+
}
553+
}
554+
}
555+
556+
// Verify sort field order mappings
557+
if (setRowMeta != null) {
558+
for (String sortField : loc.getFieldOrder()) {
559+
if (StringUtils.isNotEmpty(sortField) && setRowMeta.indexOfValue(sortField) < 0) {
560+
remarks.add(
561+
new CheckResult(
562+
ICheckResult.TYPE_RESULT_ERROR,
563+
BaseMessages.getString(
564+
PKG,
565+
"PipelineUnitTestSetLocationDialog.Validate.Result.SortFieldNotExist",
566+
sortField,
567+
datasetName),
568+
null));
569+
}
570+
}
571+
}
572+
573+
// Verify CSV file exists and can read rows
574+
if (dataSet != null) {
575+
String filename = dataSet.getActualDataSetFilename(variables);
576+
try {
577+
org.apache.commons.vfs2.FileObject file =
578+
org.apache.hop.core.vfs.HopVfs.getFileObject(filename);
579+
if (!file.exists()) {
580+
remarks.add(
581+
new CheckResult(
582+
ICheckResult.TYPE_RESULT_ERROR,
583+
BaseMessages.getString(
584+
PKG,
585+
"PipelineUnitTestSetLocationDialog.Validate.Result.CsvNotExist",
586+
filename),
587+
null));
588+
} else {
589+
remarks.add(
590+
new CheckResult(
591+
ICheckResult.TYPE_RESULT_OK, "CSV file '" + filename + "' exists.", null));
592+
try {
593+
List<Object[]> rows =
594+
dataSet.getAllRows(variables, org.apache.hop.core.logging.LogChannel.UI);
595+
remarks.add(
596+
new CheckResult(
597+
ICheckResult.TYPE_RESULT_OK,
598+
BaseMessages.getString(
599+
PKG,
600+
"PipelineUnitTestSetLocationDialog.Validate.Result.Success",
601+
String.valueOf(rows.size())),
602+
null));
603+
} catch (Exception e) {
604+
remarks.add(
605+
new CheckResult(
606+
ICheckResult.TYPE_RESULT_ERROR,
607+
BaseMessages.getString(
608+
PKG,
609+
"PipelineUnitTestSetLocationDialog.Validate.Result.CsvReadError",
610+
e.getMessage()),
611+
null));
612+
}
613+
}
614+
} catch (Exception e) {
615+
remarks.add(
616+
new CheckResult(
617+
ICheckResult.TYPE_RESULT_ERROR,
618+
"Error resolving CSV file path: " + e.getMessage(),
619+
null));
620+
}
621+
}
622+
623+
// Show CheckResultDialog
624+
CheckResultDialog checkResultDialog = new CheckResultDialog(shell, remarks);
625+
checkResultDialog.open();
626+
}
627+
431628
public void ok() {
432629
getInfo(location);
433630
ok = true;

plugins/misc/testing/src/main/resources/org/apache/hop/ui/testing/messages/messages_en_US.properties

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,14 @@ PipelineUnitTestSetLocationDialog.GetSortFields.Button=Get sort fields
6161
PipelineUnitTestSetLocationDialog.MapFields.Button=Map fields
6262
PipelineUnitTestSetLocationDialog.Shell.Title=Dataset Location
6363
PipelineUnitTestSetLocationDialog.TransformName.Label=Transform
64+
PipelineUnitTestSetLocationDialog.Validate.Button=Validate
65+
PipelineUnitTestSetLocationDialog.Validate.Result.DatasetNotSelected=Please select a dataset to validate.
66+
PipelineUnitTestSetLocationDialog.Validate.Result.TransformNotSelected=Please select a transform to validate.
67+
PipelineUnitTestSetLocationDialog.Validate.Result.DatasetNotExist=Dataset ''{0}'' does not exist.
68+
PipelineUnitTestSetLocationDialog.Validate.Result.CsvNotExist=CSV file ''{0}'' does not exist on disk.
69+
PipelineUnitTestSetLocationDialog.Validate.Result.CsvReadError=Error reading CSV rows: {0}
70+
PipelineUnitTestSetLocationDialog.Validate.Result.FieldMappingEmpty=Field mappings are empty.
71+
PipelineUnitTestSetLocationDialog.Validate.Result.TransformFieldNotExist=Transform field ''{0}'' does not exist in transform ''{1}''.
72+
PipelineUnitTestSetLocationDialog.Validate.Result.DatasetFieldNotExist=Dataset field ''{0}'' does not exist in dataset ''{1}''.
73+
PipelineUnitTestSetLocationDialog.Validate.Result.SortFieldNotExist=Sort field ''{0}'' does not exist in dataset ''{1}''.
74+
PipelineUnitTestSetLocationDialog.Validate.Result.Success=Dataset location configuration is valid. {0} rows read successfully.

0 commit comments

Comments
 (0)