From 301c0f0ea22c8bc9bd2c5134e0933e3931766354 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 12 Oct 2025 12:37:53 +0000 Subject: [PATCH 1/6] Initial plan From ef26a3bd429b43df4e6fb0c627f365b681bcfe74 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 12 Oct 2025 12:48:38 +0000 Subject: [PATCH 2/6] Add test plug-in structure for com.vogella.tasks.ui Co-authored-by: vogella <139910+vogella@users.noreply.github.com> --- com.vogella.tasks.ui.tests/.classpath | 7 ++ com.vogella.tasks.ui.tests/.project | 45 ++++++++++++ .../META-INF/MANIFEST.MF | 19 ++++++ com.vogella.tasks.ui.tests/README.md | 44 ++++++++++++ com.vogella.tasks.ui.tests/build.properties | 6 ++ .../tasks/ui/tests/LoginTestHelper.java | 39 +++++++++++ .../tasks/ui/tests/MenuStructureTest.java | 68 +++++++++++++++++++ .../tasks/ui/tests/UIStructureTest.java | 59 ++++++++++++++++ .../vogella/tasks/ui/addon/LoginAddon.java | 42 ++++++++++++ pom.xml | 1 + 10 files changed, 330 insertions(+) create mode 100644 com.vogella.tasks.ui.tests/.classpath create mode 100644 com.vogella.tasks.ui.tests/.project create mode 100644 com.vogella.tasks.ui.tests/META-INF/MANIFEST.MF create mode 100644 com.vogella.tasks.ui.tests/README.md create mode 100644 com.vogella.tasks.ui.tests/build.properties create mode 100644 com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/LoginTestHelper.java create mode 100644 com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/MenuStructureTest.java create mode 100644 com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/UIStructureTest.java create mode 100644 com.vogella.tasks.ui/src/com/vogella/tasks/ui/addon/LoginAddon.java diff --git a/com.vogella.tasks.ui.tests/.classpath b/com.vogella.tasks.ui.tests/.classpath new file mode 100644 index 00000000..375961e4 --- /dev/null +++ b/com.vogella.tasks.ui.tests/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/com.vogella.tasks.ui.tests/.project b/com.vogella.tasks.ui.tests/.project new file mode 100644 index 00000000..f6e6b240 --- /dev/null +++ b/com.vogella.tasks.ui.tests/.project @@ -0,0 +1,45 @@ + + + com.vogella.tasks.ui.tests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + + + 1749802401051 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/com.vogella.tasks.ui.tests/META-INF/MANIFEST.MF b/com.vogella.tasks.ui.tests/META-INF/MANIFEST.MF new file mode 100644 index 00000000..fce658c3 --- /dev/null +++ b/com.vogella.tasks.ui.tests/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Tasks UI Tests +Bundle-SymbolicName: com.vogella.tasks.ui.tests +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: VOGELLA +Import-Package: org.junit.jupiter.api;version="5.12.2" +Bundle-RequiredExecutionEnvironment: JavaSE-21 +Require-Bundle: org.eclipse.swt, + org.eclipse.jface, + org.eclipse.swtbot.e4.finder;bundle-version="4.3.0", + org.eclipse.swtbot.swt.finder;bundle-version="4.3.0", + org.slf4j.api;bundle-version="1.7.30", + com.vogella.tasks.ui;bundle-version="1.0.0", + org.eclipse.e4.ui.workbench, + org.eclipse.e4.core.di, + org.eclipse.e4.ui.model.workbench, + org.eclipse.e4.core.contexts +Automatic-Module-Name: com.vogella.tasks.ui.tests diff --git a/com.vogella.tasks.ui.tests/README.md b/com.vogella.tasks.ui.tests/README.md new file mode 100644 index 00000000..f634b5bc --- /dev/null +++ b/com.vogella.tasks.ui.tests/README.md @@ -0,0 +1,44 @@ +# Tasks UI Tests + +This test plug-in contains automated tests for the `com.vogella.tasks.ui` RCP application. + +## Features + +- **Menu Structure Tests**: Verifies that all expected menus are present and accessible +- **UI Structure Tests**: Tests the application window and UI components +- **Login Bypass**: Provides a mechanism to skip login dialogs during testing + +## Running the Tests + +Tests can be run using Maven/Tycho: + +```bash +mvn clean verify +``` + +## Bypassing Login Screen + +To bypass the login screen during testing, set the system property `skipLogin` to `true`: + +``` +-DskipLogin=true +``` + +This can be configured in: +1. Maven surefire configuration +2. Eclipse Run Configuration (VM arguments) +3. Programmatically using `LoginTestHelper.enableSkipLogin()` + +## Test Classes + +- `MenuStructureTest`: Tests the menu structure of the application +- `UIStructureTest`: Tests the UI structure and components +- `LoginTestHelper`: Utility class for controlling login behavior in tests + +## Dependencies + +The test plug-in requires: +- JUnit 5 (Jupiter) +- SWTBot for UI testing +- Eclipse E4 RCP bundles +- com.vogella.tasks.ui bundle diff --git a/com.vogella.tasks.ui.tests/build.properties b/com.vogella.tasks.ui.tests/build.properties new file mode 100644 index 00000000..ea0d2c6b --- /dev/null +++ b/com.vogella.tasks.ui.tests/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . +pom.model.property.tycho.surefire.useUIHarness = true +pom.model.property.tycho.surefire.useUIThread = true diff --git a/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/LoginTestHelper.java b/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/LoginTestHelper.java new file mode 100644 index 00000000..137c17eb --- /dev/null +++ b/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/LoginTestHelper.java @@ -0,0 +1,39 @@ +package com.vogella.tasks.ui.tests; + +/** + * Utility class to control login behavior for testing. + * + * When running tests, set the system property "skipLogin" to "true" to bypass + * any login dialogs: + * + * -DskipLogin=true + * + * This can also be used programmatically by setting: + * System.setProperty("skipLogin", "true"); + */ +public class LoginTestHelper { + + private static final String SKIP_LOGIN_PROPERTY = "skipLogin"; + + /** + * Check if login should be skipped (for testing purposes). + * @return true if the skipLogin system property is set to "true" + */ + public static boolean shouldSkipLogin() { + return "true".equalsIgnoreCase(System.getProperty(SKIP_LOGIN_PROPERTY)); + } + + /** + * Enable skipping login dialogs for testing. + */ + public static void enableSkipLogin() { + System.setProperty(SKIP_LOGIN_PROPERTY, "true"); + } + + /** + * Disable skipping login dialogs (restore normal behavior). + */ + public static void disableSkipLogin() { + System.clearProperty(SKIP_LOGIN_PROPERTY); + } +} diff --git a/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/MenuStructureTest.java b/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/MenuStructureTest.java new file mode 100644 index 00000000..b276f80b --- /dev/null +++ b/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/MenuStructureTest.java @@ -0,0 +1,68 @@ +package com.vogella.tasks.ui.tests; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.eclipse.swtbot.swt.finder.SWTBot; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * Tests for the menu structure of the Tasks UI application. + */ +public class MenuStructureTest { + + private static SWTBot bot; + + @BeforeEach + public void setUp() throws Exception { + // don't use SWTWorkbenchBot here which relies on Platform 3.x + bot = new SWTBot(); + } + + @Test + public void testFileMenuExists() { + SWTBotMenu fileMenu = bot.menu("File"); + assertNotNull(fileMenu, "File menu should exist"); + } + + @Test + public void testEditMenuExists() { + SWTBotMenu editMenu = bot.menu("Edit"); + assertNotNull(editMenu, "Edit menu should exist"); + } + + @Test + public void testWindowMenuExists() { + SWTBotMenu windowMenu = bot.menu("Window"); + assertNotNull(windowMenu, "Window menu should exist"); + } + + @Test + public void testProcessesMenuExists() { + SWTBotMenu processesMenu = bot.menu("Processes"); + assertNotNull(processesMenu, "Processes menu should exist"); + } + + @Test + public void testFileMenuContainsSave() { + SWTBotMenu fileMenu = bot.menu("File"); + SWTBotMenu saveMenu = fileMenu.menu("Save"); + assertNotNull(saveMenu, "File menu should contain Save menu item"); + } + + @Test + public void testWindowMenuContainsPerspectives() { + SWTBotMenu windowMenu = bot.menu("Window"); + SWTBotMenu perspectivesMenu = windowMenu.menu("Perspectives"); + assertNotNull(perspectivesMenu, "Window menu should contain Perspectives submenu"); + } + + @Test + public void testWindowMenuContainsTheme() { + SWTBotMenu windowMenu = bot.menu("Window"); + SWTBotMenu themeMenu = windowMenu.menu("Theme"); + assertNotNull(themeMenu, "Window menu should contain Theme submenu"); + } +} diff --git a/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/UIStructureTest.java b/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/UIStructureTest.java new file mode 100644 index 00000000..2a056327 --- /dev/null +++ b/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/UIStructureTest.java @@ -0,0 +1,59 @@ +package com.vogella.tasks.ui.tests; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; + +import org.eclipse.e4.core.contexts.IEclipseContext; +import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; +import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.model.application.ui.basic.MWindow; +import org.eclipse.e4.ui.workbench.modeling.EModelService; +import org.eclipse.swtbot.swt.finder.SWTBot; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * Tests for the UI structure of the Tasks UI application. + * Uses the E4 workbench model API to verify application structure. + */ +public class UIStructureTest { + + private static SWTBot bot; + + @BeforeEach + public void setUp() throws Exception { + bot = new SWTBot(); + } + + @Test + public void testApplicationWindowExists() { + // Test that the main window is present + assertTrue(bot.shells().length > 0, "At least one shell should exist"); + } + + @Test + public void testCanAccessApplication() { + // This test verifies that we can access the E4 application + // In a real test, we would inject MApplication and verify structure + // For now, we just verify the bot can find widgets + assertNotNull(bot, "SWTBot should be initialized"); + } + + /** + * Test that verifies perspectives can be accessed. + * This test uses SWTBot to interact with the UI. + */ + @Test + public void testPerspectivesAccessible() { + // Verify that we can access the Window menu which contains perspectives + try { + bot.menu("Window"); + } catch (Exception e) { + // If we can't find it, the test will fail + throw new AssertionError("Should be able to access Window menu", e); + } + } +} diff --git a/com.vogella.tasks.ui/src/com/vogella/tasks/ui/addon/LoginAddon.java b/com.vogella.tasks.ui/src/com/vogella/tasks/ui/addon/LoginAddon.java new file mode 100644 index 00000000..13113435 --- /dev/null +++ b/com.vogella.tasks.ui/src/com/vogella/tasks/ui/addon/LoginAddon.java @@ -0,0 +1,42 @@ +package com.vogella.tasks.ui.addon; + +import org.eclipse.e4.core.di.annotations.Execute; +import org.eclipse.e4.ui.workbench.lifecycle.ProcessAdditions; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; + +/** + * Lifecycle addon that shows a login dialog on application startup. + * Can be bypassed by setting the system property "skipLogin" to "true". + * + * This is useful for automated testing where login should be skipped. + */ +public class LoginAddon { + + private static final String SKIP_LOGIN_PROPERTY = "skipLogin"; + + @Execute + public void execute(Shell shell) { + // Check if we should skip login (for testing) + if (shouldSkipLogin()) { + return; + } + + // Show a simple login notification + // In a real application, this would show a proper login dialog + // For demonstration purposes, we just show an info dialog + // that doesn't block the application + if (shell != null && !shell.isDisposed()) { + shell.getDisplay().asyncExec(() -> { + if (!shell.isDisposed()) { + MessageDialog.openInformation(shell, "Login", + "Welcome! (Set -DskipLogin=true to bypass this dialog in tests)"); + } + }); + } + } + + private boolean shouldSkipLogin() { + return "true".equalsIgnoreCase(System.getProperty(SKIP_LOGIN_PROPERTY)); + } +} diff --git a/pom.xml b/pom.xml index b997850a..65e73873 100644 --- a/pom.xml +++ b/pom.xml @@ -125,6 +125,7 @@ com.vogella.osgi.taskconsumer updatesite com.vogella.tasks.product + com.vogella.tasks.ui.tests From 61db377d613fbae997047c30f8e7e4878d6250a9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 12 Oct 2025 12:57:41 +0000 Subject: [PATCH 3/6] Complete test plug-in with tests and login bypass mechanism Co-authored-by: vogella <139910+vogella@users.noreply.github.com> --- com.vogella.tasks.ui.tests/README.md | 44 ++++++++++++++++++--- com.vogella.tasks.ui.tests/build.properties | 2 + pom.xml | 1 + target-platform/target-platform.target | 3 ++ 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/com.vogella.tasks.ui.tests/README.md b/com.vogella.tasks.ui.tests/README.md index f634b5bc..b1da076e 100644 --- a/com.vogella.tasks.ui.tests/README.md +++ b/com.vogella.tasks.ui.tests/README.md @@ -5,12 +5,32 @@ This test plug-in contains automated tests for the `com.vogella.tasks.ui` RCP ap ## Features - **Menu Structure Tests**: Verifies that all expected menus are present and accessible -- **UI Structure Tests**: Tests the application window and UI components +- **UI Structure Tests**: Tests the application window and UI components - **Login Bypass**: Provides a mechanism to skip login dialogs during testing ## Running the Tests -Tests can be run using Maven/Tycho: +Tests require a graphical display (X11) to run since they test the UI. + +### Building without running tests + +To build the project without running UI tests: + +```bash +mvn clean verify -DskipTests +``` + +### Running tests with a display + +On Linux with Xvfb (X virtual framebuffer): + +```bash +Xvfb :99 -screen 0 1024x768x24 & +export DISPLAY=:99 +mvn clean verify +``` + +On systems with a display, simply run: ```bash mvn clean verify @@ -24,10 +44,11 @@ To bypass the login screen during testing, set the system property `skipLogin` t -DskipLogin=true ``` -This can be configured in: -1. Maven surefire configuration -2. Eclipse Run Configuration (VM arguments) -3. Programmatically using `LoginTestHelper.enableSkipLogin()` +This is automatically configured in the test plug-in's build.properties and will be passed to tests when they run. + +You can also configure this in: +1. Eclipse Run Configuration (VM arguments: `-DskipLogin=true`) +2. Programmatically using `LoginTestHelper.enableSkipLogin()` ## Test Classes @@ -35,6 +56,10 @@ This can be configured in: - `UIStructureTest`: Tests the UI structure and components - `LoginTestHelper`: Utility class for controlling login behavior in tests +## Login Addon + +The main application includes a `LoginAddon` class that demonstrates how to show a login dialog on startup. This addon respects the `skipLogin` system property, making it easy to bypass for automated testing. + ## Dependencies The test plug-in requires: @@ -42,3 +67,10 @@ The test plug-in requires: - SWTBot for UI testing - Eclipse E4 RCP bundles - com.vogella.tasks.ui bundle + +## CI/CD Integration + +For CI/CD pipelines without a display: +1. Use `-DskipTests` to skip test execution +2. Or configure Xvfb in your CI environment +3. Tests still compile and validate, ensuring code quality diff --git a/com.vogella.tasks.ui.tests/build.properties b/com.vogella.tasks.ui.tests/build.properties index ea0d2c6b..61c1cb16 100644 --- a/com.vogella.tasks.ui.tests/build.properties +++ b/com.vogella.tasks.ui.tests/build.properties @@ -4,3 +4,5 @@ bin.includes = META-INF/,\ . pom.model.property.tycho.surefire.useUIHarness = true pom.model.property.tycho.surefire.useUIThread = true +pom.model.property.tycho.surefire.product = com.vogella.tasks.ui.product +pom.model.property.tycho.surefire.argLine = -DskipLogin=true diff --git a/pom.xml b/pom.xml index 65e73873..5feba9a6 100644 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,7 @@ org.eclipse.e4.ui.workbench.swt.E4Application com.example.e4.rcp.product + -DskipLogin=true diff --git a/target-platform/target-platform.target b/target-platform/target-platform.target index 7cbe0ee3..33ffd4a2 100644 --- a/target-platform/target-platform.target +++ b/target-platform/target-platform.target @@ -9,6 +9,9 @@ + + + From 78d15fb1aa12d441f50862233291a7d0056f2609 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Oct 2025 09:47:11 +0000 Subject: [PATCH 6/6] Fix review comments: make bot non-static and remove unused imports Co-authored-by: vogella <139910+vogella@users.noreply.github.com> --- .../com/vogella/tasks/ui/tests/MenuStructureTest.java | 2 +- .../com/vogella/tasks/ui/tests/UIStructureTest.java | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/MenuStructureTest.java b/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/MenuStructureTest.java index b276f80b..1d992f99 100644 --- a/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/MenuStructureTest.java +++ b/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/MenuStructureTest.java @@ -13,7 +13,7 @@ */ public class MenuStructureTest { - private static SWTBot bot; + private SWTBot bot; @BeforeEach public void setUp() throws Exception { diff --git a/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/UIStructureTest.java b/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/UIStructureTest.java index 2a056327..da9e8af9 100644 --- a/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/UIStructureTest.java +++ b/com.vogella.tasks.ui.tests/src/com/vogella/tasks/ui/tests/UIStructureTest.java @@ -3,14 +3,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; - -import org.eclipse.e4.core.contexts.IEclipseContext; -import org.eclipse.e4.ui.model.application.MApplication; -import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; -import org.eclipse.e4.ui.model.application.ui.basic.MPart; -import org.eclipse.e4.ui.model.application.ui.basic.MWindow; -import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.swtbot.swt.finder.SWTBot; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -21,7 +13,7 @@ */ public class UIStructureTest { - private static SWTBot bot; + private SWTBot bot; @BeforeEach public void setUp() throws Exception {