Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Tiede2014-10-13 09:17:24 +0000
committerMarkus Tiede2014-10-15 07:18:19 +0000
commit31dc7233d75768a2883e0314b847ecfc4e68b6c9 (patch)
tree04e4b089e783fa255e8dbce90a01e8afb79f12a0 /org.eclipse.jubula.client.api
parent5c5aaaffd0e80c47f92c5cb75f8542c77fe81653 (diff)
downloadorg.eclipse.jubula.core-31dc7233d75768a2883e0314b847ecfc4e68b6c9.tar.gz
org.eclipse.jubula.core-31dc7233d75768a2883e0314b847ecfc4e68b6c9.tar.xz
org.eclipse.jubula.core-31dc7233d75768a2883e0314b847ecfc4e68b6c9.zip
Sprint task - provide API: implement connect to AUT via API - part 1.
Diffstat (limited to 'org.eclipse.jubula.client.api')
-rw-r--r--org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/AUTAgent.java6
-rw-r--r--org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/Remote.java2
-rw-r--r--org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/AUTConnection.java163
-rw-r--r--org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/BaseAUTConnection.java117
-rw-r--r--org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTAgentImpl.java6
-rw-r--r--org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTImpl.java49
6 files changed, 342 insertions, 1 deletions
diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/AUTAgent.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/AUTAgent.java
index 7b765fbcb..4337cc64e 100644
--- a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/AUTAgent.java
+++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/AUTAgent.java
@@ -40,4 +40,10 @@ public interface AUTAgent extends Remote {
* in case of a communication problem
*/
List<AutIdentifier> getAllRegisteredAUTIdentifier() throws Exception;
+
+ /**
+ * @param autID the autID to get an AUT for
+ * @return an AUT
+ */
+ AUT getAUT(AutIdentifier autID);
} \ No newline at end of file
diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/Remote.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/Remote.java
index 5c9d719bc..a655daede 100644
--- a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/Remote.java
+++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/Remote.java
@@ -20,7 +20,7 @@ public interface Remote {
/**
* disconnect from the remote side
*/
- void disconnect();
+ void disconnect() throws Exception;
/**
* @return whether a connection to the remote side is currently established
diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/AUTConnection.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/AUTConnection.java
new file mode 100644
index 000000000..8a3901f4a
--- /dev/null
+++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/AUTConnection.java
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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 org.eclipse.jubula.client.internal.exceptions.ConnectionException;
+import org.eclipse.jubula.communication.internal.message.ConnectToAutMessage;
+import org.eclipse.jubula.tools.internal.constants.EnvConstants;
+import org.eclipse.jubula.tools.internal.exception.CommunicationException;
+import org.eclipse.jubula.tools.internal.exception.JBVersionException;
+import org.eclipse.jubula.tools.internal.registration.AutIdentifier;
+import org.eclipse.jubula.tools.internal.utils.TimeUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This class represents the connection to the AUTServer which controls the
+ * application under test.
+ *
+ * This class is implemented as a singleton. The server configuration contains
+ * detailed information, how this instance can be contacted.
+ *
+ * @author BREDEX GmbH
+ * @created 22.07.2004
+ */
+public class AUTConnection extends BaseAUTConnection {
+ /** the logger */
+ static final Logger LOGGER = LoggerFactory.getLogger(AUTConnection.class);
+
+ /** the singleton instance */
+ private static AUTConnection instance = null;
+
+ /**
+ * private constructor. creates a communicator
+ *
+ * @throws ConnectionException
+ * containing a detailed message why the connection could not
+ * initialized
+ */
+ private AUTConnection() throws ConnectionException {
+ super();
+ }
+
+ /**
+ * Method to get the single instance of this class.
+ *
+ * @throws ConnectionException
+ * if an error occurs during initialization.
+ * @return the instance of this Singleton
+ */
+ public static synchronized AUTConnection getInstance()
+ throws ConnectionException {
+
+ if (instance == null) {
+ instance = new AUTConnection();
+ }
+ return instance;
+ }
+
+ /**
+ * Resets this singleton: Closes the communicator
+ * removes the listeners.<br>
+ * <b>Note: </b><br>
+ * This method is used by the Restart-AUT-Action only to avoid errors while
+ * reconnecting with the AUTServer.<br>
+ * This is necessary because the disconnect from the AUTServer is implemented
+ * badly which will be corrected in a future version!
+ */
+ public synchronized void reset() {
+ super.reset();
+
+ instance = null;
+ }
+
+ /**
+ * Establishes a connection to the Running AUT with the given ID.
+ *
+ * @param autId The ID of the Running AUT to connect to.
+ * @return <code>true</code> if a connection to the AUT could be
+ * established. Otherwise <code>false</code>.
+ */
+ public boolean connectToAut(AutIdentifier autId) {
+ if (!isConnected()) {
+ try {
+ LOGGER.info("Establishing connection to AUT..."); //$NON-NLS-1$
+ run();
+ final AutAgentConnection autAgent = AutAgentConnection
+ .getInstance();
+ autAgent.getCommunicator().send(
+ new ConnectToAutMessage(
+ EnvConstants.LOCALHOST_FQDN,
+ getCommunicator().getLocalPort(), autId));
+
+ long startTime = System.currentTimeMillis();
+ while (!isConnected()
+ && autAgent.isConnected()
+ && startTime + CONNECT_TO_AUT_TIMEOUT > System
+ .currentTimeMillis()) {
+ TimeUtil.delay(200);
+ }
+ if (isConnected()) {
+ setConnectedAutId(autId);
+ LOGGER.info("Connection to AUT established."); //$NON-NLS-1$
+// AUTStartedCommand response = new AUTStartedCommand();
+// response.setStateMessage(new AUTStateMessage(
+// AUTStateMessage.RUNNING));
+// setup(response);
+ return true;
+ }
+ LOGGER.error("Connection to AUT could not be established."); //$NON-NLS-1$
+ } catch (CommunicationException e) {
+ LOGGER.error("Error occurred while establishing connection to AUT.", e); //$NON-NLS-1$
+ } catch (JBVersionException e) {
+ LOGGER.error("Error occurred while establishing connection to AUT.", e); //$NON-NLS-1$
+ }
+ } else {
+ LOGGER.warn("Cannot establish new connection to AUT: Connection to AUT already exists."); //$NON-NLS-1$
+ }
+ return false;
+ }
+
+// /**
+// * setup the connection between API and AUT
+// *
+// * @param command
+// * the command to execute on callback
+// * @throws NotConnectedException
+// * if there is no connection to an AUT.
+// * @throws ConnectionException
+// * if no connection to an AUT could be initialized.
+// * @throws CommunicationException
+// * if an error occurs while communicating with the AUT.
+// */
+// public void setup(AUTStartedCommand command)
+// throws NotConnectedException, ConnectionException,
+// CommunicationException {
+// sendKeyboardLayoutToAUT();
+// sendResourceBundlesToAUT();
+// getAllComponentsFromAUT(command);
+// }
+//
+// /**
+// * send the resource bundles to the AUT
+// */
+// private void sendResourceBundlesToAUT() {
+// System.err.println("sendResourceBundlesToAUT()");
+// }
+//
+// /**
+// * send the keyboard layout to the AUT
+// */
+// private void sendKeyboardLayoutToAUT() {
+// System.err.println("sendKeyboardLayoutToAUT()");
+// }
+} \ No newline at end of file
diff --git a/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/BaseAUTConnection.java b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/BaseAUTConnection.java
new file mode 100644
index 000000000..4ec5ef813
--- /dev/null
+++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/BaseAUTConnection.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.io.IOException;
+
+import org.eclipse.jubula.client.internal.exceptions.ConnectionException;
+import org.eclipse.jubula.communication.internal.Communicator;
+import org.eclipse.jubula.tools.internal.messagehandling.MessageIDs;
+import org.eclipse.jubula.tools.internal.registration.AutIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** @author BREDEX GmbH */
+public class BaseAUTConnection extends BaseConnection {
+ /**
+ * the timeout used for establishing a connection to a running AUT
+ */
+ public static final int CONNECT_TO_AUT_TIMEOUT = 10000;
+
+ /** the logger */
+ static final Logger LOG = LoggerFactory.getLogger(BaseAUTConnection.class);
+
+ /**
+ * The ID of the running AUT with which a connection is currently
+ * established.
+ */
+ private AutIdentifier m_connectedAutId;
+
+ /**
+ * Constructor
+ *
+ * @throws ConnectionException
+ * containing a detailed message why the connection could not
+ * initialized
+ */
+ public BaseAUTConnection() throws ConnectionException {
+ try {
+ // create a communicator on any free port
+ Communicator communicator = new Communicator(0, this.getClass()
+ .getClassLoader());
+ communicator.setIsServerSocketClosable(false);
+ setCommunicator(communicator);
+ } catch (IOException ioe) {
+ handleInitError(ioe);
+ } catch (SecurityException se) {
+ handleInitError(se);
+ }
+ }
+
+ /**
+ * handles the fatal errors occurs during initialization
+ *
+ * @param throwable
+ * the occurred exception
+ * @throws ConnectionException
+ * a ConnectionException containing a detailed message
+ */
+ private void handleInitError(Throwable throwable)
+ throws ConnectionException {
+ String message = "Initialisation of AUTConnection failed: "; //$NON-NLS-1$
+ LOG.error(message, throwable);
+ throw new ConnectionException(message + throwable.getMessage(),
+ MessageIDs.E_AUT_CONNECTION_INIT);
+ }
+
+ /**
+ *
+ * @return the ID of the currently connected AUT, or <code>null</code> if
+ * there is currently no connection to an AUT.
+ */
+ public AutIdentifier getConnectedAutId() {
+ return m_connectedAutId;
+ }
+
+ /**
+ * Disconnects from the currently connected Running AUT. If no connection
+ * currently exists, this method is a no-op.
+ */
+ protected void disconnectFromAut() {
+ setConnectedAutId(null);
+ }
+
+ /**
+ * @param connectedAutId the connectedAutId to set
+ */
+ protected void setConnectedAutId(AutIdentifier connectedAutId) {
+ m_connectedAutId = connectedAutId;
+ }
+
+ /**
+ * Resets this singleton: Closes the communicator
+ * removes the listeners.<br>
+ * <b>Note: </b><br>
+ * This method is used by the Restart-AUT-Action only to avoid errors while
+ * reconnecting with the AUTServer.<br>
+ * This is necessary because the disconnect from the AUTServer is implemented
+ * badly which will be corrected in a future version!
+ */
+ public synchronized void reset() {
+ Communicator communicator = getCommunicator();
+ if (communicator != null) {
+ communicator.setIsServerSocketClosable(true);
+ communicator.interruptAllTimeouts();
+ communicator.clearListeners();
+ communicator.close();
+ }
+ }
+} \ No newline at end of file
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 c52970516..fb2e5ef04 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
@@ -15,6 +15,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
+import org.eclipse.jubula.client.AUT;
import org.eclipse.jubula.client.AUTAgent;
import org.eclipse.jubula.client.internal.AutAgentConnection;
import org.eclipse.jubula.client.internal.Synchronizer;
@@ -142,4 +143,9 @@ public class AUTAgentImpl implements AUTAgent {
return null;
}
+
+ /** {@inheritDoc} */
+ public AUT getAUT(AutIdentifier autID) {
+ return new AUTImpl(autID);
+ }
} \ 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
new file mode 100644
index 000000000..0c67ed5f7
--- /dev/null
+++ b/org.eclipse.jubula.client.api/src/org/eclipse/jubula/client/internal/impl/AUTImpl.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.impl;
+
+import org.eclipse.jubula.client.AUT;
+import org.eclipse.jubula.client.internal.AUTConnection;
+import org.eclipse.jubula.tools.internal.registration.AutIdentifier;
+
+/** @author BREDEX GmbH */
+public class AUTImpl implements AUT {
+ /** the AUT identifier */
+ private AutIdentifier m_autID;
+ /** the instance */
+ private AUTConnection m_instance;
+
+ /**
+ * Constructor
+ *
+ * @param autID
+ * the identifier to use for connection
+ */
+ public AUTImpl(AutIdentifier autID) {
+ m_autID = autID;
+ }
+
+ /** {@inheritDoc} */
+ public void connect() throws Exception {
+ m_instance = AUTConnection.getInstance();
+ m_instance.connectToAut(m_autID);
+ }
+
+ /** {@inheritDoc} */
+ public void disconnect() throws Exception {
+ m_instance.close();
+ }
+
+ /** {@inheritDoc} */
+ public boolean isConnected() {
+ return m_instance != null ? m_instance.isConnected() : false;
+ }
+} \ No newline at end of file

Back to the top