From 85d7690bfd92021018761932338c31f57288242b Mon Sep 17 00:00:00 2001 From: Frank Gasdorf Date: Sat, 4 Jul 2020 14:11:29 +0200 Subject: [PATCH] fixes catalog tests (remote demo WMS catalog changed) Signed-off-by: Frank Gasdorf --- .../tests/ui/workflow/DialogDriver.java | 225 +++++++++--------- .../ui/workflow/ResourceSelectionTest.java | 223 ++++++++--------- .../udig/tools/merge/MergeStartup.java | 41 ++-- 3 files changed, 244 insertions(+), 245 deletions(-) diff --git a/plugins/org.locationtech.udig.catalog.ui.tests/src/org/locationtech/udig/catalog/tests/ui/workflow/DialogDriver.java b/plugins/org.locationtech.udig.catalog.ui.tests/src/org/locationtech/udig/catalog/tests/ui/workflow/DialogDriver.java index 5f027f4442..61d30cc5ab 100644 --- a/plugins/org.locationtech.udig.catalog.ui.tests/src/org/locationtech/udig/catalog/tests/ui/workflow/DialogDriver.java +++ b/plugins/org.locationtech.udig.catalog.ui.tests/src/org/locationtech/udig/catalog/tests/ui/workflow/DialogDriver.java @@ -17,124 +17,123 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Shell; + /** * This class is insane the good part is the push and findbuttons as helpers for testing. * */ public class DialogDriver extends Job { - public static long DELAY = 100; - - Dialog dialog; - - Object[] actions; - - /** - * This should be null if no errors occurred otherwise there should be debug - * message - */ - public String error; - - public DialogDriver(Dialog dialog, Object[] actions) { - super("driver"); //$NON-NLS-1$ - - this.dialog = dialog; - this.actions = actions; - } - - @Override - protected IStatus run(IProgressMonitor monitor) { - try { - final ArrayList l = new ArrayList(); - l.add(true); - - while (l.get(0)) { - Display.getDefault().syncExec(new Runnable() { - public void run() { - l.set(0, dialog.getShell() == null - || dialog.getShell().isDisposed() - || !dialog.getShell().isVisible()); - } - }); - Thread.sleep(DELAY); - } - - for (int i = 0; i < actions.length; i++) { - final Object action = actions[i]; - dialog.getShell().getDisplay().syncExec(new Runnable() { - public void run() { - if (action instanceof Assertion) - ((Assertion) action).run(); - else if (action instanceof Runnable) - ((Runnable) action).run(); - else if (action instanceof Integer) - pushButton(dialog, ((Integer) action).intValue()); - - } - }); - - Thread.sleep(DELAY); - } - - } - - catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return Status.OK_STATUS; - } - - public static void pushButton(Dialog dialog, int id) { - Shell shell = dialog.getShell(); - Button button = findButton(shell.getChildren(), id, shell); - if( !button.isEnabled() ) - throw new RuntimeException("Error button to press is not enabled"); //$NON-NLS-1$ - button.notifyListeners(SWT.Selection, new Event()); - } - - public static Button findButton(Dialog dialog, int id) { - Shell shell = dialog.getShell(); - Button found = findButton(shell.getChildren(), id, shell); - if (found != null) - return found; - - Display display = Display.getCurrent(); - shell = display.getActiveShell(); - found = findButton(shell.getChildren(), id, shell); - if (found != null) - return found; - - Shell[] shells = display.getShells(); - for (Shell shell2 : shells) { - found = findButton(shell2.getChildren(), id, shell2); - if (found != null) - return found; - } - return null; - } - - public static Button findButton(Control[] children, int id, Shell shell) { - if (((Integer) shell.getDefaultButton().getData()).intValue() == id) - return shell.getDefaultButton(); - - for (Control child : children) { - if (child instanceof Button) { - Button button = (Button) child; - Object data = button.getData(); - if (data != null) { - if (((Integer) data).intValue() == id) - return button; - } - } - if (child instanceof Composite) { - Composite composite = (Composite) child; - Button button = findButton(composite.getChildren(), id, shell); - if (button != null) - return button; - } - } - return null; - } + public static long DELAY = 100; + + Dialog dialog; + + Object[] actions; + + /** + * This should be null if no errors occurred otherwise there should be debug message + */ + public String error; + + public DialogDriver(Dialog dialog, Object[] actions) { + super("driver"); //$NON-NLS-1$ + + this.dialog = dialog; + this.actions = actions; + } + + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + final ArrayList l = new ArrayList(); + l.add(true); + + while (l.get(0)) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + l.set(0, dialog.getShell() == null || dialog.getShell().isDisposed() + || !dialog.getShell().isVisible()); + } + }); + Thread.sleep(DELAY); + } + + for (int i = 0; i < actions.length; i++) { + final Object action = actions[i]; + dialog.getShell().getDisplay().syncExec(new Runnable() { + public void run() { + if (action instanceof Assertion) + ((Assertion) action).run(); + else if (action instanceof Runnable) + ((Runnable) action).run(); + else if (action instanceof Integer) + pushButton(dialog, ((Integer) action).intValue()); + + } + }); + + Thread.sleep(DELAY); + } + + } + + catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return Status.OK_STATUS; + } + + public static void pushButton(Dialog dialog, int id) { + Shell shell = dialog.getShell(); + Button button = findButton(shell.getChildren(), id, shell); + if (!button.isEnabled()) + throw new RuntimeException("Error button to press is not enabled"); //$NON-NLS-1$ + button.notifyListeners(SWT.Selection, new Event()); + } + + public static Button findButton(Dialog dialog, int id) { + Shell shell = dialog.getShell(); + Button found = findButton(shell.getChildren(), id, shell); + if (found != null) + return found; + + Display display = Display.getCurrent(); + shell = display.getActiveShell(); + found = findButton(shell.getChildren(), id, shell); + if (found != null) + return found; + + Shell[] shells = display.getShells(); + for (Shell shell2 : shells) { + found = findButton(shell2.getChildren(), id, shell2); + if (found != null) + return found; + } + return null; + } + + public static Button findButton(Control[] children, int id, Shell shell) { + if (((Integer) shell.getDefaultButton().getData()).intValue() == id) + return shell.getDefaultButton(); + + for (Control child : children) { + if (child instanceof Button) { + Button button = (Button) child; + Object data = button.getData(); + if (data != null) { + if (((Integer) data).intValue() == id) + return button; + } + } + if (child instanceof Composite) { + Composite composite = (Composite) child; + Button button = findButton(composite.getChildren(), id, shell); + if (button != null) + return button; + } + } + return null; + } } diff --git a/plugins/org.locationtech.udig.catalog.ui.tests/src/org/locationtech/udig/catalog/tests/ui/workflow/ResourceSelectionTest.java b/plugins/org.locationtech.udig.catalog.ui.tests/src/org/locationtech/udig/catalog/tests/ui/workflow/ResourceSelectionTest.java index 9714362384..4d88cf8c94 100644 --- a/plugins/org.locationtech.udig.catalog.ui.tests/src/org/locationtech/udig/catalog/tests/ui/workflow/ResourceSelectionTest.java +++ b/plugins/org.locationtech.udig.catalog.ui.tests/src/org/locationtech/udig/catalog/tests/ui/workflow/ResourceSelectionTest.java @@ -39,114 +39,121 @@ import org.junit.Test; public class ResourceSelectionTest { - Shell shell; - - WorkflowWizard wizard; - - WorkflowWizardDialog dialog; - - EndConnectionState conn; - ResourceSelectionState state; - - ConnectionPageDecorator connPage; - ResourceSelectionPage page; - - private Workflow workflow; - - @Before - public void setUp() throws Exception { - - ArrayList l = new ArrayList(); - l.add("org.locationtech.udig.catalog.ui.WMS"); //$NON-NLS-1$ - - UDIGConnectionFactoryDescriptor d = ConnectionFactoryManager.instance().getConnectionFactoryDescriptors(l).get(0); - - conn = new EndConnectionState(d,true); - state = new ResourceSelectionState(); - - connPage = new ConnectionPageDecorator(); - page = new ResourceSelectionPage("foo"); //$NON-NLS-1$ - - Map, WorkflowWizardPageProvider> map = - new HashMap, WorkflowWizardPageProvider>(); - - map.put(state.getClass(), new BasicWorkflowWizardPageFactory(page)); - map.put(conn.getClass(), new BasicWorkflowWizardPageFactory(connPage)); - - workflow = new Workflow(); - workflow.setStates(new State[] { conn, state }); - - wizard = new WorkflowWizard(workflow, map); - - shell = new Shell(Display.getDefault()); - dialog = new WorkflowWizardDialog(shell, wizard); - dialog.setBlockOnOpen(true); - } - - @After - public void tearDown() throws Exception { - if (!shell.isDisposed()) - shell.dispose(); - } - - @Test - public void testNormal() throws Exception { - //create a context - URL url = new URL(CatalogTestsUIPlugin.WMSTestCapabilitiesURL); - CatalogTestUtils.assumeNoConnectionException(url, 3000); - workflow.setContext(url); - - Assertion a1 = new Assertion() { - @Override - public void run() { - fail = page.getViewer().getTree().getItemCount() != 1; - if (!fail) { - fail = page.getViewer().getTree().getItem(0).getItemCount() < 1; - } - if (!fail) - fail = page.getViewer().getCheckedElements().length != 0; - } - }; - Object[] actions = new Object[]{IDialogConstants.NEXT_ID, a1, IDialogConstants.CANCEL_ID}; - - DialogDriver driver = new DialogDriver(dialog,actions); - driver.schedule(); - - dialog.open(); - - assertFalse(a1.fail); - driver.cancel(); - } - - @Test - public void testNormalSelectedGeoResource() throws Exception { - //create a workbench selection - URL url = new URL(CatalogTestsUIPlugin.WMSTestCapabilitiesURL + "#topp:tasmania_cities"); //$NON-NLS-1$ - CatalogTestUtils.assumeNoConnectionException(url, 3000); - workflow.setContext(url); - - Assertion a1 = new Assertion() { - @Override - public void run() { - fail = page.getViewer().getTree().getItemCount() != 1; - if (!fail) { - fail = page.getViewer().getTree().getItem(0).getItemCount() < 1; - } - if (!fail) - fail = page.getViewer().getCheckedElements().length != 2; - } - }; - Object[] actions = new Object[]{IDialogConstants.NEXT_ID, a1, IDialogConstants.CANCEL_ID}; - - DialogDriver driver = new DialogDriver(dialog,actions); - driver.schedule(); - - dialog.setBlockOnOpen(true); - dialog.open(); - - assertFalse(a1.fail); - driver.cancel(); - } + Shell shell; + WorkflowWizard wizard; + + WorkflowWizardDialog dialog; + + EndConnectionState conn; + + ResourceSelectionState state; + + ConnectionPageDecorator connPage; + + ResourceSelectionPage page; + + private Workflow workflow; + + @Before + public void setUp() throws Exception { + + ArrayList l = new ArrayList(); + l.add("org.locationtech.udig.catalog.ui.WMS"); //$NON-NLS-1$ + + UDIGConnectionFactoryDescriptor d = ConnectionFactoryManager.instance() + .getConnectionFactoryDescriptors(l).get(0); + + conn = new EndConnectionState(d, true); + state = new ResourceSelectionState(); + + connPage = new ConnectionPageDecorator(); + page = new ResourceSelectionPage("foo"); //$NON-NLS-1$ + + Map, WorkflowWizardPageProvider> map = new HashMap, WorkflowWizardPageProvider>(); + + map.put(state.getClass(), new BasicWorkflowWizardPageFactory(page)); + map.put(conn.getClass(), new BasicWorkflowWizardPageFactory(connPage)); + + workflow = new Workflow(); + workflow.setStates(new State[] { conn, state }); + + wizard = new WorkflowWizard(workflow, map); + + shell = new Shell(Display.getDefault()); + dialog = new WorkflowWizardDialog(shell, wizard); + dialog.setBlockOnOpen(true); + } + + @After + public void tearDown() throws Exception { + if (!shell.isDisposed()) + shell.dispose(); + } + + @Test + public void testNormal() throws Exception { + // create a context + URL url = new URL(CatalogTestsUIPlugin.WMSTestCapabilitiesURL); + CatalogTestUtils.assumeNoConnectionException(url, 3000); + workflow.setContext(url); + + Assertion a1 = new Assertion() { + @Override + public void run() { + fail = page.getViewer().getTree().getItemCount() != 1; + if (!fail) { + fail = page.getViewer().getTree().getItem(0).getItemCount() < 1; + } + if (!fail) + fail = page.getViewer().getCheckedElements().length != 0; + } + }; + Object[] actions = new Object[] { IDialogConstants.NEXT_ID, a1, + IDialogConstants.CANCEL_ID }; + + DialogDriver driver = new DialogDriver(dialog, actions); + driver.schedule(); + + dialog.open(); + + assertFalse(a1.fail); + driver.cancel(); + } + + @Test + public void testNormalSelectedGeoResource() throws Exception { + // create a workbench selection + URL url = new URL(CatalogTestsUIPlugin.WMSTestCapabilitiesURL + "#atlantis:poi"); //$NON-NLS-1$ + CatalogTestUtils.assumeNoConnectionException(url, 3000); + workflow.setContext(url); + + Assertion a1 = new Assertion() { + @Override + public void run() { + // expect 1 item + fail = !(page.getViewer().getTree().getItemCount() == 1); + if (!fail) { + // expect at least 1 element in sub-tree + fail = page.getViewer().getTree().getItem(0).getItemCount() < 1; + } + if (!fail) { + // expect two selected elements + fail = !(page.getViewer().getCheckedElements().length == 2); + } + } + }; + Object[] actions = new Object[] { IDialogConstants.NEXT_ID, a1, + IDialogConstants.CANCEL_ID }; + + DialogDriver driver = new DialogDriver(dialog, actions); + driver.schedule(); + + dialog.setBlockOnOpen(true); + dialog.open(); + + assertFalse(a1.fail); + driver.cancel(); + } } diff --git a/plugins/org.locationtech.udig.tools/src/org/locationtech/udig/tools/merge/MergeStartup.java b/plugins/org.locationtech.udig.tools/src/org/locationtech/udig/tools/merge/MergeStartup.java index 82e1a78bbf..c76062ac6c 100644 --- a/plugins/org.locationtech.udig.tools/src/org/locationtech/udig/tools/merge/MergeStartup.java +++ b/plugins/org.locationtech.udig.tools/src/org/locationtech/udig/tools/merge/MergeStartup.java @@ -9,14 +9,12 @@ */ package org.locationtech.udig.tools.merge; -import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IStartup; +import org.eclipse.ui.IViewPart; import org.eclipse.ui.IViewReference; import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; - import org.locationtech.udig.tools.merge.internal.view.MergeView; /** @@ -37,13 +35,6 @@ */ public class MergeStartup implements IStartup { - /** - * - */ - public MergeStartup() { - // TODO Auto-generated constructor stub - } - /* * (non-Javadoc) * @@ -51,20 +42,22 @@ public MergeStartup() { */ @Override public void earlyStartup() { - IWorkbench wb = PlatformUI.getWorkbench(); - // IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); - IWorkbenchWindow[] winArray = wb.getWorkbenchWindows(); - final IWorkbenchPage page = winArray[0].getActivePage(); - // IWorkbenchPage page = win.getActivePage(); - final IViewReference viewRef = page.findViewReference(MergeView.ID); - // If there is an opened MergeView then close it! - if (viewRef != null) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - page.hideView(viewRef.getView(false)); + final IWorkbench workbench = PlatformUI.getWorkbench(); + workbench.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); + if (window != null && window.getActivePage() != null) { + IViewReference viewRef = window.getActivePage().findViewReference(MergeView.ID); + if (viewRef != null) { + IViewPart mergeViewPart = viewRef.getView(false); + if (mergeViewPart != null) { + // If there is an opened MergeView then close it! + window.getActivePage().hideView(mergeViewPart); + } + } } - }); - } + } + }); } }