From 594fde9408be4fffe3805cd952309e8e88febb77 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Fri, 20 Dec 2024 09:44:50 +0900 Subject: [PATCH 1/2] fix: try to fix the flaky acceptance test Signed-off-by: Hiroshi Miura --- .../src/org/omegat/gui/main/TestCoreGUI.java | 75 +----------- .../gui/main/TestCoreGUIInitializer.java | 107 ++++++++++++++++++ .../org/omegat/gui/main/TestMainWindow.java | 2 +- .../omegat/gui/main/TestMainWindowMenu.java | 44 +++++++ 4 files changed, 155 insertions(+), 73 deletions(-) create mode 100644 test-acceptance/src/org/omegat/gui/main/TestCoreGUIInitializer.java create mode 100644 test-acceptance/src/org/omegat/gui/main/TestMainWindowMenu.java diff --git a/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java b/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java index 049113e64b..3985fcd816 100644 --- a/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java +++ b/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java @@ -29,36 +29,22 @@ import java.io.File; import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collections; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import javax.swing.JFrame; import javax.swing.SwingUtilities; import org.apache.commons.io.FileUtils; -import org.assertj.swing.edt.GuiActionRunner; import org.assertj.swing.fixture.FrameFixture; import org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase; -import org.omegat.TestMainInitializer; import org.omegat.core.Core; import org.omegat.core.CoreEvents; -import org.omegat.core.TestCoreInitializer; -import org.omegat.core.data.NotLoadedProject; -import org.omegat.core.threads.IAutoSave; -import org.omegat.filters2.master.FilterMaster; -import org.omegat.filters2.master.PluginUtils; import org.omegat.util.Preferences; -import org.omegat.util.RuntimePreferences; -import org.omegat.util.gui.UIDesignManager; public abstract class TestCoreGUI extends AssertJSwingJUnitTestCase { protected FrameFixture window; - protected JFrame frame; - protected File tmpDir; protected void closeProject() throws Exception { @@ -93,7 +79,7 @@ protected void openSampleProject(String projectPath) throws Exception { latch.countDown(); } }); - ProjectUICommands.projectOpen(tmpDir); + ProjectUICommands.projectOpen(tmpDir, true); try { latch.await(5, TimeUnit.SECONDS); } catch (InterruptedException ignored) { @@ -105,66 +91,11 @@ protected void openSampleProject(String projectPath) throws Exception { @Override protected void onTearDown() throws Exception { - window.cleanUp(); + // window.cleanUp(); } @Override protected void onSetUp() throws Exception { - Path tmp = Files.createTempDirectory("omegat"); - FileUtils.forceDeleteOnExit(tmp.toFile()); - RuntimePreferences.setConfigDir(tmp.toString()); - TestMainInitializer.initClassloader(); - // same order as Main.main - Preferences.init(); - PluginUtils.loadPlugins(Collections.emptyMap()); - FilterMaster.setFilterClasses(PluginUtils.getFilterClasses()); - Preferences.initFilters(); - Preferences.initSegmentation(); - // - frame = GuiActionRunner.execute(() -> { - Core.setProject(new NotLoadedProject()); - UIDesignManager.initialize(); - TestMainWindow mw = new TestMainWindow(TestMainWindowMenuHandler.class); - TestCoreInitializer.initMainWindow(mw); - TestCoreInitializer.initAutoSave(autoSave); - - CoreEvents.fireApplicationStartup(); - SwingUtilities.invokeLater(() -> { - // setVisible can't be executed directly, because we need to - // call all application startup listeners for initialize UI - Core.getMainWindow().getApplicationFrame().setVisible(true); - }); - return mw.getApplicationFrame(); - }); - - window = new FrameFixture(robot(), frame); - window.show(); - } - - static IAutoSave autoSave = new IAutoSave() { - public void enable() { - } - - public void disable() { - } - }; - - static class TestMainWindowMenu extends BaseMainWindowMenu { - - TestMainWindowMenu(IMainWindow mainWindow, BaseMainWindowMenuHandler mainWindowMenuHandler) { - super(mainWindow, mainWindowMenuHandler); - initComponents(); - } - - @Override - void createMenuBar() { - mainMenu.add(projectMenu); - mainMenu.add(editMenu); - mainMenu.add(gotoMenu); - mainMenu.add(viewMenu); - mainMenu.add(toolsMenu); - mainMenu.add(optionsMenu); - mainMenu.add(helpMenu); - } + window = TestCoreGUIInitializer.getInstance().initialize(); } } diff --git a/test-acceptance/src/org/omegat/gui/main/TestCoreGUIInitializer.java b/test-acceptance/src/org/omegat/gui/main/TestCoreGUIInitializer.java new file mode 100644 index 0000000000..d9004d738b --- /dev/null +++ b/test-acceptance/src/org/omegat/gui/main/TestCoreGUIInitializer.java @@ -0,0 +1,107 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2024 Hiroshi Miura + Home page: https://www.omegat.org/ + Support center: https://omegat.org/support + + This file is part of OmegaT. + + OmegaT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OmegaT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + **************************************************************************/ +package org.omegat.gui.main; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; + +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +import org.apache.commons.io.FileUtils; +import org.assertj.swing.edt.GuiActionRunner; +import org.assertj.swing.fixture.FrameFixture; + +import org.omegat.TestMainInitializer; +import org.omegat.core.Core; +import org.omegat.core.CoreEvents; +import org.omegat.core.TestCoreInitializer; +import org.omegat.core.data.NotLoadedProject; +import org.omegat.core.threads.IAutoSave; +import org.omegat.filters2.master.FilterMaster; +import org.omegat.filters2.master.PluginUtils; +import org.omegat.util.Preferences; +import org.omegat.util.RuntimePreferences; +import org.omegat.util.gui.UIDesignManager; + +public final class TestCoreGUIInitializer { + private static TestCoreGUIInitializer initializer; + private volatile JFrame frame; + private FrameFixture mainWindow; + + private TestCoreGUIInitializer() { + } + + public static TestCoreGUIInitializer getInstance() { + if (initializer == null) { + initializer = new TestCoreGUIInitializer(); + } + return initializer; + } + + public synchronized FrameFixture initialize() throws IOException { + if (frame == null) { + Path tmp = Files.createTempDirectory("omegat"); + FileUtils.forceDeleteOnExit(tmp.toFile()); + RuntimePreferences.setConfigDir(tmp.toString()); + TestMainInitializer.initClassloader(); + // same order as Main.main + Preferences.init(); + PluginUtils.loadPlugins(Collections.emptyMap()); + FilterMaster.setFilterClasses(PluginUtils.getFilterClasses()); + Preferences.initFilters(); + Preferences.initSegmentation(); + // + frame = GuiActionRunner.execute(() -> { + Core.setProject(new NotLoadedProject()); + UIDesignManager.initialize(); + TestMainWindow mw = new TestMainWindow(TestMainWindowMenuHandler.class); + TestCoreInitializer.initMainWindow(mw); + TestCoreInitializer.initAutoSave(autoSave); + + CoreEvents.fireApplicationStartup(); + SwingUtilities.invokeLater(() -> { + // setVisible can't be executed directly, because we need to + // call all application startup listeners for initialize UI + Core.getMainWindow().getApplicationFrame().setVisible(true); + }); + return mw.getApplicationFrame(); + }); + mainWindow = new FrameFixture(frame); + mainWindow.show(); + } + return mainWindow; + } + + static IAutoSave autoSave = new IAutoSave() { + public void enable() { + } + + public void disable() { + } + }; +} diff --git a/test-acceptance/src/org/omegat/gui/main/TestMainWindow.java b/test-acceptance/src/org/omegat/gui/main/TestMainWindow.java index ca3c4b3558..0150e5f68a 100644 --- a/test-acceptance/src/org/omegat/gui/main/TestMainWindow.java +++ b/test-acceptance/src/org/omegat/gui/main/TestMainWindow.java @@ -80,7 +80,7 @@ class TestMainWindow implements IMainWindow { try { BaseMainWindowMenuHandler handler = mainWindowMenuHandler .getDeclaredConstructor(IMainWindow.class).newInstance(this); - menu = new TestCoreGUI.TestMainWindowMenu(this, handler); + menu = new TestMainWindowMenu(this, handler); } catch (Exception e) { throw new RuntimeException(); } diff --git a/test-acceptance/src/org/omegat/gui/main/TestMainWindowMenu.java b/test-acceptance/src/org/omegat/gui/main/TestMainWindowMenu.java new file mode 100644 index 0000000000..3b50d5b0dd --- /dev/null +++ b/test-acceptance/src/org/omegat/gui/main/TestMainWindowMenu.java @@ -0,0 +1,44 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2024 Hiroshi Miura + Home page: https://www.omegat.org/ + Support center: https://omegat.org/support + + This file is part of OmegaT. + + OmegaT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OmegaT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + **************************************************************************/ +package org.omegat.gui.main; + +class TestMainWindowMenu extends BaseMainWindowMenu { + + TestMainWindowMenu(IMainWindow mainWindow, BaseMainWindowMenuHandler mainWindowMenuHandler) { + super(mainWindow, mainWindowMenuHandler); + initComponents(); + } + + @Override + void createMenuBar() { + mainMenu.add(projectMenu); + mainMenu.add(editMenu); + mainMenu.add(gotoMenu); + mainMenu.add(viewMenu); + mainMenu.add(toolsMenu); + mainMenu.add(optionsMenu); + mainMenu.add(helpMenu); + } +} From 0195a51763dabb9327d259a6fb92e59250b1fb50 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Fri, 20 Dec 2024 09:54:04 +0900 Subject: [PATCH 2/2] wip Signed-off-by: Hiroshi Miura --- test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java | 2 +- .../src/org/omegat/gui/main/TestCoreGUIInitializer.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java b/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java index 3985fcd816..38e20836df 100644 --- a/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java +++ b/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java @@ -96,6 +96,6 @@ protected void onTearDown() throws Exception { @Override protected void onSetUp() throws Exception { - window = TestCoreGUIInitializer.getInstance().initialize(); + window = TestCoreGUIInitializer.getInstance().initialize(robot()); } } diff --git a/test-acceptance/src/org/omegat/gui/main/TestCoreGUIInitializer.java b/test-acceptance/src/org/omegat/gui/main/TestCoreGUIInitializer.java index d9004d738b..5a62daf2f4 100644 --- a/test-acceptance/src/org/omegat/gui/main/TestCoreGUIInitializer.java +++ b/test-acceptance/src/org/omegat/gui/main/TestCoreGUIInitializer.java @@ -33,6 +33,7 @@ import javax.swing.SwingUtilities; import org.apache.commons.io.FileUtils; +import org.assertj.swing.core.Robot; import org.assertj.swing.edt.GuiActionRunner; import org.assertj.swing.fixture.FrameFixture; @@ -63,7 +64,7 @@ public static TestCoreGUIInitializer getInstance() { return initializer; } - public synchronized FrameFixture initialize() throws IOException { + public synchronized FrameFixture initialize(Robot robot) throws IOException { if (frame == null) { Path tmp = Files.createTempDirectory("omegat"); FileUtils.forceDeleteOnExit(tmp.toFile()); @@ -91,7 +92,7 @@ public synchronized FrameFixture initialize() throws IOException { }); return mw.getApplicationFrame(); }); - mainWindow = new FrameFixture(frame); + mainWindow = new FrameFixture(robot, frame); mainWindow.show(); } return mainWindow;