MonteMonitor Tests Reimplimented

This commit is contained in:
Marcus Rockwell 2023-10-05 16:35:08 -05:00
parent acdf2420e8
commit 2770a2c445
2 changed files with 132 additions and 0 deletions

View File

@ -0,0 +1,82 @@
package trick.montemonitor;
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 MonteMonitorApplication life cycle.
*
* @author hchen
* @intern mrockwell2
*
*/
public class MonteMonitorApplicationTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
WaitForMonteMonitorApplication.launchAndWait(WaitForMonteMonitorApplication.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("MonteMonitorApplicationTest 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 = {"stopMonteCarlo", "runMonteCarlo", "runSelectedSlaves", "stopSelectedSlaves", "addNewSlave"};
String[] actionTexts = {"Stop", "Start", "Start", "Stop", "Add"};
String[] actionShortDescriptions = {"Dispatch no further runs to any slave. Allow current runs to complete.",
"Begin dispatching runs to all live slaves.",
"Begin dispatching runs to all live selected slaves.",
"Dispatch no further jobs to the selected slaves. Allow current runs to complete.",
"Add and start a new slave."};
for (int i = 0; i < actionNames.length; i++) {
CheckApplicationProperties.checkAction(application().actionMap, actionNames[i]);
CheckApplicationProperties.checkActionText(application().actionMap, actionNames[i], actionTexts[i]);
CheckApplicationProperties.checkActionShortDescription(application().actionMap, actionNames[i], actionShortDescriptions[i]);
}
}*/
@Test
public void testDefinedKeyText() {
CheckApplicationProperties.checkKeyText(application().resourceMap, "fileMenu.text", "&File");
//CheckApplicationProperties.checkKeyText(application().resourceMap, "monteMenu.text", "&Monte Carlo");
//CheckApplicationProperties.checkKeyText(application().resourceMap, "slavesMenu.text", "&Slaves");
}
@Test
public void testExit() {
application().removeExitListener(application().exitListener);
application().exit();
assertTrue(application().isEnded);
}
private static WaitForMonteMonitorApplication application() {
return Application.getInstance(WaitForMonteMonitorApplication.class);
}
}

View File

@ -0,0 +1,50 @@
package trick.montemonitor;
import org.jdesktop.application.Application;
public class WaitForMonteMonitorApplication extends MonteMonitorApplication {
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 MonteMonitorApplication and block
* (wait) until it's startup() method has run.
*/
public static void launchAndWait(Class<? extends WaitForMonteMonitorApplication> applicationClass) {
synchronized(lock) {
Application.launch(applicationClass, new String[]{});
while(true) {
try {
lock.wait();
}
catch (InterruptedException e) {
System.err.println("launchAndWait interrupted!");
break;
}
Application app = Application.getInstance(WaitForMonteMonitorApplication.class);
if (app instanceof WaitForMonteMonitorApplication) {
if (((WaitForMonteMonitorApplication)app).isReady()) {
break;
}
}
}
}
}
}