Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: try to fix the flaky acceptance test #1228

Closed
Closed
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
75 changes: 3 additions & 72 deletions test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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(robot());
}
}
108 changes: 108 additions & 0 deletions test-acceptance/src/org/omegat/gui/main/TestCoreGUIInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**************************************************************************
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 <https://www.gnu.org/licenses/>.
**************************************************************************/
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.core.Robot;
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(Robot robot) 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(robot, frame);
mainWindow.show();
}
return mainWindow;
}

static IAutoSave autoSave = new IAutoSave() {
public void enable() {
}

public void disable() {
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
44 changes: 44 additions & 0 deletions test-acceptance/src/org/omegat/gui/main/TestMainWindowMenu.java
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
**************************************************************************/
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);
}
}
Loading