Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/MenuAssertion.java48
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java54
2 files changed, 77 insertions, 25 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/MenuAssertion.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/MenuAssertion.java
new file mode 100644
index 0000000000..c353cd29b0
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/MenuAssertion.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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.SWTBotButton;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
+
+/**
+ * Custom assertions on a given {@link SWTBotButton}.
+ */
+public class MenuAssertion extends AbstractSWTBotAssertion<MenuAssertion, SWTBotMenu> {
+
+ protected MenuAssertion(final SWTBotMenu actual) {
+ super(actual, MenuAssertion.class);
+ }
+
+ public static MenuAssertion assertThat(final SWTBotMenu actual) {
+ return new MenuAssertion(actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ public MenuAssertion isVisible() {
+ notNullValue();
+ if (!actual.isEnabled()) {
+ failWithMessage("Expected menu with text '%s' to be visible but it was not", actual.getText());
+ }
+ return this;
+ }
+
+ @SuppressWarnings("unchecked")
+ public MenuAssertion isNotVisible() {
+ notNullValue();
+ if (actual.isEnabled()) {
+ failWithMessage("Expected menu with text '%s' to be visible 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/views/DockerExplorerViewSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/views/DockerExplorerViewSWTBotTest.java
index f4f0ee15d8..8e692ab945 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
@@ -29,6 +29,7 @@ import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.ClearConnectionMa
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.MenuAssertion;
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;
@@ -308,8 +309,7 @@ public class DockerExplorerViewSWTBotTest {
selectContainersInTreeView("Test", "gentle_foo", "angry_bar");
final SWTBotMenu menuCommand = dockerExplorerViewBot.bot().tree().contextMenu("Start");
// then
- assertThat(menuCommand.isVisible()).isEqualTo(true);
- assertThat(menuCommand.isEnabled()).isEqualTo(true);
+ MenuAssertion.assertThat(menuCommand).isVisible().isEnabled();
}
@Test
@@ -325,8 +325,7 @@ public class DockerExplorerViewSWTBotTest {
selectContainersInTreeView("Test", "gentle_foo", "angry_bar");
final SWTBotMenu menuCommand = dockerExplorerViewBot.bot().tree().contextMenu("Start");
// then
- assertThat(menuCommand.isVisible()).isEqualTo(true);
- assertThat(menuCommand.isEnabled()).isEqualTo(false);
+ MenuAssertion.assertThat(menuCommand).isVisible().isNotEnabled();
}
@Test
@@ -342,8 +341,7 @@ public class DockerExplorerViewSWTBotTest {
selectContainersInTreeView("Test", "gentle_foo", "angry_bar");
final SWTBotMenu menuCommand = dockerExplorerViewBot.bot().tree().contextMenu("Stop");
// then
- assertThat(menuCommand.isVisible()).isEqualTo(true);
- assertThat(menuCommand.isEnabled()).isEqualTo(true);
+ MenuAssertion.assertThat(menuCommand).isVisible().isEnabled();
}
@Test
@@ -359,8 +357,7 @@ public class DockerExplorerViewSWTBotTest {
selectContainersInTreeView("Test", "gentle_foo", "angry_bar");
final SWTBotMenu menuCommand = dockerExplorerViewBot.bot().tree().contextMenu("Stop");
// then
- assertThat(menuCommand.isVisible()).isEqualTo(true);
- assertThat(menuCommand.isEnabled()).isEqualTo(false);
+ MenuAssertion.assertThat(menuCommand).isVisible().isNotEnabled();
}
@Test
@@ -376,8 +373,7 @@ public class DockerExplorerViewSWTBotTest {
selectContainersInTreeView("Test", "gentle_foo", "angry_bar");
final SWTBotMenu menuCommand = dockerExplorerViewBot.bot().tree().contextMenu("Pause");
// then
- assertThat(menuCommand.isVisible()).isEqualTo(true);
- assertThat(menuCommand.isEnabled()).isEqualTo(true);
+ MenuAssertion.assertThat(menuCommand).isVisible().isEnabled();
}
@Test
@@ -393,8 +389,7 @@ public class DockerExplorerViewSWTBotTest {
selectContainersInTreeView("Test", "gentle_foo", "angry_bar");
final SWTBotMenu menuCommand = dockerExplorerViewBot.bot().tree().contextMenu("Pause");
// then
- assertThat(menuCommand.isVisible()).isEqualTo(true);
- assertThat(menuCommand.isEnabled()).isEqualTo(false);
+ MenuAssertion.assertThat(menuCommand).isVisible().isNotEnabled();
}
@Test
@@ -410,8 +405,7 @@ public class DockerExplorerViewSWTBotTest {
selectContainersInTreeView("Test", "gentle_foo", "angry_bar");
final SWTBotMenu menuCommand = dockerExplorerViewBot.bot().tree().contextMenu("Unpause");
// then
- assertThat(menuCommand.isVisible()).isEqualTo(true);
- assertThat(menuCommand.isEnabled()).isEqualTo(true);
+ MenuAssertion.assertThat(menuCommand).isVisible().isEnabled();
}
@Test
@@ -427,8 +421,7 @@ public class DockerExplorerViewSWTBotTest {
selectContainersInTreeView("Test", "gentle_foo", "angry_bar");
final SWTBotMenu menuCommand = dockerExplorerViewBot.bot().tree().contextMenu("Unpause");
// then
- assertThat(menuCommand.isVisible()).isEqualTo(true);
- assertThat(menuCommand.isEnabled()).isEqualTo(false);
+ MenuAssertion.assertThat(menuCommand).isVisible().isNotEnabled();
}
@Test
@@ -444,8 +437,7 @@ public class DockerExplorerViewSWTBotTest {
selectContainersInTreeView("Test", "gentle_foo", "angry_bar");
final SWTBotMenu menuCommand = dockerExplorerViewBot.bot().tree().contextMenu("Kill");
// then
- assertThat(menuCommand.isVisible()).isEqualTo(true);
- assertThat(menuCommand.isEnabled()).isEqualTo(true);
+ MenuAssertion.assertThat(menuCommand).isVisible().isEnabled();
}
@Test
@@ -461,8 +453,7 @@ public class DockerExplorerViewSWTBotTest {
selectContainersInTreeView("Test", "gentle_foo", "angry_bar");
final SWTBotMenu menuCommand = dockerExplorerViewBot.bot().tree().contextMenu("Kill");
// then
- assertThat(menuCommand.isVisible()).isEqualTo(true);
- assertThat(menuCommand.isEnabled()).isEqualTo(false);
+ MenuAssertion.assertThat(menuCommand).isVisible().isNotEnabled();
}
@Test
@@ -478,12 +469,11 @@ public class DockerExplorerViewSWTBotTest {
selectContainersInTreeView("Test", "gentle_foo", "angry_bar");
final SWTBotMenu menuCommand = dockerExplorerViewBot.bot().tree().contextMenu("Remove");
// then
- assertThat(menuCommand.isVisible()).isEqualTo(true);
- assertThat(menuCommand.isEnabled()).isEqualTo(true);
+ MenuAssertion.assertThat(menuCommand).isVisible().isEnabled();
}
@Test
- public void shouldProvideRemoveCommandOnMultipleContainersAtOnce() {
+ public void shouldProvideDisabledRemoveCommandOnMultipleContainersAtOnce() {
// given
final DockerClient client = MockDockerClientFactory
.container(MockContainerFactory.name("gentle_foo").status("Running").build())
@@ -495,8 +485,22 @@ public class DockerExplorerViewSWTBotTest {
selectContainersInTreeView("Test", "gentle_foo", "angry_bar");
final SWTBotMenu menuCommand = dockerExplorerViewBot.bot().tree().contextMenu("Remove");
// then
- assertThat(menuCommand.isVisible()).isEqualTo(true);
- assertThat(menuCommand.isEnabled()).isEqualTo(false);
+ MenuAssertion.assertThat(menuCommand).isVisible().isNotEnabled();
+ }
+
+ @Test
+ public void shouldProvideEnabledRemoveCommandOnMultipleImagesAtOnce() {
+ // given
+ final DockerClient client = MockDockerClientFactory.image(MockImageFactory.name("angry_bar").build())
+ .image(MockImageFactory.name("gentle_foo").build()).build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client)
+ .withDefaultTCPConnectionSettings();
+ DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
+ // open the context menu on one of the containers
+ selectImagesInTreeView("Test", "gentle_foo", "angry_bar");
+ final SWTBotMenu menuCommand = dockerExplorerViewBot.bot().tree().contextMenu("Remove");
+ // then
+ MenuAssertion.assertThat(menuCommand).isVisible().isEnabled();
}
@Test

Back to the top