Skip to content

Commit

Permalink
Merge pull request #4306 from nadment/2008
Browse files Browse the repository at this point in the history
Cleanup XML of transform Execute Tests #2008
  • Loading branch information
bamaer authored Sep 19, 2024
2 parents 5e0ecaa + 3ec2fc0 commit 59eadc6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ The goal is to add Metadata Injection support to all transforms, The current sta
|Execute a process|Y
|Execute row SQL script|Y
|Execute SQL script|Y
|Execute Unit Tests|N
|Execute Unit Tests|Y
|Execution Information|Y
|Fake data|Y
|File exists|Y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public String open() {
wlTestNameInputField.setLayoutData(fdlTestNameInputField);
wTestNameInputField = new Combo(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wTestNameInputField.setItems(inputFieldNames);
PropsUi.setLook(wTestNameInputField);
FormData fdTestNameInputField = new FormData();
fdTestNameInputField.left = new FormAttachment(middle, 0);
fdTestNameInputField.top = new FormAttachment(lastControl, margin);
Expand All @@ -157,6 +158,7 @@ public String open() {
wlTypeToExecute.setLayoutData(fdlTypeToExecute);
wTypeToExecute = new Combo(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wTypeToExecute.setItems(DataSetConst.getTestTypeDescriptions());
PropsUi.setLook(wTypeToExecute);
FormData fdTypeToExecute = new FormData();
fdTypeToExecute.left = new FormAttachment(middle, 0);
fdTypeToExecute.top = new FormAttachment(lastControl, margin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@
package org.apache.hop.testing.transforms.exectests;

import org.apache.hop.core.annotations.Transform;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.exception.HopXmlException;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.variables.IVariables;
import org.apache.hop.core.xml.XmlHandler;
import org.apache.hop.metadata.api.HopMetadataProperty;
import org.apache.hop.metadata.api.IHopMetadataProvider;
import org.apache.hop.pipeline.transform.BaseTransformMeta;
import org.apache.hop.pipeline.transform.TransformMeta;
import org.apache.hop.testing.TestType;
import org.apache.hop.testing.UnitTestResult;
import org.w3c.dom.Node;

@Transform(
id = "ExecuteTests",
Expand All @@ -49,13 +46,28 @@ public class ExecuteTestsMeta extends BaseTransformMeta<ExecuteTests, ExecuteTes
public static final String TAG_ERROR_FIELD = "error_field";
public static final String TAG_COMMENT_FIELD = "comment_field";

@HopMetadataProperty(key = TAG_TEST_NAME_INPUT_FIELD)
private String testNameInputField;

@HopMetadataProperty(key = TAG_TYPE_TO_EXECUTE)
private TestType typeToExecute;

@HopMetadataProperty(key = TAG_PIPELINE_NAME_FIELD)
private String pipelineNameField;

@HopMetadataProperty(key = TAG_UNIT_TEST_NAME_FIELD)
private String unitTestNameField;

@HopMetadataProperty(key = TAG_DATASET_NAME_FIELD)
private String dataSetNameField;

@HopMetadataProperty(key = TAG_TRANSFORM_NAME_FIELD)
private String transformNameField;

@HopMetadataProperty(key = TAG_ERROR_FIELD)
private String errorField;

@HopMetadataProperty(key = TAG_COMMENT_FIELD)
private String commentField;

public ExecuteTestsMeta() {
Expand Down Expand Up @@ -83,53 +95,6 @@ public void getFields(
inputRowMeta.addRowMeta(rowMeta);
}

@Override
public String getXml() throws HopException {
StringBuilder xml = new StringBuilder();
xml.append(XmlHandler.addTagValue(TAG_TEST_NAME_INPUT_FIELD, testNameInputField));
xml.append(
XmlHandler.addTagValue(
TAG_TYPE_TO_EXECUTE,
typeToExecute == null ? TestType.DEVELOPMENT.name() : typeToExecute.name()));
xml.append(XmlHandler.addTagValue(TAG_PIPELINE_NAME_FIELD, pipelineNameField));
xml.append(XmlHandler.addTagValue(TAG_UNIT_TEST_NAME_FIELD, unitTestNameField));
xml.append(XmlHandler.addTagValue(TAG_DATASET_NAME_FIELD, dataSetNameField));
xml.append(XmlHandler.addTagValue(TAG_TRANSFORM_NAME_FIELD, transformNameField));
xml.append(XmlHandler.addTagValue(TAG_ERROR_FIELD, errorField));
xml.append(XmlHandler.addTagValue(TAG_COMMENT_FIELD, commentField));

return xml.toString();
}

@Override
public void loadXml(Node transformNode, IHopMetadataProvider metadataProvider)
throws HopXmlException {
try {

testNameInputField = XmlHandler.getTagValue(transformNode, TAG_TEST_NAME_INPUT_FIELD);
String typeDesc = XmlHandler.getTagValue(transformNode, TAG_TYPE_TO_EXECUTE);
try {
typeToExecute = TestType.valueOf(typeDesc);
} catch (Exception e) {
typeToExecute = TestType.DEVELOPMENT;
}
pipelineNameField = XmlHandler.getTagValue(transformNode, TAG_PIPELINE_NAME_FIELD);
unitTestNameField = XmlHandler.getTagValue(transformNode, TAG_UNIT_TEST_NAME_FIELD);
dataSetNameField = XmlHandler.getTagValue(transformNode, TAG_DATASET_NAME_FIELD);
transformNameField = XmlHandler.getTagValue(transformNode, TAG_TRANSFORM_NAME_FIELD);
errorField = XmlHandler.getTagValue(transformNode, TAG_ERROR_FIELD);
commentField = XmlHandler.getTagValue(transformNode, TAG_COMMENT_FIELD);

} catch (Exception e) {
throw new HopXmlException("Unable to load execute test transform details", e);
}
}

@Override
public String getDialogClassName() {
return ExecuteTestsDialog.class.getName();
}

@Override
public void setDefault() {
testNameInputField = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ExecuteTestsDialog.ErrorField.Label=Error output field name
ExecuteTestsDialog.PipelineNameField.Label=Pipeline output field name
ExecuteTestsDialog.Shell.Title=Execute Unit Tests
ExecuteTestsDialog.TestNameInputField.Label=Test name input field
ExecuteTestsDialog.TransformName.Label=transform name
ExecuteTestsDialog.TransformName.Label=Transform name
ExecuteTestsDialog.TransformNameField.Label=transform output field name
ExecuteTestsDialog.TypeToExecute.Label=Type of tests to run
ExecuteTestsDialog.UnitTestNameField.Label=Unit test output field name
Expand Down

0 comments on commit 59eadc6

Please sign in to comment.