Skip to content

Commit fddbde8

Browse files
committed
Rewrite "New Wizard" tests to no longer require the SWTBot runner
Newer Eclipse versions no longer launch a workspace when running a test outside the UI thread. Because this is a requirement for all of our SWTBot tests, we can no longer run them locally. The tests were originally written like that because they open a modal dialog and would thus lead to a deadlock if the test is also executed within the UI thread. But thanks to the changes to the `UiContext`, we have a way to make this work regardless.
1 parent dab6644 commit fddbde8

22 files changed

+161
-647
lines changed

org.eclipse.wb.tests/pom.xml

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -73,35 +73,6 @@
7373
<groupId>org.eclipse.tycho</groupId>
7474
<artifactId>tycho-surefire-plugin</artifactId>
7575
<version>${tycho.version}</version>
76-
<executions>
77-
<execution>
78-
<!-- Overwrites default goal! -->
79-
<id>default-test</id>
80-
<goals>
81-
<goal>test</goal>
82-
</goals>
83-
<configuration>
84-
<includes>
85-
<include>**/org.eclipse.wb.tests.designer.WindowBuilderTests.java</include>
86-
</includes>
87-
<useUIHarness>true</useUIHarness>
88-
<useUIThread>true</useUIThread>
89-
</configuration>
90-
</execution>
91-
<execution>
92-
<id>swtbot-test</id>
93-
<goals>
94-
<goal>test</goal>
95-
</goals>
96-
<configuration>
97-
<includes>
98-
<include>**/org.eclipse.wb.tests.swtbot.designer.WindowBuilderTests.java</include>
99-
</includes>
100-
<useUIHarness>true</useUIHarness>
101-
<useUIThread>false</useUIThread>
102-
</configuration>
103-
</execution>
104-
</executions>
10576
<configuration>
10677
<argLine>${ui.test.vmargs}</argLine>
10778
<appArgLine>-nl de -clearPersistedState -consoleLog</appArgLine>
@@ -114,6 +85,11 @@
11485
<version>0.0.0</version>
11586
</dependency>
11687
</dependencies>
88+
<includes>
89+
<include>**/org.eclipse.wb.tests.designer.WindowBuilderTests.java</include>
90+
</includes>
91+
<useUIHarness>true</useUIHarness>
92+
<useUIThread>true</useUIThread>
11793
</configuration>
11894
</plugin>
11995
</plugins>

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/core/nls/ui/PropertiesCompositeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import org.eclipse.wb.internal.core.nls.model.LocaleInfo;
1717
import org.eclipse.wb.internal.core.nls.ui.NewSourceDialog;
1818
import org.eclipse.wb.internal.core.nls.ui.PropertiesComposite;
19+
import org.eclipse.wb.internal.core.utils.execution.ExecutionUtils;
1920
import org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils;
2021
import org.eclipse.wb.tests.gef.UiContext;
21-
import org.eclipse.wb.tests.swtbot.designer.bot.UIUtil;
2222
import org.eclipse.wb.tests.utils.SWTBotEditableSource;
2323

