Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 5 additions & 29 deletions org.eclipse.wb.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,6 @@
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho.version}</version>
<executions>
<execution>
<!-- Overwrites default goal! -->
<id>default-test</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/org.eclipse.wb.tests.designer.WindowBuilderTests.java</include>
</includes>
<useUIHarness>true</useUIHarness>
<useUIThread>true</useUIThread>
</configuration>
</execution>
<execution>
<id>swtbot-test</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/org.eclipse.wb.tests.swtbot.designer.WindowBuilderTests.java</include>
</includes>
<useUIHarness>true</useUIHarness>
<useUIThread>false</useUIThread>
</configuration>
</execution>
</executions>
<configuration>
<argLine>${ui.test.vmargs}</argLine>
<appArgLine>-nl de -clearPersistedState -consoleLog</appArgLine>
Expand All @@ -114,6 +85,11 @@
<version>0.0.0</version>
</dependency>
</dependencies>
<includes>
<include>**/org.eclipse.wb.tests.designer.WindowBuilderTests.java</include>
</includes>
<useUIHarness>true</useUIHarness>
<useUIThread>true</useUIThread>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import org.eclipse.wb.internal.core.nls.model.LocaleInfo;
import org.eclipse.wb.internal.core.nls.ui.NewSourceDialog;
import org.eclipse.wb.internal.core.nls.ui.PropertiesComposite;
import org.eclipse.wb.internal.core.utils.execution.ExecutionUtils;
import org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils;
import org.eclipse.wb.tests.gef.UiContext;
import org.eclipse.wb.tests.swtbot.designer.bot.UIUtil;
import org.eclipse.wb.tests.utils.SWTBotEditableSource;

