Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/SearchConsoleViewTest.java')
-rw-r--r--tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/SearchConsoleViewTest.java875
1 files changed, 274 insertions, 601 deletions
diff --git a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/SearchConsoleViewTest.java b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/SearchConsoleViewTest.java
index bfa2a3d..0d026fb 100644
--- a/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/SearchConsoleViewTest.java
+++ b/tests/org.eclipse.platform.discovery.ui.test.comp/src/org/eclipse/platform/discovery/ui/test/comp/internal/SearchConsoleViewTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 SAP AG, Walldorf.
+ * Copyright (c) 2010, 2011 SAP AG, Walldorf.
* 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
@@ -8,627 +8,300 @@
* Contributors:
* SAP AG - initial API and implementation
*******************************************************************************/
-package org.eclipse.platform.discovery.ui.test.comp.internal;
-
-import java.util.HashSet;
-import java.util.Set;
+package org.eclipse.platform.discovery.ui.test.comp.internal;
+
+import java.text.MessageFormat;
+import java.util.Collection;
+
+import junit.framework.Assert;
-import org.easymock.EasyMock;
import org.eclipse.platform.discovery.core.api.ISearchContext;
-import org.eclipse.platform.discovery.core.api.SearchEvent;
import org.eclipse.platform.discovery.core.internal.ISearchSession;
-import org.eclipse.platform.discovery.core.internal.SearchConsoleController;
-import org.eclipse.platform.discovery.core.internal.console.ISearchConsoleControllerOutputView;
-import org.eclipse.platform.discovery.core.internal.events.handlers.ISearchEventHandler;
import org.eclipse.platform.discovery.runtime.api.ISearchDestination;
import org.eclipse.platform.discovery.runtime.api.ISearchParameters;
-import org.eclipse.platform.discovery.runtime.api.SearchFailedException;
-import org.eclipse.platform.discovery.runtime.internal.ISearchProviderConfiguration;
-import org.eclipse.platform.discovery.runtime.internal.ProviderNotFoundException;
-import org.eclipse.platform.discovery.testutils.utils.abbot.matchers.EnhancedTextMatcher;
-import org.eclipse.platform.discovery.testutils.utils.junit.util.assertions.Assertions;
-import org.eclipse.platform.discovery.testutils.utils.junit.util.assertions.ConditionCheckException;
-import org.eclipse.platform.discovery.testutils.utils.junit.util.assertions.IWaitCondition;
+import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IDestinationCategoryDescription;
+import org.eclipse.platform.discovery.runtime.internal.model.descriptions.IObjectTypeDescription;
import org.eclipse.platform.discovery.ui.api.IGenericViewCustomization;
-import org.eclipse.platform.discovery.ui.api.ISearchConsoleCustomization;
import org.eclipse.platform.discovery.ui.api.IViewUiContext;
-import org.eclipse.platform.discovery.ui.api.impl.DefaultSessionIds;
import org.eclipse.platform.discovery.ui.internal.plugin.DiscoveryUIMessages;
import org.eclipse.platform.discovery.ui.internal.search.advancedparams.IAdvancedSearchParamsDisplayer;
-import org.eclipse.platform.discovery.ui.internal.view.SearchConsoleView;
import org.eclipse.platform.discovery.ui.internal.view.impl.ITabbedSessionDisplayer;
import org.eclipse.platform.discovery.ui.internal.view.impl.SearchConsoleSelectionProvider;
-import org.eclipse.platform.discovery.util.api.env.IDiscoveryEnvironment;
-import org.eclipse.platform.discovery.util.internal.session.ISessionManager;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.Widget;
-import org.eclipse.ui.IViewSite;
-import org.eclipse.ui.IWorkbenchPartSite;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.forms.widgets.Hyperlink;
-
-import abbot.swt.finder.generic.MultipleFoundException;
-import abbot.swt.finder.generic.NotFoundException;
-
-
-public class SearchConsoleViewTest extends SearchConsoleTestFixture
-{
- private MyConsoleView testView;
- private IViewSite viewSite;
- private IAdvancedSearchParamsDisplayer searchParamsDisplayer;
-
- private final static String KEYWORD_SEARCH_PARAMETER = "my keyword param"; //$NON-NLS-1$
- private final static String testSessionId = "testsessionid"; //$NON-NLS-1$
-
- private Set<ISearchConsoleCustomization> viewCustomizations;
- protected ITabbedSessionDisplayer<ISearchContext>sessionDisplayer;
- protected IViewUiContext uiContext;
-
- private Shell activeShell;
- private MySearchConsoleController viewController;
-
- @SuppressWarnings("unchecked")
- @Override
- public Display setUpPDE() throws Exception
- {
- super.setUpPDE();
-
- viewCustomizations = new HashSet<ISearchConsoleCustomization>();
- uiContext = createThreadSafeNiceMock(IViewUiContext.class);
-
- getDisplay().syncExec(new Runnable()
- {
-
- @Override
- public void run()
- {
- activeShell = getDisplay().getActiveShell();
- }
- });
-
- viewSite = createThreadSafeNiceMock(IViewSite.class);
- EasyMock.expect(viewSite.getShell()).andStubReturn(activeShell);
- EasyMock.replay(viewSite);
-
- searchParamsDisplayer = createThreadSafeNiceMock(IAdvancedSearchParamsDisplayer.class);
- EasyMock.expect(searchParamsDisplayer.isEnabled()).andStubReturn(true);
- EasyMock.replay(searchParamsDisplayer);
- sessionDisplayer = createThreadSafeNiceMock(ITabbedSessionDisplayer.class);
-
- return getDisplay();
- }
-
- public void testSelectingObjectsChangesDestinations() throws NotFoundException, MultipleFoundException
- {
- createViewToTest();
-
- final Combo objectTypesCombo = getObjectTypesCombo();
- final Tree destinationsTree = getDestinationCategoriesTree();
-
- assertEquals("No objects selected expected by default", -1, comboTester.getSelectionIndex(objectTypesCombo)); //$NON-NLS-1$
- assertEquals("No destination categories expected to be visible by default", 0, treeTester.getItemCount(destinationsTree)); //$NON-NLS-1$
-
- // select the first object type
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_1);
- selectFirstPossibleDestination(destinationsTree);
-
- // select the second object type
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_2);
- selectFirstPossibleDestination(destinationsTree);
- }
-
- public void testSelectingObjectsNotifiesUpperComositeSizeListener() throws NotFoundException, MultipleFoundException
- {
- createViewToTest();
- final Combo objectTypesCombo = getObjectTypesCombo();
-
- EasyMock.reset(searchParamsDisplayer);
- searchParamsDisplayer.update(EasyMock.eq(objectType1), (ISearchDestination)EasyMock.eq(null), EasyMock.isA(IDiscoveryEnvironment.class), EasyMock.eq(uiContext));
- EasyMock.expect(searchParamsDisplayer.isEnabled()).andStubReturn(true);
- EasyMock.expectLastCall();
- EasyMock.replay(searchParamsDisplayer);
-
- // select the first object type
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_1);
- EasyMock.verify(searchParamsDisplayer);
- }
-
- public void testExpandingDestinationCategories() throws NotFoundException, MultipleFoundException
- {
- createViewToTest();
-
- final Combo objectTypesCombo = getObjectTypesCombo();
- final Tree destinationsTree = getDestinationCategoriesTree();
-
- assertEquals("No objects selected expected by default", -1, comboTester.getSelectionIndex(objectTypesCombo)); //$NON-NLS-1$
- assertEquals("No destination categories expected to be visible by default", 0, treeTester.getItemCount(destinationsTree)); //$NON-NLS-1$
-
- // select the first object type
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_1);
- selectFirstPossibleDestination(destinationsTree);
- assertNotNull("Destination 1 not visible", QUICK_FINDER.find(new EnhancedTextMatcher(DESTINATION_NAME1))); //$NON-NLS-1$
- assertNotNull("Destination 2 not visible", QUICK_FINDER.find(new EnhancedTextMatcher(DESTINATION_NAME1))); //$NON-NLS-1$
- try
- {
- QUICK_FINDER.find(new EnhancedTextMatcher(DESTINATION_NAME3));
- fail("Destination 3 visible"); //$NON-NLS-1$
- } catch (NotFoundException e)
- {
- // expected
- }
-
- // select the second object type
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_2);
- selectFirstPossibleDestination(destinationsTree);
- try
- {
- QUICK_FINDER.find(new EnhancedTextMatcher(DESTINATION_NAME1));
- fail("Destination 1 visible"); //$NON-NLS-1$
- } catch (NotFoundException e)
- {
- // expected
- }
- try
- {
- QUICK_FINDER.find(new EnhancedTextMatcher(DESTINATION_NAME2));
- fail("Destination 2 visible"); //$NON-NLS-1$
- } catch (NotFoundException e)
- {
- // expected
- }
- assertNotNull("Destination 3 not visible", QUICK_FINDER.find(new EnhancedTextMatcher(DESTINATION_NAME3))); //$NON-NLS-1$
- }
-
- public void testUiComponentsEnableProgressively() throws NotFoundException, MultipleFoundException
- {
- createViewToTest();
-
- final Combo objectTypesCombo = getObjectTypesCombo();
- final Tree destinationsTree = getDestinationCategoriesTree();
- final Text keywordsText = getKeywordsSearchText();
- final Label subDestinationsButton = getSubdestinationsButton();
- final Button searchButton = getSearchButton();
- final Combo groupByCombo = getGroupByCombo();
-
- assertTrue("Search for list should be enabled", comboTester.getEnabled(objectTypesCombo)); //$NON-NLS-1$
- assertFalse("Search in tree should be disabled", treeTester.getEnabled(destinationsTree)); //$NON-NLS-1$
- assertFalse("Keywords text should be disabled", textTester.getEnabled(keywordsText)); //$NON-NLS-1$
- assertFalse("Subdestinations should be disabled", buttonTester.getEnabled(subDestinationsButton)); //$NON-NLS-1$
- assertFalse("Search button should be disabled", buttonTester.getEnabled(searchButton)); //$NON-NLS-1$
- assertFalse("Group by combo should be disabled", comboTester.getEnabled(groupByCombo)); //$NON-NLS-1$
-
- // select the first object type
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_1);
- assertTrue("Search in list should be enabled", treeTester.getEnabled(destinationsTree)); //$NON-NLS-1$
- assertFalse("Keywords text should be disabled", textTester.getEnabled(keywordsText)); //$NON-NLS-1$
- assertFalse("Subdestinations should be disabled", buttonTester.getEnabled(subDestinationsButton)); //$NON-NLS-1$
- assertFalse("Search button should be disabled", buttonTester.getEnabled(searchButton)); //$NON-NLS-1$
- assertFalse("Group by combo should be disabled", comboTester.getEnabled(groupByCombo)); //$NON-NLS-1$
-
- // select first destination
- selectFirstPossibleDestination(destinationsTree);
- assertFalse("Keywords text should be disabled", textTester.getEnabled(keywordsText)); //$NON-NLS-1$
- assertTrue("Subdestinations should be enabled", buttonTester.getEnabled(subDestinationsButton)); //$NON-NLS-1$
- assertTrue("Search button should be enabled", buttonTester.getEnabled(searchButton)); //$NON-NLS-1$
- assertFalse("Group by combo should not be disabled", comboTester.getEnabled(groupByCombo)); //$NON-NLS-1$
-
- // Select the second object type and third destination. This would determine a search provider which has grouping hierarchy capability and supports text search
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_2);
- selectFirstPossibleDestination(destinationsTree);
- assertTrue("Group by combo should be enabled", comboTester.getEnabled(groupByCombo)); //$NON-NLS-1$
- assertTrue("Keywords text should be enabled", textTester.getEnabled(keywordsText)); //$NON-NLS-1$
-
- // Select the first object type and first destination. This would determine a search provider which has no grouping hierarchy capability and does not support text search
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_1);
- selectFirstPossibleDestination(destinationsTree);
- assertFalse("Group by combo should be disabled", comboTester.getEnabled(groupByCombo)); //$NON-NLS-1$
- assertFalse("Keywords text should be disabled", textTester.getEnabled(keywordsText)); //$NON-NLS-1$
- }
-
- public void testGroupingHieararchyComboDisplaysFirstElementByDefault() throws NotFoundException, MultipleFoundException
- {
- createViewToTest();
-
- final Combo objectTypesCombo = getObjectTypesCombo();
- final Tree destinationsTree = getDestinationCategoriesTree();
- final Combo groupByCombo = getGroupByCombo();
-
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_2);
- selectFirstPossibleDestination(destinationsTree);
- assertEquals("Group by combo does not display the item expected", groupingHierarchy1.getDisplayName(), comboTester.getText(groupByCombo)); //$NON-NLS-1$
- }
-
- public void testSubdestinationsButtonEnablement() throws NotFoundException, MultipleFoundException
- {
- createViewToTest();
-
- final Combo objectTypesCombo = getObjectTypesCombo();
- final Tree destinationsTree = getDestinationCategoriesTree();
- final Label subDestinationsButton = getSubdestinationsButton();
-
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_1);
- selectFirstPossibleDestination(destinationsTree);
-
- assertTrue("Subdestinations button should be enabled when subdestinations available", isEnabled(subDestinationsButton)); //$NON-NLS-1$
-
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_2);
- selectFirstPossibleDestination(destinationsTree);
- assertFalse("Subdestinations button should not be enabled when subdestinations available", isEnabled(subDestinationsButton)); //$NON-NLS-1$
- }
-
- public void testChangingObjectTypesDisablesKeywordandSubdestinationsSection() throws NotFoundException, MultipleFoundException
- {
- createViewToTest();
-
- final Combo objectTypesCombo = getObjectTypesCombo();
- final Tree destinationsTree = getDestinationCategoriesTree();
- final Text keywordsText = getKeywordsSearchText();
- final Label subDestinationsButton = getSubdestinationsButton();
-
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_2);
- selectFirstPossibleDestination(destinationsTree);
- assertTrue("Keywords text should be enabled", textTester.getEnabled(keywordsText)); //$NON-NLS-1$
- assertFalse("Subdestinations should be disabled", buttonTester.getEnabled(subDestinationsButton)); //$NON-NLS-1$
-
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_1);
- selectFirstPossibleDestination(destinationsTree);
- assertFalse("Keywords text should be disabled after object type change", textTester.getEnabled(keywordsText)); //$NON-NLS-1$
- assertTrue("Subdestinations should be enabled", buttonTester.getEnabled(subDestinationsButton)); //$NON-NLS-1$
- }
-
- public void testKeywordsEnablementChangesWhenActiveProivdersChange() throws NotFoundException, MultipleFoundException, InterruptedException
- {
- createViewToTest();
-
- final Combo objectTypesCombo = getObjectTypesCombo();
- final Tree destinationsTree = getDestinationCategoriesTree();
- final Text keywordsText = getKeywordsSearchText();
-
- // By default, there is nothing selected, the keyword text is set to SearchConsoleView_NoObjectTypeSelectedHint
- assertEquals("The keyword text should be set to \"" + DiscoveryUIMessages.SearchConsoleView_NoObjectTypeSelectedHint + "\" when disabled", DiscoveryUIMessages.SearchConsoleView_NoObjectTypeSelectedHint, textTester.getText(keywordsText)); //$NON-NLS-1$ //$NON-NLS-2$
- assertFalse("Keywords text should not be enabled", isEnabled(keywordsText)); //$NON-NLS-1$
-
- // Select object 3
- // When there is only one destination it should be selected by default and the keyword text is set to DiscoveryUIMessages.SearchConsoleView_EnterKeywordHint
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_3);
-// assertEquals("The keyword text should be set to \"" + DiscoveryUIMessages.SearchConsoleView_EnterKeywordHint + "\"", DiscoveryUIMessages.SearchConsoleView_EnterKeywordHint, textTester.getText(keywordsText)); //$NON-NLS-1$ //$NON-NLS-2$
- assertTrue("Keywords text should not be enabled", isEnabled(keywordsText)); //$NON-NLS-1$
-
- // Select object 1
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_2);
- // When there is no destination selected, the keyword text is set to DiscoveryUIMessages.SearchConsoleView_NoDestinationSelectedHint when the current search provider does not support text search
- assertEquals("The keyword text should be set to \"" + DiscoveryUIMessages.SearchConsoleView_NoDestinationSelectedHint + "\" when disabled", DiscoveryUIMessages.SearchConsoleView_NoDestinationSelectedHint, textTester.getText(keywordsText)); //$NON-NLS-1$ //$NON-NLS-2$
- assertFalse("Keywords text should not be enabled", isEnabled(keywordsText)); //$NON-NLS-1$
-
- selectFirstPossibleDestination(destinationsTree);
- assertTrue("Keywords text should be enabled", isEnabled(keywordsText)); //$NON-NLS-1$
- textTester.actionKeyString(keywordsText, "HELLO!"); //$NON-NLS-1$
-
- // Select object 2
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_1);
- selectFirstPossibleDestination(destinationsTree);
- assertFalse("Keywords text should not be enabled", isEnabled(keywordsText)); //$NON-NLS-1$
- // When the keyword text is disabled, its text is set to DiscoveryUIMessages.SearchConsoleView_UnsuuportedTextSearch when the current search provider does not support text search
- assertEquals("The keyword text should be set to \"" + DiscoveryUIMessages.SearchConsoleView_UnsupportedTextSearch + "\" when disabled", DiscoveryUIMessages.SearchConsoleView_UnsupportedTextSearch, textTester.getText(keywordsText)); //$NON-NLS-1$ //$NON-NLS-2$
-
- }
-
- public void testSearch() throws NotFoundException, MultipleFoundException, ProviderNotFoundException, SearchFailedException
- {
- createViewToTest();
-
- final Combo objectTypesList = getObjectTypesCombo();
- final Tree destinationsTree = getDestinationCategoriesTree();
- final Button searchButton = getSearchButton();
-
- // select the first object type
- comboTester.actionSelectItem(objectTypesList, OBJECT_TYPE_NAME_1);
- // select first destination
- selectFirstPossibleDestination(destinationsTree);
-
- assertTrue("Search button should be visible", buttonTester.isVisible(searchButton)); //$NON-NLS-1$
- EasyMock.reset(searchParamsDisplayer);
- searchParamsDisplayer.setParams(EasyMock.isA(ISearchParameters.class));
- EasyMock.expectLastCall();
- EasyMock.replay(searchParamsDisplayer);
- buttonTester.actionClick(searchButton);
-
- assertNotNull("Search handler not invoked", viewController.lastSearchEvent); //$NON-NLS-1$
- assertEquals("Unexpected object type", OBJECT_TYPE_ID1, viewController.lastSearchEvent.getSearchParameters().getObjectTypeId()); //$NON-NLS-1$
- assertEquals("Unexpected destination", DESTINATION_NAME1, viewController.lastSearchEvent.getSearchParameters().getSearchDestination().getDisplayName()); //$NON-NLS-1$
-
- EasyMock.verify(searchParamsDisplayer);
- }
-
- public void testSearchPropagatesKeywordTextToSearchParam() throws NotFoundException, MultipleFoundException, ProviderNotFoundException, SearchFailedException
- {
- createViewToTest();
-
- final Combo objectTypesCombo = getObjectTypesCombo();
- final Tree destinationsTree = getDestinationCategoriesTree();
- final Text keywordsText = getKeywordsSearchText();
- final Button searchButton = getSearchButton();
-
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_2);
- selectFirstPossibleDestination(destinationsTree);
- assertTrue("Keywords text should be enabled", isEnabled(keywordsText)); //$NON-NLS-1$
- textTester.actionKeyString(keywordsText, KEYWORD_SEARCH_PARAMETER);
-
- EasyMock.reset(searchParamsDisplayer);
- searchParamsDisplayer.setParams(EasyMock.isA(ISearchParameters.class));
- EasyMock.expectLastCall();
- EasyMock.replay(searchParamsDisplayer);
-
- buttonTester.actionClick(searchButton);
- assertNotNull("Search was not invoked", viewController.lastSearchEvent);
- assertEquals("Keyword search parameter not properly set", KEYWORD_SEARCH_PARAMETER, viewController.lastSearchEvent.getSearchParameters().getKeywordString()); //$NON-NLS-1$
- EasyMock.verify(searchParamsDisplayer);
- }
-
-
- public void testChangingDestinationsUpdatesAdvancedSearchParams() throws NotFoundException, MultipleFoundException
- {
- createViewToTest();
-
- final Combo objectTypesCombo = getObjectTypesCombo();
- final Tree destinationsTree = getDestinationCategoriesTree();
-
- EasyMock.reset(searchParamsDisplayer);
- searchParamsDisplayer.update(EasyMock.eq(objectType1), EasyMock.eq(destination1), EasyMock.isA(IDiscoveryEnvironment.class), EasyMock.eq(uiContext));
- EasyMock.expectLastCall();
- EasyMock.expect(searchParamsDisplayer.isEnabled()).andStubReturn(true);
- EasyMock.replay(searchParamsDisplayer);
-
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NAME_1);
- selectFirstPossibleDestination(destinationsTree);
-
- EasyMock.verify(searchParamsDisplayer);
- }
-
- public void testShowResultCallsDisplayer() throws NotFoundException, MultipleFoundException
- {
- final ISearchSession session = createThreadSafeNiceMock(ISearchSession.class);
- EasyMock.expect(session.getId()).andStubReturn(testSessionId);
- EasyMock.replay(session);
- final ISearchContext searchContext = createThreadSafeNiceMock(ISearchContext.class);
- EasyMock.expect(searchContext.searchProviderId()).andStubReturn(SUPPORTING_TEXT_SEARCH_SEARCH_PROVIDER_ID);
- EasyMock.expect(searchContext.session()).andStubReturn(session);
- EasyMock.replay(searchContext);
-
- final ISearchConsoleCustomization customizationToUse = EasyMock.createMock(ISearchConsoleCustomization.class);
- EasyMock.expect(customizationToUse.acceptSearchProvider(SUPPORTING_TEXT_SEARCH_SEARCH_PROVIDER_ID)).andStubReturn(true);
- EasyMock.replay(customizationToUse);
-
- final ISearchConsoleCustomization customizationNotToUse = EasyMock.createMock(ISearchConsoleCustomization.class);
- EasyMock.expect(customizationNotToUse.acceptSearchProvider(SUPPORTING_TEXT_SEARCH_SEARCH_PROVIDER_ID)).andStubReturn(false);
- EasyMock.replay(customizationNotToUse);
-
- viewCustomizations.add(customizationNotToUse);
- viewCustomizations.add(customizationToUse);
-
- sessionDisplayer.display(EasyMock.same(session));
- EasyMock.expectLastCall();
- EasyMock.expectLastCall();
- EasyMock.replay(sessionDisplayer);
-
- createViewToTest();
- testView.registerViewCustomization(customizationNotToUse);
- testView.registerViewCustomization(customizationToUse);
- getDisplay().syncExec(new Runnable()
- {
- @Override
- public void run()
- {
- testView.showResult(searchContext);
- }
- });
-
- EasyMock.verify(sessionDisplayer);
- }
-
- public void testViewRegistersProperSelectionProvider()
- {
- viewSite = EasyMock.createMock(IViewSite.class);
- viewSite.setSelectionProvider(EasyMock.isA(SearchConsoleSelectionProvider.class));
- EasyMock.expectLastCall();
- EasyMock.expect(viewSite.getShell()).andStubReturn(activeShell);
- EasyMock.replay(viewSite);
-
- createViewToTest();
- EasyMock.verify(viewSite);
- }
-
- public void testManageDestinationsHyperLink()
- {
- createViewToTest();
- try
- {
- Hyperlink hl = findManageDestinationsLink();
- TESTER.click(hl);
- //pref page window is open
-
- Widget w = FINDER.find(new EnhancedTextMatcher("DiscoveryUiTestPreferencePage")); //$NON-NLS-1$
- TESTER.click(w);
- FINDER.find(new EnhancedTextMatcher("MyTestLabel")); //$NON-NLS-1$
- FINDER.find(new EnhancedTextMatcher("Button1")); //$NON-NLS-1$
-
- //close pref page window
- Button cancelButton = (Button)FINDER.find(new EnhancedTextMatcher("Cancel", Button.class)); //$NON-NLS-1$
- assertNotNull(cancelButton);
- TESTER.click(cancelButton);
- }
- catch (Exception e) {
- fail("Unexpexted exception was thrown: "+e.getMessage()); //$NON-NLS-1$
- }
+import org.eclipse.platform.discovery.ui.test.comp.internal.fixture.SearchConsoleTestFixture;
+import org.eclipse.platform.discovery.ui.test.comp.internal.pageobjects.SearchConsolePageObject;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+
+public class SearchConsoleViewTest
+{
+ private SearchConsolePageObject consolePageObject;
+ private static SearchConsoleTestFixture fixture;
+
+ @Mock
+ private IAdvancedSearchParamsDisplayer searchParamsDisplayer;
+
+ private final static String KEYWORD_SEARCH_PARAMETER = "my keyword param"; //$NON-NLS-1$
+ private final static String testSessionId = "testsessionid"; //$NON-NLS-1$
+
+ protected ITabbedSessionDisplayer<ISearchContext> sessionDisplayer;
+ protected IViewUiContext uiContext;
+
+ @BeforeClass
+ public static void initFixture()
+ {
+ fixture = new SearchConsoleTestFixture();
}
- public void testObjectTypeWithNoDestinations() throws NotFoundException, MultipleFoundException
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp()
{
- createViewToTest();
- final Combo objectTypesCombo = getObjectTypesCombo();
- comboTester.actionSelectItem(objectTypesCombo, OBJECT_TYPE_NO_DESTINATIONS_NAME);
- Text keywordSearchText = getKeywordsSearchText();
- assertTrue("keyword text should be enabled", textTester.isEnabled(keywordSearchText));
- assertEquals("did not expect a search criteria", "", textTester.getText(keywordSearchText));
- assertTrue("keyword text should be editable", textTester.getEditable(keywordSearchText));
- assertFalse("Search should be disabled because there is no search criteria", buttonTester.isEnabled(getSearchButton()));
-
- textTester.actionKeyString(getKeywordsSearchText(), "asd");
- assertTrue("Search should be enabled because search criteria was provided", buttonTester.isEnabled(getSearchButton()));
+ MockitoAnnotations.initMocks(this);
+
+ sessionDisplayer = Mockito.mock(ITabbedSessionDisplayer.class);
+ searchParamsDisplayer = Mockito.mock(IAdvancedSearchParamsDisplayer.class);
+
+ consolePageObject = new SearchConsolePageObject(fixture.searchProviderConfiguration, sessionDisplayer, searchParamsDisplayer, fixture.environment, fixture.viewUiContext);
+ consolePageObject.open();
+ }
+
+ @After
+ public void tearDown()
+ {
+ consolePageObject.close();
+ }
+
+ @Test
+ public void testSelectingObjectsChangesDestinations()
+ {
+ Assert.assertNull("No objects selected expected by default", consolePageObject.getSelectedObject());
+ Assert.assertEquals("No destination categories expected to be visible by default", 0, consolePageObject.getCategories().size());
+
+ // select the first object type
+ selectObject(fixture.objectType1);
+ consolePageObject.expandDestinations();
+ assertSingleCategoryVisible(fixture.category1);
+ assertDestinationsVisible(fixture.category1, fixture.destination1, fixture.destination2);
+
+ // select the second object type
+ selectObject(fixture.objectType2);
+ consolePageObject.expandDestinations();
+ assertSingleCategoryVisible(fixture.category2);
+ assertDestinationsVisible(fixture.category2, fixture.destination3, fixture.destination4);
}
+ private void assertDestinationsVisible(final IDestinationCategoryDescription category, final ISearchDestination... expectedDestinations)
+ {
+ final Collection<String> visibleDestinations = consolePageObject.getDestinationsForCategory(category.getDisplayName());
+ Assert.assertEquals(MessageFormat.format("Unexpected destinations caount for category {0}", category.getDisplayName()), expectedDestinations.length, visibleDestinations.size());
+ for(ISearchDestination expectedDest : expectedDestinations)
+ {
+ Assert.assertTrue(MessageFormat.format("Destination {0} not visible", expectedDest.getDisplayName()), visibleDestinations.contains(expectedDest.getDisplayName()));
+ }
+ }
+
+ private void assertSingleCategoryVisible(final IDestinationCategoryDescription category)
+ {
+ final Collection<String> visibleCategories = consolePageObject.getCategories();
+ Assert.assertTrue(MessageFormat.format("Category {0} not available", category.getDisplayName()), visibleCategories.contains(category.getDisplayName()));
+ Assert.assertEquals("Expected to display exactly one category", 1, visibleCategories.size());
+ }
+
+ @Test
+ public void testSelectingObjectsNotifiesAdvancedParametersComponent()
+ {
+ selectObject(fixture.objectType1);
+ Mockito.verify(searchParamsDisplayer, Mockito.atLeastOnce()).update(fixture.objectType1, null, fixture.environment, fixture.viewUiContext);
+ }
+
+ @Test
+ public void testUiComponentsEnableProgressively()
+ {
+ Assert.assertTrue("Search for list should be enabled", consolePageObject.canSelectObject());
+ Assert.assertFalse("Search in tree should be disabled", consolePageObject.canSelectDestination());
+ Assert.assertFalse("Keywords text should be disabled", consolePageObject.canEnterSearchText());
+ Assert.assertFalse("Subdestinations should be disabled", consolePageObject.canSelectSubdestination());
+ Assert.assertFalse("Search button should be disabled", consolePageObject.canSearch());
+ Assert.assertFalse("Group by combo should be disabled", consolePageObject.canSelectHierarchy());
+
+ // select the first object type
+ selectObject(fixture.objectType1);
+ Assert.assertTrue("Search in list should be enabled", consolePageObject.canSelectDestination());
+ Assert.assertFalse("Keywords text should be disabled", consolePageObject.canEnterSearchText());
+ Assert.assertFalse("Subdestinations should be disabled", consolePageObject.canSelectSubdestination());
+ Assert.assertFalse("Search button should be disabled", consolePageObject.canSearch());
+ Assert.assertFalse("Group by combo should be disabled", consolePageObject.canSelectHierarchy());
+
+ // select first destination
+ consolePageObject.selectFirstPossibleDestination();
+ Assert.assertFalse("Keywords text should be disabled", consolePageObject.canEnterSearchText());
+ Assert.assertTrue("Subdestinations should be enabled", consolePageObject.canSelectDestination());
+ Assert.assertTrue("Search button should be enabled", consolePageObject.canSearch());
+ Assert.assertFalse("Group by combo should not be disabled", consolePageObject.canSelectHierarchy());
+
+ // Select the second object type and third destination. This would select a search provider which has grouping hierarchy capability and
+ // supports text search
+ selectObject(fixture.objectType2);
+ consolePageObject.selectFirstPossibleDestination();
+ Assert.assertTrue("Group by combo should be enabled", consolePageObject.canSelectHierarchy());
+ Assert.assertTrue("Keywords text should be enabled", consolePageObject.canEnterSearchText());
+
+ // Select the first object type and first destination. This would determine a search provider which has no grouping hierarchy capability and
+ // does not support text search
+ selectObject(fixture.objectType1);
+ consolePageObject.selectFirstPossibleDestination();
+ Assert.assertFalse("Group by combo should be disabled", consolePageObject.canSelectHierarchy());
+ Assert.assertFalse("Keywords text should be disabled", consolePageObject.canEnterSearchText());
+ }
+
+ @Test
+ public void testGroupingHieararchyComboDisplaysFirstElementByDefault()
+ {
+ selectObject(fixture.objectType2);
+ consolePageObject.selectFirstPossibleDestination();
+ Assert.assertEquals("Group by combo does not display the item expected", fixture.groupingHierarchy1.getDisplayName(), consolePageObject.getSelectedGroupingHierarchy());
+ }
+
+ @Test
+ public void testSubdestinationsButtonEnablement()
+ {
+ selectObject(fixture.objectType1);
+ consolePageObject.selectFirstPossibleDestination();
+ Assert.assertTrue("Subdestinations button should be enabled when subdestinations available", consolePageObject.canSelectSubdestination());
+
+ selectObject(fixture.objectType2);
+ consolePageObject.selectFirstPossibleDestination();
+ Assert.assertFalse("Subdestinations button should not be enabled when subdestinations not available", consolePageObject.canSelectSubdestination());
+ }
+
+ private void selectObject(final IObjectTypeDescription object)
+ {
+ consolePageObject.selectObject(object.getDisplayName());
+ }
+
+ @Test
+ public void testChangingObjectTypesDisablesKeywordAndSubdestinationsSection()
+ {
+ selectObject(fixture.objectType2);
+ consolePageObject.selectFirstPossibleDestination();
+ Assert.assertTrue("Keywords text should be enabled", consolePageObject.canEnterSearchText());
+ Assert.assertFalse("Subdestinations should be disabled", consolePageObject.canSelectSubdestination());
+
+ selectObject(fixture.objectType1);
+ consolePageObject.selectFirstPossibleDestination();
+ Assert.assertFalse("Keywords text should be disabled after object type change", consolePageObject.canEnterSearchText());
+ Assert.assertTrue("Subdestinations should be enabled", consolePageObject.canSelectSubdestination());
+ }
+
+ @Test
+ public void testKeywordsEnablementChangesWhenActiveProvidersChange()
+ {
+ // By default, there is nothing selected, the keyword text is set to SearchConsoleView_NoObjectTypeSelectedHint
+ Assert.assertEquals(MessageFormat.format("The keyword text should be set to \"{0}\" when disabled", DiscoveryUIMessages.SearchConsoleView_NoObjectTypeSelectedHint), DiscoveryUIMessages.SearchConsoleView_NoObjectTypeSelectedHint, consolePageObject.getKeyword());
+ Assert.assertFalse("Keywords text should not be enabled", consolePageObject.canEnterSearchText());
+
+ // Select object 3
+ // When there is only one destination it should be selected by default and the keyword text is set to
+ // DiscoveryUIMessages.SearchConsoleView_EnterKeywordHint
+ selectObject(fixture.objectType3);
+ Assert.assertEquals(MessageFormat.format("The keyword text should be set to \"{0}\"", DiscoveryUIMessages.SearchConsoleView_EnterKeywordHint), DiscoveryUIMessages.SearchConsoleView_EnterKeywordHint, consolePageObject.getKeyword());
+ Assert.assertTrue("Keywords text should not be enabled", consolePageObject.canEnterSearchText());
+
+ // Select object 2
+ selectObject(fixture.objectType2);
+ // When there is no destination selected, the keyword text is set to DiscoveryUIMessages.SearchConsoleView_NoDestinationSelectedHint when the current search provider does not support text search
+ Assert.assertEquals(MessageFormat.format("The keyword text should be set to \"{0}\" when disabled", DiscoveryUIMessages.SearchConsoleView_NoDestinationSelectedHint), DiscoveryUIMessages.SearchConsoleView_NoDestinationSelectedHint, consolePageObject.getKeyword());
+ Assert.assertFalse("Keywords text should not be enabled", consolePageObject.canEnterSearchText());
+
+ consolePageObject.selectFirstPossibleDestination();
+ Assert.assertTrue("Keywords text should be enabled", consolePageObject.canEnterSearchText());
+ consolePageObject.enterKeyword("HELLO!");
+
+ // Select object 1
+ selectObject(fixture.objectType1);
+ consolePageObject.selectFirstPossibleDestination();
+ Assert.assertFalse("Keywords text should not be enabled", consolePageObject.canEnterSearchText());
+ // When the keyword text is disabled, its text is set to DiscoveryUIMessages.SearchConsoleView_UnsuuportedTextSearch when the current search
+ // provider does not support text search
+ Assert.assertEquals(MessageFormat.format("The keyword text should be set to \"{0}\" when disabled", DiscoveryUIMessages.SearchConsoleView_UnsupportedTextSearch), DiscoveryUIMessages.SearchConsoleView_UnsupportedTextSearch, consolePageObject.getKeyword());
+ }
+
+ @Test
+ public void testSearch()
+ {
+ selectObject(fixture.objectType2);
+ consolePageObject.selectDestination(fixture.category2.getDisplayName(), fixture.destination4.getDisplayName());
+ consolePageObject.enterKeyword(KEYWORD_SEARCH_PARAMETER);
+ consolePageObject.search();
+
+ consolePageObject.verifySearchPerformed(fixture.objectType2.getId(), fixture.destination4.getDisplayName(), KEYWORD_SEARCH_PARAMETER);
+ Mockito.verify(searchParamsDisplayer).setParams(Mockito.any(ISearchParameters.class));
+ }
+
+ @Test
+ public void testChangingDestinationsUpdatesAdvancedSearchParams()
+ {
+ Mockito.stub(searchParamsDisplayer.isEnabled()).toReturn(true);
+ selectObject(fixture.objectType1);
+ consolePageObject.selectFirstPossibleDestination();
+ Mockito.verify(searchParamsDisplayer).update(fixture.objectType1, fixture.destination1, fixture.environment, fixture.viewUiContext);
+ }
+
+ @Test
+ public void testShowResultInSession()
+ {
+ final ISearchSession session = Mockito.mock(ISearchSession.class);
+ Mockito.stub(session.getId()).toReturn(testSessionId);
+
+ final String searchProviderId = fixture.supportingTextSearchProviderDescription.getId();
+ final ISearchContext searchContext = Mockito.mock(ISearchContext.class);
+ Mockito.stub(searchContext.searchProviderId()).toReturn(searchProviderId);
+ Mockito.stub(searchContext.session()).toReturn(session);
+
+ consolePageObject.showResult(searchContext);
+ Mockito.verify(sessionDisplayer).display(session);
+ }
+
+ @Test
+ public void testViewRegistersProperSelectionProvider()
+ {
+ Mockito.verify(consolePageObject.getViewSiteMock()).setSelectionProvider(Mockito.any(SearchConsoleSelectionProvider.class));
+ }
+
+ @Test
+ public void testManageDestinations()
+ {
+ consolePageObject.verifyManageDestinationsWorksCorrectly();
+ }
+
+ @Test
+ public void testObjectTypeWithNoDestinations()
+ {
+ selectObject(fixture.objectTypeNoDestinations);
+ Assert.assertTrue("keyword text should be enabled", consolePageObject.canEnterSearchText());
+ Assert.assertFalse("Search should be disabled because there is no search criteria", consolePageObject.canSearch());
+
+ consolePageObject.enterKeyword("asd");
+ Assert.assertTrue("Search should be enabled because search criteria was provided", consolePageObject.canSearch());
+ }
+
+ @Test
public void testRegisteringIllegalViewCustomization()
{
- createViewToTest();
-
- final IGenericViewCustomization illegalCustomization = EasyMock.createMock(IGenericViewCustomization.class);
+ final IGenericViewCustomization illegalCustomization = Mockito.mock(IGenericViewCustomization.class);
try
{
- testView.registerViewCustomization(illegalCustomization);
- fail("IllegalArgumentException for illegal customization"); //$NON-NLS-1$
+ consolePageObject.registerViewCustomization(illegalCustomization);
+ Assert.fail("IllegalArgumentException for illegal customization"); //$NON-NLS-1$
}
- catch(IllegalArgumentException e)
+ catch (IllegalArgumentException e)
{
- //expected
+ // expected
}
}
-
-
- private Hyperlink findManageDestinationsLink()
- {
- final Hyperlink[] result = new Hyperlink[1];
- Assertions.waitAssert(new IWaitCondition()
- {
- @Override
- public boolean checkCondition() throws ConditionCheckException
- {
- Hyperlink hl;
- try
- {
- //hl = (Hyperlink)FINDER.find(new ClassMatcher<Widget>(Hyperlink.class));
- hl = (Hyperlink)FINDER.find(new EnhancedTextMatcher(DiscoveryUIMessages.SearchConsoleView_MANAGED_CONFIGS_LINK, true, Hyperlink.class));
- } catch (NotFoundException e)
- {
- return false;
- } catch (MultipleFoundException e)
- {
- return false;
- }
-
- result[0] = hl;
-
- return true;
- }
- }, "Hyperlink not found");
-
- return result[0];
- }
-
- private MyConsoleView createTestView()
- {
- final MyConsoleView[] v = new MyConsoleView[1];
- getDisplay().syncExec(new Runnable(){
- public void run()
- {
- v[0] = new MyConsoleView();
- v[0].setEnvironment(environment);
- v[0].setUiContext(uiContext);
- }});
- return v[0];
- }
-
- private void createViewToTest()
- {
- testShell = createTestShell();
- testView = createTestView();
- openView(testView, testShell);
- }
-
- private void openView(final SearchConsoleView view, final Shell shell)
- {
- final String[] shellName = new String[1];
- getDisplay().syncExec(new Runnable()
- {
- public void run()
- {
- shellName[0] = shell.getText();
- }
- });
- getDisplay().asyncExec(new Runnable()
- {
-
- public void run()
- {
- shell.setLayout(new FillLayout(SWT.HORIZONTAL));
- view.createPartControl(shell);
- shell.open();
- shell.layout();
- view.setDefaultSessionId(DefaultSessionIds.mainSearchSessionId);
- view.setEnvironment(environment);
- viewController = new MySearchConsoleController(searchProviderConfiguration, view, environment, null, DefaultSessionIds.mainSearchSessionId);
- view.registerController(viewController);
- view.initializationCompleted();
- }
- });
- waitForShell(shellName[0]);
- }
-
- private class MyConsoleView extends SearchConsoleView
- {
- protected ISearchProviderConfiguration getSearchProviderConfiguration()
- {
- return searchProviderConfiguration;
- };
-
- @Override
- protected ITabbedSessionDisplayer<ISearchContext> createSessionsDisplayer()
- {
- return sessionDisplayer;
- }
-
- @Override
- public IWorkbenchPartSite getSite()
- {
- return viewSite;
- }
-
- @Override
- protected IAdvancedSearchParamsDisplayer createAdvancedSearchParamsDisplayer( Composite parent, FormToolkit formToolkit) {
- return searchParamsDisplayer;
- }
- }
-
- private class MySearchConsoleController extends SearchConsoleController
- {
- public SearchEvent lastSearchEvent;
-
- public MySearchConsoleController(ISearchProviderConfiguration providerConfiguration, ISearchConsoleControllerOutputView searchConsoleView, IDiscoveryEnvironment consoleEnv,
- ISessionManager<ISearchSession> sessionManager, String defaultSessionId)
- {
- super(providerConfiguration, searchConsoleView, consoleEnv, sessionManager, defaultSessionId);
- }
-
- @Override
- protected ISearchEventHandler createSearchEventHandler()
- {
- return new ISearchEventHandler()
- {
- @Override
- public void handleSearch(SearchEvent event) throws ProviderNotFoundException, SearchFailedException
- {
- lastSearchEvent = event;
- }
- };
- }
-
- }
-}
+}

Back to the top