-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…#346 Squashed commit of the following: commit 4dd1092 Author: Enda O Brien <E.OBrien@pilz.ie> Date: Fri Sep 20 17:52:36 2024 +0100 2 failing tests to demonstrate issue #345 ExtendedMarkersView .. Limit #346 Squashed commit of the following: commit 03b85b8 Merge: 693a6f1 c40b7a1 Author: eobrienPilz <58333578+eobrienPilz@users.noreply.github.com> Date: Mon Mar 25 12:31:05 2024 +0000 Merge branch 'master' into 345_ViewerFilterWithLimit commit 693a6f1 Author: Enda O Brien <E.OBrien@pilz.ie> Date: Tue Sep 20 13:01:09 2022 +0100 2 failing tests to demonstrate issue #345 ExtendedMarkersView .. Limit
- Loading branch information
1 parent
0986115
commit 73cf9be
Showing
4 changed files
with
330 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
232 changes: 232 additions & 0 deletions
232
...ipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/LimitAndViewerFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Enda O'Brien and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which accompanies this distribution, | ||
* and is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.ui.tests.markers; | ||
|
||
import org.eclipse.core.resources.IMarker; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.resources.IWorkspace; | ||
import org.eclipse.core.resources.ResourcesPlugin; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.jface.preference.IPreferenceStore; | ||
import org.eclipse.jface.viewers.ISelectionProvider; | ||
import org.eclipse.jface.viewers.ITreeContentProvider; | ||
import org.eclipse.jface.viewers.TreeViewer; | ||
import org.eclipse.swt.widgets.TreeItem; | ||
import org.eclipse.ui.IWorkbenchPage; | ||
import org.eclipse.ui.IWorkbenchWindow; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.eclipse.ui.internal.ide.IDEInternalPreferences; | ||
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; | ||
import org.eclipse.ui.tests.harness.util.UITestCase; | ||
import org.eclipse.ui.views.markers.MarkerItem; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
/** | ||
* | ||
* @since 3.5 | ||
* | ||
* Test that both the Content provider and TreeViewer for | ||
* ExtendedMarkersView are giving consistent results when applying a | ||
* ViewerFilter and marker limit. | ||
* | ||
*/ | ||
@RunWith(JUnit4.class) | ||
public class LimitAndViewerFilterTest extends UITestCase { | ||
|
||
/** | ||
* @param testName | ||
Check warning on line 51 in tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/LimitAndViewerFilterTest.java Jenkins - Eclipse Platform / JavaDocJavaDoc @param
|
||
*/ | ||
public LimitAndViewerFilterTest() { | ||
super(LimitAndViewerFilterTest.class.getSimpleName()); | ||
} | ||
|
||
final static int MARKER_LIMIT = 5, RED_MARKER_COUNT = 4, BLUE_MARKER_COUNT = 4; | ||
public static final String MARKER_COLOR_BLUE = "BLUE"; | ||
|
||
/** | ||
* Test set up with - A marker limit set to 5. - creates 4 red and 4 blue | ||
* markers in the workspace. | ||
* | ||
*/ | ||
@Before | ||
public void before() { | ||
// Enable Marker limit and set to 5 | ||
IPreferenceStore preferenceStore = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); | ||
preferenceStore.setValue(IDEInternalPreferences.USE_MARKER_LIMITS, true); | ||
preferenceStore.setValue(IDEInternalPreferences.MARKER_LIMITS_VALUE, MARKER_LIMIT); | ||
|
||
IWorkspace workspace = ResourcesPlugin.getWorkspace(); | ||
|
||
// create 4 red and 4 blue markers | ||
try { | ||
createMarkers(workspace, RED_MARKER_COUNT, RedProblemMarkerViewView.MARKER_COLOR_RED); | ||
createMarkers(workspace, BLUE_MARKER_COUNT, MARKER_COLOR_BLUE); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@After | ||
public void after() { | ||
IWorkspace workspace = ResourcesPlugin.getWorkspace(); | ||
deleteMarkers(workspace); | ||
} | ||
|
||
/** | ||
* | ||
* Test using a view that only displays red markers. The expected result is that | ||
* the TreeViewer should contain the 4 red markers and no blue markers. | ||
* | ||
* @throws Exception | ||
*/ | ||
|
||
@Test | ||
public void expectTreeViewerToContain4Markers() throws Exception { | ||
|
||
// Open the Red marker view and expand the view | ||
openView(); | ||
expandView(); | ||
// As the limit is 5, Expect that 4 red markers makes it into the tree | ||
// viewer | ||
validateViewerMarkerCounts(RED_MARKER_COUNT); | ||
} | ||
|
||
/** | ||
* Test using a view that only displays red markers. The expected result is that | ||
* the Content provider should display the 4 red markers and no blue markers. | ||
* | ||
* @throws Exception | ||
*/ | ||
|
||
@Test | ||
public void expectContentProviderToContainOnlyRedMarkers() throws Exception { | ||
// Open the Red marker view and expand the view | ||
openView(); | ||
expandView(); | ||
// Expect that only red markers makes it into the tree viewer | ||
validateContentProviderMarkerColors(RedProblemMarkerViewView.MARKER_COLOR_RED); | ||
} | ||
|
||
void openView() { | ||
IWorkbenchWindow ww = fWorkbench.getActiveWorkbenchWindow(); | ||
// Get current page | ||
|
||
try { | ||
IWorkbenchPage wp = ww.getActivePage(); | ||
|
||
wp.showView(RedProblemMarkerViewView.ID); | ||
|
||
processEventsUntil(() -> ww.getShell() != null, 10000); | ||
} catch (Exception e) { | ||
|
||
} | ||
} | ||
|
||
void expandView() { | ||
|
||
// Get current page | ||
IWorkbenchPage wp = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | ||
|
||
RedProblemMarkerViewView view; | ||
try { | ||
view = (RedProblemMarkerViewView) wp.showView(RedProblemMarkerViewView.ID); | ||
|
||
ISelectionProvider provider = view.getSite().getSelectionProvider(); | ||
TreeViewer viewer = (TreeViewer) provider; | ||
|
||
viewer.expandAll(); | ||
processEventsUntil(() -> viewer.getExpandedElements().length > 0, 10000); | ||
waitForJobs(100, 1000); | ||
} catch (Exception e) { | ||
throw new RuntimeException(); | ||
} | ||
} | ||
|
||
void validateViewerMarkerCounts(int expectedCount) { | ||
// Get current page | ||
IWorkbenchPage wp = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | ||
|
||
RedProblemMarkerViewView view; | ||
|
||
view = (RedProblemMarkerViewView) wp.findView(RedProblemMarkerViewView.ID); | ||
|
||
ISelectionProvider provider = view.getSite().getSelectionProvider(); | ||
TreeViewer viewer = (TreeViewer) provider; | ||
|
||
TreeItem[] viewerGroupRows = viewer.getTree().getItems(); | ||
TreeItem[] viewerMarkers = viewerGroupRows[0].getItems(); | ||
|
||
assertEquals(expectedCount, viewerMarkers.length); | ||
} | ||
|
||
void validateContentProviderMarkerColors(String expectedColor) { | ||
|
||
// Get current page | ||
IWorkbenchPage wp = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | ||
|
||
RedProblemMarkerViewView view; | ||
|
||
view = (RedProblemMarkerViewView) wp.findView(RedProblemMarkerViewView.ID); | ||
|
||
ISelectionProvider provider = view.getSite().getSelectionProvider(); | ||
TreeViewer viewer = (TreeViewer) provider; | ||
|
||
ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider(); | ||
Object[] contentProvGroupRows = contentProvider.getElements(null); | ||
Object[] contentProvMarkers = contentProvider.getChildren(contentProvGroupRows[0]); | ||
|
||
for (Object item : contentProvMarkers) { | ||
MarkerItem marker = (MarkerItem) item; | ||
String markerColor = marker.getAttributeValue(RedProblemMarkerViewView.MARKER_COLOR_ATTRIBUTE, ""); | ||
assertEquals(expectedColor, markerColor); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Create the given number of problem markers in the workspace and set the color | ||
* attribute using the color argument. | ||
* | ||
* @param workspace | ||
* @param count | ||
* @param color | ||
* @throws Exception | ||
*/ | ||
void createMarkers(IWorkspace workspace, int count, String color) throws Exception { | ||
for (int i = 0; i < count; i++) { | ||
IMarker marker = workspace.getRoot().createMarker(IMarker.PROBLEM); | ||
marker.setAttribute(RedProblemMarkerViewView.MARKER_COLOR_ATTRIBUTE, color); | ||
marker.setAttribute(IMarker.MESSAGE, color + ": " + i); | ||
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); | ||
} | ||
} | ||
|
||
/** | ||
* Delete all problem markers from the workspace. | ||
* | ||
* @param workspace | ||
*/ | ||
|
||
void deleteMarkers(IWorkspace workspace) { | ||
try { | ||
workspace.getRoot().deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); | ||
} catch (CoreException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
...ipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/markers/RedProblemMarkerViewView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Enda O'Brien and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which accompanies this distribution, | ||
* and is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.ui.tests.markers; | ||
|
||
import org.eclipse.jface.viewers.ISelectionProvider; | ||
import org.eclipse.jface.viewers.TreeViewer; | ||
import org.eclipse.jface.viewers.Viewer; | ||
import org.eclipse.jface.viewers.ViewerFilter; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.ui.IWorkbenchPage; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.eclipse.ui.views.markers.MarkerItem; | ||
import org.eclipse.ui.views.markers.MarkerSupportView; | ||
import org.eclipse.ui.views.markers.internal.MarkerSupportRegistry; | ||
|
||
/** | ||
* @since 3.5 | ||
* | ||
* A problem view that uses a VierweFilter to only show red markers. A | ||
* red marker is a problem marker with a color attribute set to red. | ||
*/ | ||
public class RedProblemMarkerViewView extends MarkerSupportView { | ||
public static final String ID = "org.eclipse.ui.tests.LimitAndViewerFilterView"; | ||
|
||
public static final String MARKER_COLOR_ATTRIBUTE = "COLOR"; | ||
public static final String MARKER_COLOR_RED = "RED"; | ||
|
||
/** | ||
* create the view using the problem marker generator | ||
*/ | ||
|
||
public RedProblemMarkerViewView() { | ||
super(MarkerSupportRegistry.PROBLEMS_GENERATOR); | ||
} | ||
|
||
@Override | ||
public void createPartControl(Composite parent) { | ||
super.createPartControl(parent); | ||
addViewerFilter(); | ||
} | ||
|
||
/** | ||
* Add a filter that removes all markers other than red markers. i.e. markers | ||
* where the value of MARKER_COLOR_ATTRIBUTE is MARKER_COLOR_RED | ||
*/ | ||
|
||
void addViewerFilter() { | ||
|
||
// Get current page | ||
IWorkbenchPage wp = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | ||
|
||
RedProblemMarkerViewView view; | ||
try { | ||
view = (RedProblemMarkerViewView) wp.showView(org.eclipse.ui.tests.markers.RedProblemMarkerViewView.ID); | ||
|
||
ISelectionProvider provider = view.getSite().getSelectionProvider(); | ||
|
||
TreeViewer viewer = (TreeViewer) provider; | ||
|
||
viewer.addFilter(new ViewerFilter() { | ||
|
||
@Override | ||
public boolean select(Viewer viewer, Object parentElement, Object element) { | ||
if (element instanceof MarkerItem) { | ||
MarkerItem item = (MarkerItem) element; | ||
|
||
// keep the group row | ||
if (item.getMarker() == null) { | ||
return true; | ||
} | ||
return MARKER_COLOR_RED.equals(item.getAttributeValue(MARKER_COLOR_ATTRIBUTE, "")); | ||
} | ||
return false; | ||
} | ||
}); | ||
} catch (Exception e) { | ||
throw new RuntimeException(); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters