Skip to content

Commit

Permalink
chore: introduce acceptance test
Browse files Browse the repository at this point in the history
- Use AssertJ-Swing for test framework
- Add Sample project folder
- Test Menu - help - about dialog for sample

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
  • Loading branch information
miurahr committed May 24, 2024
1 parent 02c43b7 commit 70bc29b
Show file tree
Hide file tree
Showing 24 changed files with 1,177 additions and 12 deletions.
33 changes: 33 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ sourceSets {
srcDir 'test/fixtures'
}
}
testAcceptance {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir 'test-acceptance/src'
}
}
testIntegration {
java {
srcDir 'test-integration/src'
Expand All @@ -204,6 +211,8 @@ configurations {
all
[testRuntime, testCompile]*.exclude group: 'org.languagetool', module: 'language-all'
testIntegrationImplementation.extendsFrom implementation
testAcceptanceImplementation.extendsFrom testImplementation
testAcceptanceRuntime.extendsFrom testRuntime
jaxb
genMac
}
Expand Down Expand Up @@ -332,6 +341,7 @@ dependencies {
testFixturesApi(libs.slf4j.api)
testFixturesImplementation(libs.commons.io)
testFixturesImplementation(libs.omegat.vldocking)
testFixturesImplementation(libs.assertj.swing.junit)

testImplementation(libs.xmlunit.legacy)
// LanguageTool unit tests exercise these languages
Expand All @@ -352,6 +362,14 @@ dependencies {
// genMac only
genMac(libs.omegat.appbundler)

testAcceptanceImplementation sourceSets.main.output
testAcceptanceImplementation(libs.commons.io)
testAcceptanceImplementation(libs.slf4j.jdk14)
testAcceptanceImplementation(libs.slf4j.format.jdk14)
testAcceptanceImplementation(testFixtures(project.rootProject))
testAcceptanceImplementation(libs.assertj.swing.junit)
testAcceptanceImplementation(libs.bundles.jackson)

testIntegrationImplementation sourceSets.main.output, sourceSets.test.output
testIntegrationImplementation(testFixtures(project.rootProject))
testIntegrationRuntimeOnly(libs.slf4j.jdk14)
Expand Down Expand Up @@ -1580,6 +1598,21 @@ tasks.register('testOnJava21', Test) {
group = 'verification'
}

tasks.register('testAcceptance', Test) {
description = 'Run Acceptance GUI test'
group = 'verification'
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(17)
vendor = JvmVendorSpec.ADOPTIUM
}
jvmArgs(["--add-opens", "java.desktop/sun.awt.X11=ALL-UNNAMED",
"--add-opens", "java.base/java.util=ALL-UNNAMED"])
testClassesDirs = sourceSets.testAcceptance.output.classesDirs
classpath = sourceSets.testAcceptance.runtimeClasspath
systemProperties = System.properties
shouldRunAfter(tasks.test)
}

ext.mavenStyleVersion = version.replace('_', '-')

publishing {
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jna = "5.13.0"
jfa = "1.2.0"
tipoftheday = "0.4.4"
flatlaf="3.4.1"
assertj_swing_junit = "4.0.0-beta-1"

[libraries]
slf4j-api = {group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j"}
Expand Down Expand Up @@ -132,6 +133,7 @@ jna = {group = "net.java.dev.jna", name = "jna-platform", version.ref = "jna"}
jfa = {group = "de.jangassen", name = "jfa", version.ref = "jfa"}
flatlaf = {group = "com.formdev", name = "flatlaf", version.ref = "flatlaf"}
language-detector = {group = "org.omegat", name = "language-detector", version.ref = "languagedetector"}
assertj_swing_junit = {group = "tokyo.northside", name = "assertj-swing-junit", version.ref = "assertj_swing_junit"}

[bundles]
groovy = ["groovy-jsr223", "groovy-dateutil", "groovy-json", "groovy-xml", "groovy-swing", "groovy-templates", "ivy"]
Expand Down
7 changes: 3 additions & 4 deletions src/org/omegat/gui/accesstool/AccessTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@
import org.omegat.core.Core;
import org.omegat.core.CoreEvents;
import org.omegat.core.events.IProjectEventListener;
import org.omegat.gui.main.BaseMainWindowMenuHandler;
import org.omegat.gui.main.MainMenuIcons;
import org.omegat.gui.main.MainWindow;
import org.omegat.gui.main.MainWindowMenuHandler;
import org.omegat.gui.main.ProjectUICommands;
import org.omegat.util.OConsts;
import org.omegat.util.OStrings;
Expand All @@ -72,14 +71,14 @@ public class AccessTools extends JPanel {

private ProjectComboBoxModel projectComboBoxModel;
private SourceComboBoxModel sourceComboBoxModel;
private final MainWindowMenuHandler mainWindowMenuHandler;
private final BaseMainWindowMenuHandler mainWindowMenuHandler;

private URI selectedProject = null;

private static final int MAX_PATH_LENGTH_SHOWN = 25;
private static final float CHECKBOX_HEIGHT_RATIO = 1.8f;

public AccessTools(final MainWindow mainWindow, final MainWindowMenuHandler mainWindowMenuHandler) {
public AccessTools(final BaseMainWindowMenuHandler mainWindowMenuHandler) {
this.mainWindowMenuHandler = mainWindowMenuHandler;
initComponents();
}
Expand Down
18 changes: 18 additions & 0 deletions src/org/omegat/gui/dialogs/AboutDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ public class AboutDialog extends JDialog {
/** A return status code - returned if OK button has been pressed */
public static final int RET_OK = 1;

public static final String DIALOG_NAME = "about_dialog";
public static final String OK_BUTTON_NAME = "about_dialog_ok_button";
public static final String ABOUT_TEXT_NAME = "about_dialog_about_text";
public static final String VERSION_LABEL_NAME = "about_dialog_version_label";
public static final String MEMORY_USAGE_LABEL_NAME = "about_dialog_memory_usage_label";
public static final String JAVA_VERSION_LABEL_NAME = "about_dialog_java_version_label";
public static final String LICENSE_BUTTON_NAME = "about_dialog_license_button";
public static final String COPY_SUPPORT_INFO_BUTTON = "about_dialog_copy_support_info_button";

/** Creates new form AboutDialog */
public AboutDialog(Frame parent) {
super(parent, true);
Expand All @@ -67,6 +76,15 @@ public AboutDialog(Frame parent) {

initComponents();

setName(DIALOG_NAME);
licenseButton.setName(LICENSE_BUTTON_NAME);
okButton.setName(OK_BUTTON_NAME);
abouttext.setName(ABOUT_TEXT_NAME);
versionLabel.setName(VERSION_LABEL_NAME);
memoryusage.setName(MEMORY_USAGE_LABEL_NAME);
javaversion.setName(JAVA_VERSION_LABEL_NAME);
copySupportInfoButton.setName(COPY_SUPPORT_INFO_BUTTON);

StaticUIUtils.setCaretUpdateEnabled(abouttext, false);
abouttext.setText(StringUtil.format(OStrings.getString("ABOUTDIALOG_CONTRIBUTORS"), getContributors(),
getLibraries()));
Expand Down
18 changes: 12 additions & 6 deletions src/org/omegat/gui/main/BaseMainWindowMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,22 @@ public abstract class BaseMainWindowMenu implements ActionListener, MenuListener

private static final Logger LOGGER = Logger.getLogger(BaseMainWindowMenu.class.getName());

public static final String HELP_MENU = "help_menu";
public static final String HELP_ABOUT_MENUITEM = "help_about_menuitem";

/** MainWindow instance. */
protected final MainWindow mainWindow;
protected final IMainWindow mainWindow;

/** menu bar instance */
protected final JMenuBar mainMenu = new JMenuBar();

/** MainWindow menu handler instance. */
protected final MainWindowMenuHandler mainWindowMenuHandler;
protected final BaseMainWindowMenuHandler mainWindowMenuHandler;

private final Map<MenuExtender.MenuKey, JMenu> menus = new EnumMap<>(MenuExtender.MenuKey.class);

public BaseMainWindowMenu(final MainWindow mainWindow,
final MainWindowMenuHandler mainWindowMenuHandler) {
public BaseMainWindowMenu(final IMainWindow mainWindow,
final BaseMainWindowMenuHandler mainWindowMenuHandler) {
this.mainWindow = mainWindow;
this.mainWindowMenuHandler = mainWindowMenuHandler;
}
Expand Down Expand Up @@ -204,6 +207,7 @@ protected void createComponents() {
toolsMenu = createMenu("TF_MENU_TOOLS", MenuExtender.MenuKey.TOOLS);
optionsMenu = createMenu("MW_OPTIONSMENU", MenuExtender.MenuKey.OPTIONS);
helpMenu = createMenu("TF_MENU_HELP", MenuExtender.MenuKey.HELP);
helpMenu.setName(HELP_MENU);

projectNewMenuItem = createMenuItem("TF_MENU_FILE_CREATE");
projectTeamNewMenuItem = createMenuItem("TF_MENU_FILE_TEAM_CREATE");
Expand Down Expand Up @@ -410,6 +414,7 @@ protected void createComponents() {

helpContentsMenuItem = createMenuItem("TF_MENU_HELP_CONTENTS");
helpAboutMenuItem = createMenuItem("TF_MENU_HELP_ABOUT");
helpAboutMenuItem.setName(HELP_ABOUT_MENUITEM);
helpLastChangesMenuItem = createMenuItem("TF_MENU_HELP_LAST_CHANGES");
helpLogMenuItem = createMenuItem("TF_MENU_HELP_LOG");
helpUpdateCheckMenuItem = createMenuItem("TF_MENU_HELP_CHECK_FOR_UPDATES");
Expand Down Expand Up @@ -653,8 +658,9 @@ public void menuCanceled(MenuEvent e) {

String key = "findInProjectReuseLastWindow";
KeyStroke stroke = PropertiesShortcuts.getMainMenuShortcuts().getKeyStroke(key);
mainWindow.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, key);
mainWindow.getRootPane().getActionMap().put(key, new AbstractAction() {
mainWindow.getApplicationFrame().getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke,
key);
mainWindow.getApplicationFrame().getRootPane().getActionMap().put(key, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Log.logInfoRB("LOG_MENU_CLICK", key);
Expand Down
77 changes: 77 additions & 0 deletions src/org/omegat/gui/main/BaseMainWindowMenuHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**************************************************************************
OmegaT - Computer Assisted Translation (CAT) tool
with fuzzy matching, translation memory, keyword search,
glossaries, and translation leveraging into updated projects.
Copyright (C) 2000-2006 Keith Godfrey, Maxym Mykhalchuk, Henry Pijffers,
Benjamin Siband, and Kim Bruning
2007 Zoltan Bartko
2008 Andrzej Sawula, Alex Buloichik
2009 Didier Briel, Alex Buloichik
2010 Wildrich Fourie, Didier Briel
2012 Wildrich Fourie, Guido Leenders, Didier Briel
2013 Zoltan Bartko, Didier Briel, Yu Tang
2014 Aaron Madlon-Kay
2015 Yu Tang, Aaron Madlon-Kay, Didier Briel
2017 Didier Briel
2019 Thomas Cordonnier
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;

/**
* @author Hiroshi Miura
*/
public abstract class BaseMainWindowMenuHandler {

/**
* Common base class for menu handler.
* <p>
* There should be a mandatory methods for mandatory
* commands.
*/
public BaseMainWindowMenuHandler() {
}

public void projectExitMenuItemActionPerformed() {
System.exit(0);
}

public void editFindInProjectMenuItemActionPerformed() {
}

public void optionsPreferencesMenuItemActionPerformed() {
}

public void projectNewMenuItemActionPerformed() {
}

public void projectOpenMenuItemActionPerformed() {
}

public void projectTeamNewMenuItemActionPerformed() {
}

void findInProjectReuseLastWindow() {
}

public void helpAboutMenuItemActionPerformed() {
}

}
2 changes: 1 addition & 1 deletion src/org/omegat/gui/main/MainWindowBurgerMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ void createMenuBar() {
burgerMenu.add(helpMenu);
burgerMenu.add(burgerMenu);
mainMenu.add(burgerMenu);
mainMenu.add(new AccessTools(mainWindow, mainWindowMenuHandler));
mainMenu.add(new AccessTools(mainWindowMenuHandler));
}
}
2 changes: 1 addition & 1 deletion src/org/omegat/gui/main/MainWindowMenuHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
* @author Yu Tang
* @author Aaron Madlon-Kay
*/
public final class MainWindowMenuHandler {
public final class MainWindowMenuHandler extends BaseMainWindowMenuHandler {
private static final String PROP_ORIGIN = ProjectTMX.PROP_ORIGIN;

private final MainWindow mainWindow;
Expand Down
3 changes: 3 additions & 0 deletions test-acceptance/data/project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project_stats.txt
project_stats.json
*.bak
Empty file.
2 changes: 2 additions & 0 deletions test-acceptance/data/project/glossary/glossary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Glossary in tab-separated format -*- coding: utf-8 -*-
Introduction 紹介
33 changes: 33 additions & 0 deletions test-acceptance/data/project/omegat.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version='1.0' encoding='UTF-8'?>
<omegat>
<project version="1.0">
<source_dir>__DEFAULT__</source_dir>
<source_dir_excludes>
<mask>**/.svn/**</mask>
<mask>**/CVS/**</mask>
<mask>**/.cvs/**</mask>
<mask>**/.git/**</mask>
<mask>**/.hg/**</mask>
<mask>**/.repositories/**</mask>
<mask>**/desktop.ini</mask>
<mask>**/Thumbs.db</mask>
<mask>**/.DS_Store</mask>
<mask>**/~$*</mask>
</source_dir_excludes>
<target_dir>__DEFAULT__</target_dir>
<tm_dir>__DEFAULT__</tm_dir>
<glossary_dir>__DEFAULT__</glossary_dir>
<glossary_file>__DEFAULT__</glossary_file>
<dictionary_dir>__DEFAULT__</dictionary_dir>
<export_tm_dir>__DEFAULT__</export_tm_dir>
<export_tm_levels></export_tm_levels>
<source_lang>en</source_lang>
<target_lang>fr</target_lang>
<source_tok>org.omegat.tokenizer.LuceneEnglishTokenizer</source_tok>
<target_tok>org.omegat.tokenizer.LuceneFrenchTokenizer</target_tok>
<sentence_seg>false</sentence_seg>
<support_default_translations>true</support_default_translations>
<remove_tags>true</remove_tags>
<external_command></external_command>
</project>
</omegat>
Empty file.
Empty file.
17 changes: 17 additions & 0 deletions test-acceptance/data/project/omegat/project_save.tmx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE tmx SYSTEM "tmx11.dtd">
<tmx version="1.1">
<header creationtool="OmegaT" o-tmf="OmegaT TMX" adminlang="EN-US" datatype="plaintext" creationtoolversion="6.1.0_0_f59958c" segtype="paragraph" srclang="en"/>
<body>
<!-- Default translations -->
<tu>
<tuv lang="en">
<seg>Birds in Oregon</seg>
</tuv>
<tuv lang="fr" changeid="Hiroshi Miura" changedate="20240302T051308Z" creationid="Hiroshi Miura" creationdate="20240302T051308Z">
<seg>Birds in Oregon</seg>
</tuv>
</tu>
<!-- Alternative translations -->
</body>
</tmx>
36 changes: 36 additions & 0 deletions test-acceptance/data/project/source/Bundle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# OmegaT - Computer Assisted Translation (CAT) tool
# with fuzzy matching, translation memory, keyword search,
# glossaries, and translation leveraging into updated projects.
#
# Copyright (C) 2023 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/>.
#
MT_ENGINE_APERTIUM=Apertium

MT_JSON_ERROR=Error while reading MT results

APERTIUM_ERROR=Error {0}: {1}
APERTIUM_CUSTOM_SERVER_LABEL=Connect to custom server instead of apertium.org
APERTIUM_CUSTOM_SERVER_URL_LABEL=Custom server URL
APERTIUM_CUSTOM_SERVER_KEY_LABEL=API key (optional)
APERTIUM_CUSTOM_SERVER_NOTFOUND=Unable to connect to server. Ensure the server URL is correct.
APERTIUM_CUSTOM_SERVER_INVALID=The server is not a valid Apertium server. Ensure the URL is correct.
APERTIUM_MARKUNKNOWN_LABEL=Mark unknown words

Empty file.
Empty file.

0 comments on commit 70bc29b

Please sign in to comment.