import static org.eclipse.swtbot.swt.finder.matchers.WidgetOfType.widgetOfType;
Expand Down Expand Up @@ -302,8 +302,8 @@ private static SWTBotTreeItem getItem(SWTBotTreeItem item, String... pathElement
*/
private static SWTBotEditableSource getEditableSource(SWTBot shell) throws Exception {
PropertiesComposite composite = shell.getFinder().findControls(widgetOfType(PropertiesComposite.class)).get(0);
IEditableSource editableSource = (IEditableSource) UIUtil
.syncCall(() -> ReflectionUtils.invokeMethod(composite, "getSelectedSource()"));
IEditableSource editableSource = (IEditableSource) UIThreadRunnable.syncExec(
() -> ExecutionUtils.runObject(() -> ReflectionUtils.invokeMethod(composite, "getSelectedSource()")));
return new SWTBotEditableSource(editableSource);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*******************************************************************************
* Copyright (c) 2023, 2025 Patrick Ziegler and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.tests.designer.rcp;

import org.eclipse.wb.tests.designer.TestUtils;
import org.eclipse.wb.tests.designer.core.model.parser.AbstractJavaInfoRelatedTest;
import org.eclipse.wb.tests.gef.UiContext;

import static org.eclipse.swtbot.swt.finder.waits.Conditions.shellCloses;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.ui.PlatformUI;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.osgi.framework.Version;

import java.util.Arrays;

/**
* Abstract base class for all tests that create Java files using the
* {@code New Wizard}.
*/
public abstract class AbstractWizardTest extends RcpModelTest {
private static Version ECLIPSE_VERSION = Platform.getBundle("org.eclipse.ui.workbench").getVersion();
private static Version VERSION = new Version(3, 135, 0);
// https://github.com/eclipse-platform/eclipse.platform/issues/1749
private static String WIZARD_NAME = ECLIPSE_VERSION.compareTo(VERSION) > 0 ? "New" : "Select a wizard";
private static boolean m_firstDesignerTest = true;
private SWTWorkbenchBot workbench;
private IFile editorFile;
protected SWTBot editor;

@Override
@BeforeEach
public void setUp() throws Exception {
super.setUp();
if (m_firstDesignerTest) {
m_firstDesignerTest = false;
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().resetPerspective();
}
workbench = new SWTWorkbenchBot();
}

@Override
@AfterEach
public void tearDown() throws Exception {
if (editorFile != null) {
forceDeleteResource(editorFile);
}
super.tearDown();
}


@AfterAll
public static void tearDownAll() throws Exception {
AbstractJavaInfoRelatedTest.tearDownAll();
TestUtils.closeAllViews();
m_firstDesignerTest = true;
}

protected final void testTemplateViaProjectExplorer(String... fullPath) throws Exception {
new UiContext().executeAndCheck(() -> {
SWTBot projectExplorer = workbench.viewById("org.eclipse.ui.navigator.ProjectExplorer").bot();
projectExplorer.tree().getTreeItem("TestProject").contextMenu().menu("New", "Other...").click();
}, bot -> createTemplate(bot, fullPath));
}

protected final void testTemplateViaMenu(String... fullPath) throws Exception {
new UiContext().executeAndCheck(() -> {
workbench.shell().menu().menu("File").menu("New", "Other...").click();
}, bot -> createTemplate(bot, fullPath));
}

private void createTemplate(SWTBot activeShell, String... fullPath) throws CoreException {
assertTrue(fullPath.length > 1, "path requires at least one argument (template name)");
String[] path = Arrays.copyOf(fullPath, fullPath.length - 1);
String name = fullPath[fullPath.length - 1];
String fileName = name.replace(' ', '_').replaceAll("\\(|\\)", "");

SWTBotShell shell = activeShell.shell(WIZARD_NAME);
SWTBot bot = shell.bot();
bot.tree().expandNode(path).getNode(name).select();
bot.button("Next >").click();
bot.text(1).setText("test");
bot.text(2).setText(fileName);
bot.button("Finish").click();
// Wait for file creation
bot.waitUntil(shellCloses(shell));
// Open design page
SWTBotEditor activeEditor = new SWTWorkbenchBot().activeEditor();
editorFile = activeEditor.getReference().getEditorInput().getAdapter(IFile.class);
editor = activeEditor.bot();
editor.cTabItem("Design").activate();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2024 Google, Inc. and others.
* Copyright (c) 2011, 2025 Google, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -19,6 +19,7 @@
import org.eclipse.wb.tests.designer.rcp.nebula.NebulaTests;
import org.eclipse.wb.tests.designer.rcp.resource.ResourceTests;
import org.eclipse.wb.tests.designer.rcp.swing2swt.Swing2SwtTests;
import org.eclipse.wb.tests.designer.rcp.wizard.WizardTests;

import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
Expand All @@ -36,7 +37,8 @@
NebulaTests.class,
Swing2SwtTests.class,
GefTests.class,
BindingTests.class
BindingTests.class,
WizardTests.class
})
public class RcpTests {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 Patrick Ziegler and others.
* Copyright (c) 2023, 2025 Patrick Ziegler and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -10,9 +10,9 @@
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.tests.swtbot.designer.rcp.wizard;
package org.eclipse.wb.tests.designer.rcp.wizard;

import org.eclipse.wb.tests.swtbot.designer.AbstractWizardTest;
import org.eclipse.wb.tests.designer.rcp.AbstractWizardTest;

import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 Patrick Ziegler and others.
* Copyright (c) 2023, 2025 Patrick Ziegler and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -10,14 +10,12 @@
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.tests.swtbot.designer.rcp.wizard;
package org.eclipse.wb.tests.designer.rcp.wizard;

import org.eclipse.wb.tests.swtbot.designer.AbstractWizardTest;
import org.eclipse.wb.tests.designer.rcp.AbstractWizardTest;

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

import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.jupiter.api.Test;

public class JFaceWizardTest extends AbstractWizardTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 Patrick Ziegler and others.
* Copyright (c) 2023, 2025 Patrick Ziegler and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -10,14 +10,12 @@
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.tests.swtbot.designer.rcp.wizard;
package org.eclipse.wb.tests.designer.rcp.wizard;

import org.eclipse.wb.tests.swtbot.designer.AbstractWizardTest;
import org.eclipse.wb.tests.designer.rcp.AbstractWizardTest;

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

import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.jupiter.api.Test;

public class RcpWizardTest extends AbstractWizardTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 Patrick Ziegler and others.
* Copyright (c) 2023, 2025 Patrick Ziegler and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -10,9 +10,9 @@
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.tests.swtbot.designer.rcp.wizard;
package org.eclipse.wb.tests.designer.rcp.wizard;

import org.eclipse.wb.tests.swtbot.designer.AbstractWizardTest;
import org.eclipse.wb.tests.designer.rcp.AbstractWizardTest;

import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.tests.swtbot.designer.rcp.wizard;
package org.eclipse.wb.tests.designer.rcp.wizard;

import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.wb.tests.designer.swing.laf.LookAndFeelTest;
import org.eclipse.wb.tests.designer.swing.model.ModelTests;
import org.eclipse.wb.tests.designer.swing.swingx.SwingXTests;
import org.eclipse.wb.tests.designer.swing.wizard.WizardTests;

import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
Expand All @@ -29,6 +30,7 @@
CustomizeTest.class,
ModelTests.class,
SwingXTests.class,
WizardTests.class
// WaitForMemoryProfilerTest.class,
})
public class SwingTests {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 Patrick Ziegler and others.
* Copyright (c) 2023, 2025 Patrick Ziegler and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -10,11 +10,9 @@
* Contributors:
* Patrick Ziegler - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.tests.swtbot.designer.swing.wizard;
package org.eclipse.wb.tests.designer.swing.wizard;

import org.eclipse.wb.tests.swtbot.designer.AbstractWizardTest;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.eclipse.wb.tests.designer.rcp.AbstractWizardTest;

import org.junit.jupiter.api.Test;

Expand All @@ -37,7 +35,7 @@ public void testCreateNewJDialog() throws Exception {

@Test
public void testCreateNewJApplet() throws Exception {
testTemplateViaProjectExplorer("WindowBuilder", "Swing Designer", "JApplet");
testTemplateViaProjectExplorer("WindowBuilder", "Swing Designer", "(Deprecated) JApplet");
}

@Test
Expand All @@ -52,13 +50,13 @@ public void testCreateNewApplicationWindow() throws Exception {

@Test
public void testCreateWithJavaModules() throws Exception {
bot.setFileContent("module-info.java", """
setFileContentSrc("module-info.java", """
module test {
}""");
//
testTemplateViaProjectExplorer("WindowBuilder", "Swing Designer", "JFrame");
// We can't use code blocks as they don't consider carriage-returns
assertArrayEquals(bot.getFileContent("module-info.java").split(System.lineSeparator()),
assertArrayEquals(getFileContentSrc("module-info.java").split(System.lineSeparator()),
new String[] {
"module test {",
" requires java.desktop;",
Expand All @@ -83,7 +81,7 @@ public void testCreateNewJDialogNoSelection() throws Exception {

@Test
public void testCreateNewJAppletNoSelection() throws Exception {
testTemplateViaMenu("WindowBuilder", "Swing Designer", "JApplet");
testTemplateViaMenu("WindowBuilder", "Swing Designer", "(Deprecated) JApplet");
}

@Test
Expand All @@ -98,13 +96,13 @@ public void testCreateNewApplicationWindowNoSelection() throws Exception {

@Test
public void testCreateWithJavaModulesNoSelection() throws Exception {
bot.setFileContent("module-info.java", """
setFileContentSrc("module-info.java", """
module test {
}""");
//
testTemplateViaMenu("WindowBuilder", "Swing Designer", "JFrame");
// We can't use code blocks as they don't consider carriage-returns
assertArrayEquals(bot.getFileContent("module-info.java").split(System.lineSeparator()),
assertArrayEquals(getFileContentSrc("module-info.java").split(System.lineSeparator()),
new String[] {
"module test {",
" requires java.desktop;",
Expand Down
Loading
Loading