Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Tiede2014-10-21 15:12:39 +0000
committerMarkus Tiede2014-10-21 15:12:43 +0000
commit3018416c72b8f1a29ea63064afefdadf632a42c5 (patch)
tree10947475c8f95fdd354aed5aeb96af88b2b15050 /org.eclipse.jubula.client.api
parent78d6c16dc6e8b8602bb2589587f960387f06e805 (diff)
downloadorg.eclipse.jubula.core-3018416c72b8f1a29ea63064afefdadf632a42c5.tar.gz
org.eclipse.jubula.core-3018416c72b8f1a29ea63064afefdadf632a42c5.tar.xz
org.eclipse.jubula.core-3018416c72b8f1a29ea63064afefdadf632a42c5.zip
Non-sprint task - added basic parameter and state validation for client API.
Diffstat (limited to 'org.eclipse.jubula.client.api')
-rw-r--r--org.eclipse.jubula.client.api/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/Synchronizer.java10
-rw-r--r--org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTAgentImpl.java38
-rw-r--r--org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTImpl.java26
-rw-r--r--org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ObjectMappingImpl.java9
-rw-r--r--org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ResultImpl.java3
6 files changed, 69 insertions, 18 deletions
diff --git a/org.eclipse.jubula.client.api/META-INF/MANIFEST.MF b/org.eclipse.jubula.client.api/META-INF/MANIFEST.MF
index 6965cc260..a0b5cbfce 100644
--- a/org.eclipse.jubula.client.api/META-INF/MANIFEST.MF
+++ b/org.eclipse.jubula.client.api/META-INF/MANIFEST.MF
@@ -9,6 +9,7 @@ Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Require-Bundle: org.slf4j.api;bundle-version="[1.7.2,2.0.0)",
org.apache.commons.codec;bundle-version="[1.3.0,2.0.0)",
+ org.apache.commons.lang;bundle-version="[2.4.0,3.0.0)",
org.eclipse.jdt.annotation;bundle-version="[1.1.0,2.0.0)",
org.eclipse.jubula.tools;bundle-version="[2.4.0,2.5.0)",
org.eclipse.jubula.toolkit.api;bundle-version="[2.4.0,2.5.0)",
diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/Synchronizer.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/Synchronizer.java
index 4b90abe66..9f29aa985 100644
--- a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/Synchronizer.java
+++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/Synchronizer.java
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2010 BREDEX GmbH.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * BREDEX GmbH - initial API and implementation and/or initial documentation
+ *******************************************************************************/
package org.eclipse.jubula.client.internal;
import java.util.concurrent.Exchanger;
diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTAgentImpl.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTAgentImpl.java
index e38d8aa9e..e20944fd1 100644
--- a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTAgentImpl.java
+++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTAgentImpl.java
@@ -16,6 +16,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
+import org.apache.commons.lang.Validate;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jubula.client.AUT;
import org.eclipse.jubula.client.AUTAgent;
@@ -32,6 +33,7 @@ import org.eclipse.jubula.tools.internal.constants.AUTStartResponse;
import org.eclipse.jubula.tools.internal.constants.AutConfigConstants;
import org.eclipse.jubula.tools.internal.constants.ToolkitConstants;
import org.eclipse.jubula.tools.internal.registration.AutIdentifier;
+import org.eclipse.jubula.tools.internal.utils.NetUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,36 +41,46 @@ import org.slf4j.LoggerFactory;
public class AUTAgentImpl implements AUTAgent {
/** the logger */
private static Logger log = LoggerFactory.getLogger(AUTAgentImpl.class);
-
/** the hosts name */
private String m_hostname;
/** the port */
- private int m_port;
+ private String m_port;
/** the connection to the AUT-Agent */
private AutAgentConnection m_agent;
/**
* @param hostname
* the hosts name
- * @param port
+ * @param iPort
* the port
*/
- public AUTAgentImpl(String hostname, int port) {
+ public AUTAgentImpl(String hostname, int iPort) {
+ Validate.notEmpty(hostname, "The hostname must not be empty."); //$NON-NLS-1$
+ final String port = String.valueOf(iPort);
+ String portNumberMessage = NetUtil.isPortNumberValid(port);
+ Validate.isTrue(portNumberMessage == null, portNumberMessage);
+
m_hostname = hostname;
m_port = port;
}
/** {@inheritDoc} */
public void connect() throws Exception {
- AutAgentConnection.createInstance(m_hostname, String.valueOf(m_port));
- m_agent = AutAgentConnection.getInstance();
- m_agent.run();
+ if (!isConnected()) {
+ AutAgentConnection.createInstance(m_hostname, m_port);
+ m_agent = AutAgentConnection.getInstance();
+ m_agent.run();
+ } else {
+ throw new IllegalStateException("AUT-Agent connection is already made"); //$NON-NLS-1$
+ }
}
/** {@inheritDoc} */
public void disconnect() {
- if (m_agent != null) {
+ if (isConnected()) {
m_agent.close();
+ } else {
+ throw new IllegalStateException("AUT-Agent connection is already disconnected"); //$NON-NLS-1$
}
}
@@ -81,6 +93,8 @@ public class AUTAgentImpl implements AUTAgent {
public AUTIdentifier startAUT(
@NonNull AUTConfiguration configuration)
throws Exception {
+ Validate.notNull(configuration, "The configuration must not be null."); //$NON-NLS-1$
+
Map<String, String> autConfigMap = configuration.getLaunchInformation();
// add relevant information for the AUT-Agent
@@ -131,8 +145,9 @@ public class AUTAgentImpl implements AUTAgent {
/** {@inheritDoc} */
public void stopAUT(
@NonNull AUTIdentifier aut) throws Exception {
- m_agent.send(new StopAUTServerMessage(
- (AutIdentifier)aut));
+ Validate.notNull(aut, "The AUT-Identifier must not be null."); //$NON-NLS-1$
+
+ m_agent.send(new StopAUTServerMessage((AutIdentifier)aut));
}
/** {@inheritDoc} */
@@ -160,6 +175,9 @@ public class AUTAgentImpl implements AUTAgent {
@NonNull public AUT getAUT(
@NonNull AUTIdentifier autID,
@NonNull ToolkitInfo information) {
+ Validate.notNull(autID, "The AUT-Identifier must not be null."); //$NON-NLS-1$
+ Validate.notNull(information, "The toolkit information must not be null."); //$NON-NLS-1$
+
return new AUTImpl((AutIdentifier) autID, information);
}
} \ No newline at end of file
diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTImpl.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTImpl.java
index 4aa402ad4..6627c65b9 100644
--- a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTImpl.java
+++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTImpl.java
@@ -12,6 +12,7 @@ package org.eclipse.jubula.client.internal.impl;
import java.util.Map;
+import org.apache.commons.lang.Validate;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jubula.client.AUT;
@@ -61,6 +62,8 @@ public class AUTImpl implements AUT {
public AUTImpl(
@NonNull AutIdentifier autID,
@NonNull ToolkitInfo information) {
+ Validate.notNull(autID, "The AUT-Identifier must not be null."); //$NON-NLS-1$
+ Validate.notNull(information, "The toolkit information must not be null."); //$NON-NLS-1$
m_autID = autID;
setToolkitInformation((AbstractToolkitInfo)information);
@@ -68,15 +71,23 @@ public class AUTImpl implements AUT {
/** {@inheritDoc} */
public void connect() throws Exception {
- final Map<ComponentClass, String> typeMapping =
- getInformation().getTypeMapping();
- m_instance = AUTConnection.getInstance();
- m_instance.connectToAut(m_autID, typeMapping);
+ if (!isConnected()) {
+ final Map<ComponentClass, String> typeMapping =
+ getInformation().getTypeMapping();
+ m_instance = AUTConnection.getInstance();
+ m_instance.connectToAut(m_autID, typeMapping);
+ } else {
+ throw new IllegalStateException("AUT connection is already made"); //$NON-NLS-1$
+ }
}
/** {@inheritDoc} */
public void disconnect() throws Exception {
- m_instance.close();
+ if (isConnected()) {
+ m_instance.close();
+ } else {
+ throw new IllegalStateException("AUT connection is already disconnected"); //$NON-NLS-1$
+ }
}
/** {@inheritDoc} */
@@ -89,8 +100,8 @@ public class AUTImpl implements AUT {
return m_autID;
}
- /** {@inheritDoc} */
- public void setToolkitInformation(AbstractToolkitInfo information) {
+ /** @param information the toolkit information to set */
+ private void setToolkitInformation(AbstractToolkitInfo information) {
m_information = information;
}
@@ -106,6 +117,7 @@ public class AUTImpl implements AUT {
@NonNull CAP cap,
@Nullable T payload)
throws ExecutionException {
+ Validate.notNull(cap, "The CAP must not be null."); //$NON-NLS-1$
final ResultImpl<T> result = new ResultImpl<T>(cap, payload);
try {
diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ObjectMappingImpl.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ObjectMappingImpl.java
index 93a5c8cd6..28a9f4c97 100644
--- a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ObjectMappingImpl.java
+++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ObjectMappingImpl.java
@@ -16,6 +16,9 @@ import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
+import org.apache.commons.lang.Validate;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jubula.client.ObjectMapping;
import org.eclipse.jubula.client.exceptions.LoadResourceException;
import org.eclipse.jubula.client.internal.utils.SerilizationUtils;
@@ -46,6 +49,8 @@ public class ObjectMappingImpl implements ObjectMapping {
*/
public ObjectMappingImpl(InputStream input) {
super();
+ Validate.notNull(input, "The input stream must not be null."); //$NON-NLS-1$
+
try {
m_objectMappingAssociations.load(input);
for (Object obj : m_objectMappingAssociations.keySet()) {
@@ -69,7 +74,9 @@ public class ObjectMappingImpl implements ObjectMapping {
}
/** {@inheritDoc} */
- public ComponentIdentifier get(String compName) {
+ @Nullable public ComponentIdentifier get(@NonNull String compName) {
+ Validate.notNull(compName, "The component name must not be null."); //$NON-NLS-1$
+
return m_map.get(compName);
}
diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ResultImpl.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ResultImpl.java
index bfc7386d6..085c5b5f8 100644
--- a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ResultImpl.java
+++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/ResultImpl.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.jubula.client.internal.impl;
+import org.apache.commons.lang.Validate;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jubula.client.Result;
@@ -37,6 +38,8 @@ public class ResultImpl<T> implements Result<T> {
* the payload to use
*/
public ResultImpl(@NonNull CAP cap, @Nullable T payload) {
+ Validate.notNull(cap, "The CAP must not be null."); //$NON-NLS-1$
+
m_cap = cap;
m_payload = payload;
}

Back to the top