diff options
author | Danail Branekov | 2011-08-30 10:39:21 +0000 |
---|---|---|
committer | Danail Branekov | 2011-08-30 10:39:21 +0000 |
commit | 6dee8ef69a62f04e367496f1e1640259e89edb51 (patch) | |
tree | 2e3f33dc757881550912986ac5474be6fb1ccbb0 | |
parent | ac1f15ce77e10469baac9aa2dd6b242684cd9576 (diff) | |
download | org.eclipse.e4.search-6dee8ef69a62f04e367496f1e1640259e89edb51.tar.gz org.eclipse.e4.search-6dee8ef69a62f04e367496f1e1640259e89edb51.tar.xz org.eclipse.e4.search-6dee8ef69a62f04e367496f1e1640259e89edb51.zip |
Implement UI tests in SwtBot
9 files changed, 484 insertions, 328 deletions
diff --git a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/AllAbbotTestsSuite.java b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/AllAbbotTestsSuite.java index c0dbdef..049fbe9 100644 --- a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/AllAbbotTestsSuite.java +++ b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/AllAbbotTestsSuite.java @@ -18,10 +18,8 @@ import org.eclipse.platform.discovery.ui.test.comp.internal.AdvancedSearchParams import org.eclipse.platform.discovery.ui.test.comp.internal.DiscoveryTreeViewerFactoryAbbotTest; import org.eclipse.platform.discovery.ui.test.comp.internal.InteractiveComboSelectorTest; import org.eclipse.platform.discovery.ui.test.comp.internal.SearchConsoleViewTest; -import org.eclipse.platform.discovery.ui.test.comp.internal.SearchDestinationsSelectorTest; import org.eclipse.platform.discovery.ui.test.comp.internal.SearchFavoritesViewTest; import org.eclipse.platform.discovery.ui.test.comp.internal.SubdestinationsSelectedListenerTest; -import org.eclipse.platform.discovery.ui.test.comp.internal.TextControlTest; import org.eclipse.platform.discovery.ui.view.ViewProgressMonitorTest; @@ -37,12 +35,10 @@ public class AllAbbotTestsSuite extends ActiveSWTTestSuite final AllAbbotTestsSuite suite = new AllAbbotTestsSuite();
suite.addTestSuite(SearchConsoleViewTest.class);
suite.addTestSuite(SubdestinationsSelectedListenerTest.class);
- suite.addTestSuite(SearchDestinationsSelectorTest.class);
suite.addTestSuite(AdvancedSearchParamsDisplayerTest.class);
suite.addTestSuite(ViewProgressMonitorTest.class);
suite.addTestSuite(SearchFavoritesViewTest.class);
suite.addTestSuite(InteractiveComboSelectorTest.class);
- suite.addTestSuite(TextControlTest.class);
suite.addTestSuite(DiscoveryTreeViewerFactoryAbbotTest.class);
return suite;
diff --git a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/AllSWTBotTests.java b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/AllSWTBotTests.java index 1e4e1dc..666efcc 100644 --- a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/AllSWTBotTests.java +++ b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/AllSWTBotTests.java @@ -3,16 +3,18 @@ package org.eclipse.platform.discovery.ui.test.comp; import org.eclipse.platform.discovery.ui.test.comp.internal.ComboSelectorTest;
import org.eclipse.platform.discovery.ui.test.comp.internal.ErrorHandlerTest;
import org.eclipse.platform.discovery.ui.test.comp.internal.OpenPropsViewActionTest;
+import org.eclipse.platform.discovery.ui.test.comp.internal.SearchDestinationsSelectorTest;
import org.eclipse.platform.discovery.ui.test.comp.internal.SlidingCompositeHorizontalTest;
import org.eclipse.platform.discovery.ui.test.comp.internal.SlidingCompositeTest;
import org.eclipse.platform.discovery.ui.test.comp.internal.TabbedSessionDisplayerTest;
+import org.eclipse.platform.discovery.ui.test.comp.internal.TextControlTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ErrorHandlerTest.class,SlidingCompositeTest.class,SlidingCompositeHorizontalTest.class,
- TabbedSessionDisplayerTest.class,OpenPropsViewActionTest.class, ComboSelectorTest.class})
+ TabbedSessionDisplayerTest.class,OpenPropsViewActionTest.class, ComboSelectorTest.class, TextControlTest.class, SearchDestinationsSelectorTest.class})
public class AllSWTBotTests {
}
diff --git a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/SearchDestinationsSelectorTest.java b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/SearchDestinationsSelectorTest.java index 51792ac..cae9f8a 100644 --- a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/SearchDestinationsSelectorTest.java +++ b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/SearchDestinationsSelectorTest.java @@ -8,190 +8,131 @@ * Contributors: * SAP AG - initial API and implementation *******************************************************************************/ -package org.eclipse.platform.discovery.ui.test.comp.internal;
-
+package org.eclipse.platform.discovery.ui.test.comp.internal; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; -import org.easymock.EasyMock; import org.eclipse.platform.discovery.runtime.api.IDestinationsProvider; import org.eclipse.platform.discovery.runtime.api.ISearchDestination; import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IDestinationCategoryDescription; -import org.eclipse.platform.discovery.testutils.utils.abbot.matchers.EnhancedTextMatcher; -import org.eclipse.platform.discovery.ui.api.IViewUiContext; -import org.eclipse.platform.discovery.ui.internal.selector.SearchDestinationsSelector; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.platform.discovery.ui.test.comp.internal.pageobjects.SearchDestinationsSelectorPageObject; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; import abbot.swt.finder.generic.MultipleFoundException; import abbot.swt.finder.generic.NotFoundException; -
-
-public class SearchDestinationsSelectorTest extends SearchConsoleTestFixture
-{
- private List<ISearchDestination> destinationsToShow;
-
- @Override
- public Display setUpPDE() throws Exception
- {
- super.setUpPDE();
-
- destinationsToShow = new ArrayList<ISearchDestination>();
- destinationsToShow.add(destination1);
- return getDisplay();
- }
-
- private SearchDestinationsSelector createSelector(final Shell shell, final IDestinationsProvider destProvider)
- {
- final IViewUiContext uiContext = createThreadSafeNiceMock(IViewUiContext.class);
- EasyMock.expect(uiContext.controlsSpacing()).andStubReturn(5);
- EasyMock.expect(uiContext.getSecondColumnPosition()).andStubReturn(VIEWERS_OFFSET);
- EasyMock.replay(uiContext);
-
- final SearchDestinationsSelector selector = new SearchDestinationsSelector(shell, new FormToolkit(getDisplay()), 60, null){
-
- @Override
- protected Set<IDestinationsProvider> getDestinationProvidersForCategory(IDestinationCategoryDescription category)
- {
- return new HashSet<IDestinationsProvider>(Arrays.asList(new IDestinationsProvider[]{destProvider}));
- }
-
- @Override
- protected List<ISearchDestination> getSearchDestinations(IDestinationCategoryDescription category,
- IDestinationsProvider destinationsProvider)
- {
- return destinationsToShow;
- } - - @Override - public void handleSelectionChange(ISearchDestination newSelection) { - - }
- };
-
- selector.setInput(Arrays.asList(new IDestinationCategoryDescription[]{category1}));
- return selector;
- }
-
- private SearchDestinationsSelector openSelector()
- {
- final SearchDestinationsSelector[] selector = new SearchDestinationsSelector[]{null};
- testShell = createTestShell();
- getDisplay().asyncExec(new Runnable()
- {
-
- public void run()
- {
- testShell.setLayout(new FillLayout(SWT.VERTICAL));
- selector[0] = createSelector(testShell, destProvider_cat1);
- testShell.open();
- testShell.layout();
- }
- });
- waitForShell(TEST_SHELL_TEXT);
- return selector[0];
- }
-
- public void testUpdatingSelector() throws NotFoundException, MultipleFoundException
- {
- final SearchDestinationsSelector selector = openSelector();
- selectFirstPossibleDestination(getDestinationCategoriesTree());
- List<String> itemNames = getTreeItemNames(treeTester.getItems(getDestinationCategoriesTree()));
- assertEquals("2 items expected", 2, itemNames.size());
- assertTrue("Destination category item not found", itemNames.contains(category1.getDisplayName()));
- assertTrue("Destinaion 1 not shown", itemNames.contains(destination1.getDisplayName()));
-
- destinationsToShow.add(destination2);
-
- getDisplay().syncExec(new Runnable()
- {
- public void run()
- {
- selector.update();
- }
- });
-
- selectFirstPossibleDestination(getDestinationCategoriesTree());
- itemNames = getTreeItemNames(treeTester.getItems(getDestinationCategoriesTree()));
- assertEquals("3 items expected", 3, itemNames.size());
- assertTrue("Destination category item not found", itemNames.contains(category1.getDisplayName()));
- assertTrue("Destinaion 1 not shown", itemNames.contains(destination1.getDisplayName()));
- assertTrue("Destinaion 2 not shown", itemNames.contains(destination2.getDisplayName()));
- }
-
- public void testUpdatingCurrentlySelectedItem() throws NotFoundException, MultipleFoundException
- {
- final SearchDestinationsSelector selector = openSelector();
- selectFirstPossibleDestination(getDestinationCategoriesTree());
- List<String> itemNames = getTreeItemNames(treeTester.getItems(getDestinationCategoriesTree()));
- assertEquals("2 items expected", 2, itemNames.size());
- assertTrue("Destination category item not found", itemNames.contains(category1.getDisplayName()));
- assertTrue("Destinaion 1 not shown", itemNames.contains(destination1.getDisplayName()));
-
- destinationsToShow.clear();
- destinationsToShow.add(destination2);
-
- getDisplay().syncExec(new Runnable()
- {
- public void run()
- {
- selector.update();
- }
- });
-
- waitFor(1000);
- selectFirstPossibleDestination(getDestinationCategoriesTree());
- itemNames = getTreeItemNames(treeTester.getItems(getDestinationCategoriesTree()));
- assertEquals("2 items expected", 2, itemNames.size());
- assertTrue("Destination category item not found", itemNames.contains(category1.getDisplayName()));
- assertTrue("Destinaion 2 not shown", itemNames.contains(destination2.getDisplayName()));
- }
-
- public void testSelectionIsPreservedWhenSameDestinationsAreShown() throws NotFoundException, MultipleFoundException
- {
- destinationsToShow.add(destination2);
- final SearchDestinationsSelector selector = openSelector();
- final TreeItem destination2Item = (TreeItem) FINDER.find(new EnhancedTextMatcher(DESTINATION_NAME2, TreeItem.class));
- treeItemTester.actionClick(destination2Item);
-
- destinationsToShow.remove(destination1);
- getDisplay().syncExec(new Runnable()
- {
- @Override
- public void run()
- {
- selector.update();
- }
- });
-
- final ISearchDestination[] selectedDestination = new ISearchDestination[1];
- getDisplay().syncExec(new Runnable()
- {
- @Override
- public void run()
- {
- selectedDestination[0] = selector.getSelectedItem();
- }
- });
- assertSame("Destination 2 is not selected after update", destination2, selectedDestination[0]);
- }
-
- private List<String> getTreeItemNames(final TreeItem[] items)
- {
- final List<String> result = new ArrayList<String>();
- for(TreeItem ti : items)
- {
- result.add(treeItemTester.getText(ti));
- result.addAll(getTreeItemNames(treeItemTester.getItems(ti)));
- }
-
- return result;
- }
-}
+ +public class SearchDestinationsSelectorTest +{ + private static final String DESTINATION_NAME_1 = "My First Destination"; + private static final String DESTINATION_NAME_2 = "My Second Destination"; + private static final String CATEGORY_NAME = "My Category"; + + private List<ISearchDestination> destinationsToShow; + private SearchDestinationsSelectorPageObject selector; + private ISearchDestination destination_1; + private ISearchDestination destination_2; + + @Before + public void setUp() + { + destination_1 = mockDestination(DESTINATION_NAME_1); + destination_2 = mockDestination(DESTINATION_NAME_2); + destinationsToShow = new ArrayList<ISearchDestination>(Arrays.asList(new ISearchDestination[] { destination_1 })); + selector = new SearchDestinationsSelectorPageObject(destinationsToShow, createDestinationsProvider(destination_1, destination_2)); + selector.open(); + selector.setInput(Arrays.asList(new IDestinationCategoryDescription[] { mockCategory() })); + } + + @After + public void tearDown() + { + selector.close(); + } + + @Test + public void testUpdatingSelector() throws NotFoundException, MultipleFoundException + { + selector.selectFirstPossibleDestination(); + verifyDisplayedItems(CATEGORY_NAME, DESTINATION_NAME_1); + + destinationsToShow.add(destination_2); + selector.update(); + + selector.selectFirstPossibleDestination(); + verifyDisplayedItems(CATEGORY_NAME, DESTINATION_NAME_1, DESTINATION_NAME_2); + } + + @Test + public void testUpdatingCurrentlySelectedItem() throws NotFoundException, MultipleFoundException + { + selector.selectFirstPossibleDestination(); + verifyDisplayedItems(CATEGORY_NAME, DESTINATION_NAME_1); + + destinationsToShow.clear(); + destinationsToShow.add(destination_2); + selector.update(); + selector.selectFirstPossibleDestination(); + + selector.selectFirstPossibleDestination(); + verifyDisplayedItems(CATEGORY_NAME, DESTINATION_NAME_2); + } + + public void testSelectionIsPreservedWhenSameDestinationsAreShown() throws NotFoundException, MultipleFoundException + { + destinationsToShow.add(destination_2); + selector.update(); + selector.select(DESTINATION_NAME_2); + + destinationsToShow.remove(destination_1); + selector.update(); + + final ISearchDestination selectedDestination = selector.getSelectedDestination(); + assertSame("Destination 2 is not selected after update", destination_2, selectedDestination); + } + + private void verifyDisplayedItems(final String category, final String... destinations) + { + final List<String> itemNames = selector.getAllItemsNames(); + final int expectedItemsCount = destinations.length + 1; + assertEquals(MessageFormat.format("{0} items expected", expectedItemsCount), expectedItemsCount, itemNames.size()); + assertTrue(MessageFormat.format("Destination category '{0}' not found", category), itemNames.contains(category)); + for (String destName : destinations) + { + assertTrue(MessageFormat.format("Destinaion '{0}' not shown", destName), itemNames.contains(destName)); + } + } + + private IDestinationCategoryDescription mockCategory() + { + final IDestinationCategoryDescription cat = Mockito.mock(IDestinationCategoryDescription.class); + Mockito.stub(cat.getDisplayName()).toReturn(CATEGORY_NAME); + return cat; + } + + private IDestinationsProvider createDestinationsProvider(final ISearchDestination... destinations) + { + final Set<ISearchDestination> destinationSet = new HashSet<ISearchDestination>(Arrays.asList(destinations)); + final IDestinationsProvider provider = Mockito.mock(IDestinationsProvider.class); + Mockito.stub(provider.getSearchDestinations()).toReturn(destinationSet); + return provider; + } + + private ISearchDestination mockDestination(String destinationName) + { + final ISearchDestination dest = Mockito.mock(ISearchDestination.class); + Mockito.stub(dest.getDisplayName()).toReturn(destinationName); + return dest; + } +} diff --git a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/TextControlTest.java b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/TextControlTest.java index f35b4d5..73b05bb 100644 --- a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/TextControlTest.java +++ b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/TextControlTest.java @@ -8,139 +8,67 @@ * Contributors: * SAP AG - initial API and implementation *******************************************************************************/ -package org.eclipse.platform.discovery.ui.test.comp.internal;
-
-import org.eclipse.platform.discovery.testutils.utils.abbot.matchers.SiblingTextMatcher; -import org.eclipse.platform.discovery.ui.internal.view.impl.TextControl; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; +package org.eclipse.platform.discovery.ui.test.comp.internal; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.platform.discovery.ui.test.comp.internal.pageobjects.TextControlPageObject; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import abbot.swt.finder.generic.MultipleFoundException; import abbot.swt.finder.generic.NotFoundException; -
-
-public class TextControlTest extends SearchConsoleTestFixture
-{
- private static final String TEXT_TITLE = "Text to test";
-
- private TextControl openTextControl()
- {
- final TextControl[] control = new TextControl[1];
- testShell = createTestShell();
- getDisplay().asyncExec(new Runnable()
- {
-
- public void run()
- {
- testShell.setLayout(new FillLayout(SWT.VERTICAL));
- final Label l = new Label(testShell, SWT.NONE);
- l.setText(TEXT_TITLE);
- final Text text = new Text(testShell, SWT.NONE);
- control[0] = new TextControl(text, l);
- testShell.open();
- testShell.layout();
- }
- });
- waitForShell(TEST_SHELL_TEXT);
- return control[0];
- }
-
- public void testTextIsRestoredWhenControlIsEnabled() throws NotFoundException, MultipleFoundException
- {
- final TextControl textControl = openTextControl();
- final String testText = "12345_6789";
- textTester.actionKeyString(getSwtText(), testText);
- assertEquals("Unexpected text value", testText, getTextControlValue(textControl));
- assertEquals("Unexpected text in SWT text", testText, textTester.getText(getSwtText()));
-
- assertEquals("Unexpected text value", testText, getTextControlValue(textControl));
- setEnabled(textControl, false);
- assertEquals("SWT text should be empty", "", textTester.getText(getSwtText()));
- assertEquals("Unexpected text value", "", getTextControlValue(textControl));
-
- setEnabled(textControl, true);
- assertEquals("Unexpected text value", testText, getTextControlValue(textControl));
- assertEquals("Unexpected text in SWT text", testText, textTester.getText(getSwtText()));
- }
-
- public void testTextMessageAmongEnabledStates() throws NotFoundException, MultipleFoundException
- {
- final TextControl textControl = openTextControl();
- final String message = "MyMessage";
- textTester.actionClick(getSwtText());
- setMessage(textControl, message);
-
- assertEquals("Unexpected message", message, getMessage(getSwtText()));
- assertEquals("Unexpected swt text", "", textTester.getText(getSwtText()));
-
- setEnabled(textControl, false);
- assertEquals("Unexpected message", "", getMessage(getSwtText()));
- assertEquals("Unexpected swt text", message, textTester.getText(getSwtText()));
-
- setEnabled(textControl, true);
- assertEquals("Unexpected message", message, getMessage(getSwtText()));
- assertEquals("Unexpected swt text", "", textTester.getText(getSwtText()));
- }
-
- private void setMessage(final TextControl tc, final String msg)
- {
- getDisplay().syncExec(new Runnable()
- {
- @Override
- public void run()
- {
- tc.setMessage(msg);
- }
- });
- }
-
- private String getMessage(final Text t)
- {
- final String[] result = new String[1];
-
- getDisplay().syncExec(new Runnable()
- {
- @Override
- public void run()
- {
- result[0] = t.getMessage();
- }
- });
-
- return result[0];
- }
-
- private Text getSwtText() throws NotFoundException, MultipleFoundException
- {
- return (Text) FINDER.find(new SiblingTextMatcher(TEXT_TITLE, null, Text.class));
- }
-
- private String getTextControlValue(final TextControl tControl)
- {
- final String[] string = new String[1];
- getDisplay().syncExec(new Runnable()
- {
- @Override
- public void run()
- {
- string[0] = tControl.get();
- }
- });
-
- return string[0];
- }
-
- private void setEnabled(final TextControl tControl, final boolean enabled)
- {
- getDisplay().syncExec(new Runnable()
- {
- @Override
- public void run()
- {
- tControl.setEnabled(enabled);
- }
- });
- }
-}
+ +public class TextControlTest +{ + private TextControlPageObject textControl; + + @Before + public void setUp() + { + textControl = new TextControlPageObject(); + textControl.open(); + } + + @After + public void tearDown() + { + textControl.close(); + } + + @Test + public void testTextIsRestoredWhenControlIsEnabled() throws NotFoundException, MultipleFoundException + { + final String testText = "12345_6789"; + textControl.enterText(testText); + assertEquals("Unexpected text value", testText, textControl.get()); + assertEquals("Unexpected text in SWT text", testText, textControl.getDisplayedText()); + + textControl.setEnabled(false); + assertEquals("SWT text should be empty", "", textControl.getDisplayedText()); + assertEquals("Unexpected text value", "", textControl.get()); + + textControl.setEnabled(true); + assertEquals("Unexpected text value", testText, textControl.get()); + assertEquals("Unexpected text in SWT text", testText, textControl.getDisplayedText()); + } + + @Test + public void testTextMessageAmongEnabledStates() throws NotFoundException, MultipleFoundException + { + final String message = "MyMessage"; + textControl.setMessage(message); + textControl.focus(); + assertEquals("Unexpected message", message, textControl.getMessage()); + assertEquals("Unexpected text displayed", "", textControl.getDisplayedText()); + + textControl.setEnabled(false); + assertEquals("Unexpected message", "", textControl.getMessage()); + assertEquals("Unexpected text displayed", message, textControl.getDisplayedText()); + + textControl.setEnabled(true); + assertEquals("Unexpected message", message, textControl.getMessage()); + assertEquals("Unexpected text displayed", "", textControl.getDisplayedText()); + } +} diff --git a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/ComboSelectorPageObject.java b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/ComboSelectorPageObject.java index 0bcacc8..f5a1246 100644 --- a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/ComboSelectorPageObject.java +++ b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/ComboSelectorPageObject.java @@ -45,14 +45,15 @@ public class ComboSelectorPageObject<T extends IDisplayableObject> extends InShe public void setInput(final Collection<T> input)
{
- display().syncExec(new Runnable()
+ new RunInUI<Void>(display())
{
@Override
- public void run()
+ protected Void perform()
{
selector.setInput(input);
+ return null;
}
- });
+ };
}
public String getSelectedItem()
@@ -82,13 +83,14 @@ public class ComboSelectorPageObject<T extends IDisplayableObject> extends InShe public void setEnabled(final boolean enabled)
{
- display().syncExec(new Runnable()
- {
+ new RunInUI<Void>(display()){
+
@Override
- public void run()
+ protected Void perform()
{
selector.setEnabled(enabled);
+ return null;
}
- });
+ };
}
}
diff --git a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/InShellPageObject.java b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/InShellPageObject.java index b6b4a59..1b76d77 100644 --- a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/InShellPageObject.java +++ b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/InShellPageObject.java @@ -19,20 +19,14 @@ import org.eclipse.ui.forms.widgets.FormToolkit; */
abstract class InShellPageObject
{
- private final SWTBot bot;
private SWTBotShell botShell;
private static final String TEST_SHELL_LABEL = "Testing Shell";
private FormToolkit formToolkit;
- InShellPageObject()
- {
- bot = new SWTBot();
- }
-
public void open()
{
createShell();
- botShell = bot.shell(TEST_SHELL_LABEL);
+ botShell = new SWTBot().shell(TEST_SHELL_LABEL);
botShell.activate();
}
@@ -97,7 +91,7 @@ abstract class InShellPageObject }
protected SWTBot bot() {
- return bot;
+ return botShell.bot();
}
protected SWTBotShell shell()
diff --git a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/RunInUI.java b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/RunInUI.java new file mode 100644 index 0000000..0b0d7f4 --- /dev/null +++ b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/RunInUI.java @@ -0,0 +1,48 @@ +package org.eclipse.platform.discovery.ui.test.comp.internal.pageobjects;
+
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Utility for running routines in the UI thread synchronously
+ *
+ * @author Danail Branekov
+ *
+ */
+abstract class RunInUI<T>
+{
+ private T result;
+
+ RunInUI(final Display display)
+ {
+ this.run(display);
+ }
+
+ private void run(final Display display)
+ {
+ display.syncExec(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ result = perform();
+ }
+ });
+ }
+
+ /**
+ * Implement the routine here; called from the UI thread
+ *
+ * @returns the result of the routine
+ */
+ protected abstract T perform();
+
+ /**
+ * Retrieves the result of the routine
+ *
+ * @see #perform()
+ */
+ public T getResult()
+ {
+ return result;
+ }
+}
diff --git a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/SearchDestinationsSelectorPageObject.java b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/SearchDestinationsSelectorPageObject.java new file mode 100644 index 0000000..826ab96 --- /dev/null +++ b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/SearchDestinationsSelectorPageObject.java @@ -0,0 +1,151 @@ +package org.eclipse.platform.discovery.ui.test.comp.internal.pageobjects;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.platform.discovery.runtime.api.IDestinationsProvider;
+import org.eclipse.platform.discovery.runtime.api.ISearchDestination;
+import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IDestinationCategoryDescription;
+import org.eclipse.platform.discovery.ui.internal.selector.SearchDestinationsSelector;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+public class SearchDestinationsSelectorPageObject extends InShellPageObject
+{
+ private final List<ISearchDestination> destinationsToShow;
+ private SearchDestinationsSelector selector;
+ private final IDestinationsProvider destProvider;
+
+ public SearchDestinationsSelectorPageObject(final List<ISearchDestination> destinationsToShow, final IDestinationsProvider destProvider)
+ {
+ this.destinationsToShow = destinationsToShow;
+ this.destProvider = destProvider;
+ }
+
+ @Override
+ protected void createContent(final Shell parent, final FormToolkit formToolkit)
+ {
+ selector = new SearchDestinationsSelector(parent, formToolkit, 60, null)
+ {
+ @Override
+ protected Set<IDestinationsProvider> getDestinationProvidersForCategory(IDestinationCategoryDescription category)
+ {
+ return new HashSet<IDestinationsProvider>(Arrays.asList(new IDestinationsProvider[] { destProvider }));
+ }
+
+ @Override
+ protected List<ISearchDestination> getSearchDestinations(IDestinationCategoryDescription category, IDestinationsProvider destinationsProvider)
+ {
+ return destinationsToShow;
+ }
+
+ @Override
+ public void handleSelectionChange(ISearchDestination newSelection)
+ {
+
+ }
+ };
+ }
+
+ public void setInput(final List<IDestinationCategoryDescription> input)
+ {
+ new RunInUI<Void>(display())
+ {
+
+ @Override
+ protected Void perform()
+ {
+ selector.setInput(input);
+ return null;
+ }
+ };
+ }
+
+ private SWTBotTree destinationsTree()
+ {
+ return bot().tree();
+ }
+
+ public void selectFirstPossibleDestination()
+ {
+ destinationsTree().select(findFirstDestination());
+ }
+
+ private SWTBotTreeItem findFirstDestination()
+ {
+ for (SWTBotTreeItem treeItem : getAllItems())
+ {
+ if (isDestination(treeItem))
+ {
+ return treeItem;
+ }
+ }
+ throw new IllegalStateException("Could not find destinations");
+ }
+
+ private boolean isDestination(final SWTBotTreeItem treeItem)
+ {
+ for (ISearchDestination dest : this.destinationsToShow)
+ {
+ if (dest.getDisplayName().equals(treeItem.getText()))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public List<String> getAllItemsNames()
+ {
+ final List<String> result = new ArrayList<String>();
+ for (SWTBotTreeItem item : getAllItems())
+ {
+ result.add(item.getText());
+ }
+ return result;
+ }
+
+ private List<SWTBotTreeItem> getAllItems()
+ {
+ return getItems(destinationsTree().getAllItems());
+ }
+
+ private List<SWTBotTreeItem> getItems(SWTBotTreeItem[] allItems)
+ {
+ final List<SWTBotTreeItem> result = new ArrayList<SWTBotTreeItem>();
+ for (SWTBotTreeItem item : allItems)
+ {
+ result.add(item);
+ result.addAll(getItems(item.getItems()));
+ }
+ return result;
+ }
+
+ public void update()
+ {
+ new RunInUI<Void>(display())
+ {
+ @Override
+ protected Void perform()
+ {
+ selector.update();
+ return null;
+ }
+ };
+ }
+
+ public void select(final String itemName)
+ {
+ destinationsTree().select(itemName);
+ }
+
+ public ISearchDestination getSelectedDestination()
+ {
+ return selector.getSelectedItem();
+ }
+}
diff --git a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/TextControlPageObject.java b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/TextControlPageObject.java new file mode 100644 index 0000000..598b227 --- /dev/null +++ b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/pageobjects/TextControlPageObject.java @@ -0,0 +1,94 @@ +package org.eclipse.platform.discovery.ui.test.comp.internal.pageobjects;
+
+import org.eclipse.platform.discovery.ui.internal.view.impl.TextControl;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+public class TextControlPageObject extends InShellPageObject
+{
+ private static final String LABEL_TEXT = "The Label";
+ private TextControl textControl;
+
+ @Override
+ protected void createContent(final Shell parent, final FormToolkit formToolkit)
+ {
+ final Label label = formToolkit.createLabel(parent, LABEL_TEXT, SWT.NONE);
+ final Text text = formToolkit.createText(parent, "", SWT.NONE);
+ textControl = new TextControl(text, label);
+ }
+
+ public void enterText(final String text)
+ {
+ swtBotText().typeText(text);
+ }
+
+ public String get()
+ {
+ return new RunInUI<String>(display())
+ {
+ @Override
+ protected String perform()
+ {
+ return textControl.get();
+ }
+ }.getResult();
+ }
+
+ public String getDisplayedText()
+ {
+ return swtBotText().getText();
+ }
+
+ public void setEnabled(final boolean enabled)
+ {
+ new RunInUI<Void>(display())
+ {
+
+ @Override
+ protected Void perform()
+ {
+ textControl.setEnabled(enabled);
+ return null;
+ }
+ };
+ }
+
+ public void setMessage(final String message)
+ {
+ new RunInUI<Void>(display())
+ {
+ @Override
+ protected Void perform()
+ {
+ textControl.setMessage(message);
+ return null;
+ }
+ };
+ }
+
+ private SWTBotText swtBotText()
+ {
+ return bot().text();
+ }
+
+ public String getMessage()
+ {
+ return new RunInUI<String>(display())
+ {
+ @Override
+ protected String perform()
+ {
+ return textControl.getControl().getMessage();
+ }
+ }.getResult();
+ }
+
+ public void focus()
+ {
+ swtBotText().setFocus();
+ }
+}
|