This is an automated email from the ASF dual-hosted git repository.

hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/master by this push:
     new 534911125a task #1996 Cleanup XML of action Telnet
     new b5e6dbb8c6 Merge pull request #3104 from gvdutra/1996
534911125a is described below

commit 534911125acff52d75e30ae5d310a2a401b9c92d
Author: Gabriel Dutra <[email protected]>
AuthorDate: Sun Jul 23 21:47:52 2023 -0700

    task #1996 Cleanup XML of action Telnet
---
 .../hop/workflow/actions/telnet/ActionTelnet.java  | 39 +++----------
 .../actions/telnet/ActionTelnetDialog.java         |  4 +-
 .../workflow/actions/telnet/ActionTelnetTest.java  | 65 ++++++++++++++++++++++
 .../telnet/WorkflowActionTelnetLoadSaveTest.java   |  4 +-
 .../telnet/src/test/resources/telnet-action.xml    | 33 +++++++++++
 5 files changed, 109 insertions(+), 36 deletions(-)

diff --git 
a/plugins/actions/telnet/src/main/java/org/apache/hop/workflow/actions/telnet/ActionTelnet.java
 
b/plugins/actions/telnet/src/main/java/org/apache/hop/workflow/actions/telnet/ActionTelnet.java
index f7340711c7..16c622615c 100644
--- 
a/plugins/actions/telnet/src/main/java/org/apache/hop/workflow/actions/telnet/ActionTelnet.java
+++ 
b/plugins/actions/telnet/src/main/java/org/apache/hop/workflow/actions/telnet/ActionTelnet.java
@@ -21,12 +21,11 @@ import org.apache.hop.core.Const;
 import org.apache.hop.core.ICheckResult;
 import org.apache.hop.core.Result;
 import org.apache.hop.core.annotations.Action;
-import org.apache.hop.core.exception.HopXmlException;
 import org.apache.hop.core.util.SocketUtil;
 import org.apache.hop.core.util.Utils;
 import org.apache.hop.core.variables.IVariables;
-import org.apache.hop.core.xml.XmlHandler;
 import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.metadata.api.HopMetadataProperty;
 import org.apache.hop.metadata.api.IHopMetadataProvider;
 import org.apache.hop.resource.ResourceEntry;
 import org.apache.hop.resource.ResourceEntry.ResourceType;
@@ -36,7 +35,6 @@ import org.apache.hop.workflow.action.ActionBase;
 import org.apache.hop.workflow.action.IAction;
 import org.apache.hop.workflow.action.validator.ActionValidatorUtils;
 import org.apache.hop.workflow.action.validator.AndValidator;
-import org.w3c.dom.Node;
 
 import java.util.List;
 
