use of junit.extensions.jfcunit.finder.NamedComponentFinder in project JMRI by JMRI.
the class TurnoutTableWindowTest method testShowAndClose.
public void testShowAndClose() throws Exception {
if (GraphicsEnvironment.isHeadless()) {
// can't Assume in TestCase
return;
}
// ask for the window to open
TurnoutTableAction a = new TurnoutTableAction();
a.actionPerformed(new java.awt.event.ActionEvent(a, 1, ""));
// Find new table window by name
JmriJFrame ft = JmriJFrame.getFrame(Bundle.getMessage("TitleTurnoutTable"));
flushAWT();
// Find the Automatic retry checkbox
AbstractButtonFinder arfinder = new AbstractButtonFinder(Bundle.getMessage("AutomaticRetry"));
JCheckBox ar = (JCheckBox) arfinder.find(ft, 0);
Assert.assertNotNull(ar);
// Click checkbox to select Automatic retry
getHelper().enterClickAndLeave(new MouseEventData(this, ar));
Assert.assertNotNull("AR selected", ar.getSelectedObjects());
// Find the Show Feedback information checkbox
AbstractButtonFinder fbfinder = new AbstractButtonFinder(Bundle.getMessage("ShowFeedbackInfo"));
JCheckBox fb = (JCheckBox) fbfinder.find(ft, 0);
Assert.assertNotNull(fb);
// Click checkbox to select Show feedback information
getHelper().enterClickAndLeave(new MouseEventData(this, fb));
Assert.assertNotNull("FBbox selected", fb.getSelectedObjects());
// Find the Show Lock information checkbox
AbstractButtonFinder lkfinder = new AbstractButtonFinder(Bundle.getMessage("ShowLockInfo"));
JCheckBox lk = (JCheckBox) lkfinder.find(ft, 0);
Assert.assertNotNull(lk);
// Click checkbox to select Show feedback information
getHelper().enterClickAndLeave(new MouseEventData(this, lk));
Assert.assertNotNull("LKbox selected", lk.getSelectedObjects());
// Find the Show Turnout Speed details checkbox
AbstractButtonFinder tsfinder = new AbstractButtonFinder(Bundle.getMessage("ShowTurnoutSpeedDetails"));
JCheckBox ts = (JCheckBox) tsfinder.find(ft, 0);
Assert.assertNotNull(ts);
// Click checkbox to select Show feedback information
getHelper().enterClickAndLeave(new MouseEventData(this, ts));
Assert.assertNotNull("TSbox selected", ts.getSelectedObjects());
// Find the Add... button
AbstractButtonFinder abfinder = new AbstractButtonFinder(Bundle.getMessage("ButtonAdd"));
JButton ad = (JButton) abfinder.find(ft, 0);
Assert.assertNotNull(ad);
// Click button to open Add Turnout pane
getHelper().enterClickAndLeave(new MouseEventData(this, ad));
// Find Add Turnout pane by name
JmriJFrame fa = JmriJFrame.getFrame(Bundle.getMessage("TitleAddTurnout"));
Assert.assertNotNull("Add window found", fa);
// Find hardware number field
NamedComponentFinder ncfinder = new NamedComponentFinder(JComponent.class, "sysName");
JTextField sysNameField = (JTextField) ncfinder.find(fa, 0);
Assert.assertNotNull(sysNameField);
// set to "1"
// The following line works on the CI servers, but not in some standalone cases
//getHelper().sendString(new StringEventData(this, sysNameField, "1"));
// workaround
sysNameField.setText("1");
flushAWT();
Assert.assertEquals("name content", "1", sysNameField.getText());
// Find system combobox
ncfinder = new NamedComponentFinder(JComponent.class, "prefixBox");
JComboBox<?> prefixBox = (JComboBox<?>) ncfinder.find(fa, 0);
Assert.assertNotNull(prefixBox);
// set to "Internal"
prefixBox.setSelectedItem("Internal");
// this connection type is always available
Assert.assertEquals("Selected system item", "Internal", prefixBox.getSelectedItem());
// Find the Add OK button
AbstractButtonFinder okfinder = new AbstractButtonFinder(Bundle.getMessage("ButtonOK"));
JButton okbutton = (JButton) okfinder.find(fa, 0);
Assert.assertNotNull(okbutton);
// Click button to add turnout
getHelper().enterClickAndLeave(new MouseEventData(this, okbutton));
// Ask to close Add pane
TestHelper.disposeWindow(fa, this);
// Open the Edit Turnout IT1 pane, how to find & click the LT1 Edit col button?
// Find the Edit button in EDITCOL of line 0 (for LT1)
//AbstractButtonFinder edfinder = new AbstractButtonFinder("Edit");
//JButton editbutton = (JButton) edfinder.find(ft, 0);
//Assert.assertNotNull(editbutton);
// Click button to edit turnout
//getHelper().enterClickAndLeave(new MouseEventData(this, editbutton));
// open Edit pane by method instead
Turnout it1 = InstanceManager.turnoutManagerInstance().getTurnout("IT1");
// open edit pane
a.editButton(it1);
// Find Edit Turnout pane by name
JmriJFrame fe = JmriJFrame.getFrame("Edit Turnout IT1");
Assert.assertNotNull("Edit window", fe);
// Find the Edit Cancel button
AbstractButtonFinder canceleditfinder = new AbstractButtonFinder(Bundle.getMessage("ButtonCancel"));
JButton cancelbutton = (JButton) canceleditfinder.find(fe, 0);
Assert.assertNotNull(cancelbutton);
// Click button to cancel edit turnout
getHelper().enterClickAndLeave(new MouseEventData(this, cancelbutton));
// Ask to close Edit pane
TestHelper.disposeWindow(fe, this);
// Ask to close turnout table window
TestHelper.disposeWindow(ft, this);
flushAWT();
// check that turnout was created
Assert.assertNotNull(jmri.InstanceManager.turnoutManagerInstance().getTurnout("IT1"));
}
use of junit.extensions.jfcunit.finder.NamedComponentFinder in project JMRI by JMRI.
the class SwingTestCaseTest method testCheckBox.
/**
* Simple test of creating a Swing frame with a checkbox, checking the box,
* and seeing that the check changed its state.
*/
public void testCheckBox() {
if (GraphicsEnvironment.isHeadless()) {
// can't Assume because TestCase
return;
}
// create a little GUI with a single check box
JFrame f = new JFrame("SwingTextCaseTest");
// checkbox must be visible for test to work
f.setSize(100, 100);
JCheckBox b = new JCheckBox("Check");
b.setName("Check");
f.add(b);
f.setVisible(true);
// find the check box and confirm not yet checked
NamedComponentFinder finder = new NamedComponentFinder(JCheckBox.class, "Check");
JCheckBox testBox = (JCheckBox) finder.find(f, 0);
Assert.assertNotNull(testBox);
Assert.assertTrue(!testBox.isSelected());
// set the check in the box by clicking it
getHelper().enterClickAndLeave(new MouseEventData(this, testBox));
// test for selected
Assert.assertTrue(testBox.isSelected());
f.dispose();
}
use of junit.extensions.jfcunit.finder.NamedComponentFinder in project JMRI by JMRI.
the class SensorTableWindowTest method testShowAndClose.
public void testShowAndClose() throws Exception {
if (GraphicsEnvironment.isHeadless()) {
// can't Assume in TestCase
return;
}
// ask for the window to open
SensorTableAction a = new SensorTableAction();
a.actionPerformed(new java.awt.event.ActionEvent(a, 1, ""));
// Find new table window by name
JmriJFrame ft = JmriJFrame.getFrame(Bundle.getMessage("TitleSensorTable"));
flushAWT();
// Find the add button
AbstractButtonFinder abfinder = new AbstractButtonFinder("Add...");
JButton button = (JButton) abfinder.find(ft, 0);
Assert.assertNotNull(button);
// Click button to open add window
getHelper().enterClickAndLeave(new MouseEventData(this, button));
// Find add window by name
JmriJFrame fa = JmriJFrame.getFrame("Add New Sensor");
Assert.assertNotNull("add window", fa);
// Find system name field
NamedComponentFinder ncfinder = new NamedComponentFinder(JComponent.class, "sysName");
JTextField sysNameField = (JTextField) ncfinder.find(fa, 0);
Assert.assertNotNull("sys name field", sysNameField);
// set to "1"
// The following line works on the CI servers, but not in some standalone cases
//getHelper().sendString(new StringEventData(this, sysNameField, "1"));
// workaround
sysNameField.setText("1");
flushAWT();
Assert.assertEquals("name content", "1", sysNameField.getText());
// Find system combobox
ncfinder = new NamedComponentFinder(JComponent.class, "prefixBox");
JComboBox<?> prefixBox = (JComboBox<?>) ncfinder.find(fa, 0);
Assert.assertNotNull(prefixBox);
// set to "Internal"
prefixBox.setSelectedItem("Internal");
Assert.assertEquals("Selected system item", "Internal", prefixBox.getSelectedItem());
// Find the OK button
abfinder = new AbstractButtonFinder("OK");
button = (JButton) abfinder.find(fa, 0);
Assert.assertNotNull(button);
// Click button to add sensor
getHelper().enterClickAndLeave(new MouseEventData(this, button));
// Ask to close add window
TestHelper.disposeWindow(fa, this);
// Ask to close table window
TestHelper.disposeWindow(ft, this);
flushAWT();
// check for existing sensor
Assert.assertNotNull(jmri.InstanceManager.sensorManagerInstance().getSensor("IS1"));
}
Aggregations