Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task #1996 Cleanup XML of action Telnet #3104

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
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;
Expand All @@ -36,7 +35,6 @@
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;

Expand All @@ -51,9 +49,11 @@
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;
Expand All @@ -76,31 +76,6 @@ public Object clone() {
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;
}
Expand All @@ -125,15 +100,15 @@ public String getRealHostname() {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void getData() {
}

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();
Expand All @@ -212,7 +212,7 @@ private void ok() {
action.setName(wName.getText());
action.setHostname(wHostname.getText());
action.setPort(wPort.getText());
action.setTimeOut(wTimeOut.getText());
action.setTimeout(wTimeOut.getText());

dispose();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ protected Map<String, String> createGettersMap() {
return toMap(
"hostname", "getHostname",
"port", "getPort",
"timeout", "getTimeOut");
"timeout", "getTimeout");
}

@Override
protected Map<String, String> createSettersMap() {
return toMap(
"hostname", "setHostname",
"port", "setPort",
"timeout", "setTimeOut");
"timeout", "setTimeout");
}
}
33 changes: 33 additions & 0 deletions plugins/actions/telnet/src/test/resources/telnet-action.xml
Original file line number Diff line number Diff line change
@@ -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>