Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2016-01-05 09:45:42 +0000
committerXavier Coulon2016-01-19 19:50:45 +0000
commit7656de6fb0591b3e77553e00ea7b0502ebf46b31 (patch)
treeea999a8981b93b81071257695a5213478689f9b8
parent71f1fb9f372667fabbf0b97237028482a49cf8e1 (diff)
downloadorg.eclipse.linuxtools-7656de6fb0591b3e77553e00ea7b0502ebf46b31.tar.gz
org.eclipse.linuxtools-7656de6fb0591b3e77553e00ea7b0502ebf46b31.tar.xz
org.eclipse.linuxtools-7656de6fb0591b3e77553e00ea7b0502ebf46b31.zip
Bug 483678 - [docker image search] provide API to trigger search when Wizard opens
Automatically trigger the search if the term is not blank Added some SWTBot tests Change-Id: Ife709feec57499aa93cab538c140a2e42b138452 Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/63456 Tested-by: Hudson CI (cherry picked from commit 15546b6a0c8bf9f70f8f17cb0e56205b3deabf9f) Reviewed-on: https://git.eclipse.org/r/64683
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockDockerClientFactory.java21
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockImageSearchResultFactory.java43
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/swt/CloseWizardRule.java4
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchSWTBotTest.java111
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/wizards/ImageSearch.java4
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchPage.java10
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageTagSelectionPage.java6
7 files changed, 197 insertions, 2 deletions
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 2301780afc..6cdd0277d2 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,7 +12,11 @@
package org.eclipse.linuxtools.internal.docker.ui.testutils;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
import org.eclipse.linuxtools.docker.core.IDockerContainer;
@@ -27,6 +31,7 @@ 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.ImageSearchResult;
import com.spotify.docker.client.messages.Info;
/**
@@ -82,6 +87,12 @@ public class MockDockerClientFactory {
builder.container(container, containerInfo);
return builder;
}
+
+ public static Builder onSearch(final String term, final ImageSearchResult... results) {
+ final Builder builder = new Builder();
+ builder.onSearch(term, Arrays.asList(results));
+ return builder;
+ }
public static class Builder {
@@ -91,6 +102,8 @@ public class MockDockerClientFactory {
private final List<Container> containers = new ArrayList<>();
+ private final Map<String, List<ImageSearchResult>> searchResults = new HashMap<>();
+
private Builder() {
this.dockerClient = Mockito.mock(DockerClient.class);
try {
@@ -140,10 +153,18 @@ public class MockDockerClientFactory {
return this;
}
+ public Builder onSearch(final String term, final List<ImageSearchResult> results) {
+ this.searchResults.put(term, results);
+ return this;
+ }
+
public DockerClient build() {
try {
Mockito.when(this.dockerClient.listImages(Matchers.any())).thenReturn(this.images);
Mockito.when(this.dockerClient.listContainers(Matchers.any())).thenReturn(this.containers);
+ for(Entry<String, List<ImageSearchResult>> searchResult : this.searchResults.entrySet()) {
+ Mockito.when(this.dockerClient.searchImages(searchResult.getKey())).thenReturn(searchResult.getValue());
+ }
} catch (DockerException | InterruptedException e) {
// nothing may happen when mocking the method call
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockImageSearchResultFactory.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockImageSearchResultFactory.java
new file mode 100644
index 0000000000..dce4e1b442
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/testutils/MockImageSearchResultFactory.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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 org.mockito.Mockito;
+
+import com.spotify.docker.client.messages.ImageSearchResult;
+
+/**
+ * Factory for mocked {@link ImageSearchResult} instances.
+ */
+public class MockImageSearchResultFactory {
+
+ public static ImageSearchResultBuilder name(final String name) {
+ return new ImageSearchResultBuilder(name);
+ }
+
+ public static class ImageSearchResultBuilder {
+
+ private final String name;
+
+ public ImageSearchResultBuilder(final String name) {
+ this.name = name;
+ }
+
+ public ImageSearchResult build() {
+ final ImageSearchResult imageSearchResult = Mockito.mock(ImageSearchResult.class);
+ Mockito.when(imageSearchResult.getName()).thenReturn(this.name);
+ return imageSearchResult;
+ }
+
+ }
+
+}
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
index cd65be6789..f765a53b51 100644
--- 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
@@ -16,7 +16,7 @@ import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.junit.rules.ExternalResource;
/**
- * Closes the wizard after each test, if the "Cancel" button is available
+ * Closes the wizard(s) after each test, if the "Cancel" button is available
*/
public class CloseWizardRule extends ExternalResource {
@@ -24,7 +24,7 @@ public class CloseWizardRule extends ExternalResource {
protected void after() {
final SWTWorkbenchBot bot = new SWTWorkbenchBot();
try {
- if (bot.button("Cancel") != null) {
+ while (bot.button("Cancel") != null) {
bot.button("Cancel").click();
}
} catch (WidgetNotFoundException e) {
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchSWTBotTest.java
new file mode 100644
index 0000000000..becc4d2ccc
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchSWTBotTest.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.docker.ui.wizards.ImageSearch;
+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.MockImageSearchResultFactory;
+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 ImageSearch} wizard.
+ */
+public class ImageSearchSWTBotTest {
+
+ 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 shouldTriggerSearchIfTermWasGiven() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.onSearch("foo", MockImageSearchResultFactory.name("foo").build())
+ .build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
+ // expand the 'Images' node
+ SWTUtils.syncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ final SWTBotTreeItem imagesTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images");
+
+ // when opening the "Pull..." wizard
+ final SWTBotTree dockerExplorerViewTreeBot = dockerExplorerViewBot.bot().tree();
+ dockerExplorerViewTreeBot.select(imagesTreeItem);
+ dockerExplorerViewTreeBot.contextMenu("Pull...").click();
+
+ // when specify a term
+ bot.textWithLabel(WizardMessages.getString("ImagePull.name.label")).setText("foo");
+
+ // when clicking on the "Search..." button
+ bot.button(WizardMessages.getString("ImagePull.search.label")).click();
+ // then the search should have been triggered and results should be available
+ assertThat(bot.table().rowCount()).isEqualTo(1);
+ }
+
+ @Test
+ public void shouldNotTriggerSearchIfNoTermWasGiven() throws InterruptedException {
+ // given
+ final DockerClient client = MockDockerClientFactory.onSearch("foo", MockImageSearchResultFactory.name("foo").build())
+ .build();
+ final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).get();
+ DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
+ // expand the 'Images' node
+ SWTUtils.syncExec(() -> dockerExplorerView.getCommonViewer().expandAll());
+ final SWTBotTreeItem imagesTreeItem = SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images");
+
+ // when opening the "Pull..." wizard
+ final SWTBotTree dockerExplorerViewTreeBot = dockerExplorerViewBot.bot().tree();
+ dockerExplorerViewTreeBot.select(imagesTreeItem);
+ dockerExplorerViewTreeBot.contextMenu("Pull...").click();
+
+ // when clicking on the "Search..." button
+ bot.button(WizardMessages.getString("ImagePull.search.label")).click();
+ // then the search should have been triggered and results should be available
+ assertThat(bot.table().rowCount()).isEqualTo(0);
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/wizards/ImageSearch.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/wizards/ImageSearch.java
index 55ebd3566a..ef38f1d8bd 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/wizards/ImageSearch.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/docker/ui/wizards/ImageSearch.java
@@ -70,6 +70,10 @@ public class ImageSearch extends Wizard {
return true;
}
+ /**
+ * @return the selected docker Image as a {@link String} concatenation of
+ * the name and tag.
+ */
public String getSelectedImage() {
return this.imageSearchPage.getSelectedImage().getName() + ":"
+ this.imageTagSelectionPage.getSelectedImageTag().getName();
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchPage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchPage.java
index 752b3cfa35..fe7fe2e942 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchPage.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageSearchPage.java
@@ -81,6 +81,9 @@ public class ImageSearchPage extends WizardPage {
/**
* Default constructor.
+ *
+ * @param model
+ * the model for this page
*/
public ImageSearchPage(final ImageSearchModel model) {
super("ImageSearchPage", //$NON-NLS-1$
@@ -89,6 +92,9 @@ public class ImageSearchPage extends WizardPage {
this.model = model;
}
+ /**
+ * @return the selected Docker Image in the result table
+ */
public IDockerImageSearchResult getSelectedImage() {
return model.getSelectedImage();
}
@@ -209,6 +215,10 @@ public class ImageSearchPage extends WizardPage {
// attach the Databinding context status to this wizard page.
WizardPageSupport.create(this, this.ctx);
setControl(container);
+ // trigger a search if an image name was provided
+ if (model.getTerm() != null && !model.getTerm().isEmpty()) {
+ searchImages();
+ }
}
private TableViewerColumn addTableViewerColum(final TableViewer tableViewer,
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageTagSelectionPage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageTagSelectionPage.java
index 3453ceb2e2..28c9b14031 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageTagSelectionPage.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/ImageTagSelectionPage.java
@@ -58,6 +58,9 @@ public class ImageTagSelectionPage extends WizardPage {
/**
* Default constructor.
+ *
+ * @param model
+ * the model associated to this page
*/
public ImageTagSelectionPage(final ImageSearchModel model) {
super("ImageTagSelectionPage", //$NON-NLS-1$
@@ -151,6 +154,9 @@ public class ImageTagSelectionPage extends WizardPage {
}
}
+ /**
+ * @return the selected tag in the search result table
+ */
public DockerImageTagSearchResult getSelectedImageTag() {
return model.getSelectedImageTag();
}

Back to the top