146 lines
5.5 KiB
Java
146 lines
5.5 KiB
Java
package jmri.jmrit.throttle;
|
|
|
|
import java.awt.GraphicsEnvironment;
|
|
|
|
import jmri.*;
|
|
import jmri.jmrit.throttle.implementation.ThrottleFrame;
|
|
import jmri.jmrix.internal.InternalSystemConnectionMemo;
|
|
import jmri.util.JUnitUtil;
|
|
import jmri.util.swing.JemmyUtil;
|
|
|
|
import org.junit.Assert;
|
|
import org.junit.Assume;
|
|
import org.junit.jupiter.api.*;
|
|
|
|
/**
|
|
* Test sharing functionality of ThrottleFrame
|
|
*
|
|
* @author Paul Bender Copyright (C) 2018
|
|
* @author Steve Young Copyright (C) 2019
|
|
*/
|
|
public class SharingThrottleTest {
|
|
|
|
private ThrottleWindow frame = null;
|
|
private ThrottleFrame panel = null;
|
|
private ThrottleOperator to = null;
|
|
|
|
@Disabled("Jemmy has trouble locating internal frame")
|
|
@Test
|
|
public void testSetAndReleaseWithShare() {
|
|
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
|
|
|
|
to.typeAddressValue(42);
|
|
to.getQueueTool().waitEmpty(); //pause
|
|
|
|
// because of the throttle manager we are using, a steal
|
|
// request is expected next, and we want to steal.
|
|
Thread add1 = JemmyUtil.createModalDialogOperatorThread(
|
|
Bundle.getMessage("ShareRequestTitle"), Bundle.getMessage("ButtonYes")); // NOI18N
|
|
to.pushSetButton();
|
|
|
|
JUnitUtil.waitFor(()->{return !(add1.isAlive());}, "dialog finished"); // NOI18N
|
|
to.getQueueTool().waitEmpty(); //pause
|
|
|
|
Assert.assertEquals("address set", new DccLocoAddress(42, false),
|
|
to.getAddressValue());
|
|
|
|
to.pushReleaseButton();
|
|
}
|
|
|
|
@Disabled("Jemmy has trouble locating internal frame")
|
|
@Test
|
|
public void testSetAndRefuseShare() {
|
|
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
|
|
|
|
to.typeAddressValue(42);
|
|
to.getQueueTool().waitEmpty(); //pause
|
|
|
|
// because of the throttle manager we are using, a share
|
|
// request is expected next, and we do not want to share.
|
|
Thread add1 = JemmyUtil.createModalDialogOperatorThread(
|
|
Bundle.getMessage("ShareRequestTitle"), Bundle.getMessage("ButtonNo"));
|
|
to.pushSetButton();
|
|
JUnitUtil.waitFor(()->{return !(add1.isAlive());}, "dialog finished"); // NOI18N
|
|
to.getQueueTool().waitEmpty(); //pause
|
|
|
|
Assert.assertFalse("release button disabled", to.releaseButtonEnabled());
|
|
Assert.assertTrue("set button enabled", to.setButtonEnabled());
|
|
}
|
|
|
|
@Disabled("Jemmy has trouble locating internal frame")
|
|
@Test
|
|
public void testRefuseOneShareOne() {
|
|
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
|
|
|
|
to.typeAddressValue(42);
|
|
to.getQueueTool().waitEmpty(); //pause
|
|
|
|
// because of the throttle manager we are using, a share
|
|
// request is expected next, and we do not want to share.
|
|
Thread add1 = JemmyUtil.createModalDialogOperatorThread(
|
|
Bundle.getMessage("ShareRequestTitle"), Bundle.getMessage("ButtonNo")); // NOI18N
|
|
to.pushSetButton();
|
|
JUnitUtil.waitFor(()->{return !(add1.isAlive());}, "dialog finished"); // NOI18N
|
|
to.getQueueTool().waitEmpty(); //pause
|
|
|
|
Assert.assertFalse("release button disabled", to.releaseButtonEnabled());
|
|
Assert.assertTrue("set button enabled", to.setButtonEnabled());
|
|
Assert.assertTrue("address field enabled", to.addressFieldEnabled());
|
|
|
|
/* Removing bellow test, focus issue on address text field for the bellow typeAddressValue
|
|
* testing for addressFieldEnabled above is already good enough
|
|
|
|
to.typeAddressValue(45);
|
|
to.getQueueTool().waitEmpty(); //pause
|
|
|
|
// because of the throttle manager we are using, a share
|
|
// request is expected next, and we want to share.
|
|
Thread add2 = JemmyUtil.createModalDialogOperatorThread(
|
|
Bundle.getMessage("ShareRequestTitle"), Bundle.getMessage("ButtonYes")); // NOI18N
|
|
to.pushSetButton();
|
|
JUnitUtil.waitFor(()->{return !(add2.isAlive());}, "dialog2 finished"); // NOI18N
|
|
to.getQueueTool().waitEmpty(); //pause
|
|
|
|
Assert.assertEquals("address set", new DccLocoAddress(4245, true),
|
|
to.getAddressValue());
|
|
|
|
to.pushReleaseButton();*/
|
|
}
|
|
|
|
@BeforeEach
|
|
public void setUp() {
|
|
JUnitUtil.setUp();
|
|
JUnitUtil.resetProfileManager();
|
|
JUnitUtil.initRosterConfigManager();
|
|
// these tests use the SharingThrottleManager.
|
|
var memo = InstanceManager.getDefault(InternalSystemConnectionMemo.class);
|
|
ThrottleManager m = new jmri.managers.SharingThrottleManager(memo);
|
|
memo.store(m, ThrottleManager.class);
|
|
jmri.InstanceManager.setThrottleManager(m);
|
|
|
|
if (!GraphicsEnvironment.isHeadless()) {
|
|
frame = new ThrottleWindow();
|
|
panel = new ThrottleFrame(frame);
|
|
frame.setExtendedState(frame.getExtendedState() | java.awt.Frame.MAXIMIZED_BOTH);
|
|
panel.toFront();
|
|
to = new ThrottleOperator(Bundle.getMessage("ThrottleTitle"));
|
|
}
|
|
}
|
|
|
|
@AfterEach
|
|
public void tearDown() {
|
|
if (!GraphicsEnvironment.isHeadless()) {
|
|
to.requestClose();
|
|
new org.netbeans.jemmy.QueueTool().waitEmpty(); //pause for frame to close
|
|
JUnitUtil.dispose(frame);
|
|
// the throttle list frame gets created above, but needs to be shown to be disposed
|
|
InstanceManager.getDefault(ThrottleFrameManager.class).showThrottlesList();
|
|
JUnitUtil.disposeFrame(Bundle.getMessage("ThrottleListFrameTile"), true, true);
|
|
}
|
|
panel = null;
|
|
frame = null;
|
|
to = null;
|
|
JUnitUtil.tearDown();
|
|
}
|
|
}
|