@@ -51,9 +49,11 @@ import java.util.List;
     documentationUrl = "/workflow/actions/telnet.html")
 public class ActionTelnet extends ActionBase implements Cloneable, IAction {
   private static final Class<?> PKG = ActionTelnet.class; // For Translator
-
+  @HopMetadataProperty(key = "hostname")
   private String hostname;
+  @HopMetadataProperty(key = "port")
   private String port;
+  @HopMetadataProperty(key = "timeout")
   private String timeout;
 
   public static final int DEFAULT_TIME_OUT = 3000;
@@ -76,31 +76,6 @@ public class ActionTelnet extends ActionBase implements 
Cloneable, IAction {
     return je;
   }
 
-  @Override
-  public String getXml() {
-    StringBuilder retval = new StringBuilder(100);
-
-    retval.append(super.getXml());
-    retval.append("      ").append(XmlHandler.addTagValue("hostname", 
hostname));
-    retval.append("      ").append(XmlHandler.addTagValue("port", port));
-    retval.append("      ").append(XmlHandler.addTagValue("timeout", timeout));
-
-    return retval.toString();
-  }
-
-  @Override
-  public void loadXml(Node entrynode, IHopMetadataProvider metadataProvider, 
IVariables variables)
-      throws HopXmlException {
-    try {
-      super.loadXml(entrynode);
-      hostname = XmlHandler.getTagValue(entrynode, "hostname");
-      port = XmlHandler.getTagValue(entrynode, "port");
-      timeout = XmlHandler.getTagValue(entrynode, "timeout");
-    } catch (HopXmlException xe) {
-      throw new HopXmlException("Unable to load action of type 'Telnet' from 
XML node", xe);
-    }
-  }
-
   public String getPort() {
     return port;
   }
@@ -125,15 +100,15 @@ public class ActionTelnet extends ActionBase implements 
Cloneable, IAction {
     return resolve(getHostname());
   }
 
-  public String getTimeOut() {
+  public String getTimeout() {
     return timeout;
   }
 
   public String getRealTimeOut() {
-    return resolve(getTimeOut());
+    return resolve(getTimeout());
   }
 
-  public void setTimeOut(String timeout) {
+  public void setTimeout(String timeout) {
     this.timeout = timeout;
   }
 
diff --git 
a/plugins/actions/telnet/src/main/java/org/apache/hop/workflow/actions/telnet/ActionTelnetDialog.java
 
b/plugins/actions/telnet/src/main/java/org/apache/hop/workflow/actions/telnet/ActionTelnetDialog.java
index fd706bca58..d3b4499ebf 100644
--- 
a/plugins/actions/telnet/src/main/java/org/apache/hop/workflow/actions/telnet/ActionTelnetDialog.java
+++ 
b/plugins/actions/telnet/src/main/java/org/apache/hop/workflow/actions/telnet/ActionTelnetDialog.java
@@ -189,7 +189,7 @@ public class ActionTelnetDialog extends ActionDialog 
implements IActionDialog {
     }
 
     wPort.setText(Const.NVL(action.getPort(), 
String.valueOf(ActionTelnet.DEFAULT_PORT)));
-    wTimeOut.setText(Const.NVL(action.getTimeOut(), 
String.valueOf(ActionTelnet.DEFAULT_TIME_OUT)));
+    wTimeOut.setText(Const.NVL(action.getTimeout(), 
String.valueOf(ActionTelnet.DEFAULT_TIME_OUT)));
 
     wName.selectAll();
     wName.setFocus();
@@ -212,7 +212,7 @@ public class ActionTelnetDialog extends ActionDialog 
implements IActionDialog {
     action.setName(wName.getText());
     action.setHostname(wHostname.getText());
     action.setPort(wPort.getText());
-    action.setTimeOut(wTimeOut.getText());
+    action.setTimeout(wTimeOut.getText());
 
     dispose();
   }
diff --git 
a/plugins/actions/telnet/src/test/java/org/apache/hop/workflow/actions/telnet/ActionTelnetTest.java
 
b/plugins/actions/telnet/src/test/java/org/apache/hop/workflow/actions/telnet/ActionTelnetTest.java
new file mode 100644
index 0000000000..961f33c0b7
--- /dev/null
+++ 
b/plugins/actions/telnet/src/test/java/org/apache/hop/workflow/actions/telnet/ActionTelnetTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.workflow.actions.telnet;
+
+import org.apache.hop.core.HopClientEnvironment;
+import org.apache.hop.core.logging.HopLogStore;
+import org.apache.hop.workflow.WorkflowMeta;
+import org.apache.hop.workflow.action.ActionMeta;
+import org.apache.hop.workflow.action.ActionSerializationTestUtil;
+import org.apache.hop.workflow.engine.IWorkflowEngine;
+import org.apache.hop.workflow.engines.local.LocalWorkflowEngine;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class ActionTelnetTest {
+
+  private IWorkflowEngine<WorkflowMeta> workflow;
+  private ActionTelnet action;
+
+  @BeforeClass
+  public static void setUpBeforeClass() {
+    HopLogStore.init();
+  }
+
+  @AfterClass
+  public static void tearDownAfterClass() {}
+
+  @Before
+  public void setUp() throws Exception {
+    workflow = new LocalWorkflowEngine(new WorkflowMeta());
+    action = new ActionTelnet();
+    workflow.getWorkflowMeta().addAction(new ActionMeta(action));
+    action.setParentWorkflow(workflow);
+    workflow.setStopped(false);
+  }
+
+  @Test
+  public void testSerialization() throws Exception {
+    HopClientEnvironment.init();
+    ActionTelnet action =
+        ActionSerializationTestUtil.testSerialization("/telnet-action.xml", 
ActionTelnet.class);
+    assertEquals("24", action.getPort());
+    assertEquals("2023", action.getTimeout());
+    assertEquals("Hop", action.getHostname());
+  }
+}
diff --git 
a/plugins/actions/telnet/src/test/java/org/apache/hop/workflow/actions/telnet/WorkflowActionTelnetLoadSaveTest.java
 
b/plugins/actions/telnet/src/test/java/org/apache/hop/workflow/actions/telnet/WorkflowActionTelnetLoadSaveTest.java
index 334e851ea7..909b53cfb7 100644
--- 
a/plugins/actions/telnet/src/test/java/org/apache/hop/workflow/actions/telnet/WorkflowActionTelnetLoadSaveTest.java
+++ 
b/plugins/actions/telnet/src/test/java/org/apache/hop/workflow/actions/telnet/WorkflowActionTelnetLoadSaveTest.java
@@ -44,7 +44,7 @@ public class WorkflowActionTelnetLoadSaveTest
     return toMap(
         "hostname", "getHostname",
         "port", "getPort",
-        "timeout", "getTimeOut");
+        "timeout", "getTimeout");
   }
 
   @Override
@@ -52,6 +52,6 @@ public class WorkflowActionTelnetLoadSaveTest
     return toMap(
         "hostname", "setHostname",
         "port", "setPort",
-        "timeout", "setTimeOut");
+        "timeout", "setTimeout");
   }
 }
diff --git a/plugins/actions/telnet/src/test/resources/telnet-action.xml 
b/plugins/actions/telnet/src/test/resources/telnet-action.xml
new file mode 100644
index 0000000000..07562665ec
--- /dev/null
+++ b/plugins/actions/telnet/src/test/resources/telnet-action.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ~ 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. ~ -->
+<action>
+    <name>Telnet a host</name>
+    <description/>
+    <type>TELNET</type>
+    <attributes></attributes>
+    <hostname>Hop</hostname>
+    <port>24</port>
+    <timeout>2023</timeout>
+    <parallel>N</parallel>
+    <xloc>384</xloc>
+    <yloc>320</yloc>
+    <attributes_hac></attributes_hac>
+</action>
\ No newline at end of file

Reply via email to