use of junit.extensions.jfcunit.eventdata.MouseEventData in project JMRI by JMRI.
the class TurnoutIconWindowTest method testPanelEditor.
@SuppressWarnings("unchecked")
public void testPanelEditor() throws Exception {
if (GraphicsEnvironment.isHeadless()) {
// can't Assume in TestCase
return;
}
jmri.jmrit.display.panelEditor.PanelEditor panel = new jmri.jmrit.display.panelEditor.PanelEditor("TurnoutIconWindowTest.testPanelEditor");
JComponent jf = panel.getTargetPanel();
TurnoutIcon icon = new TurnoutIcon(panel);
Turnout sn = jmri.InstanceManager.turnoutManagerInstance().provideTurnout("IT1");
icon.setTurnout(new NamedBeanHandle<Turnout>("IT1", sn));
icon.setDisplayLevel(Editor.TURNOUTS);
icon.setIcon("TurnoutStateClosed", new NamedIcon("resources/icons/smallschematics/tracksegments/os-lefthand-east-closed.gif", "resources/icons/smallschematics/tracksegments/os-lefthand-east-closed.gif"));
icon.setIcon("TurnoutStateThrown", new NamedIcon("resources/icons/smallschematics/tracksegments/os-lefthand-east-thrown.gif", "resources/icons/smallschematics/tracksegments/os-lefthand-east-thrown.gif"));
icon.setIcon("BeanStateInconsistent", new NamedIcon("resources/icons/smallschematics/tracksegments/os-lefthand-east-error.gif", "resources/icons/smallschematics/tracksegments/os-lefthand-east-error.gif"));
icon.setIcon("BeanStateUnknown", new NamedIcon("resources/icons/smallschematics/tracksegments/os-lefthand-east-unknown.gif", "resources/icons/smallschematics/tracksegments/os-lefthand-east-unknown.gif"));
panel.putItem(icon);
panel.setVisible(true);
Assert.assertEquals("initial state", Turnout.UNKNOWN, sn.getState());
// Click icon change state to Active
java.awt.Point location = new java.awt.Point(icon.getLocation().x + icon.getSize().width / 2, icon.getLocation().y + icon.getSize().height / 2);
getHelper().enterClickAndLeave(new MouseEventData(this, // component
jf, // number clicks
1, // modifiers
EventDataConstants.DEFAULT_MOUSE_MODIFIERS, // isPopUpTrigger
false, // sleeptime
10, // position
EventDataConstants.CUSTOM, location));
Assert.assertEquals("state after one click", Turnout.CLOSED, sn.getState());
// Click icon change state to inactive
getHelper().enterClickAndLeave(new MouseEventData(this, icon));
Assert.assertEquals("state after two clicks", Turnout.THROWN, sn.getState());
// if OK to here, close window
TestHelper.disposeWindow(panel.getTargetFrame(), this);
// that pops dialog, find and press Delete
List<JDialog> dialogList = new DialogFinder(null).findAll(panel.getTargetFrame());
JDialog d = dialogList.get(0);
// Find the button that deletes the panel
AbstractButtonFinder bf = new AbstractButtonFinder("Delete Panel");
JButton button = (JButton) bf.find(d, 0);
Assert.assertNotNull(button);
// Click button to delete panel and close window
getHelper().enterClickAndLeave(new MouseEventData(this, button));
// that pops dialog, find and press Yes - Delete
dialogList = new DialogFinder(null).findAll(panel.getTargetFrame());
d = dialogList.get(0);
// Find the button that deletes the panel
bf = new AbstractButtonFinder("Yes - Dele");
button = (JButton) bf.find(d, 0);
Assert.assertNotNull(button);
// Click button to delete panel and close window
getHelper().enterClickAndLeave(new MouseEventData(this, button));
}
use of junit.extensions.jfcunit.eventdata.MouseEventData in project JMRI by JMRI.
the class NXFrameTest method testNXWarrant.
// For types from DialogFinder().findAll(..)
@SuppressWarnings("unchecked")
public void testNXWarrant() throws Exception {
if (GraphicsEnvironment.isHeadless()) {
// can't Assume in TestCase
return;
}
// load and display
File f = new File("java/test/jmri/jmrit/logix/valid/NXWarrantTest.xml");
InstanceManager.getDefault(ConfigureManager.class).load(f);
_OBlockMgr = InstanceManager.getDefault(OBlockManager.class);
_sensorMgr = InstanceManager.getDefault(SensorManager.class);
OBlock block = _OBlockMgr.getBySystemName("OB0");
NXFrame nxFrame = NXFrame.getDefault();
nxFrame.init();
nxFrame.setVisible(true);
nxFrame.setThrottleIncrement(0.075f);
nxFrame.setTimeInterval(1000);
nxFrame.setThrottleFactor(0.75f);
flushAWT();
pressButton(nxFrame, Bundle.getMessage("ButtonCancel"));
// wait to calm down after cancel
flushAWT();
flushAWT();
// after cancel, try again
nxFrame = NXFrame.getDefault();
nxFrame.init();
nxFrame.setVisible(true);
nxFrame._maxSpeedBox.setText("0.30");
nxFrame._origin.blockBox.setText("OB0");
nxFrame._destination.blockBox.setText("OB10");
pressButton(nxFrame, Bundle.getMessage("ButtonRunNX"));
confirmJOptionPane(null, Bundle.getMessage("WarningTitle"), Bundle.getMessage("NoLoco"), "OK");
nxFrame.setAddress("666");
nxFrame.setTrainName("Nick");
flushAWT();
pressButton(nxFrame, Bundle.getMessage("ButtonRunNX"));
DialogFinder finder = new DialogFinder(Bundle.getMessage("DialogTitle"));
java.awt.Container pickDia = (java.awt.Container) finder.find();
Assert.assertNotNull("PickRoute Dialog not found", pickDia);
pressButton(pickDia, Bundle.getMessage("ButtonReview"));
confirmJOptionPane(null, Bundle.getMessage("WarningTitle"), Bundle.getMessage("SelectRoute"), "OK");
List<JRadioButton> list = getRadioButtons(pickDia);
Assert.assertNotNull("Route RadioButtons not found", list);
Assert.assertEquals("Number of RadioButton Routes", 4, list.size());
getHelper().enterClickAndLeave(new MouseEventData(this, list.get(3)));
pressButton(pickDia, Bundle.getMessage("ButtonReview"));
getHelper().enterClickAndLeave(new MouseEventData(this, list.get(1)));
pressButton(pickDia, Bundle.getMessage("ButtonReview"));
nxFrame.setThrottleIncrement(0.05f);
pressButton(pickDia, Bundle.getMessage("ButtonSelect"));
//pause for NXFrame to make commands
flushAWT();
WarrantTableFrame tableFrame = WarrantTableFrame.getDefault();
Assert.assertNotNull("tableFrame", tableFrame);
WarrantTableModel model = tableFrame.getModel();
Assert.assertNotNull("tableFrame model", model);
JUnitUtil.waitFor(() -> {
return model.getRowCount() > 0;
}, "NXWarrant loaded into table");
Warrant warrant = tableFrame.getModel().getWarrantAt(0);
Assert.assertNotNull("warrant", warrant);
Assert.assertNotNull("warrant.getBlockOrders(", warrant.getBlockOrders());
List<BlockOrder> orders = warrant.getBlockOrders();
if (orders.size() != 7) {
System.out.println();
System.out.println(warrant.getSystemName() + " " + warrant.getUserName());
for (BlockOrder bo : orders) {
System.out.println(bo.toString());
}
List<ThrottleSetting> commands = warrant.getThrottleCommands();
for (ThrottleSetting ts : commands) {
System.out.println(ts.toString());
}
}
Assert.assertEquals("Num Blocks in Route", 7, warrant.getBlockOrders().size());
Assert.assertTrue("Num Comands", warrant.getThrottleCommands().size() > 5);
String name = block.getDisplayName();
jmri.util.JUnitUtil.waitFor(() -> {
return warrant.getRunningMessage().equals(Bundle.getMessage("waitForDelayStart", warrant.getTrainName(), name));
}, "Waiting message");
Sensor sensor0 = _sensorMgr.getBySystemName("IS0");
Assert.assertNotNull("Senor IS0 not found", sensor0);
jmri.util.ThreadingUtil.runOnLayout(() -> {
try {
sensor0.setState(Sensor.ACTIVE);
} catch (jmri.JmriException e) {
Assert.fail("Unexpected Exception: " + e);
}
});
jmri.util.JUnitUtil.releaseThread(this);
Assert.assertEquals("Start Block Active", (OBlock.ALLOCATED | OBlock.OCCUPIED | OBlock.RUNNING), block.getState());
JUnitUtil.waitFor(() -> {
return Bundle.getMessage("Halted", name, "0").equals(warrant.getRunningMessage());
}, "Warrant processed sensor change");
Assert.assertEquals("Halted/Resume message", warrant.getRunningMessage(), Bundle.getMessage("Halted", block.getDisplayName(), "0"));
jmri.util.ThreadingUtil.runOnGUI(() -> {
warrant.controlRunTrain(Warrant.RESUME);
});
jmri.util.JUnitUtil.waitFor(() -> {
String m = warrant.getRunningMessage();
return m.endsWith("Cmd #7.");
}, "Train starts to move at 7th command");
// OBlock sensor names
String[] route = { "OB0", "OB1", "OB2", "OB3", "OB7", "OB5", "OB10" };
block = _OBlockMgr.getOBlock("OB10");
// runtimes() in next line runs the train, then checks location
Assert.assertEquals("Train in last block", block.getSensor().getDisplayName(), runtimes(route).getDisplayName());
flushAWT();
// let calm down before running abort
flushAWT();
jmri.util.ThreadingUtil.runOnGUI(() -> {
warrant.controlRunTrain(Warrant.ABORT);
});
flushAWT();
// passed test - cleanup. Do it here so failure leaves traces.
TestHelper.disposeWindow(tableFrame, this);
ControlPanelEditor panel = (ControlPanelEditor) jmri.util.JmriJFrame.getFrame("NXWarrantTest");
// disposing this way allows test to be rerun (i.e. reload panel file) multiple times
panel.dispose(true);
// TestHelper.disposeWindow(panel, this);
// Dialog has popped up, so handle that. First, locate it.
// List<JDialog> dialogList = new DialogFinder(null).findAll(panel);
// TestHelper.disposeWindow(dialogList.get(0), this);
// confirm one message logged
jmri.util.JUnitAppender.assertWarnMessage("RosterSpeedProfile not found. Using default ThrottleFactor 0.75");
}
use of junit.extensions.jfcunit.eventdata.MouseEventData in project JMRI by JMRI.
the class NXFrameTest method pressButton.
private javax.swing.AbstractButton pressButton(java.awt.Container frame, String text) {
AbstractButtonFinder buttonFinder = new AbstractButtonFinder(text);
javax.swing.AbstractButton button = (javax.swing.AbstractButton) buttonFinder.find(frame, 0);
Assert.assertNotNull(text + " Button not found", button);
getHelper().enterClickAndLeave(new MouseEventData(this, button));
return button;
}
Aggregations