Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2015-11-24 08:21:42 +0000
committerXavier Coulon2015-11-25 15:46:04 +0000
commit22ec078ee9b1257ccda419b0187d011838a63ac6 (patch)
tree987948c9ef694f639618156011c6469194ec7a84 /containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools
parentdb8dd4400d77b4a5583656f0dd13598d95b87f14 (diff)
downloadorg.eclipse.linuxtools-22ec078ee9b1257ccda419b0187d011838a63ac6.tar.gz
org.eclipse.linuxtools-22ec078ee9b1257ccda419b0187d011838a63ac6.tar.xz
org.eclipse.linuxtools-22ec078ee9b1257ccda419b0187d011838a63ac6.zip
Bug 481219 - Validate container name in "Image Run" wizard
Raise an error message when a container with the same name exists. Also added checks to avoid NPE when initializing ContainerInfo and ImageInfo Refactored some SWT utility classes used to setup the mock connection and moved some reusable blocks in JUnit rules. Change-Id: Ie8363fb4af6e8e5d210734c7f9028b27ac70548a Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/61113 Tested-by: Hudson CI
Diffstat (limited to 'containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools')
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java7
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtilsSWTBotTest.java82
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java89
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/ClearConnectionManagerRule.java42
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/CloseWizardRule.java29
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerConnectionManagerUtils.java46
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTBotTreeItemAssertions.java4
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/TestLoggerRule.java26
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java91
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSWTBotTest.java112
10 files changed, 390 insertions, 138 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java
index e9c3893d57..58945c42e7 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java
@@ -39,9 +39,9 @@ public class DockerConnectionManagerTest {
}
@Test
- public void shouldRegisterConnectionOnRefreshContainersManager() throws InterruptedException {
+ public void shouldRegisterConnectionOnRefreshContainersManager() {
// given
- final DockerClient client = MockDockerClientFactory.noImages().noContainers();
+ final DockerClient client = MockDockerClientFactory.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
dockerConnectionManager
.setConnectionStorageManager(MockDockerConnectionStorageManagerFactory.providing(dockerConnection));
@@ -55,7 +55,7 @@ public class DockerConnectionManagerTest {
@Test
public void shouldUnregisterConnectionOnRefreshContainersManager() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages().noContainers();
+ final DockerClient client = MockDockerClientFactory.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
dockerConnectionManager
.setConnectionStorageManager(MockDockerConnectionStorageManagerFactory.providing(dockerConnection));
@@ -66,6 +66,5 @@ public class DockerConnectionManagerTest {
SWTUtils.asyncExec(() -> dockerConnectionManager.removeConnection(dockerConnection));
// then
Assertions.assertThat(dockerContainersRefreshManager.getConnections()).isEmpty();
-
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtilsSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtilsSWTBotTest.java
index feb9fd7d39..6af527e64c 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtilsSWTBotTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/commands/CommandUtilsSWTBotTest.java
@@ -11,31 +11,26 @@
package org.eclipse.linuxtools.internal.docker.ui.commands;
-import java.util.stream.Stream;
-
import org.assertj.core.api.Assertions;
-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.core.DockerConnection;
import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerClientFactory;
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.MockDockerContainerFactory;
import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerContainerInfoFactory;
import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerImageFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.ClearConnectionManagerRule;
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.CloseWelcomePageRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.DockerConnectionManagerUtils;
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.SWTUtils;
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.widgets.SWTBotTreeItem;
import org.eclipse.ui.PlatformUI;
-import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import com.spotify.docker.client.DockerClient;
@@ -52,6 +47,9 @@ public class CommandUtilsSWTBotTest {
@ClassRule
public static CloseWelcomePageRule closeWelcomePage = new CloseWelcomePageRule();
+ @Rule
+ public ClearConnectionManagerRule clearConnectionManager = new ClearConnectionManagerRule();
+
@Before
public void lookupDockerExplorerView() throws InterruptedException {
SWTUtils.asyncExec(() -> {
@@ -71,38 +69,14 @@ public class CommandUtilsSWTBotTest {
.forEach(v -> v.close());
}
- @After
- public void clearConnectionManager() throws InterruptedException {
- SWTUtils.syncExec(() -> {
- Stream.of(DockerConnectionManager.getInstance().getConnections())
- .forEach(c -> DockerConnectionManager.getInstance().removeConnection(c));
- dockerExplorerView.getCommonViewer().refresh(true);
- });
- }
-
- @AfterClass
- public static void restoreDefaultConfig() {
- DockerConnectionManager.getInstance().setConnectionStorageManager(new DefaultDockerConnectionStorageManager());
- }
-
- private void configureConnectionManager(final IDockerConnection... connections) throws InterruptedException {
- DockerConnectionManager.getInstance()
- .setConnectionStorageManager(MockDockerConnectionStorageManagerFactory.providing(connections));
- SWTUtils.asyncExec(() -> {
- DockerConnectionManager.getInstance().reloadConnections();
- dockerExplorerView.getCommonViewer().refresh();
- });
-
- }
-
@Test
public void shouldRetrieveConnectionFromSelectedContainersCategory() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages()
+ final DockerClient client = MockDockerClientFactory
.container(MockDockerContainerFactory.name("foo_bar").build()).build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
- SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
+ SWTUtils.syncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
// when selecting the container
SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Containers").select();
// then current connection should be found
@@ -112,11 +86,11 @@ public class CommandUtilsSWTBotTest {
@Test
public void shouldRetrieveConnectionFromSelectedContainer() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages()
+ final DockerClient client = MockDockerClientFactory
.container(MockDockerContainerFactory.name("foo_bar").build()).build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
- SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
+ SWTUtils.syncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
// when selecting the container
SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Containers", "foo_bar").select();
// then current connection should be found
@@ -126,12 +100,12 @@ public class CommandUtilsSWTBotTest {
@Test
public void shouldRetrieveConnectionFromSelectedContainerLinksCategory() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages()
+ final DockerClient client = MockDockerClientFactory
.container(MockDockerContainerFactory.name("foo_bar").build(),
MockDockerContainerInfoFactory.link("/foo:/bar/foo").build())
.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
final SWTBotTreeItem containersTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test",
"Containers");
@@ -146,12 +120,12 @@ public class CommandUtilsSWTBotTest {
@Test
public void shouldRetrieveConnectionFromSelectedContainerLink() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages()
+ final DockerClient client = MockDockerClientFactory
.container(MockDockerContainerFactory.name("foo_bar").build(),
MockDockerContainerInfoFactory.link("/foo:/bar/foo").build())
.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
final SWTBotTreeItem containersTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test",
"Containers");
@@ -167,12 +141,12 @@ public class CommandUtilsSWTBotTest {
@Test
public void shouldRetrieveConnectionFromSelectedContainerVolumesCategory() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages()
+ final DockerClient client = MockDockerClientFactory
.container(MockDockerContainerFactory.name("foo_bar").build(),
MockDockerContainerInfoFactory.volume("/path/to/host:/path/to/container:Z,ro").build())
.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
final SWTBotTreeItem containersTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test",
"Containers");
@@ -188,12 +162,12 @@ public class CommandUtilsSWTBotTest {
@Test
public void shouldRetrieveConnectionFromSelectedContainerVolume() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages()
+ final DockerClient client = MockDockerClientFactory
.container(MockDockerContainerFactory.name("foo_bar").build(),
MockDockerContainerInfoFactory.volume("/path/to/host:/path/to/container:Z,ro").build())
.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
final SWTBotTreeItem containersTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test",
"Containers");
@@ -209,12 +183,12 @@ public class CommandUtilsSWTBotTest {
@Test
public void shouldRetrieveConnectionFromSelectedContainerPortsCategory() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages()
+ final DockerClient client = MockDockerClientFactory
.container(MockDockerContainerFactory.name("foo_bar").build(),
MockDockerContainerInfoFactory.port("8080/tcp", "0.0.0.0", "8080").build())
.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
final SWTBotTreeItem containersTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test",
"Containers");
@@ -229,12 +203,12 @@ public class CommandUtilsSWTBotTest {
@Test
public void shouldRetrieveConnectionFromSelectedContainerPort() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages()
+ final DockerClient client = MockDockerClientFactory
.container(MockDockerContainerFactory.name("foo_bar").build(),
MockDockerContainerInfoFactory.port("8080/tcp", "0.0.0.0", "8080").build())
.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
final SWTBotTreeItem containersTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test",
"Containers");
@@ -250,10 +224,10 @@ public class CommandUtilsSWTBotTest {
@Test
public void shouldRetrieveConnectionFromSelectedImagesCategory() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.images(MockDockerImageFactory.name("foo").build())
+ final DockerClient client = MockDockerClientFactory.image(MockDockerImageFactory.name("foo").build())
.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
// when selecting the images category
SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images").select();
@@ -264,10 +238,10 @@ public class CommandUtilsSWTBotTest {
@Test
public void shouldRetrieveConnectionFromSelectedImage() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.images(MockDockerImageFactory.name("foo").build())
+ final DockerClient client = MockDockerClientFactory.image(MockDockerImageFactory.name("foo").build())
.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
// when selecting the image
SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images", "foo").select();
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java
index 51f9bddfba..7ceaca7ea8 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java
@@ -12,10 +12,11 @@
package org.eclipse.linuxtools.internal.docker.ui.testutils;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
+import org.eclipse.linuxtools.docker.core.IDockerContainer;
+import org.eclipse.linuxtools.docker.core.IDockerImage;
import org.mockito.Matchers;
import org.mockito.Mockito;
@@ -24,50 +25,112 @@ import com.spotify.docker.client.DockerException;
import com.spotify.docker.client.messages.Container;
import com.spotify.docker.client.messages.ContainerInfo;
import com.spotify.docker.client.messages.Image;
+import com.spotify.docker.client.messages.ImageInfo;
+import com.spotify.docker.client.messages.Info;
/**
* Factory for mocked {@link IDockerConnection}
*/
public class MockDockerClientFactory {
- public static Builder images(final Image... images) {
+ /**
+ * @return an {@link DockerClient} with no {@link IDockerImage} and no {@link IDockerContainer}.
+ */
+ public static DockerClient build() {
+ return image(null).build();
+ }
+
+ /**
+ * @param image the first {@link Image} to use to build the {@link DockerClient}
+ * @return a {@link Builder} to build a {@link DockerClient}
+ */
+ public static Builder image(final Image image) {
final Builder builder = new Builder();
- builder.images(Arrays.asList(images));
+ builder.image(image);
return builder;
}
- public static Builder noImages() {
- return images();
+ /**
+ * @param image the first {@link Image} to use to build the {@link DockerClient}
+ * @param imageInfo the associated {@link ImageInfo}
+ * @return a {@link Builder} to build a {@link DockerClient}
+ */
+ public static Builder image(final Image image, final ImageInfo imageInfo) {
+ final Builder builder = new Builder();
+ builder.image(image, imageInfo);
+ return builder;
+ }
+
+ /**
+ * @param image the first {@link Container} to use to build the {@link DockerClient}
+ * @return a {@link Builder} to build a {@link DockerClient}
+ */
+ public static Builder container(final Container container) {
+ final Builder builder = new Builder();
+ builder.container(container);
+ return builder;
}
+ /**
+ * @param container the first {@link Container} to use to build the {@link DockerClient}
+ * @param containerInfo the associated {@link ContainerInfo}
+ * @return a {@link Builder} to build a {@link DockerClient}
+ */
+ public static Builder container(final Container container, final ContainerInfo containerInfo) {
+ final Builder builder = new Builder();
+ builder.container(container, containerInfo);
+ return builder;
+ }
public static class Builder {
private final DockerClient dockerClient;
+ private final List<Image> images = new ArrayList<>();
+
private final List<Container> containers = new ArrayList<>();
private Builder() {
this.dockerClient = Mockito.mock(DockerClient.class);
+ try {
+ final Info info = Mockito.mock(Info.class);
+ Mockito.when(info.memTotal()).thenReturn(1024L);
+ Mockito.when(dockerClient.info()).thenReturn(info);
+ } catch (DockerException | InterruptedException e) {
+ // ignore while setting-up the mock instance
+ }
}
- public Builder images(final List<Image> images) {
+ public Builder image(final Image image) {
+ if(image != null) {
+ this.images.add(image);
+ }
+ return this;
+ }
+
+ public Builder image(final Image image, final ImageInfo imageInfo) {
+ if(image != null ) {
+ this.images.add(image);
+ }
try {
- Mockito.when(dockerClient.listImages(Matchers.any())).thenReturn(images);
+ Mockito.when(this.dockerClient.inspectImage(image.id())).thenReturn(imageInfo);
} catch (DockerException | InterruptedException e) {
// rest assured, nothing will happen while mocking the DockerClient
}
return this;
}
-
public Builder container(final Container container) {
- this.containers.add(container);
+ if(container != null) {
+ this.containers.add(container);
+ }
return this;
}
public Builder container(final Container container, final ContainerInfo containerInfo) {
- this.containers.add(container);
+ if(container != null) {
+ this.containers.add(container);
+ }
try {
Mockito.when(this.dockerClient.inspectContainer(container.id())).thenReturn(containerInfo);
} catch (DockerException | InterruptedException e) {
@@ -78,17 +141,13 @@ public class MockDockerClientFactory {
public DockerClient build() {
try {
+ Mockito.when(this.dockerClient.listImages(Matchers.any())).thenReturn(this.images);
Mockito.when(this.dockerClient.listContainers(Matchers.any())).thenReturn(this.containers);
} catch (DockerException | InterruptedException e) {
// nothing may happen when mocking the method call
}
return this.dockerClient;
}
-
- public DockerClient noContainers() {
- return this.dockerClient;
- }
-
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/ClearConnectionManagerRule.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/ClearConnectionManagerRule.java
new file mode 100644
index 0000000000..b448362689
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/ClearConnectionManagerRule.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.ui.testutils.swt;
+
+import java.util.stream.Stream;
+
+import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
+import org.eclipse.linuxtools.internal.docker.core.DefaultDockerConnectionSettingsFinder;
+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.junit.rules.ExternalResource;
+
+/**
+ * Clears the connection manager after each test.
+ */
+public class ClearConnectionManagerRule extends ExternalResource {
+
+ @Override
+ protected void after() {
+ final SWTWorkbenchBot bot = new SWTWorkbenchBot();
+ final SWTBotView dockerExplorerViewBot = bot.viewById("org.eclipse.linuxtools.docker.ui.dockerExplorerView");
+ final DockerExplorerView dockerExplorerView = (DockerExplorerView) (dockerExplorerViewBot.getViewReference()
+ .getView(true));
+ SWTUtils.syncExec(() -> {
+ Stream.of(DockerConnectionManager.getInstance().getConnections())
+ .forEach(c -> DockerConnectionManager.getInstance().removeConnection(c));
+ dockerExplorerView.getCommonViewer().refresh(true);
+ dockerExplorerView.showConnectionsOrExplanations();
+ });
+ DockerConnectionManager.getInstance().setConnectionSettingsFinder(new DefaultDockerConnectionSettingsFinder());
+ }
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/CloseWizardRule.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/CloseWizardRule.java
new file mode 100644
index 0000000000..b34acc2ae8
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/CloseWizardRule.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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 org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.junit.rules.ExternalResource;
+
+/**
+ * Clears the connection manager after each test.
+ */
+public class CloseWizardRule extends ExternalResource {
+
+ @Override
+ protected void after() {
+ final SWTWorkbenchBot bot = new SWTWorkbenchBot();
+ if (bot.button("Cancel") != null) {
+ bot.button("Cancel").click();
+ }
+ }
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerConnectionManagerUtils.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerConnectionManagerUtils.java
new file mode 100644
index 0000000000..365ca030f6
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/DockerConnectionManagerUtils.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 java.util.concurrent.TimeUnit;
+
+import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
+import org.eclipse.linuxtools.docker.core.IDockerConnection;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerConnectionStorageManagerFactory;
+import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerView;
+
+/**
+ *
+ */
+public class DockerConnectionManagerUtils {
+
+ /**
+ * Configures the {@link DockerConnectionManager} with the given array of
+ * {@link IDockerConnection} (can be mocked) and refreshes the associated
+ * {@link DockerExplorerView}.
+ *
+ * @param dockerExplorerView
+ * @param connections
+ * @throws InterruptedException
+ */
+ public static void configureConnectionManager(final DockerExplorerView dockerExplorerView,
+ final IDockerConnection... connections) throws InterruptedException {
+ DockerConnectionManager.getInstance()
+ .setConnectionStorageManager(MockDockerConnectionStorageManagerFactory.providing(connections));
+ SWTUtils.syncExec(() -> {
+ DockerConnectionManager.getInstance().reloadConnections();
+ dockerExplorerView.getCommonViewer().refresh();
+ dockerExplorerView.showConnectionsOrExplanations();
+ });
+ Thread.sleep(TimeUnit.SECONDS.toMillis(1));
+ }
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTBotTreeItemAssertions.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTBotTreeItemAssertions.java
index 5ac1a21c5e..68d3b3f724 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTBotTreeItemAssertions.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/SWTBotTreeItemAssertions.java
@@ -32,7 +32,7 @@ public class SWTBotTreeItemAssertions extends AbstractSWTBotAssertion<SWTBotTree
public SWTBotTreeItemAssertions isExpanded() {
notNullValue();
if(!actual.isExpanded()) {
- failWithMessage("Expected tree item %s to be expanded but it was not.", actual.getText());;
+ failWithMessage("Expected tree item %s to be expanded but it was not.", actual.getText());
}
return this;
}
@@ -45,7 +45,7 @@ public class SWTBotTreeItemAssertions extends AbstractSWTBotAssertion<SWTBotTree
public SWTBotTreeItemAssertions hasChildItems(final int expectedCount) {
notNullValue();
if(actual.getItems().length != expectedCount) {
- failWithMessage("Expected tree item %s to be have %s items but it had %s.", actual.getText(), expectedCount, actual.getItems().length);;
+ failWithMessage("Expected tree item %s to be have %s items but it had %s.", actual.getText(), expectedCount, actual.getItems().length);
}
for (SWTBotTreeItem swtBotTreeItem : actual.getItems()) {
Assertions.assertThat(swtBotTreeItem.getText()).isNotNull();
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/TestLoggerRule.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/TestLoggerRule.java
new file mode 100644
index 0000000000..b7c3d4b43a
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/TestLoggerRule.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * 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 org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+
+/**
+ *
+ */
+public class TestLoggerRule extends TestWatcher {
+
+ @Override
+ protected void starting(final Description description) {
+ System.out.println("Starting " + description.getClassName() + "." + description.getMethodName());
+ }
+}
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
index 8121be146e..a8aa9fb4ab 100644
--- 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
@@ -11,25 +11,21 @@
package org.eclipse.linuxtools.internal.docker.ui.views;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Stream;
-
import org.assertj.core.api.Assertions;
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.core.DockerConnection;
import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerClientFactory;
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.MockDockerContainerFactory;
import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerContainerInfoFactory;
import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerImageFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.ClearConnectionManagerRule;
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.CloseWelcomePageRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.DockerConnectionManagerUtils;
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.DockerExplorerViewAssertion;
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.SWTBotTreeItemAssertions;
import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.SWTUtils;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.TestLoggerRule;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
@@ -37,15 +33,11 @@ import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.PlatformUI;
-import org.junit.After;
-import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.TestWatcher;
-import org.junit.runner.Description;
import org.junit.runner.RunWith;
import com.spotify.docker.client.DockerClient;
@@ -65,12 +57,10 @@ public class DockerExplorerViewSWTBotTest {
public static CloseWelcomePageRule closeWelcomePage = new CloseWelcomePageRule();
@Rule
- public TestWatcher watcher = new TestWatcher() {
- @Override
- protected void starting(final Description description) {
- System.out.println("Starting " + description.getClassName() + "." + description.getMethodName());
- }
- };
+ public TestLoggerRule watcher = new TestLoggerRule();
+
+ @Rule
+ public ClearConnectionManagerRule clearConnectionManager = new ClearConnectionManagerRule();
@Before
public void setup() throws InterruptedException {
@@ -90,34 +80,10 @@ public class DockerExplorerViewSWTBotTest {
.forEach(v -> v.close());
}
- @After
- public void clearConnectionManager() {
- SWTUtils.syncExec(() -> { Stream.of(DockerConnectionManager.getInstance().getConnections())
- .forEach(c -> DockerConnectionManager.getInstance().removeConnection(c));
- dockerExplorerView.getCommonViewer().refresh(true);
- dockerExplorerView.showConnectionsOrExplanations();});
- }
-
- @AfterClass
- public static void restoreDefaultConfig() {
- DockerConnectionManager.getInstance().setConnectionStorageManager(new DefaultDockerConnectionStorageManager());
- }
-
- private void configureConnectionManager(final IDockerConnection... connections) throws InterruptedException {
- DockerConnectionManager.getInstance()
- .setConnectionStorageManager(MockDockerConnectionStorageManagerFactory.providing(connections));
- SWTUtils.syncExec(() -> {
- DockerConnectionManager.getInstance().reloadConnections();
- dockerExplorerView.getCommonViewer().refresh();
- dockerExplorerView.showConnectionsOrExplanations();
- });
- Thread.sleep(TimeUnit.SECONDS.toMillis(1));
- }
-
@Test
public void shouldDisplayExplanationPane() throws InterruptedException {
// given
- configureConnectionManager();
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView);
// then
DockerExplorerViewAssertion.assertThat(dockerExplorerView).isEmpty();
}
@@ -125,9 +91,9 @@ public class DockerExplorerViewSWTBotTest {
@Test
public void shouldDisplayConnectionsPane() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages().noContainers();
+ final DockerClient client = MockDockerClientFactory.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
// then
DockerExplorerViewAssertion.assertThat(dockerExplorerView).isNotEmpty();
}
@@ -135,9 +101,9 @@ public class DockerExplorerViewSWTBotTest {
@Test
public void shouldRefreshImagesAndShowChanges() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages().noContainers();
+ final DockerClient client = MockDockerClientFactory.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
final SWTBotTreeItem[] allItems = dockerExplorerViewBot.bot().tree().getAllItems();
Assertions.assertThat(allItems).hasSize(1);
@@ -148,7 +114,8 @@ public class DockerExplorerViewSWTBotTest {
Assertions.assertThat(imagesTreeItem.getItems().length).isEqualTo(0);
// update the client
- final DockerClient updatedClient = MockDockerClientFactory.images(MockDockerImageFactory.name("foo/bar").build()).noContainers();
+ final DockerClient updatedClient = MockDockerClientFactory.image(MockDockerImageFactory.name("foo/bar").build())
+ .build();
dockerConnection.setClient(updatedClient);
// when locating the 'Images' node and hit refresh
dockerExplorerViewTreeBot = dockerExplorerViewBot.bot().tree();
@@ -165,9 +132,9 @@ public class DockerExplorerViewSWTBotTest {
@Test
public void shouldRefreshContainersAndShowChanges() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages().noContainers();
+ final DockerClient client = MockDockerClientFactory.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
Conditions.waitForJobs(DockerExplorerView.class, "Docker Explorer View jobs");
final SWTBotTreeItem[] allItems = dockerExplorerViewBot.bot().tree().getAllItems();
@@ -180,7 +147,7 @@ public class DockerExplorerViewSWTBotTest {
Assertions.assertThat(containersTreeItem.getItems().length).isEqualTo(0);
// update the client
- final DockerClient updatedClient = MockDockerClientFactory.noImages().container(MockDockerContainerFactory.name("foo_bar").build()).build();
+ final DockerClient updatedClient = MockDockerClientFactory.container(MockDockerContainerFactory.name("foo_bar").build()).build();
dockerConnection.setClient(updatedClient);
dockerExplorerViewTreeBot = dockerExplorerViewBot.bot().tree();
dockerExplorerViewTreeBot.select(containersTreeItem);
@@ -195,12 +162,12 @@ public class DockerExplorerViewSWTBotTest {
@Test
public void shouldShowContainerPortMapping() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages()
+ final DockerClient client = MockDockerClientFactory
.container(MockDockerContainerFactory.name("foo_bar").build(), MockDockerContainerInfoFactory
.port("8080/tcp", "0.0.0.0", "8080").port("8787/tcp", "0.0.0.0", "8787").build())
.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
// when a second call to expand the container is done (because the first
// expandAll stopped with a "Loading..." job that retrieved the
@@ -224,12 +191,12 @@ public class DockerExplorerViewSWTBotTest {
@Test
public void shouldShowContainerLinks() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages()
+ final DockerClient client = MockDockerClientFactory
.container(MockDockerContainerFactory.name("foo_bar").build(), MockDockerContainerInfoFactory
.link("/postgres-demo:/foo_bar/postgres1").link("/postgres-demo:/foo_bar/postgres2").build())
.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
// when a second call to expand the container is done (because the first
// expandAll stopped with a "Loading..." job that retrieved the
@@ -250,14 +217,14 @@ public class DockerExplorerViewSWTBotTest {
@Test
public void shouldShowContainerVolumes() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages()
+ final DockerClient client = MockDockerClientFactory
.container(MockDockerContainerFactory.name("foo_bar").build(),
MockDockerContainerInfoFactory.volume("/path/to/container")
.volume("/path/to/host:/path/to/container")
.volume("/path/to/host:/path/to/container:Z,ro").build())
.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
// when a second call to expand the container is done (because the first
// expandAll stopped with a "Loading..." job that retrieved the
@@ -281,7 +248,7 @@ public class DockerExplorerViewSWTBotTest {
@Test
public void shouldRemainExpandedAfterRefresh() throws InterruptedException {
// given
- final DockerClient client = MockDockerClientFactory.noImages()
+ final DockerClient client = MockDockerClientFactory
.container(MockDockerContainerFactory.name("foo_bar").build(),
MockDockerContainerInfoFactory.volume("/path/to/container")
.port("8080/tcp", "0.0.0.0", "8080")
@@ -289,7 +256,7 @@ public class DockerExplorerViewSWTBotTest {
.volume("/path/to/host:/path/to/container:Z,ro").build())
.build();
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
- configureConnectionManager(dockerConnection);
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
SWTUtils.asyncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
final SWTBotTreeItem containersTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test (null)",
"Containers");
@@ -305,11 +272,9 @@ public class DockerExplorerViewSWTBotTest {
SWTBotTreeItemAssertions.assertThat(SWTUtils.getTreeItem(containerTreeItem, "Volumes")).isExpanded();
});
// when refreshing the container
- SWTUtils.asyncExec(() -> {
- dockerExplorerViewTreeBot = dockerExplorerViewBot.bot().tree();
- dockerExplorerViewTreeBot.select(containersTreeItem);
- dockerExplorerViewTreeBot.contextMenu("Refresh").click();
- });
+ dockerExplorerViewTreeBot = dockerExplorerViewBot.bot().tree();
+ dockerExplorerViewTreeBot.select(containersTreeItem);
+ dockerExplorerViewTreeBot.contextMenu("Refresh").click();
SWTUtils.asyncExec(() -> containersTreeItem.expand());
// then all items should remain expanded (after they were reloaded)
SWTUtils.syncAssert(() -> {
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSWTBotTest.java
new file mode 100644
index 0000000000..d1730c62ef
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageRunSWTBotTest.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * 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 static org.assertj.core.api.Assertions.assertThat;
+
+import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerClientFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerConnectionFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerContainerFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerImageFactory;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.ClearConnectionManagerRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.CloseWelcomePageRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.CloseWizardRule;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.DockerConnectionManagerUtils;
+import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.SWTUtils;
+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.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.spotify.docker.client.DockerClient;
+
+/**
+ * Testing the {@link ImageRun} wizard
+ */
+public class ImageRunSWTBotTest {
+
+ private SWTWorkbenchBot bot = new SWTWorkbenchBot();
+ private DockerExplorerView dockerExplorerView;
+ private SWTBotView dockerExplorerViewBot;
+
+ @ClassRule
+ public static CloseWelcomePageRule closeWelcomePage = new CloseWelcomePageRule();
+
+ @Rule
+ public ClearConnectionManagerRule clearConnectionManager = new ClearConnectionManagerRule();
+
+ @Rule
+ public CloseWizardRule closeWizard = new CloseWizardRule();
+
+ @Before
+ public void lookupDockerExplorerView() {
+ dockerExplorerViewBot = bot.viewById("org.eclipse.linuxtools.docker.ui.dockerExplorerView");
+ dockerExplorerView = (DockerExplorerView) (dockerExplorerViewBot.getViewReference().getView(true));
+ dockerExplorerViewBot.show();
+ dockerExplorerViewBot.setFocus();
+ }
+
+ @Test
+ public void shouldReportErrorIfContainerWithSameNameExists() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.image(MockDockerImageFactory.name("foo:latest").build())
+ .container(MockDockerContainerFactory.name("foo_bar").build()).build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
+ // expand the 'Images' node
+ SWTUtils.syncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ final SWTBotTreeItem imagesTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images");
+ final SWTBotTreeItem imageTreeItem = SWTUtils.getTreeItem(imagesTreeItem, "foo");
+
+ // when opening the "Run Image..." wizard
+ final SWTBotTree dockerExplorerViewTreeBot = dockerExplorerViewBot.bot().tree();
+ dockerExplorerViewTreeBot.select(imageTreeItem);
+ dockerExplorerViewTreeBot.contextMenu("Run Image...").click();
+
+ // when use an existing container name
+ bot.textWithLabel(WizardMessages.getString("ImageRunSelectionPage.containerName")).setText("foo_bar");
+ // then
+ // wait for https://bugs.eclipse.org/bugs/show_bug.cgi?id=482889 to be able to check the wiazard validation message
+ //assertThat(bot.text(WizardMessages.getString("ImageRunSelectionPage.containerWithSameName"))).isNotNull();
+ assertThat(bot.button("Finish").isEnabled()).isEqualTo(false);
+ }
+
+ @Test
+ public void shouldNotReportErrorIfNoContainerWithSameNameExists() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.image(MockDockerImageFactory.name("foo:latest").build())
+ .container(MockDockerContainerFactory.name("foo_bar").build()).build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ DockerConnectionManagerUtils.configureConnectionManager(dockerExplorerView, dockerConnection);
+ // expand the 'Images' node
+ SWTUtils.syncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ final SWTBotTreeItem imagesTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images");
+ final SWTBotTreeItem imageTreeItem = SWTUtils.getTreeItem(imagesTreeItem, "foo");
+
+ // when opening the "Run Image..." wizard
+ final SWTBotTree dockerExplorerViewTreeBot = dockerExplorerViewBot.bot().tree();
+ dockerExplorerViewTreeBot.select(imageTreeItem);
+ dockerExplorerViewTreeBot.contextMenu("Run Image...").click();
+
+ // when use an existing container name
+ bot.textWithLabel(WizardMessages.getString("ImageRunSelectionPage.containerName")).setText("foo_bar_baz");
+ // then
+ assertThat(bot.button("Finish").isEnabled()).isEqualTo(true);
+ }
+
+}

Back to the top