From d5a9ffcee1844a633f25db6cc848e4e4b06a93f9 Mon Sep 17 00:00:00 2001 From: Hans Van Akelyen Date: Mon, 28 Oct 2024 09:21:37 +0100 Subject: [PATCH] Cleanup XML of action Run Pipeline Tests, fixes #2007 remove comments --- .../actions/runtests/RunPipelineTests.java | 68 ++++--------------- .../runtests/RunPipelineTestsDialog.java | 8 ++- .../runtests/RunPipelineTestsField.java | 30 ++++++++ 3 files changed, 47 insertions(+), 59 deletions(-) create mode 100644 plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTestsField.java diff --git a/plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTests.java b/plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTests.java index 7beb99cea0f..ad28f013373 100644 --- a/plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTests.java +++ b/plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTests.java @@ -20,13 +20,14 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +import lombok.Getter; +import lombok.Setter; import org.apache.hop.core.Result; import org.apache.hop.core.annotations.Action; import org.apache.hop.core.exception.HopException; -import org.apache.hop.core.exception.HopXmlException; import org.apache.hop.core.file.IHasFilename; 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.metadata.api.IHopMetadataSerializer; import org.apache.hop.testing.PipelineUnitTest; @@ -34,7 +35,6 @@ import org.apache.hop.testing.util.UnitTestUtil; import org.apache.hop.workflow.action.ActionBase; import org.apache.hop.workflow.action.IAction; -import org.w3c.dom.Node; @Action( id = "RunPipelineTests", @@ -44,12 +44,15 @@ keywords = "i18n::RunPipelineTests.Keywords", image = "Test_tube_icon.svg", documentationUrl = "/workflow/actions/runpipelinetests.html") +@Getter +@Setter public class RunPipelineTests extends ActionBase implements IAction, Cloneable { public static final String TEST_NAMES = "test_names"; public static final String TEST_NAME = "test_name"; - private List testNames; + @HopMetadataProperty(key = TEST_NAME, groupKey = TEST_NAMES) + private List testNames; public RunPipelineTests(String name, String description) { super(name, description); @@ -73,9 +76,9 @@ public Result execute(Result prevResult, int nr) throws HopException { AtomicBoolean success = new AtomicBoolean(true); - for (String testName : testNames) { + for (RunPipelineTestsField testName : testNames) { - PipelineUnitTest test = testSerializer.load(testName); + PipelineUnitTest test = testSerializer.load(testName.getTestName()); UnitTestUtil.executeUnitTest( test, @@ -134,38 +137,7 @@ public Result execute(Result prevResult, int nr) throws HopException { return prevResult; } - - @Override - public String getXml() { - StringBuilder xml = new StringBuilder(); - - xml.append(super.getXml()); - - xml.append(XmlHandler.openTag(TEST_NAMES)); - for (String testName : testNames) { - xml.append(XmlHandler.openTag(TEST_NAME)); - xml.append(XmlHandler.addTagValue("name", testName)); - xml.append(XmlHandler.closeTag(TEST_NAME)); - } - xml.append(XmlHandler.closeTag(TEST_NAMES)); - - return xml.toString(); - } - - @Override - public void loadXml(Node entryNode, IHopMetadataProvider metadataProvider, IVariables variables) - throws HopXmlException { - super.loadXml(entryNode); - - Node testNamesNode = XmlHandler.getSubNode(entryNode, TEST_NAMES); - List testNameNodes = XmlHandler.getNodes(testNamesNode, TEST_NAME); - testNames = new ArrayList<>(); - for (Node testNameNode : testNameNodes) { - String name = XmlHandler.getTagValue(testNameNode, "name"); - testNames.add(name); - } - } - + @Override public String[] getReferencedObjectDescriptions() { String[] descriptions = new String[testNames.size()]; @@ -190,8 +162,8 @@ public IHasFilename loadReferencedObject( IHopMetadataSerializer testSerializer = metadataProvider.getSerializer(PipelineUnitTest.class); - String testName = testNames.get(index); - PipelineUnitTest test = testSerializer.load(testName); + RunPipelineTestsField testName = testNames.get(index); + PipelineUnitTest test = testSerializer.load(testName.getTestName()); if (test == null) { throw new HopException("Unit test '" + testName + "' could not be found"); } @@ -207,20 +179,4 @@ public boolean isEvaluation() { public boolean isUnconditional() { return false; } - - /** - * Gets testNames - * - * @return value of testNames - */ - public List getTestNames() { - return testNames; - } - - /** - * @param testNames The testNames to set - */ - public void setTestNames(List testNames) { - this.testNames = testNames; - } } diff --git a/plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTestsDialog.java b/plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTestsDialog.java index b8c41bdcee4..cd9ea4fe58d 100644 --- a/plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTestsDialog.java +++ b/plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTestsDialog.java @@ -227,9 +227,9 @@ private void getData() { wName.setText(Const.NVL(action.getName(), "")); int rowNr = 0; - for (String testName : action.getTestNames()) { + for (RunPipelineTestsField testName : action.getTestNames()) { TableItem item = wTestNames.table.getItem(rowNr++); - item.setText(1, Const.NVL(testName, "")); + item.setText(1, Const.NVL(testName.getTestName(), "")); } wTestNames.setRowNums(); wTestNames.optWidth(true); @@ -247,7 +247,9 @@ private void ok() { action.getTestNames().clear(); for (int i = 0; i < wTestNames.nrNonEmpty(); i++) { TableItem item = wTestNames.getNonEmpty(i); - action.getTestNames().add(item.getText(1)); + RunPipelineTestsField testName = new RunPipelineTestsField(); + testName.setTestName(item.getText(1)); + action.getTestNames().add(testName); } action.setChanged(); diff --git a/plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTestsField.java b/plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTestsField.java new file mode 100644 index 00000000000..ec347bb65ad --- /dev/null +++ b/plugins/misc/testing/src/main/java/org/apache/hop/testing/actions/runtests/RunPipelineTestsField.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hop.testing.actions.runtests; + +import lombok.Getter; +import lombok.Setter; +import org.apache.hop.metadata.api.HopMetadataProperty; + +@Getter +@Setter +public class RunPipelineTestsField { + + @HopMetadataProperty(key = "name") + String testName; +}