2424
import static org.eclipse.swtbot.swt.finder.matchers.WidgetOfType.widgetOfType;
@@ -302,8 +302,8 @@ private static SWTBotTreeItem getItem(SWTBotTreeItem item, String... pathElement
302302
*/
303303
private static SWTBotEditableSource getEditableSource(SWTBot shell) throws Exception {
304304
PropertiesComposite composite = shell.getFinder().findControls(widgetOfType(PropertiesComposite.class)).get(0);
305-
IEditableSource editableSource = (IEditableSource) UIUtil
306-
.syncCall(() -> ReflectionUtils.invokeMethod(composite, "getSelectedSource()"));
305+
IEditableSource editableSource = (IEditableSource) UIThreadRunnable.syncExec(
306+
() -> ExecutionUtils.runObject(() -> ReflectionUtils.invokeMethod(composite, "getSelectedSource()")));
307307
return new SWTBotEditableSource(editableSource);
308308
}
309309
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023, 2025 Patrick Ziegler and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* https://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Patrick Ziegler - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.wb.tests.designer.rcp;
14+
15+
import org.eclipse.wb.tests.designer.TestUtils;
16+
import org.eclipse.wb.tests.designer.core.model.parser.AbstractJavaInfoRelatedTest;
17+
import org.eclipse.wb.tests.gef.UiContext;
18+
19+
import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellCloses;
20+
21+
import org.eclipse.core.resources.IFile;
22+
import org.eclipse.core.runtime.CoreException;
23+
import org.eclipse.core.runtime.Platform;
24+
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
25+
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
26+
import org.eclipse.swtbot.swt.finder.SWTBot;
27+
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
28+
import org.eclipse.ui.PlatformUI;
29+
30+
import org.junit.jupiter.api.AfterAll;
31+
import org.junit.jupiter.api.AfterEach;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.osgi.framework.Version;
34+
35+
import java.util.Arrays;
36+
37+
/**
38+
* Abstract base class for all tests that create Java files using the
39+
* {@code New Wizard}.
40+
*/
41+
public abstract class AbstractWizardTest extends RcpModelTest {
42+
private static Version ECLIPSE_VERSION = Platform.getBundle("org.eclipse.ui.workbench").getVersion();
43+
private static Version VERSION = new Version(3, 135, 0);
44+
// https://github.com/eclipse-platform/eclipse.platform/issues/1749
45+
private static String WIZARD_NAME = ECLIPSE_VERSION.compareTo(VERSION) > 0 ? "New" : "Select a wizard";
46+
private static boolean m_firstDesignerTest = true;
47+
private SWTWorkbenchBot workbench;
48+
private IFile editorFile;
49+
protected SWTBot editor;
50+
51+
@Override
52+
@BeforeEach
53+
public void setUp() throws Exception {
54+
super.setUp();
55+
if (m_firstDesignerTest) {
56+
m_firstDesignerTest = false;
57+
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().resetPerspective();
58+
}
59+
workbench = new SWTWorkbenchBot();
60+
}
61+
62+
@Override
63+
@AfterEach
64+
public void tearDown() throws Exception {
65+
if (editorFile != null) {
66+
forceDeleteResource(editorFile);
67+
}
68+
super.tearDown();
69+
}
70+
71+
72+
@AfterAll
73+
public static void tearDownAll() throws Exception {
74+
AbstractJavaInfoRelatedTest.tearDownAll();
75+
TestUtils.closeAllViews();
76+
m_firstDesignerTest = true;
77+
}
78+
79+
protected final void testTemplateViaProjectExplorer(String... fullPath) throws Exception {
80+
new UiContext().executeAndCheck(() -> {
81+
SWTBot projectExplorer = workbench.viewById("org.eclipse.ui.navigator.ProjectExplorer").bot();
82+
projectExplorer.tree().getTreeItem("TestProject").contextMenu().menu("New", "Other...").click();
83+
}, bot -> createTemplate(bot, fullPath));
84+
}
85+
86+
protected final void testTemplateViaMenu(String... fullPath) throws Exception {
87+
new UiContext().executeAndCheck(() -> {
88+
workbench.shell().menu().menu("File").menu("New", "Other...").click();
89+
}, bot -> createTemplate(bot, fullPath));
90+
}
91+
92+
private void createTemplate(SWTBot activeShell, String... fullPath) throws CoreException {
93+
assertTrue(fullPath.length > 1, "path requires at least one argument (template name)");
94+
String[] path = Arrays.copyOf(fullPath, fullPath.length - 1);
95+
String name = fullPath[fullPath.length - 1];
96+
String fileName = name.replace(' ', '_').replaceAll("\\(|\\)", "");
97+
98+
SWTBotShell shell = activeShell.shell(WIZARD_NAME);
99+
SWTBot bot = shell.bot();
100+
bot.tree().expandNode(path).getNode(name).select();
101+
bot.button("Next >").click();
102+
bot.text(1).setText("test");
103+
bot.text(2).setText(fileName);
104+
bot.button("Finish").click();
105+
// Wait for file creation
106+
bot.waitUntil(shellCloses(shell));
107+
// Open design page
108+
SWTBotEditor activeEditor = new SWTWorkbenchBot().activeEditor();
109+
editorFile = activeEditor.getReference().getEditorInput().getAdapter(IFile.class);
110+
editor = activeEditor.bot();
111+
editor.cTabItem("Design").activate();
112+
}
113+
}

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/rcp/RcpTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2024 Google, Inc. and others.
2+
* Copyright (c) 2011, 2025 Google, Inc. and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -19,6 +19,7 @@
1919
import org.eclipse.wb.tests.designer.rcp.nebula.NebulaTests;
2020
import org.eclipse.wb.tests.designer.rcp.resource.ResourceTests;
2121
import org.eclipse.wb.tests.designer.rcp.swing2swt.Swing2SwtTests;
22+
import org.eclipse.wb.tests.designer.rcp.wizard.WizardTests;
2223

2324
import org.junit.platform.suite.api.SelectClasses;
2425
import org.junit.platform.suite.api.Suite;
@@ -36,7 +37,8 @@
3637
NebulaTests.class,
3738
Swing2SwtTests.class,
3839
GefTests.class,
39-
BindingTests.class
40+
BindingTests.class,
41+
WizardTests.class
4042
})
4143
public class RcpTests {
4244
}

org.eclipse.wb.tests/src/org/eclipse/wb/tests/swtbot/designer/rcp/wizard/Eclipse4WizardTest.java renamed to org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/rcp/wizard/Eclipse4WizardTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023, 2024 Patrick Ziegler and others.
2+
* Copyright (c) 2023, 2025 Patrick Ziegler and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -10,9 +10,9 @@
1010
* Contributors:
1111
* Patrick Ziegler - initial API and implementation
1212
*******************************************************************************/
13-
package org.eclipse.wb.tests.swtbot.designer.rcp.wizard;
13+
package org.eclipse.wb.tests.designer.rcp.wizard;
1414

