Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2015-09-21 04:05:03 -0400
committerXavier Coulon2015-11-03 15:39:21 -0500
commita9a65b73f50d13db8147199b8f663de24fbf3e86 (patch)
treeb3867db95843f6ed6a0fe8dbb9ed7ec69a7ce428
parent91cfeea5a294d419d94a300f540bcee1ff2f0c95 (diff)
downloadorg.eclipse.linuxtools-a9a65b73f50d13db8147199b8f663de24fbf3e86.tar.gz
org.eclipse.linuxtools-a9a65b73f50d13db8147199b8f663de24fbf3e86.tar.xz
org.eclipse.linuxtools-a9a65b73f50d13db8147199b8f663de24fbf3e86.zip
Bug 477912 - Mock the Docker daemon in unit tests
- Refactoring the code to move the logic of discovering connection settings into a new interface/implementation. - Added a hierarchy of connection settings classes for Unix sockets vs TCP - New pluggable utility class to discover connection settings - Refactored the ConnectionManager by moving the storage logic (load/save connections) in an external class that implements the new IDockerConnectionStorageManager interface - In unit tests, the interfaces mentionned above are mocked to return anything needed (no connection, valid socket, etc.) - Added a bundle to wrap the org.hamcrest dependencies and expose a single exported package for Mockito. (See https://bugs.eclipse.org/bugs/show_bug.cgi?id=403676#c10) Change-Id: I3dcfcd674ab8c17eff63d037a7a1d6f2250e1677 Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/56859 Tested-by: Hudson CI
-rw-r--r--.gitignore1
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/.classpath4
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/META-INF/MANIFEST.MF2
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java183
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnectionSettings.java40
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnectionSettingsFinder.java23
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnectionStorageManager.java36
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Messages.properties2
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/BaseConnectionSettings.java42
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultDockerConnectionSettingsFinder.java377
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultDockerConnectionStorageManager.java142
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java4
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/TCPConnectionSettings.java78
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/UnixSocketConnectionSettings.java45
-rw-r--r--containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.classpath7
-rw-r--r--containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.project34
-rw-r--r--containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.settings/org.eclipse.core.resources.prefs2
-rw-r--r--containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.settings/org.eclipse.m2e.core.prefs4
-rw-r--r--containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/META-INF/MANIFEST.MF9
-rw-r--r--containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/README.adoc4
-rw-r--r--containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/build.properties3
-rw-r--r--containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/pom.xml13
-rw-r--r--containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/src/org/hamcrest/package-info.java15
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/.classpath4
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/.project6
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/.settings/org.eclipse.core.resources.prefs2
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/.settings/org.eclipse.m2e.core.prefs4
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/META-INF/MANIFEST.MF23
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/pom.xml97
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/BaseSWTBotTest.java54
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionFactory.java40
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionSettingsFinder.java68
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionStorageManagerFactory.java40
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/package-info.java15
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/AbstractSWTBotAssertion.java47
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/CheckBoxAssertion.java46
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerExplorerViewAssertion.java47
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/RadioAssertion.java46
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/TextAssertion.java47
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/package-info.java15
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java74
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/package-info.java15
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionSWTBotTest.java137
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/META-INF/MANIFEST.MF1
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerView.java18
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java49
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPageModel.java4
-rw-r--r--containers/pom.xml1
49 files changed, 1805 insertions, 172 deletions
diff --git a/.gitignore b/.gitignore
index 36eb334b8c..46a867a3bd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ target/
bin/
**/screenshots
*.pxm
+lib
diff --git a/containers/org.eclipse.linuxtools.docker.core/.classpath b/containers/org.eclipse.linuxtools.docker.core/.classpath
index 46cec6ed2a..f2156e9916 100644
--- a/containers/org.eclipse.linuxtools.docker.core/.classpath
+++ b/containers/org.eclipse.linuxtools.docker.core/.classpath
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src/"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
diff --git a/containers/org.eclipse.linuxtools.docker.core/META-INF/MANIFEST.MF b/containers/org.eclipse.linuxtools.docker.core/META-INF/MANIFEST.MF
index 65bf44413e..4dbe1fa1d3 100644
--- a/containers/org.eclipse.linuxtools.docker.core/META-INF/MANIFEST.MF
+++ b/containers/org.eclipse.linuxtools.docker.core/META-INF/MANIFEST.MF
@@ -21,7 +21,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.10.0",
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.linuxtools.docker.core,
- org.eclipse.linuxtools.internal.docker.core;x-friends:="org.eclipse.linuxtools.docker.ui"
+ org.eclipse.linuxtools.internal.docker.core;x-friends:="org.eclipse.linuxtools.docker.ui,org.eclipse.linuxtools.docker.ui.tests"
Import-Package: com.fasterxml.jackson.annotation;version="2.5.0",
org.eclipse.jface.preference
Bundle-ClassPath: .
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java
index 4d5c420701..9c7a6309f3 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java
@@ -10,168 +10,60 @@
*******************************************************************************/
package org.eclipse.linuxtools.docker.core;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.eclipse.core.runtime.IPath;
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ListenerList;
-import org.eclipse.equinox.security.storage.ISecurePreferences;
-import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
-import org.eclipse.equinox.security.storage.StorageException;
-import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.internal.docker.core.DefaultDockerConnectionSettingsFinder;
+import org.eclipse.linuxtools.internal.docker.core.DefaultDockerConnectionStorageManager;
public class DockerConnectionManager {
- public final static String CONNECTIONS_FILE_NAME = "dockerconnections.xml"; //$NON-NLS-1$
-
private static DockerConnectionManager instance;
- private ArrayList<IDockerConnection> connections;
+ private List<IDockerConnection> connections;
private ListenerList connectionManagerListeners;
- private DockerConnectionManager() {
- connections = new ArrayList<>();
- loadConnections();
- }
+ private IDockerConnectionSettingsFinder connectionSettingsFinder = new DefaultDockerConnectionSettingsFinder();
+ private IDockerConnectionStorageManager connectionStorageManager = new DefaultDockerConnectionStorageManager();
- static public DockerConnectionManager getInstance() {
- if (instance == null)
+ public static DockerConnectionManager getInstance() {
+ if (instance == null) {
instance = new DockerConnectionManager();
-
+ }
return instance;
}
- private void loadConnections() {
- IPath stateLocation = Activator.getDefault().getStateLocation();
- File connectionFile = stateLocation.append(CONNECTIONS_FILE_NAME)
- .toFile();
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- try {
- DocumentBuilder db = dbf.newDocumentBuilder();
- if (connectionFile.exists()) {
- Document d = db.parse(connectionFile);
- Element e = d.getDocumentElement();
- // Get the stored configuration data
- NodeList connectionNodes = e.getElementsByTagName("connection"); // $NON-NLS-1$
- for (int x = 0; x < connectionNodes.getLength(); ++x) {
- Node n = connectionNodes.item(x);
- NamedNodeMap attrs = n.getAttributes();
- Node nameNode = attrs.getNamedItem("name"); //$NON-NLS-1$
- Node uriNode = attrs.getNamedItem("uri"); //$NON-NLS-1$
- Node usernameNode = attrs.getNamedItem("username"); //$NON-NLS-1$
- Node certNode = attrs.getNamedItem("cert"); //$NON-NLS-1$
- if (uriNode != null) {
- String uri = uriNode.getNodeValue();
- String name = nameNode.getNodeValue();
-
- if (usernameNode != null) {
- String username = usernameNode.getNodeValue();
- String key = DockerConnection.getPreferencesKey(
- uri, username);
- ISecurePreferences root = SecurePreferencesFactory
- .getDefault();
- ISecurePreferences node = root.node(key);
- @SuppressWarnings("unused")
- String password;
- try {
- password = node.get("password", null); //$NON-NLS-1$
- } catch (StorageException e1) {
- e1.printStackTrace();
- }
- }
-
- DockerConnection.Builder builder = new DockerConnection.Builder()
- .name(name);
- if (uri.startsWith("unix:")) { //$NON-NLS-1$
- builder = builder.unixSocket(uri);
- } else {
- builder = builder.tcpHost(uri);
- if (certNode != null) {
- String cert = certNode.getNodeValue();
- builder = builder.tcpCertPath(cert);
- }
- }
- try {
- DockerConnection connection = builder.build();
- addConnection(connection);
- } catch (DockerException e1) {
- Activator.log(e1);
- }
- }
- }
+ private DockerConnectionManager() {
+ reloadConnections();
+ }
+
+ public void reloadConnections() {
+ this.connections = connectionStorageManager.loadConnections();
+ for (IDockerConnection connection : connections) {
+ try {
+ connection.open(true);
+ } catch (DockerException e) {
+ Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ e.getMessage()));
}
- } catch (ParserConfigurationException e) {
- Activator.log(e);
- } catch (SAXException e) {
- Activator.log(e);
- } catch (IOException e) {
- Activator.log(e);
}
+ notifyListeners(IDockerConnectionManagerListener.ADD_EVENT);
+ }
- /*if (connections.size() == 0) {
- // create a new connection from the UI preferences
- final IEclipsePreferences preferences = InstanceScope.INSTANCE
- .getNode("org.eclipse.linuxtools.docker.ui"); //$NON-NLS-1$
- final int bindingMode = preferences.getInt(BINDING_MODE, UNIX_SOCKET);
- try {
- if(bindingMode == UNIX_SOCKET) {
- final String unixSocketPath = preferences.get(UNIX_SOCKET_PATH, DEFAULT_UNIX_SOCKET_PATH);
- connections.add(new DockerConnection.Builder().unixSocket(unixSocketPath).build());
- } else {
- final String tcpHost = preferences.get(TCP_HOST, null);
- final String tcpCertPath = preferences.get(TCP_CERT_PATH, null);
- connections.add(new DockerConnection.Builder().tcpHost(tcpHost).tcpCertPath(tcpCertPath).build()); //$NON-NLS-1$
- }
- } catch (DockerCertificateException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } //$NON-NLS-1$
- }*/
+ public void setConnectionSettingsFinder(
+ final IDockerConnectionSettingsFinder connectionSettingsFinder) {
+ this.connectionSettingsFinder = connectionSettingsFinder;
+ }
+
+ public void setConnectionStorageManager(
+ final IDockerConnectionStorageManager connectionStorageManager) {
+ this.connectionStorageManager = connectionStorageManager;
}
public void saveConnections() {
- try {
- IPath stateLocation = Activator.getDefault().getStateLocation();
- File ConnectionFile = stateLocation.append(CONNECTIONS_FILE_NAME)
- .toFile();
- if (!ConnectionFile.exists())
- ConnectionFile.createNewFile();
- if (ConnectionFile.exists()) {
- PrintWriter p = new PrintWriter(new BufferedWriter(
- new FileWriter(ConnectionFile)));
- p.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$
- p.println("<connections>"); // $NON-NLS-1$
- for (IDockerConnection d : connections) {
- p.print("<connection name=\"" + d.getName() + //$NON-NLS-1$
- "\" uri=\"" + d.getUri()); //$NON-NLS-1$
- if (d.getUsername() != null) {
- p.print("\" username=\"" + d.getUsername()); //$NON-NLS-1$
- }
- if (d.getTcpCertPath() != null) {
- p.print("\" cert=\"" + d.getTcpCertPath()); //$NON-NLS-1$
- }
- p.println("\"/>");
- }
- p.println("</connections>"); //$NON-NLS-1$
- p.close();
- }
- } catch (Exception e) {
- Activator.log(e);
- }
+ this.connectionStorageManager.saveConnections(this.connections);
}
public IDockerConnection[] getConnections() {
@@ -231,4 +123,9 @@ public class DockerConnectionManager {
}
}
+ public List<IDockerConnectionSettings> findConnectionSettings() {
+ // delegate the call to a utility class.
+ return connectionSettingsFinder.findConnectionSettings();
+ }
+
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnectionSettings.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnectionSettings.java
new file mode 100644
index 0000000000..962c4ed1bb
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnectionSettings.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.docker.core;
+
+/**
+ * Settings for an {@link IDockerConnection}
+ */
+public interface IDockerConnectionSettings {
+
+ public enum BindingType {
+ UNIX_SOCKET_CONNECTION, TCP_CONNECTION;
+ }
+
+ /**
+ * @return the type of binding
+ */
+ public abstract BindingType getType();
+
+ /**
+ * @return the name of the Docker daemon
+ */
+ public abstract String getName();
+
+ /**
+ * @return <code>true</code> if the connection could be established and
+ * Docker daemon responded to a 'ping' request, <code>false</code>
+ * otherwise.
+ */
+ public abstract boolean isSettingsResolved();
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnectionSettingsFinder.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnectionSettingsFinder.java
new file mode 100644
index 0000000000..e5c6416028
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnectionSettingsFinder.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+package org.eclipse.linuxtools.docker.core;
+
+import java.util.List;
+
+/**
+ * Interface for Docker Connection Settings finder utilities. This bundle
+ * provides a default implementation, which can be replaced if needed (hint: for
+ * testing purposes)
+ */
+public interface IDockerConnectionSettingsFinder {
+
+ public List<IDockerConnectionSettings> findConnectionSettings();
+}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnectionStorageManager.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnectionStorageManager.java
new file mode 100644
index 0000000000..3af0e8d70a
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/IDockerConnectionStorageManager.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.docker.core;
+
+import java.util.List;
+
+/**
+ * Manager that takes care of loading and saving connections settings in a file.
+ */
+public interface IDockerConnectionStorageManager {
+
+ /**
+ * Loads connections from the underlying file
+ *
+ * @return {@link List} of {@link IDockerConnection}
+ */
+ public List<IDockerConnection> loadConnections();
+
+ /**
+ * Saves the given {@link List} of {@link IDockerConnection} into a file
+ *
+ * @param connections
+ * the connections to save
+ */
+ public void saveConnections(List<IDockerConnection> connections);
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Messages.properties b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Messages.properties
index 38168d3171..8ff695386b 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Messages.properties
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/Messages.properties
@@ -21,7 +21,7 @@ Removal_In_Progress_specifier=Removal In Progress
Missing_Default_Settings=Could not find default settings to connect to a local Docker daemon
Missing_Settings=Unable to open a new client to the Docker daemon: missing configuration
Retrieve_Default_Settings_Failure=Failed to retrieve default connection settings
-Open_Connection_Failure=Failed to open a connection
+Open_Connection_Failure=Failed to open connection '''{0}'''
Docker_Daemon_Ping_Failure=Failed to ping the Docker daemon
Retrieve_Docker_Certificates_Failure=Unable to retrieve certificates to connect to the Docker daemon
List_Docker_Containers_Failure=Failed to load list of Docker containers from {0}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/BaseConnectionSettings.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/BaseConnectionSettings.java
new file mode 100644
index 0000000000..49c181265e
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/BaseConnectionSettings.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.docker.core;
+
+import org.eclipse.linuxtools.docker.core.IDockerConnectionSettings;
+
+public abstract class BaseConnectionSettings
+ implements IDockerConnectionSettings {
+
+ /** the connection name. */
+ private String name = null;
+
+ /** flag indicating if the Docker responded to a ping request. */
+ private boolean settingsResolved = false;
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ public void setSettingsResolved(boolean settingsResolved) {
+ this.settingsResolved = settingsResolved;
+ }
+
+ @Override
+ public boolean isSettingsResolved() {
+ return this.settingsResolved;
+ }
+
+} \ No newline at end of file
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultDockerConnectionSettingsFinder.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultDockerConnectionSettingsFinder.java
new file mode 100644
index 0000000000..571fcddb09
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultDockerConnectionSettingsFinder.java
@@ -0,0 +1,377 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.core;
+
+import static org.eclipse.linuxtools.docker.core.EnumDockerConnectionSettings.BINDING_MODE;
+import static org.eclipse.linuxtools.docker.core.EnumDockerConnectionSettings.TCP_CERT_PATH;
+import static org.eclipse.linuxtools.docker.core.EnumDockerConnectionSettings.TCP_HOST;
+import static org.eclipse.linuxtools.docker.core.EnumDockerConnectionSettings.TCP_TLS_VERIFY;
+import static org.eclipse.linuxtools.docker.core.EnumDockerConnectionSettings.UNIX_SOCKET;
+import static org.eclipse.linuxtools.docker.core.EnumDockerConnectionSettings.UNIX_SOCKET_PATH;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.docker.core.Activator;
+import org.eclipse.linuxtools.docker.core.DockerException;
+import org.eclipse.linuxtools.docker.core.EnumDockerConnectionSettings;
+import org.eclipse.linuxtools.docker.core.IDockerConnection;
+import org.eclipse.linuxtools.docker.core.IDockerConnectionInfo;
+import org.eclipse.linuxtools.docker.core.IDockerConnectionSettings;
+import org.eclipse.linuxtools.docker.core.IDockerConnectionSettingsFinder;
+import org.eclipse.linuxtools.docker.core.Messages;
+
+import jnr.unixsocket.UnixSocketAddress;
+import jnr.unixsocket.UnixSocketChannel;
+
+/**
+ * A utility class that looks for candidate {@link IDockerConnection}s on the
+ * host system.
+ */
+public class DefaultDockerConnectionSettingsFinder
+ implements IDockerConnectionSettingsFinder {
+
+ public static final String DOCKER_CERT_PATH = "DOCKER_CERT_PATH"; //$NON-NLS-1$
+ public static final String DOCKER_TLS_VERIFY = "DOCKER_TLS_VERIFY"; //$NON-NLS-1$
+ public static final String DOCKER_TLS_VERIFY_TRUE = "1"; //$NON-NLS-1$
+ public static final String DOCKER_HOST = "DOCKER_HOST"; //$NON-NLS-1$
+
+ @Override
+ public List<IDockerConnectionSettings> findConnectionSettings() {
+ final List<IDockerConnectionSettings> availableConnectionSettings = new ArrayList<>();
+ final IDockerConnectionSettings defaultsWithUnixSocket = defaultsWithUnixSocket();
+ if (defaultsWithUnixSocket != null) {
+ availableConnectionSettings.add(defaultsWithUnixSocket);
+ }
+ final IDockerConnectionSettings defaultsWithSystemEnv = defaultsWithSystemEnv();
+ if (defaultsWithSystemEnv != null) {
+ availableConnectionSettings.add(defaultsWithSystemEnv);
+ }
+ final IDockerConnectionSettings defaultsWithShellEnv = defaultsWithShellEnv();
+ if (defaultsWithShellEnv != null) {
+ availableConnectionSettings.add(defaultsWithShellEnv);
+ }
+ // now that we have connection settings, let's ping them and retrieve the connection info.
+ for (IDockerConnectionSettings connectionSettings : availableConnectionSettings) {
+ switch(connectionSettings.getType()) {
+ case UNIX_SOCKET_CONNECTION:
+ final UnixSocketConnectionSettings unixSocketConnectionSettings = (UnixSocketConnectionSettings) connectionSettings;
+ final DockerConnection unixSocketConnection = new DockerConnection.Builder()
+ .unixSocket(unixSocketConnectionSettings.getPath())
+ .build();
+ resolveDockerName(unixSocketConnectionSettings,
+ unixSocketConnection);
+ break;
+ case TCP_CONNECTION:
+ final TCPConnectionSettings tcpConnectionSettings = (TCPConnectionSettings) connectionSettings;
+ final DockerConnection tcpConnection = new DockerConnection.Builder()
+ .tcpHost(tcpConnectionSettings.getHost())
+ .tcpCertPath(
+ tcpConnectionSettings.getPathToCertificates())
+ .build();
+ resolveDockerName(tcpConnectionSettings, tcpConnection);
+ break;
+ }
+ }
+ return availableConnectionSettings;
+ }
+
+ private void resolveDockerName(
+ final BaseConnectionSettings connectionSettings,
+ final DockerConnection connection) {
+ try {
+ connection.open(false);
+ final IDockerConnectionInfo info = connection.getInfo();
+ if (info != null) {
+ connectionSettings.setName(info.getName());
+ connectionSettings.setSettingsResolved(true);
+ }
+ } catch (DockerException e) {
+ // ignore and keep 'settingsResolved' to false
+ connectionSettings.setSettingsResolved(false);
+ } finally {
+ connection.close();
+ }
+ }
+
+ /**
+ * Checks if there is a Unix socket available at the given location
+ *
+ * @return {@code IDockerConnectionSettings} if the Unix socket exists and
+ * is readable and writable, {@code null} otherwise.
+ */
+ private IDockerConnectionSettings defaultsWithUnixSocket() {
+ final File unixSocketFile = new File("/var/run/docker.sock"); //$NON-NLS-1$
+ if (unixSocketFile.exists() && unixSocketFile.canRead()
+ && unixSocketFile.canWrite()) {
+ final UnixSocketAddress address = new UnixSocketAddress(
+ unixSocketFile);
+ try (final UnixSocketChannel channel = UnixSocketChannel
+ .open(address)) {
+ // assume socket works
+ return new UnixSocketConnectionSettings(
+ unixSocketFile.getAbsolutePath());
+ } catch (IOException e) {
+ // do nothing, just assume socket did not work.
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Checks if there are {@code DOCKER_xxx} environment variables in the
+ * current Eclipse process.
+ *
+ * @return {@code IDockerConnectionSettings} if the {@code DOCKER_xxx}
+ * environment variables exist, {@code null} otherwise.
+ */
+ private IDockerConnectionSettings defaultsWithSystemEnv() {
+ final String dockerHostEnv = System.getenv(DOCKER_HOST);
+ if (dockerHostEnv != null) {
+ final String tlsVerifyEnv = System.getenv(DOCKER_TLS_VERIFY);
+ final boolean useTls = tlsVerifyEnv != null
+ && tlsVerifyEnv.equals(DOCKER_TLS_VERIFY_TRUE); // $NON-NLS-1$
+ final String pathToCertificates = System.getenv(DOCKER_CERT_PATH);
+ return new TCPConnectionSettings(dockerHostEnv, useTls,
+ pathToCertificates);
+ }
+ return null;
+ }
+
+ /**
+ * Checks if there are {@code DOCKER_xxx} environment variables when running
+ * a script in a shell.
+ *
+ * @return {@code IDockerConnectionSettings} if the {@code DOCKER_xxx}
+ * environment variables exist, {@code null} otherwise.
+ * @throws DockerException
+ */
+ private IDockerConnectionSettings defaultsWithShellEnv() {
+ try {
+ final String connectionSettingsDetectionScriptName = getConnectionSettingsDetectionScriptName();
+ if (connectionSettingsDetectionScriptName == null) {
+ Activator.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID,
+ Messages.Docker_No_Settings_Description_Script));
+ return null;
+ }
+ final File connectionSettingsDetectionScript = getConnectionSettingsDetectionScript(
+ connectionSettingsDetectionScriptName);
+ final String[] cmdArray = getConnectionSettingsDetectionCommandArray(
+ connectionSettingsDetectionScript);
+ final Process process = Runtime.getRuntime().exec(cmdArray);
+ process.waitFor();
+ final int exitValue = process.exitValue();
+ if (exitValue == 0) {
+ final InputStream processInputStream = process.getInputStream();
+ // read content from process input stream
+ final Properties dockerSettings = new Properties();
+ dockerSettings.load(processInputStream);
+ final Object dockerHostEnvVariable = dockerSettings.get(DOCKER_HOST);
+ final Object dockerTlsVerifyEnvVariable = dockerSettings
+ .get(DOCKER_TLS_VERIFY);
+ final Object dockerCertPathEnvVariable = dockerSettings
+ .get(DOCKER_CERT_PATH);
+ return new TCPConnectionSettings(
+ dockerHostEnvVariable != null
+ ? dockerHostEnvVariable.toString() : null,
+ dockerTlsVerifyEnvVariable != null
+ ? dockerTlsVerifyEnvVariable
+ .equals(DOCKER_TLS_VERIFY_TRUE)
+ : null,
+ dockerCertPathEnvVariable != null
+ ? dockerCertPathEnvVariable.toString() : null);
+ } else {
+ // log what happened if the process did not end as expected
+ // an exit value of 1 should indicate no connection found
+ if (exitValue != 1) {
+ final InputStream processErrorStream = process
+ .getErrorStream();
+ final String errorMessage = streamToString(
+ processErrorStream);
+ Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ errorMessage));
+ }
+ }
+ } catch (IOException | IllegalArgumentException
+ | InterruptedException e) {
+ Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ Messages.Retrieve_Default_Settings_Failure, e));
+ }
+ return null;
+ }
+
+ /**
+ * @param script
+ * the script to execute
+ * @return the OS-specific command to run the connection settings
+ * detection script.
+ */
+ private String[] getConnectionSettingsDetectionCommandArray(
+ final File script) {
+ final String osName = System.getProperty("os.name"); //$NON-NLS-1$
+ if (osName.toLowerCase().startsWith("win")) { //$NON-NLS-1$
+ return new String[] { "cmd.exe", "/C", //$NON-NLS-1$ //$NON-NLS-2$
+ script.getAbsolutePath() };
+ } else if (osName.toLowerCase().startsWith("mac") //$NON-NLS-1$
+ || osName.toLowerCase().contains("linux") //$NON-NLS-1$
+ || osName.toLowerCase().contains("nix")) { //$NON-NLS-1$
+ return new String[] { script.getAbsolutePath() };
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Finds the script file in the data directory of the bundle given its
+ * name, or creates it from the 'resources' dir in the bundle if it was
+ * not found in the data dir.
+ *
+ * @param scriptName
+ * the name of the script to load in the data dir or in the
+ * 'resources' dir in the bundle
+ * @return the script {@link File}
+ */
+ private File getConnectionSettingsDetectionScript(
+ final String scriptName) {
+ final File script = Activator.getDefault().getBundle()
+ .getDataFile(scriptName);
+ // if the script file does not exist or is outdated.
+ if (script != null
+ && (!script.exists() || script.lastModified() < Activator
+ .getDefault().getBundle().getLastModified())) {
+ try (final FileOutputStream output = new FileOutputStream(
+ script);
+ final InputStream is = DockerConnection.class
+ .getResourceAsStream(
+ "/resources/" + scriptName)) { //$NON-NLS-1$
+ byte[] buff = new byte[1024];
+ int n;
+ while ((n = is.read(buff)) > 0) {
+ output.write(buff, 0, n);
+ }
+ script.setExecutable(true);
+ } catch (IOException e) {
+ Activator.logErrorMessage(e.getMessage());
+ }
+ }
+ return script;
+ }
+
+ /**
+ * @return the name of the script to run, depending on the OS (Windows,
+ * MAc, *Nix)
+ */
+ private String getConnectionSettingsDetectionScriptName() {
+ final String osName = System.getProperty("os.name"); //$NON-NLS-1$
+ if (osName.toLowerCase().startsWith("win")) { //$NON-NLS-1$
+ return "script.bat"; //$NON-NLS-1$
+ } else if (osName.toLowerCase().startsWith("mac") //$NON-NLS-1$
+ || osName.toLowerCase().contains("linux") //$NON-NLS-1$
+ || osName.toLowerCase().contains("nix")) { //$NON-NLS-1$
+ return "script.sh";//$NON-NLS-1$
+ } else {
+ return null;
+ }
+ }
+
+ private String streamToString(InputStream stream) {
+ BufferedReader buff = new BufferedReader(
+ new InputStreamReader(stream));
+ StringBuffer res = new StringBuffer();
+ String line = "";
+ try {
+ while ((line = buff.readLine()) != null) {
+ res.append(System.getProperty("line.separator")); //$NON-NLS-1$
+ res.append(line);
+ }
+ buff.close();
+ } catch (IOException e) {
+ }
+ return res.length() > 0 ? res.substring(1) : "";
+ }
+
+ public static class Defaults {
+
+ public static final String DEFAULT_UNIX_SOCKET_PATH = "unix:///var/run/docker.sock"; //$NON-NLS-1$
+
+ private boolean settingsResolved;
+ private String name = null;
+ private final Map<EnumDockerConnectionSettings, Object> settings = new HashMap<>();
+
+ public boolean isSettingsResolved() {
+ return settingsResolved;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return the default binding mode that was found, or UNIX_SOCKET if
+ * the property was not was not found.
+ */
+ public EnumDockerConnectionSettings getBindingMode() {
+ if (settings.containsKey(BINDING_MODE)) {
+ return (EnumDockerConnectionSettings) settings
+ .get(BINDING_MODE);
+ }
+ return UNIX_SOCKET;
+ }
+
+ /**
+ * @return the path to the Unix socket, or {@code null} if if the
+ * property was not was not found.
+ */
+ public String getUnixSocketPath() {
+ return (String) settings.get(UNIX_SOCKET_PATH);
+ }
+
+ /**
+ * @return the TCP host, or {@code null} if none was found.
+ */
+ public String getTcpHost() {
+ return (String) settings.get(TCP_HOST);
+ }
+
+ /**
+ * @return the TLS_VERIFY {@link Boolean} flag, or {@code false} if the
+ * property was not was not found.
+ */
+ public boolean getTcpTlsVerify() {
+ if (settings.containsKey(TCP_TLS_VERIFY)) {
+ return (Boolean) settings.get(TCP_TLS_VERIFY);
+ }
+ return false;
+ }
+
+ /**
+ * @return the path to the TCP certificates, or {@code null} if the
+ * property was not was found.
+ */
+ public String getTcpCertPath() {
+ return (String) settings.get(TCP_CERT_PATH);
+ }
+
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultDockerConnectionStorageManager.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultDockerConnectionStorageManager.java
new file mode 100644
index 0000000000..65792a2d50
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultDockerConnectionStorageManager.java
@@ -0,0 +1,142 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.core;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.equinox.security.storage.ISecurePreferences;
+import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
+import org.eclipse.equinox.security.storage.StorageException;
+import org.eclipse.linuxtools.docker.core.Activator;
+import org.eclipse.linuxtools.docker.core.IDockerConnection;
+import org.eclipse.linuxtools.docker.core.IDockerConnectionStorageManager;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * Default implementation of the {@link IDockerConnectionStorageManager}.
+ */
+public class DefaultDockerConnectionStorageManager
+ implements IDockerConnectionStorageManager {
+
+ public final static String CONNECTIONS_FILE_NAME = "dockerconnections.xml"; //$NON-NLS-1$
+
+ @Override
+ public List<IDockerConnection> loadConnections() {
+ final List<IDockerConnection> connections = new ArrayList<>();
+ final IPath stateLocation = Activator.getDefault().getStateLocation();
+ final File connectionFile = stateLocation.append(CONNECTIONS_FILE_NAME)
+ .toFile();
+ final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ try {
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ if (connectionFile.exists()) {
+ Document d = db.parse(connectionFile);
+ Element e = d.getDocumentElement();
+ // Get the stored configuration data
+ NodeList connectionNodes = e.getElementsByTagName("connection"); // $NON-NLS-1$
+ for (int x = 0; x < connectionNodes.getLength(); ++x) {
+ Node n = connectionNodes.item(x);
+ NamedNodeMap attrs = n.getAttributes();
+ Node nameNode = attrs.getNamedItem("name"); //$NON-NLS-1$
+ Node uriNode = attrs.getNamedItem("uri"); //$NON-NLS-1$
+ Node usernameNode = attrs.getNamedItem("username"); //$NON-NLS-1$
+ Node certNode = attrs.getNamedItem("cert"); //$NON-NLS-1$
+ if (uriNode != null) {
+ String uri = uriNode.getNodeValue();
+ String name = nameNode.getNodeValue();
+
+ if (usernameNode != null) {
+ String username = usernameNode.getNodeValue();
+ String key = DockerConnection.getPreferencesKey(uri,
+ username);
+ ISecurePreferences root = SecurePreferencesFactory
+ .getDefault();
+ ISecurePreferences node = root.node(key);
+ @SuppressWarnings("unused")
+ String password;
+ try {
+ password = node.get("password", null); //$NON-NLS-1$
+ } catch (StorageException e1) {
+ e1.printStackTrace();
+ }
+ }
+
+ DockerConnection.Builder builder = new DockerConnection.Builder()
+ .name(name);
+ if (uri.startsWith("unix:")) { //$NON-NLS-1$
+ builder = builder.unixSocket(uri);
+ } else {
+ builder = builder.tcpHost(uri);
+ if (certNode != null) {
+ builder = builder
+ .tcpCertPath(certNode.getNodeValue());
+ }
+ }
+ DockerConnection connection = builder.build();
+ connections.add(connection);
+ }
+ }
+ }
+ } catch (ParserConfigurationException | SAXException | IOException e) {
+ Activator.log(e);
+ }
+ return connections;
+ }
+
+ @Override
+ public void saveConnections(List<IDockerConnection> connections) {
+ final IPath stateLocation = Activator.getDefault().getStateLocation();
+ final File connectionFile = stateLocation.append(CONNECTIONS_FILE_NAME)
+ .toFile();
+ try {
+ if (!connectionFile.exists()) {
+ connectionFile.createNewFile();
+ }
+ try (final PrintWriter p = new PrintWriter(
+ new BufferedWriter(new FileWriter(connectionFile)))) {
+ p.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$
+ p.println("<connections>"); // $NON-NLS-1$
+ for (IDockerConnection d : connections) {
+ p.print("<connection name=\"" + d.getName() + //$NON-NLS-1$
+ "\" uri=\"" + d.getUri()); //$NON-NLS-1$
+ if (d.getUsername() != null) {
+ p.print("\" username=\"" + d.getUsername()); //$NON-NLS-1$
+ }
+ if (d.getTcpCertPath() != null) {
+ p.print("\" cert=\"" + d.getTcpCertPath()); //$NON-NLS-1$
+ }
+ p.println("\"/>"); //$NON-NLS-1$
+ }
+ p.println("</connections>"); //$NON-NLS-1$
+ }
+ } catch (Exception e) {
+ Activator.log(e);
+ }
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
index e1ddc56765..6eecdef4ab 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerConnection.java
@@ -111,6 +111,7 @@ import jnr.unixsocket.UnixSocketChannel;
*/
public class DockerConnection implements IDockerConnection, Closeable {
+ @Deprecated
public static class Defaults {
public static final String DEFAULT_UNIX_SOCKET_PATH = "unix:///var/run/docker.sock"; //$NON-NLS-1$
@@ -585,7 +586,8 @@ public class DockerConnection implements IDockerConnection, Closeable {
}
}
} catch (DockerCertificateException e) {
- throw new DockerException(Messages.Open_Connection_Failure, e);
+ throw new DockerException(
+ NLS.bind(Messages.Open_Connection_Failure, this.name));
}
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/TCPConnectionSettings.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/TCPConnectionSettings.java
new file mode 100644
index 0000000000..f0f0889c85
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/TCPConnectionSettings.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.core;
+
+/**
+ * TCP Connection settings
+ */
+public class TCPConnectionSettings extends BaseConnectionSettings {
+
+ /**
+ * the host to connect to (a URI representation, including 'tcp' scheme and
+ * port number).
+ */
+ private final String host;
+
+ /** flag to indicate if TLS is used. */
+ private final boolean tlsVerify;
+
+ /**
+ * absolute path to folder containing the certificates (ca.pem, key.pem and
+ * cert.pem).
+ */
+ private final String pathToCertificates;
+
+ /**
+ * Constructor
+ *
+ * @param host
+ * host to connect to
+ * @param tlsVerify
+ * flag to indicate if TLS is used
+ * @param pathToCertificates
+ * absolute path to folder containing the certificates
+ */
+ public TCPConnectionSettings(final String host, final boolean tlsVerify,
+ final String pathToCertificates) {
+ super();
+ this.host = host;
+ this.tlsVerify = tlsVerify;
+ this.pathToCertificates = pathToCertificates;
+ }
+
+ @Override
+ public BindingType getType() {
+ return BindingType.TCP_CONNECTION;
+ }
+
+ /**
+ * @return the host
+ */
+ public String getHost() {
+ return host;
+ }
+
+ /**
+ * @return the tlsVerify
+ */
+ public boolean isTlsVerify() {
+ return tlsVerify;
+ }
+
+ /**
+ * @return the pathToCertificates
+ */
+ public String getPathToCertificates() {
+ return pathToCertificates;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/UnixSocketConnectionSettings.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/UnixSocketConnectionSettings.java
new file mode 100644
index 0000000000..7ba03bd671
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/UnixSocketConnectionSettings.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.core;
+
+/**
+ * Unix Socket Connection Settings
+ */
+public class UnixSocketConnectionSettings extends BaseConnectionSettings {
+
+ /** The path to the Unix Socket, including scheme (unix://). */
+ private final String path;
+
+ /**
+ * Constructor
+ *
+ * @param path
+ * the path to the Unix Socket
+ */
+ public UnixSocketConnectionSettings(String path) {
+ super();
+ this.path = path;
+ }
+
+ @Override
+ public BindingType getType() {
+ return BindingType.UNIX_SOCKET_CONNECTION;
+ }
+
+ /**
+ * @return the path to the Unix Socket
+ */
+ public String getPath() {
+ return path;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.classpath b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.classpath
new file mode 100644
index 0000000000..b9a5b1ec64
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.project b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.project
new file mode 100644
index 0000000000..5ca0061372
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.project
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.linuxtools.docker.tests.hamcrest-wrap</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.settings/org.eclipse.core.resources.prefs b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000000..99f26c0203
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/<project>=UTF-8
diff --git a/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.settings/org.eclipse.jdt.core.prefs b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..f42de363af
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.settings/org.eclipse.m2e.core.prefs b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000000..f897a7f1cb
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/META-INF/MANIFEST.MF b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..5c2e9d8406
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Wrapper for hamcrest
+Bundle-SymbolicName: org.eclipse.linuxtools.docker.tests.hamcrest-wrap
+Bundle-Version: 1.1.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+Require-Bundle: org.hamcrest.core;bundle-version="1.3.0",
+ org.hamcrest.library;bundle-version="1.3.0"
+Export-Package: org.hamcrest;version="1.3.0"
diff --git a/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/README.adoc b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/README.adoc
new file mode 100644
index 0000000000..9bed7fc983
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/README.adoc
@@ -0,0 +1,4 @@
+This is a wrapper bundle for the hamcrest split packages.
+This solves the dependency issues raised by Mockito 1.9.5
+at runtime
+See https://bugs.eclipse.org/bugs/show_bug.cgi?id=403676#c10 \ No newline at end of file
diff --git a/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/build.properties b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/build.properties
new file mode 100644
index 0000000000..b107977f4e
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/build.properties
@@ -0,0 +1,3 @@
+source.. = src/
+bin.includes = META-INF/,\
+ .
diff --git a/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/pom.xml b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/pom.xml
new file mode 100644
index 0000000000..dd826af4e2
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/pom.xml
@@ -0,0 +1,13 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.eclipse.linuxtools</groupId>
+ <artifactId>org.eclipse.linuxtools.docker</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>org.eclipse.linuxtools.docker.tests.hamcrest-wrap</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <packaging>eclipse-plugin</packaging>
+
+</project>
diff --git a/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/src/org/hamcrest/package-info.java b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/src/org/hamcrest/package-info.java
new file mode 100644
index 0000000000..422d89ce0e
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.tests.hamcrest-wrap/src/org/hamcrest/package-info.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+/**
+ * Placeholder for the org.hamcrest package
+ */
+package org.hamcrest; \ No newline at end of file
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/.classpath b/containers/org.eclipse.linuxtools.docker.ui.tests/.classpath
index eca7bdba8f..cf36b56119 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/.classpath
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/.classpath
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
+ <classpathentry kind="src" path="src/"/>
+ <classpathentry kind="output" path="target/classes"/>
</classpath>
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/.project b/containers/org.eclipse.linuxtools.docker.ui.tests/.project
index dec8106d9d..f2cabc87d1 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/.project
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/.project
@@ -20,8 +20,14 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/.settings/org.eclipse.core.resources.prefs b/containers/org.eclipse.linuxtools.docker.ui.tests/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000000..99f26c0203
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/<project>=UTF-8
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/.settings/org.eclipse.m2e.core.prefs b/containers/org.eclipse.linuxtools.docker.ui.tests/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000000..f897a7f1cb
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/META-INF/MANIFEST.MF b/containers/org.eclipse.linuxtools.docker.ui.tests/META-INF/MANIFEST.MF
index 125d6ca787..5d6742566e 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/META-INF/MANIFEST.MF
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/META-INF/MANIFEST.MF
@@ -1,12 +1,25 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
-Bundle-Name: Tests
+Bundle-Name: UI Tests
Bundle-SymbolicName: org.eclipse.linuxtools.docker.ui.tests
Bundle-Version: 1.1.0.qualifier
-Export-Package: org.eclipse.linuxtools.internal.docker.ui.wizards
-Require-Bundle: org.junit;bundle-version="4.12.0",
- org.eclipse.linuxtools.docker.ui;bundle-version="1.0.0",
+Require-Bundle: org.eclipse.linuxtools.docker.ui;bundle-version="1.0.0",
org.eclipse.core.runtime,
org.hamcrest.library;bundle-version="1.3.0",
- org.eclipse.core.databinding
+ org.hamcrest.core;bundle-version="1.3.0",
+ org.junit;bundle-version="4.12.0",
+ org.eclipse.core.databinding;bundle-version="1.5.0",
+ com.spotify.docker.client;bundle-version="3.1.1",
+ org.eclipse.swtbot.junit4_x;bundle-version="2.3.0",
+ org.eclipse.swtbot.swt.finder;bundle-version="2.3.0",
+ org.eclipse.swtbot.eclipse.finder;bundle-version="2.3.0",
+ org.eclipse.ui;bundle-version="3.107.0",
+ org.apache.log4j;bundle-version="1.2.15",
+ org.eclipse.linuxtools.docker.core;bundle-version="1.1.0",
+ org.eclipse.ui.views.properties.tabbed;bundle-version="3.6.100",
+ org.eclipse.ui.navigator;bundle-version="3.6.0",
+ org.assertj;bundle-version="1.7.1",
+ org.mockito;bundle-version="1.9.5",
+ org.eclipse.linuxtools.docker.tests.hamcrest-wrap;bundle-version="1.1.0"
+Bundle-ClassPath: .
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/pom.xml b/containers/org.eclipse.linuxtools.docker.ui.tests/pom.xml
index 1ae81d75b4..56347b90d8 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/pom.xml
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/pom.xml
@@ -2,12 +2,103 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.eclipse.linuxtools</groupId>
- <artifactId>org.eclipse.linuxtools.docker</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <groupId>org.eclipse.linuxtools</groupId>
+ <artifactId>org.eclipse.linuxtools.docker</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.linuxtools.docker.ui.tests</artifactId>
<version>1.1.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
+
+ <properties>
+ <tycho.test.jvmArgs>-Xmx800m</tycho.test.jvmArgs>
+ <tycho.surefire.timeout>900</tycho.surefire.timeout>
+ </properties>
+
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-surefire-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <configuration>
+ <!-- useUIHarness>true</useUIHarness -->
+ <useUIThread>false</useUIThread>
+ <!-- kill test JVM if tests take more than 10 minutes (600 seconds)
+ to finish -->
+ <forkedProcessTimeoutInSeconds>${tycho.surefire.timeout}</forkedProcessTimeoutInSeconds>
+ <argLine>${tycho.test.jvmArgs}</argLine>
+ <includes>
+ <include>**/*Test.class</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <profiles>
+ <profile>
+ <!-- Ignore optional deps to swt.macosx -->
+ <id>ignore-mac-deps-on-other-os</id>
+ <activation>
+ <os>
+ <family>!mac</family>
+ </os>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>target-platform-configuration</artifactId>
+ <configuration>
+ <dependency-resolution>
+ <optionalDependencies>ignore</optionalDependencies>
+ </dependency-resolution>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-compiler-plugin</artifactId>
+ <configuration>
+ <optionalDependencies>ignore</optionalDependencies>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>mac</id>
+ <activation>
+ <os>
+ <family>mac</family>
+ </os>
+ </activation>
+ <properties>
+ <!-- Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=388084 -->
+ <!-- THE FOLLOWING LINE MUST NOT BE BROKEN BY AUTOFORMATTING -->
+ <tycho.test.jvmArgs>-Xmx800m -XstartOnFirstThread</tycho.test.jvmArgs>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>target-platform-configuration</artifactId>
+ <configuration>
+ <environments>
+ <environment>
+ <os>macosx</os>
+ <ws>cocoa</ws>
+ <arch>x86_64</arch>
+ </environment>
+ </environments>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
</project>
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/BaseSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/BaseSWTBotTest.java
new file mode 100644
index 0000000000..7a9c348131
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/BaseSWTBotTest.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.ui;
+
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerView;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+
+/**
+ * Base class for SWTBot Test
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public abstract class BaseSWTBotTest {
+
+ protected static SWTWorkbenchBot bot;
+ protected SWTBotView dockerExplorerViewBot;
+ protected DockerExplorerView dockerExplorerView;
+
+ @BeforeClass
+ public static void beforeClass() throws InterruptedException {
+ //System.err.println("Closing Welcome page");
+ bot = new SWTWorkbenchBot();
+ //bot.views().stream().map(v -> v.getViewReference().getId()).forEach(s -> System.err.println(s));
+ bot.views().stream().filter(v -> v.getReference().getTitle().equals("Welcome")).forEach(v -> v.close());
+ bot.perspectiveById("org.eclipse.linuxtools.docker.ui.perspective").activate();
+ //System.err.println("In Docker perspective");
+ bot.views().stream().map(v -> v.getViewReference().getId()).forEach(s -> System.err.println(s));
+ Thread.sleep(TimeUnit.SECONDS.toMillis(1));
+ }
+
+ @Before
+ public void setup() {
+ dockerExplorerViewBot = bot.viewById("org.eclipse.linuxtools.docker.ui.dockerExplorerView");
+ dockerExplorerViewBot.show();
+ dockerExplorerView = (DockerExplorerView) (dockerExplorerViewBot.getViewReference().getView(false));
+ }
+
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionFactory.java
new file mode 100644
index 0000000000..185d6eb602
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionFactory.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.ui.testutils;
+
+import java.util.Collections;
+
+import org.eclipse.linuxtools.docker.core.IDockerConnection;
+import org.mockito.Mockito;
+
+/**
+ * Factory for mocked {@link IDockerConnection}
+ */
+public class MockDockerConnectionFactory {
+
+ public static IDockerConnection noImageNoContainer(final String name) {
+ final IDockerConnection connection = Mockito
+ .mock(IDockerConnection.class);
+ Mockito.when(connection.getName()).thenReturn(name);
+ noImageAvailable(connection);
+ noContainerAvailable(connection);
+ return connection;
+ }
+
+ private static void noImageAvailable(final IDockerConnection connection) {
+ Mockito.when(connection.getImages()).thenReturn(Collections.emptyList());
+ }
+
+ private static void noContainerAvailable(final IDockerConnection connection) {
+ Mockito.when(connection.getContainers()).thenReturn(Collections.emptyList());
+ }
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionSettingsFinder.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionSettingsFinder.java
new file mode 100644
index 0000000000..20e57c400d
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionSettingsFinder.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.ui.testutils;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
+import org.eclipse.linuxtools.docker.core.IDockerConnectionSettingsFinder;
+import org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings;
+import org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings;
+import org.mockito.Mockito;
+
+/**
+ * Factory for mocked {@link IDockerConnectionSettingsFinder}
+ */
+public class MockDockerConnectionSettingsFinder {
+
+ /**
+ * Configures the {@link DockerConnectionManager} singleton to not being
+ * able to detect any connection to Docker daemons.
+ * @return the mocked {@link IDockerConnectionSettingsFinder}
+ */
+ public static IDockerConnectionSettingsFinder noDockerConnectionAvailable() {
+ final IDockerConnectionSettingsFinder noDockerDaemonAvailable = Mockito
+ .mock(IDockerConnectionSettingsFinder.class);
+ Mockito.when(noDockerDaemonAvailable.findConnectionSettings()).thenReturn(Collections.emptyList());
+ return noDockerDaemonAvailable;
+ }
+
+ /**
+ * Configures the {@link DockerConnectionManager} singleton to being
+ * able to detect a <strong>valid Unix Socket</strong> to a Docker daemon.
+ */
+ public static void validUnixSocketConnectionAvailable() {
+ final IDockerConnectionSettingsFinder validUnixSocketConnectionAvailable = Mockito
+ .mock(IDockerConnectionSettingsFinder.class);
+ final UnixSocketConnectionSettings unixSocketConnectionSettings = new UnixSocketConnectionSettings("unix://var/run/docker.sock");
+ unixSocketConnectionSettings.setName("mock");
+ unixSocketConnectionSettings.setSettingsResolved(true);
+ Mockito.when(validUnixSocketConnectionAvailable.findConnectionSettings()).thenReturn(Arrays.asList(unixSocketConnectionSettings));
+ DockerConnectionManager.getInstance().setConnectionSettingsFinder(validUnixSocketConnectionAvailable);
+ }
+
+ /**
+ * Configures the {@link DockerConnectionManager} singleton to being
+ * able to detect a <strong>valid TCP Connection</strong> to a Docker daemon.
+ */
+ public static void validTCPConnectionAvailable() {
+ final IDockerConnectionSettingsFinder validTCPSocketConnectionAvailable = Mockito
+ .mock(IDockerConnectionSettingsFinder.class);
+ final TCPConnectionSettings tcpConnectionSettings = new TCPConnectionSettings("tcp://1.2.3.4:1234",true, "/path/to/certs");
+ tcpConnectionSettings.setName("mock");
+ tcpConnectionSettings.setSettingsResolved(true);
+ Mockito.when(validTCPSocketConnectionAvailable.findConnectionSettings()).thenReturn(Arrays.asList(tcpConnectionSettings));
+ DockerConnectionManager.getInstance().setConnectionSettingsFinder(validTCPSocketConnectionAvailable);
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionStorageManagerFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionStorageManagerFactory.java
new file mode 100644
index 0000000000..ad555527ec
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerConnectionStorageManagerFactory.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.ui.testutils;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import org.eclipse.linuxtools.docker.core.IDockerConnection;
+import org.eclipse.linuxtools.docker.core.IDockerConnectionStorageManager;
+import org.mockito.Mockito;
+
+/**
+ * Factory for mocked {@link IDockerConnection}
+ */
+public class MockDockerConnectionStorageManagerFactory {
+
+ public static IDockerConnectionStorageManager loadNone() {
+ final IDockerConnectionStorageManager connectionStorageManager = Mockito
+ .mock(IDockerConnectionStorageManager.class);
+ Mockito.when(connectionStorageManager.loadConnections()).thenReturn(Collections.emptyList());
+ return connectionStorageManager;
+ }
+
+ public static IDockerConnectionStorageManager load(IDockerConnection... mockedConnections) {
+ final IDockerConnectionStorageManager connectionStorageManager = Mockito
+ .mock(IDockerConnectionStorageManager.class);
+ Mockito.when(connectionStorageManager.loadConnections()).thenReturn(Arrays.asList(mockedConnections));
+ return connectionStorageManager;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/package-info.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/package-info.java
new file mode 100644
index 0000000000..4c8ce4c4bb
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/package-info.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+/**
+ *
+ */
+package org.eclipse.linuxtools.internal.docker.ui.testutils; \ No newline at end of file
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/AbstractSWTBotAssertion.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/AbstractSWTBotAssertion.java
new file mode 100644
index 0000000000..23b02f0bbe
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/AbstractSWTBotAssertion.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.docker.ui.testutils.swt;
+
+import static org.hamcrest.Matchers.notNullValue;
+
+import org.assertj.core.api.AbstractAssert;
+import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBot;
+
+/**
+ * Custom assertions on a given {@link AbstractSWTBot} widget
+ * @param <SWTWidget>
+ */
+public abstract class AbstractSWTBotAssertion<Assertion extends AbstractSWTBotAssertion<Assertion, SWTWidget>, SWTWidget extends AbstractSWTBot<?>>
+ extends AbstractAssert<Assertion, SWTWidget> {
+
+ protected AbstractSWTBotAssertion(final SWTWidget actual, final Class<Assertion> clazz) {
+ super(actual, clazz);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Assertion isEnabled() {
+ notNullValue();
+ if(!actual.isEnabled()) {
+ failWithMessage("Expected checkbox with text '%s' to be enabled but it was not", actual.getText());
+ }
+ return (Assertion) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Assertion isNotEnabled() {
+ notNullValue();
+ if(actual.isEnabled()) {
+ failWithMessage("Expected checkbox with text '%s' to be disabled but it was not", actual.getText());
+ }
+ return (Assertion) this;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/CheckBoxAssertion.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/CheckBoxAssertion.java
new file mode 100644
index 0000000000..0c8c925dc3
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/CheckBoxAssertion.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.docker.ui.testutils.swt;
+
+import static org.hamcrest.Matchers.notNullValue;
+
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
+
+/**
+ * Custom assertions on a given {@link SWTBotCheckBox}.
+ */
+public class CheckBoxAssertion extends AbstractSWTBotAssertion<CheckBoxAssertion, SWTBotCheckBox> {
+
+ protected CheckBoxAssertion(final SWTBotCheckBox actual) {
+ super(actual, CheckBoxAssertion.class);
+ }
+
+ public static CheckBoxAssertion assertThat(final SWTBotCheckBox actual) {
+ return new CheckBoxAssertion(actual);
+ }
+
+ public CheckBoxAssertion isChecked() {
+ notNullValue();
+ if(!actual.isChecked()) {
+ failWithMessage("Expected checkbox with text '%s' to be checked but it was not", actual.getText());
+ }
+ return this;
+ }
+
+ public CheckBoxAssertion isNotChecked() {
+ notNullValue();
+ if(actual.isChecked()) {
+ failWithMessage("Expected checkbox with text '%s' to be unchecked but it was not", actual.getText());
+ }
+ return this;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerExplorerViewAssertion.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerExplorerViewAssertion.java
new file mode 100644
index 0000000000..20f6187738
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerExplorerViewAssertion.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.ui.testutils.swt;
+
+import static org.hamcrest.Matchers.notNullValue;
+
+import org.assertj.core.api.AbstractAssert;
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerView;
+
+/**
+ * Custom assertions on an {@link DockerExplorerView}.
+ */
+public class DockerExplorerViewAssertion extends AbstractAssert<DockerExplorerViewAssertion, DockerExplorerView> {
+
+ protected DockerExplorerViewAssertion(final DockerExplorerView actual) {
+ super(actual, DockerExplorerViewAssertion.class);
+ }
+
+ public static DockerExplorerViewAssertion assertThat(final DockerExplorerView actual) {
+ return new DockerExplorerViewAssertion(actual);
+ }
+
+ public DockerExplorerViewAssertion isEmpty() {
+ notNullValue();
+ if(actual.isShowingConnectionsPane()) {
+ failWithMessage("Expected Docker Explorer View to show the explanation pane but it did not");
+ }
+ return this;
+ }
+
+ public DockerExplorerViewAssertion isNotEmpty() {
+ notNullValue();
+ if(!actual.isShowingConnectionsPane()) {
+ failWithMessage("Expected Docker Explorer View to show the connections pane but it did not");
+ }
+ return this;
+ }
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/RadioAssertion.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/RadioAssertion.java
new file mode 100644
index 0000000000..646c202a82
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/RadioAssertion.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.docker.ui.testutils.swt;
+
+import static org.hamcrest.Matchers.notNullValue;
+
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio;
+
+/**
+ * Custom assertions on a given {@link SWTBotRadio}.
+ */
+public class RadioAssertion extends AbstractSWTBotAssertion<RadioAssertion, SWTBotRadio> {
+
+ protected RadioAssertion(final SWTBotRadio actual) {
+ super(actual, RadioAssertion.class);
+ }
+
+ public static RadioAssertion assertThat(final SWTBotRadio actual) {
+ return new RadioAssertion(actual);
+ }
+
+ public RadioAssertion isSelected() {
+ notNullValue();
+ if(!actual.isSelected()) {
+ failWithMessage("Expected checkbox with text '%s' to be checked but it was not", actual.getText());
+ }
+ return this;
+ }
+
+ public RadioAssertion isNotSelected() {
+ notNullValue();
+ if(actual.isSelected()) {
+ failWithMessage("Expected checkbox with text '%s' to be unchecked but it was not", actual.getText());
+ }
+ return this;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/TextAssertion.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/TextAssertion.java
new file mode 100644
index 0000000000..7865aa69d4
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/TextAssertion.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.ui.testutils.swt;
+
+import static org.hamcrest.Matchers.notNullValue;
+
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
+
+/**
+ * Custom assertions on an {@link SWTBotText}.
+ */
+public class TextAssertion extends AbstractSWTBotAssertion<TextAssertion, SWTBotText> {
+
+ protected TextAssertion(final SWTBotText actual) {
+ super(actual, TextAssertion.class);
+ }
+
+ public static TextAssertion assertThat(final SWTBotText actual) {
+ return new TextAssertion(actual);
+ }
+
+ public TextAssertion isEmpty() {
+ notNullValue();
+ if(!actual.getText().isEmpty()) {
+ failWithMessage("Expected text widget to be empty but it contained '%s'", actual.getText());
+ }
+ return this;
+ }
+
+ public TextAssertion textEquals(final String expectedContent) {
+ notNullValue();
+ if(!actual.getText().equals(expectedContent)) {
+ failWithMessage("Expected text widget to contain '%s' but it contained '%s'", expectedContent, actual.getText());
+ }
+ return this;
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/package-info.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/package-info.java
new file mode 100644
index 0000000000..beccf4d962
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/package-info.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+/**
+ * Classes to perform assertions on SWTBot controls.
+ */
+package org.eclipse.linuxtools.internal.docker.ui.testutils.swt; \ No newline at end of file
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java
new file mode 100644
index 0000000000..0ba458b661
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.ui.views;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
+import org.eclipse.linuxtools.docker.core.IDockerConnection;
+import org.eclipse.linuxtools.internal.docker.core.DefaultDockerConnectionStorageManager;
+import org.eclipse.linuxtools.internal.docker.ui.BaseSWTBotTest;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerConnectionFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerConnectionStorageManagerFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.DockerExplorerViewAssertion;
+import org.eclipse.swt.widgets.Display;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Testing the {@link DockerExplorerView} {@link Viewer}
+ */
+public class DockerExplorerViewSWTBotTest extends BaseSWTBotTest {
+
+ @Override
+ @Before
+ public void setup() {
+ super.setup();
+ bot.views().stream()
+ .filter(v -> v.getReference().getId().equals("org.eclipse.linuxtools.docker.ui.dockerContainersView")
+ || v.getReference().getId().equals("org.eclipse.linuxtools.docker.ui.dockerImagesView"))
+ .forEach(v -> v.close());
+ }
+
+
+ @AfterClass
+ public static void restoreDefaultConfig() {
+ DockerConnectionManager.getInstance().setConnectionStorageManager(new DefaultDockerConnectionStorageManager());
+ }
+
+ private void configureConnectionManager(final IDockerConnection... connections) {
+ DockerConnectionManager.getInstance()
+ .setConnectionStorageManager(MockDockerConnectionStorageManagerFactory.load(connections));
+ Display.getDefault().syncExec(() -> DockerConnectionManager.getInstance().reloadConnections());
+ }
+
+ @Test
+ public void shouldDisplayExplanationPane() {
+ // given
+ configureConnectionManager();
+ // when
+ dockerExplorerViewBot.getToolbarButtons().get(1).click();
+ // then
+ DockerExplorerViewAssertion.assertThat(dockerExplorerView).isEmpty();
+ }
+
+ @Test
+ public void shouldDisplayConnectionsPane() {
+ // given
+ configureConnectionManager(MockDockerConnectionFactory.noImageNoContainer("Empty"));
+ // when
+ dockerExplorerViewBot.getToolbarButtons().get(1).click();
+ // then
+ DockerExplorerViewAssertion.assertThat(dockerExplorerView).isNotEmpty();
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/package-info.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/package-info.java
new file mode 100644
index 0000000000..62cc14f43b
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/package-info.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+/**
+ *
+ */
+package org.eclipse.linuxtools.internal.docker.ui.views; \ No newline at end of file
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionSWTBotTest.java
new file mode 100644
index 0000000000..3b032f3426
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionSWTBotTest.java
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Red Hat.
+ * 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:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.docker.ui.wizards;
+
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
+import org.eclipse.linuxtools.internal.docker.core.DefaultDockerConnectionSettingsFinder;
+import org.eclipse.linuxtools.internal.docker.ui.BaseSWTBotTest;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerConnectionSettingsFinder;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.CheckBoxAssertion;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.RadioAssertion;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.TextAssertion;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Testing the {@link NewDockerConnection} {@link Wizard}
+ */
+public class NewDockerConnectionSWTBotTest extends BaseSWTBotTest {
+
+ private SWTBotToolbarButton addConnectionButton;
+
+ @Override
+ @Before
+ public void setup() {
+ super.setup();
+ this.addConnectionButton = getAddConnectionButton();
+ }
+
+ @After
+ public void closeWizard() {
+ if (bot.button("Cancel") != null) {
+ bot.button("Cancel").click();
+ }
+ DockerConnectionManager.getInstance().setConnectionSettingsFinder(new DefaultDockerConnectionSettingsFinder());
+ }
+
+ private static SWTBotToolbarButton getAddConnectionButton() {
+ final SWTBotToolbarButton button = bot.toolbarButtonWithTooltip("&Add Connection");
+ if (button == null) {
+ Assert.fail("Failed to find the 'Add Connection' button");
+ }
+ return button;
+ }
+
+ @Test
+ public void shouldShowCustomUnixSocketSettingsWhenNoConnectionAvailable() {
+ // given
+ DockerConnectionManager.getInstance()
+ .setConnectionSettingsFinder(MockDockerConnectionSettingsFinder.noDockerConnectionAvailable());
+ // when
+ // TODO: should wait until dialog appears after call to click()
+ addConnectionButton.click();
+ // then
+ // Empty Connection name
+ TextAssertion.assertThat(bot.text(0)).isEnabled().isEmpty();
+ // "Use custom connection settings" should be enabled and checked
+ CheckBoxAssertion.assertThat(bot.checkBox(0)).isEnabled().isChecked();
+ // "Unix socket" radio should be enabled and selected
+ RadioAssertion.assertThat(bot.radio(0)).isEnabled().isSelected();
+ // "Unix socket path" text should be enabled and empty
+ TextAssertion.assertThat(bot.text(1)).isEnabled().isEmpty();
+ // "TCP Connection" radio should be enabled but unselected
+ RadioAssertion.assertThat(bot.radio(1)).isEnabled().isNotSelected();
+ // "URI" should be disabled but empty
+ TextAssertion.assertThat(bot.text(2)).isNotEnabled().isEmpty();
+ // "Enable Auth" checkbox should be unselected and disabled
+ CheckBoxAssertion.assertThat(bot.checkBox(1)).isNotEnabled().isNotChecked();
+ // "Path" for certs should be disabled and empty
+ TextAssertion.assertThat(bot.text(3)).isNotEnabled().isEmpty();
+ }
+
+ @Test
+ public void shouldShowDefaultUnixSocketConnectionSettingsWithValidConnectionAvailable() {
+ // given
+ MockDockerConnectionSettingsFinder.validUnixSocketConnectionAvailable();
+ // when
+ addConnectionButton.click();
+ // TODO: should wait until dialog appears.
+ // then
+ // Connection name
+ TextAssertion.assertThat(bot.text(0)).isEnabled().textEquals("mock");
+ // "Use custom connection settings" should be enabled but unchecked
+ CheckBoxAssertion.assertThat(bot.checkBox(0)).isEnabled().isNotChecked();
+ // "Unix socket" radio should be disabled and selected
+ RadioAssertion.assertThat(bot.radio(0)).isNotEnabled().isSelected();
+ // "Unix socket path" text should be disabled and not empty
+ TextAssertion.assertThat(bot.text(1)).isNotEnabled().textEquals("unix://var/run/docker.sock");
+ // "TCP Connection" radio should be unselected and disabled
+ RadioAssertion.assertThat(bot.radio(1)).isNotEnabled().isNotSelected();
+ // "URI" should be disabled and empty
+ TextAssertion.assertThat(bot.text(2)).isNotEnabled().isEmpty();
+ // "Enable Auth" checkbox should be unselected and disabled
+ CheckBoxAssertion.assertThat(bot.checkBox(1)).isNotEnabled().isNotChecked();
+ // "Path" for certs should be disabled but not empty
+ TextAssertion.assertThat(bot.text(3)).isNotEnabled().isEmpty();
+ }
+
+ @Test
+ public void shouldShowDefaultTCPSettingsWithValidConnectionAvailable() {
+ // given
+ MockDockerConnectionSettingsFinder.validTCPConnectionAvailable();
+ // when
+ addConnectionButton.click();
+ // TODO: should wait until dialog appears.
+ // then
+ // Connection name
+ TextAssertion.assertThat(bot.text(0)).isEnabled().textEquals("mock");
+ // "Use custom connection settings" should be enabled but unchecked
+ CheckBoxAssertion.assertThat(bot.checkBox(0)).isEnabled().isNotChecked();
+ // "Unix socket" radio should be disabled and unselected
+ RadioAssertion.assertThat(bot.radio(0)).isNotEnabled().isNotSelected();
+ // "Unix socket path" text should be disabled and not empty
+ TextAssertion.assertThat(bot.text(1)).isNotEnabled().isEmpty();
+ // "TCP Connection" radio should be selected but diabled
+ RadioAssertion.assertThat(bot.radio(1)).isNotEnabled().isSelected();
+ // "URI" should be disabled but not empty
+ TextAssertion.assertThat(bot.text(2)).isNotEnabled().textEquals("tcp://1.2.3.4:1234");
+ // "Enable Auth" checkbox should be selected but disabled
+ CheckBoxAssertion.assertThat(bot.checkBox(1)).isNotEnabled().isChecked();
+ // "Path" for certs should be disabled but not empty
+ TextAssertion.assertThat(bot.text(3)).isNotEnabled().textEquals("/path/to/certs");
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/META-INF/MANIFEST.MF b/containers/org.eclipse.linuxtools.docker.ui/META-INF/MANIFEST.MF
index 0f29967a04..7685cb8328 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/META-INF/MANIFEST.MF
+++ b/containers/org.eclipse.linuxtools.docker.ui/META-INF/MANIFEST.MF
@@ -30,4 +30,5 @@ Export-Package: org.eclipse.linuxtools.docker.ui,
org.eclipse.linuxtools.docker.ui.launch,
org.eclipse.linuxtools.docker.ui.wizards,
org.eclipse.linuxtools.internal.docker.ui.preferences,
+ org.eclipse.linuxtools.internal.docker.ui.views;x-friends:="org.eclipse.linuxtools.docker.ui.tests",
org.eclipse.linuxtools.internal.docker.ui.wizards;x-friends:="org.eclipse.linuxtools.docker.ui.tests"
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerView.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerView.java
index 9772593a6e..6311d8fa28 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerView.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerView.java
@@ -20,6 +20,7 @@ import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.AbstractTreeViewer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.window.Window;
@@ -53,7 +54,9 @@ import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributo
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
/**
- * @author xcoulon
+ * {@link CommonNavigator} that display a tree of available
+ * {@link IDockerConnection}s and for each one, the {@link IDockerContainer}s
+ * and {@link IDockerImage}s under separate categories.
*
*/
public class DockerExplorerView extends CommonNavigator implements
@@ -65,6 +68,7 @@ public class DockerExplorerView extends CommonNavigator implements
private Control connectionsPane;
private Control explanationsPane;
+ private Control currentPane;
private PageBook pageBook;
private Map<IDockerConnection, ContainersRefresher> containersRefreshers = new HashMap<>();
private Map<IDockerConnection, ImagesRefresher> imagesRefreshers = new HashMap<>();
@@ -117,7 +121,6 @@ public class DockerExplorerView extends CommonNavigator implements
getCommonViewer().addFilter(containersAndImagesSearchFilter);
DockerConnectionManager.getInstance()
.addConnectionManagerListener(this);
-
}
/**
@@ -230,12 +233,23 @@ public class DockerExplorerView extends CommonNavigator implements
private void showConnectionsOrExplanations() {
if (DockerConnectionManager.getInstance().getConnections().length < 1) {
pageBook.showPage(explanationsPane);
+ this.currentPane = explanationsPane;
} else {
pageBook.showPage(connectionsPane);
+ this.currentPane = connectionsPane;
registerListeners();
}
}
+ /**
+ * @return <code>true</code> if the current panel is the one containing a
+ * {@link TreeViewer} of {@link IDockerConnection}s,
+ * <code>false</code> otherwise.
+ */
+ public boolean isShowingConnectionsPane() {
+ return this.currentPane == connectionsPane;
+ }
+
@Override
public void changeEvent(int type) {
showConnectionsOrExplanations();
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java
index 425166c673..70799f7e02 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java
@@ -49,10 +49,13 @@ import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
import org.eclipse.linuxtools.docker.core.DockerException;
import org.eclipse.linuxtools.docker.core.EnumDockerConnectionSettings;
+import org.eclipse.linuxtools.docker.core.IDockerConnectionSettings;
import org.eclipse.linuxtools.docker.ui.Activator;
import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
import org.eclipse.linuxtools.internal.docker.core.DockerConnection.Builder;
import org.eclipse.linuxtools.internal.docker.core.DockerMachine;
+import org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings;
+import org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings;
import org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@@ -400,16 +403,42 @@ public class NewDockerConnectionPage extends WizardPage {
monitor.beginTask(WizardMessages.getString(
"NewDockerConnectionPage.retrieveTask"), //$NON-NLS-1$
1);
- final DockerConnection.Defaults defaults = new DockerConnection.Defaults();
- model.setTcpCertPath(defaults.getTcpCertPath());
- model.setTcpTLSVerify(defaults.getTcpTlsVerify());
- model.setTcpHost(defaults.getTcpHost());
- model.setUnixSocketPath(
- defaults.getUnixSocketPath());
- model.setBindingMode(defaults.getBindingMode());
- model.setCustomSettings(
- !defaults.isSettingsResolved());
- model.setConnectionName(defaults.getName());
+ final List<IDockerConnectionSettings> defaults = DockerConnectionManager
+ .getInstance().findConnectionSettings();
+ if (!defaults.isEmpty()) {
+ final IDockerConnectionSettings defaultConnectionSettings = defaults
+ .get(0);
+ model.setCustomSettings(
+ !defaultConnectionSettings
+ .isSettingsResolved());
+ model.setConnectionName(
+ defaultConnectionSettings.getName());
+ switch (defaultConnectionSettings.getType()) {
+ case TCP_CONNECTION:
+ final TCPConnectionSettings tcpConnectionSettings = (TCPConnectionSettings) defaultConnectionSettings;
+ model.setTcpConnectionBindingMode(true);
+ model.setTcpCertPath(tcpConnectionSettings
+ .getPathToCertificates());
+ model.setTcpTLSVerify(tcpConnectionSettings
+ .isTlsVerify());
+ model.setTcpHost(
+ tcpConnectionSettings.getHost());
+ break;
+ case UNIX_SOCKET_CONNECTION:
+ model.setUnixSocketBindingMode(true);
+ final UnixSocketConnectionSettings unixSocketConnectionSettings = (UnixSocketConnectionSettings) defaultConnectionSettings;
+ model.setUnixSocketPath(
+ unixSocketConnectionSettings
+ .getPath());
+ break;
+ }
+ } else {
+ // fall-back to custom settings, suggesting a
+ // Unix Socket connection to the user.
+ model.setCustomSettings(true);
+ model.setUnixSocketBindingMode(true);
+ }
+
monitor.done();
}
});
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPageModel.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPageModel.java
index 3f2056a497..5e2e03e9ee 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPageModel.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPageModel.java
@@ -31,9 +31,9 @@ public class NewDockerConnectionPageModel extends BaseDatabindingModel {
/** the name of the connection. */
private String connectionName;
/** flag to indicate if custom settings are used. */
- private boolean customSettings = true;
+ private boolean customSettings = false;
/** flag to indicate if the binding uses Unix socket. */
- private boolean unixSocketBindingMode = true;
+ private boolean unixSocketBindingMode = false;
/** the path to the Unix socket (if used). */
private String unixSocketPath = null;
/** flag to indicate if the binding uses a TCP connection. */
diff --git a/containers/pom.xml b/containers/pom.xml
index aac727e8fd..cdf9779a0d 100644
--- a/containers/pom.xml
+++ b/containers/pom.xml
@@ -25,6 +25,7 @@
<modules>
<module>org.eclipse.linuxtools.docker.core</module>
<module>org.eclipse.linuxtools.docker.ui</module>
+ <module>org.eclipse.linuxtools.docker.tests.hamcrest-wrap</module>
<module>org.eclipse.linuxtools.docker.ui.tests</module>
<module>org.eclipse.linuxtools.docker.docs</module>
<module>org.eclipse.linuxtools.docker-feature</module>

Back to the top