From 0be90e3791a7992dc6357c944937c09d7ce0e38f Mon Sep 17 00:00:00 2001 From: Marcus Rockwell Date: Mon, 2 Oct 2023 18:23:36 -0500 Subject: [PATCH] Got maven set up so that the tests run --- trick_source/java/Makefile | 6 +- trick_source/java/pom.xml | 3 + .../common/CheckApplicationProperties.java | 88 +++++++++++++++++++ .../java/trick/dre/DreApplicationTest.java | 80 +++++++++++++++++ .../java/trick/dre/WaitForDreApplication.java | 51 +++++++++++ .../src/test/java/trick/test/Testing.java | 31 +++++++ 6 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 trick_source/java/src/test/java/trick/common/CheckApplicationProperties.java create mode 100644 trick_source/java/src/test/java/trick/dre/DreApplicationTest.java create mode 100644 trick_source/java/src/test/java/trick/dre/WaitForDreApplication.java create mode 100644 trick_source/java/src/test/java/trick/test/Testing.java diff --git a/trick_source/java/Makefile b/trick_source/java/Makefile index fe72a9e0..886ce504 100644 --- a/trick_source/java/Makefile +++ b/trick_source/java/Makefile @@ -6,7 +6,11 @@ include ${TRICK_HOME}/share/trick/makefiles/Makefile.common all: @echo "Building java application..." - @${MVN} package -q -Dcmake=false -Dmaven.wagon.http.retryHandler.count=15 + @${MVN} package -q -Dmaven.test.skip -Dcmake=false -Dmaven.wagon.http.retryHandler.count=15 + +test: + @echo "Building java tests..." + @${MVN} test --quiet -Dcmake=false -Dmaven.wagon.http.retryHandler.count=15 javadoc: ${MVN} javadoc:javadoc diff --git a/trick_source/java/pom.xml b/trick_source/java/pom.xml index d29ec2a4..86794f39 100644 --- a/trick_source/java/pom.xml +++ b/trick_source/java/pom.xml @@ -313,6 +313,9 @@ maven-surefire-plugin 2.22.1 + + true + diff --git a/trick_source/java/src/test/java/trick/common/CheckApplicationProperties.java b/trick_source/java/src/test/java/trick/common/CheckApplicationProperties.java new file mode 100644 index 00000000..044780a8 --- /dev/null +++ b/trick_source/java/src/test/java/trick/common/CheckApplicationProperties.java @@ -0,0 +1,88 @@ +package trick.common; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import javax.swing.ActionMap; +import javax.swing.Icon; + +import org.jdesktop.application.ResourceMap; + +/** + * A class for checking different properties of an {@link Application}. + * + * @author Hong Chen + */ +public abstract class CheckApplicationProperties{ + + + public static String getActionText(javax.swing.Action action) { + return (String)action.getValue(javax.swing.Action.NAME); + } + + public static String getActionShortDescription(javax.swing.Action action) { + return (String)action.getValue(javax.swing.Action.SHORT_DESCRIPTION); + } + + // check to see if the action exists (the related @Action code needs to be implemented) + public static javax.swing.Action checkAction(ActionMap aMap, String actionKey) { + javax.swing.Action action = aMap.get(actionKey); + assertNotNull(actionMapGetString(actionKey), action); + return action; + } + + // check to see if the action text exists + public static void checkActionText(ActionMap aMap, String actionKey) { + javax.swing.Action action = checkAction(aMap, actionKey); + assertNotNull(actionMapGetString(actionKey) + ".getValue(javax.swing.Action.Name)", getActionText(action)); + } + + // check to see if the action short description exists + public static void checkActionShortDescription(ActionMap aMap, String actionKey) { + javax.swing.Action action = checkAction(aMap, actionKey); + assertNotNull(actionMapGetString(actionKey) + ".getValue(javax.swing.Action.SHORT_DESCRIPTION)", getActionShortDescription(action)); + } + + // check to see if the action text is as expected + public static void checkActionText(ActionMap aMap, String actionKey, String expectedValue) { + javax.swing.Action action = aMap.get(actionKey); + assertEquals(actionMapGetString(actionKey) + ".getValue(javax.swing.Action.Name)", expectedValue, (String)action.getValue(javax.swing.Action.NAME)); + } + + // check to see if the action short description is as expected + public static void checkActionShortDescription(ActionMap aMap, String actionKey, String expectedValue) { + javax.swing.Action action = checkAction(aMap, actionKey); + assertEquals(actionMapGetString(actionKey) + ".getValue(javax.swing.Action.SHORT_DESCRIPTION)", expectedValue, getActionShortDescription(action)); + } + + // check to see if the action icon is specified + public static void checkActionIcon(ActionMap aMap, String actionKey) { + javax.swing.Action action = checkAction(aMap, actionKey); + Icon icon = (Icon)(action.getValue(javax.swing.Action.SMALL_ICON)); + assertNotNull(actionMapGetString(actionKey) + ".getValue(javax.swing.Action.SMALL_ICON)", icon); + } + + // check to see if the text of a key is defined + public static void checkKeyText(ResourceMap rMap, String key) { + assertNotNull(rMap.getString(key)); + } + + // check to see if the text of a key is as expected + public static void checkKeyText(ResourceMap rMap, String key, String expectedValue) { + String keyText = rMap.getString(key); + assertNotNull(keyText); + if (expectedValue != null) { + assertEquals(resourceMapGetString(key), expectedValue, keyText); + } + } + + private static String actionMapGetString(String actionKey) { + return "ActionMap.get(\"" + actionKey + "\")"; + } + + private static String resourceMapGetString(String key) { + return "ResourceMap.get(\"" + key + "\")"; + } + +} \ No newline at end of file diff --git a/trick_source/java/src/test/java/trick/dre/DreApplicationTest.java b/trick_source/java/src/test/java/trick/dre/DreApplicationTest.java new file mode 100644 index 00000000..f7ad26d6 --- /dev/null +++ b/trick_source/java/src/test/java/trick/dre/DreApplicationTest.java @@ -0,0 +1,80 @@ +package trick.dre; + +import static org.junit.Assert.assertTrue; + +import org.jdesktop.application.Application; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import trick.common.CheckApplicationProperties; + +/** + * + * Test DreApplication life cycle. + * + * @author hchen + * + */ +public class DreApplicationTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + WaitForDreApplication.launchAndWait(WaitForDreApplication.class); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testReady() { + assertTrue("DreApplicationTest is not ready yet!", application().isReady()); + } + + /** + * Verify that all implemented actions exist as well as their text, shortDescription properties. + */ + @Test + public void testDefinedActions() { + String[] actionNames = {"openDR", "saveDR", "selectDRBinary", "selectDRAscii", "selectDRHDF5", + "selectDRAlways", "selectDRChanges", "selectDRStepChanges", "toggleSinglePrecision", + "selectDRBuffer", "selectDRNoBuffer", "selectDRRingBuffer", "selectDRThreadBuffer", + "addVariables", "removeSelected", "removeAll"}; + String[] actionTexts = {"Open...", "Save...", "DR Binary", "DR Ascii", "DR HDF5", "DR Always", "DR Changes", + "DR Step Changes", "Single Precision", "DR Buffer", "DR No Buffer", "DR Ring Buffer", + "DR Thread Buffer", "Add", "Remove Selected", "Remove All"}; + + for (int i = 0; i < actionNames.length; i++) { + CheckApplicationProperties.checkAction(application().actionMap, actionNames[i]); + CheckApplicationProperties.checkActionText(application().actionMap, actionNames[i], actionTexts[i]); + } + } + + @Test + public void testDefinedKeyText() { + CheckApplicationProperties.checkKeyText(application().resourceMap, "fileMenu.text", "&File"); + CheckApplicationProperties.checkKeyText(application().resourceMap, "optionsMenu.text", "&Options"); + } + + @Test + public void testExit() { + application().removeExitListener(application().exitListener); + application().exit(); + assertTrue(application().isEnded); + } + + private static WaitForDreApplication application() { + return Application.getInstance(WaitForDreApplication.class); + } +} \ No newline at end of file diff --git a/trick_source/java/src/test/java/trick/dre/WaitForDreApplication.java b/trick_source/java/src/test/java/trick/dre/WaitForDreApplication.java new file mode 100644 index 00000000..62494506 --- /dev/null +++ b/trick_source/java/src/test/java/trick/dre/WaitForDreApplication.java @@ -0,0 +1,51 @@ +package trick.dre; + + +import org.jdesktop.application.Application; + + +public class WaitForDreApplication extends DreApplication { + static Object lock = new Object(); + + boolean isEnded; + + @Override + protected void end() { + isEnded = true; + } + + @Override + protected void ready() { + super.ready(); + synchronized(lock) { + lock.notifyAll(); + } + } + + + /** + * Launch the specified subclsas of DreApplication and block + * (wait) until it's startup() method has run. + */ + public static void launchAndWait(Class applicationClass) { + synchronized(lock) { + sieResourcePath ="resources" + java.io.File.separator + "S_sie.resource"; + Application.launch(applicationClass, new String[]{}); + while(true) { + try { + lock.wait(); + } + catch (InterruptedException e) { + System.err.println("launchAndWait interrupted!"); + break; + } + Application app = Application.getInstance(WaitForDreApplication.class); + if (app instanceof WaitForDreApplication) { + if (((WaitForDreApplication)app).isReady()) { + break; + } + } + } + } + } +} \ No newline at end of file diff --git a/trick_source/java/src/test/java/trick/test/Testing.java b/trick_source/java/src/test/java/trick/test/Testing.java new file mode 100644 index 00000000..8d0588f2 --- /dev/null +++ b/trick_source/java/src/test/java/trick/test/Testing.java @@ -0,0 +1,31 @@ +package trick.test; +import static org.junit.Assert.assertTrue; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +public class Testing { + @BeforeClass + public static void beforeClassmethod() { + System.out.println("Hi welcome in Before Class Method"); + } + @Before + public void beforemethod() { + System.out.println("Hello there welcome in Before Test Case strategy "); + } + @Test + public void Test(){ + System.out.println("Welcome in First Test"); + int num = 5; + assertTrue(num == 5); + } + @After + public void aftermethod() { + System.out.println("Hi welcome in After Test Case"); + } + @AfterClass + public static void afterClassmethod() { + System.out.println("Hi welcome in After Class"); + } +} \ No newline at end of file