15-
import org.eclipse.wb.tests.swtbot.designer.AbstractWizardTest;
15+
import org.eclipse.wb.tests.designer.rcp.AbstractWizardTest;
1616

1717
import org.junit.jupiter.api.Test;
1818

org.eclipse.wb.tests/src/org/eclipse/wb/tests/swtbot/designer/rcp/wizard/JFaceWizardTest.java renamed to org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/rcp/wizard/JFaceWizardTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023, 2024 Patrick Ziegler and others.
2+
* Copyright (c) 2023, 2025 Patrick Ziegler and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -10,14 +10,12 @@
1010
* Contributors:
1111
* Patrick Ziegler - initial API and implementation
1212
*******************************************************************************/
13-
package org.eclipse.wb.tests.swtbot.designer.rcp.wizard;
13+
package org.eclipse.wb.tests.designer.rcp.wizard;
1414

15-
import org.eclipse.wb.tests.swtbot.designer.AbstractWizardTest;
15+
import org.eclipse.wb.tests.designer.rcp.AbstractWizardTest;
1616

1717
import static org.eclipse.swtbot.swt.finder.matchers.WithText.withText;
1818

19-
import static org.junit.jupiter.api.Assertions.assertNotNull;
20-
2119
import org.junit.jupiter.api.Test;
2220

2321
public class JFaceWizardTest extends AbstractWizardTest {

org.eclipse.wb.tests/src/org/eclipse/wb/tests/swtbot/designer/rcp/wizard/RcpWizardTest.java renamed to org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/rcp/wizard/RcpWizardTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023, 2024 Patrick Ziegler and others.
2+
* Copyright (c) 2023, 2025 Patrick Ziegler and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -10,14 +10,12 @@
1010
* Contributors:
1111
* Patrick Ziegler - initial API and implementation
1212
*******************************************************************************/
13-
package org.eclipse.wb.tests.swtbot.designer.rcp.wizard;
13+
package org.eclipse.wb.tests.designer.rcp.wizard;
1414

15-
import org.eclipse.wb.tests.swtbot.designer.AbstractWizardTest;
15+
import org.eclipse.wb.tests.designer.rcp.AbstractWizardTest;
1616

1717
import static org.eclipse.swtbot.swt.finder.matchers.WithText.withText;
1818

19-
import static org.junit.jupiter.api.Assertions.assertNotNull;
20-
2119
import org.junit.jupiter.api.Test;
2220

2321
public class RcpWizardTest extends AbstractWizardTest {

org.eclipse.wb.tests/src/org/eclipse/wb/tests/swtbot/designer/rcp/wizard/SwtWizardTest.java renamed to org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/rcp/wizard/SwtWizardTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023, 2024 Patrick Ziegler and others.
2+
* Copyright (c) 2023, 2025 Patrick Ziegler and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -10,9 +10,9 @@
1010
* Contributors:
1111
* Patrick Ziegler - initial API and implementation
1212
*******************************************************************************/
13-
package org.eclipse.wb.tests.swtbot.designer.rcp.wizard;
13+
package org.eclipse.wb.tests.designer.rcp.wizard;
1414

15-
import org.eclipse.wb.tests.swtbot.designer.AbstractWizardTest;
15+
import org.eclipse.wb.tests.designer.rcp.AbstractWizardTest;
1616

1717
import org.junit.jupiter.api.Test;
1818

org.eclipse.wb.tests/src/org/eclipse/wb/tests/swtbot/designer/rcp/wizard/WizardTests.java renamed to org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/rcp/wizard/WizardTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Contributors:
1111
* Patrick Ziegler - initial API and implementation
1212
*******************************************************************************/
13-
package org.eclipse.wb.tests.swtbot.designer.rcp.wizard;
13+
package org.eclipse.wb.tests.designer.rcp.wizard;
1414

1515
import org.junit.platform.suite.api.SelectClasses;
1616
import org.junit.platform.suite.api.Suite;

org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/SwingTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.eclipse.wb.tests.designer.swing.laf.LookAndFeelTest;
1616
import org.eclipse.wb.tests.designer.swing.model.ModelTests;
1717
import org.eclipse.wb.tests.designer.swing.swingx.SwingXTests;
18+
import org.eclipse.wb.tests.designer.swing.wizard.WizardTests;
1819

1920
import org.junit.platform.suite.api.SelectClasses;
2021
import org.junit.platform.suite.api.Suite;
@@ -29,6 +30,7 @@
2930
CustomizeTest.class,
3031
ModelTests.class,
3132
SwingXTests.class,
33+
WizardTests.class
3234
// WaitForMemoryProfilerTest.class,
3335
})
3436
public class SwingTests {

0 commit comments

Comments
 (0)