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 Menus

Signed-off-by: Hiroshi Miura <[email protected]>
  • Loading branch information
miurahr committed May 3, 2024
1 parent 02c43b7 commit 26bb779
Show file tree
Hide file tree
Showing 21 changed files with 1,349 additions and 0 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
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.
20 changes: 20 additions & 0 deletions test-acceptance/src/org/omegat/TestMainInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.omegat;

import javax.swing.UIManager;

import org.omegat.filters2.master.PluginUtils;

public final class TestMainInitializer {

private TestMainInitializer() {
}

public static void initClassloader() {
ClassLoader cl = ClassLoader.getSystemClassLoader();
MainClassLoader mainClassLoader = (cl instanceof MainClassLoader) ? (MainClassLoader) cl
: new MainClassLoader(cl);
PluginUtils.getThemePluginJars().forEach(mainClassLoader::add);
UIManager.put("ClassLoader", mainClassLoader);
}

}
81 changes: 81 additions & 0 deletions test-acceptance/src/org/omegat/gui/GlossaryEntryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.omegat.gui;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.awt.event.KeyEvent;
import java.io.File;
import java.nio.file.Files;

import javax.swing.SwingUtilities;

import org.apache.commons.io.FileUtils;
import org.junit.Test;

import org.omegat.gui.dialogs.CreateGlossaryEntry;
import org.omegat.gui.glossary.GlossaryTextArea;
import org.omegat.gui.main.BaseMainWindowMenu;
import org.omegat.gui.main.ProjectUICommands;
import org.omegat.gui.main.TestCoreGUI;
import org.omegat.util.Preferences;

public class GlossaryEntryTest extends TestCoreGUI {

private File tmpDir;

/**
* Test case to create glossary entry and see a result.
*
* @throws Exception
*/
@Test
public void testOpenGlossaryEntryDialog() throws Exception {
// 0. Prepare project folder
tmpDir = Files.createTempDirectory("omegat-sample-project-").toFile();
File projSrc = new File("test-acceptance/data/project/");
FileUtils.copyDirectory(projSrc, tmpDir);
FileUtils.forceDeleteOnExit(tmpDir);
// 1. Prepare preference for the test;
// * OmegaT doesn't show a file list dialog on a project load event.
// * Glossary sort order preference
Preferences.setPreference(Preferences.PROJECT_FILES_SHOW_ON_LOAD, false);
Preferences.setPreference(Preferences.GLOSSARY_SORT_BY_LENGTH, false);
Preferences.setPreference(Preferences.GLOSSARY_SORT_BY_SRC_LENGTH, false);
assertFalse(Preferences.isPreferenceDefault(Preferences.PROJECT_FILES_SHOW_ON_LOAD, true));
// 2. Open a sample project.
SwingUtilities.invokeAndWait(() -> ProjectUICommands.projectOpen(tmpDir));
// 3. Operate Glossary preference from menu.
Preferences.setPreference(Preferences.GLOSSARY_STEMMING, true);
window.menuItem(BaseMainWindowMenu.OPTIONS_MENU).click();
window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_SUBMENU).click();
assertTrue(window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_FUZZY_MATCHING_CHECKBOX_MENUITEM)
.target().getModel().isSelected());
window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_FUZZY_MATCHING_CHECKBOX_MENUITEM).click();
// 4. toggle options > glossary menu
window.menuItem(BaseMainWindowMenu.OPTIONS_MENU).click();
window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_SUBMENU).click();
assertFalse(window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_FUZZY_MATCHING_CHECKBOX_MENUITEM)
.target().getModel().isSelected());
// 5. Click menu Edit > Create glossary menu items.
window.menuItem(BaseMainWindowMenu.EDIT_MENU).click();
window.menuItem(BaseMainWindowMenu.EDIT_CREATE_GLOSSARY_MENUITEM).click();
// 6. Check Create glossary dialog visible
window.dialog(CreateGlossaryEntry.DIALOG_NAME).requireVisible();
// 7. Enter glossary keyword and translation in the field
window.dialog(CreateGlossaryEntry.DIALOG_NAME).textBox(CreateGlossaryEntry.SOURCE_TEXT_FIELD)
.enterText("Apertium");
window.dialog(CreateGlossaryEntry.DIALOG_NAME).textBox(CreateGlossaryEntry.TARGET_TEXT_FIELD)
.enterText("Translation Engine");
// 8. Click a OK button
window.dialog(CreateGlossaryEntry.DIALOG_NAME).button(CreateGlossaryEntry.OK_BUTTON).click();
// 9. Enforce refresh glossary pane
GlossaryTextArea glossaryTextArea = ((GlossaryTextArea) (window
.textBox(GlossaryTextArea.TEXTPANE_NAME).target()));
glossaryTextArea.refresh();
// 10. Wait showing a search result during some operation
window.textBox(GlossaryTextArea.TEXTPANE_NAME).rightClick();
window.pressKey(KeyEvent.VK_ESCAPE);
// Check the glossary pane shown in the pane
assertFalse(glossaryTextArea.getDisplayedEntries().isEmpty());
}
}
76 changes: 76 additions & 0 deletions test-acceptance/src/org/omegat/gui/ProjectMenuTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**************************************************************************
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;

import static org.junit.Assert.assertFalse;

import java.io.File;
import java.nio.file.Files;

import org.junit.Test;

import org.omegat.core.Core;
import org.omegat.gui.dialogs.NewProjectFileChooser;
import org.omegat.gui.main.BaseMainWindowMenu;
import org.omegat.gui.main.TestCoreGUI;

public class ProjectMenuTest extends TestCoreGUI {

File tempDir;

@Override
protected void onSetUp() throws Exception {
super.onSetUp();
tempDir = Files.createTempDirectory("omegat").toFile();
}

/**
* Test project menus.
*/
@Test
public void testNewProject() {
window.requireTitle("OmegaT 6.1.0");
// 2. click menu Project > new project
window.menuItem(BaseMainWindowMenu.PROJECT_MENU).click();
window.menuItem(BaseMainWindowMenu.PROJECT_NEW_MENUITEM).click();
window.fileChooser(NewProjectFileChooser.DIALOG_NAME).requireEnabled();
window.fileChooser().selectFile(tempDir);
window.fileChooser().approve();
assertFalse(Core.getProject().isProjectLoaded());
/*
* window.dialog(Timeout.timeout(30000L)).requireVisible();
* window.dialog(ProjectPropertiesDialog.DIALOG_NAME).requireModal();
* window.dialog(ProjectPropertiesDialog.DIALOG_NAME).button(
* ProjectPropertiesDialog.OK_BUTTON_NAME).click();
* assertTrue(Core.getProject().isProjectLoaded());
*/
// 3. select project > Exit menu.
window.menuItem(BaseMainWindowMenu.PROJECT_MENU).click();
window.menuItem(BaseMainWindowMenu.PROJECT_EXIT_MENUITEM).click();
window.requireNotVisible();
window.requireDisabled();
}

}
Loading

0 comments on commit 26bb779

Please sign in to comment.