Skip to content

Commit

Permalink
Cleanup XML of action Run Pipeline Tests, fixes apache#2007
Browse files Browse the repository at this point in the history
remove comments
  • Loading branch information
hansva committed Oct 28, 2024
1 parent 2377655 commit d5a9ffc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
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;
import org.apache.hop.testing.UnitTestResult;
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",
Expand All @@ -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<String> testNames;
@HopMetadataProperty(key = TEST_NAME, groupKey = TEST_NAMES)
private List<RunPipelineTestsField> testNames;

public RunPipelineTests(String name, String description) {
super(name, description);
Expand All @@ -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,
Expand Down Expand Up @@ -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<Node> 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()];
Expand All @@ -190,8 +162,8 @@ public IHasFilename loadReferencedObject(

IHopMetadataSerializer<PipelineUnitTest> 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");
}
Expand All @@ -207,20 +179,4 @@ public boolean isEvaluation() {
public boolean isUnconditional() {
return false;
}

/**
* Gets testNames
*
* @return value of testNames
*/
public List<String> getTestNames() {
return testNames;
}

/**
* @param testNames The testNames to set
*/
public void setTestNames(List<String> testNames) {
this.testNames = testNames;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit d5a9ffc

Please sign in to comment.