Search in sources :

Example 11 with MouseEventData

use of junit.extensions.jfcunit.eventdata.MouseEventData in project JMRI by JMRI.

the class SensorIconWindowTest method testLayoutEditor.

// DialogFinder not parameterized
@SuppressWarnings("unchecked")
public void testLayoutEditor() throws Exception {
    if (GraphicsEnvironment.isHeadless()) {
        // can't Assume in TestCase
        return;
    }
    jmri.jmrit.display.layoutEditor.LayoutEditor panel = new jmri.jmrit.display.layoutEditor.LayoutEditor("SensorIconWindowTest.testLayoutEditor");
    JComponent jf = panel.getTargetPanel();
    SensorIcon icon = new SensorIcon(panel);
    panel.putItem(icon);
    Sensor sn = jmri.InstanceManager.sensorManagerInstance().provideSensor("IS1");
    icon.setSensor("IS1");
    icon.setIcon("BeanStateUnknown", new NamedIcon("resources/icons/smallschematics/tracksegments/circuit-error.gif", "resources/icons/smallschematics/tracksegments/circuit-error.gif"));
    //daboudreau added this for Win7
    icon.setDisplayLevel(Editor.SENSORS);
    panel.setVisible(true);
    //jf.setVisible(true);
    Assert.assertEquals("initial state", Sensor.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", Sensor.INACTIVE, sn.getState());
    // Click icon change state to inactive
    getHelper().enterClickAndLeave(new MouseEventData(this, icon));
    Assert.assertEquals("state after two clicks", Sensor.ACTIVE, 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));
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData) DialogFinder(junit.extensions.jfcunit.finder.DialogFinder) AbstractButtonFinder(junit.extensions.jfcunit.finder.AbstractButtonFinder) JDialog(javax.swing.JDialog) Sensor(jmri.Sensor)

Example 12 with MouseEventData

use of junit.extensions.jfcunit.eventdata.MouseEventData 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"));
}
Also used : NamedComponentFinder(junit.extensions.jfcunit.finder.NamedComponentFinder) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) JComponent(javax.swing.JComponent) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData) JTextField(javax.swing.JTextField) AbstractButtonFinder(junit.extensions.jfcunit.finder.AbstractButtonFinder) JmriJFrame(jmri.util.JmriJFrame)

Example 13 with MouseEventData

use of junit.extensions.jfcunit.eventdata.MouseEventData in project JMRI by JMRI.

the class LearnWarrantTest 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));
    flushAWT();
    return button;
}
Also used : AbstractButtonFinder(junit.extensions.jfcunit.finder.AbstractButtonFinder) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData)

Example 14 with MouseEventData

use of junit.extensions.jfcunit.eventdata.MouseEventData in project JMRI by JMRI.

the class LayoutEditorWindowTest method testShowAndClose.

@SuppressWarnings("unchecked")
public void testShowAndClose() throws Exception {
    if (GraphicsEnvironment.isHeadless()) {
        // Can't Assume in TestCase
        return;
    }
    jmri.configurexml.ConfigXmlManager cm = new jmri.configurexml.ConfigXmlManager() {
    };
    // load and display sample file
    java.io.File f = new java.io.File("java/test/jmri/jmrit/display/layoutEditor/valid/SimpleLayoutEditorTest.xml");
    cm.load(f);
    // time for internal listeners to calm down
    sleep(100);
    // Find new window by name (should be more distinctive, comes from sample file)
    LayoutEditor le = (LayoutEditor) jmri.util.JmriJFrame.getFrame("My Layout");
    // It's up at this point, and can be manipulated
    // Ask to close window
    TestHelper.disposeWindow(le, this);
    // Dialog has popped up, so handle that. First, locate it.
    List<JDialog> dialogList = new DialogFinder(null).findAll(le);
    JDialog d = dialogList.get(0);
    // Find the button that deletes the panel
    AbstractButtonFinder finder = new AbstractButtonFinder("Delete Panel");
    JButton button = (JButton) finder.find(d, 0);
    Assert.assertNotNull(button);
    // Click button to delete panel and close window
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
    // another dialog has popped up, so handle that by finding the "Yes - Delete" button.
    dialogList = new DialogFinder(null).findAll(le);
    d = dialogList.get(0);
    finder = new AbstractButtonFinder("Yes - Delete");
    button = (JButton) finder.find(d, 0);
    Assert.assertNotNull(button);
    // Click to say yes, I really mean it.
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
    le.dispose();
}
Also used : JButton(javax.swing.JButton) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData) DialogFinder(junit.extensions.jfcunit.finder.DialogFinder) AbstractButtonFinder(junit.extensions.jfcunit.finder.AbstractButtonFinder) JDialog(javax.swing.JDialog)

Example 15 with MouseEventData

use of junit.extensions.jfcunit.eventdata.MouseEventData in project JMRI by JMRI.

the class MultiJfcUnitTest method testShow.

public void testShow() throws Exception {
    if (GraphicsEnvironment.isHeadless()) {
        // Can't assume in TestCase
        return;
    }
    // show the window
    JFrame f1 = new MultiPaneWindow("test", "java/test/jmri/util/swing/xml/Gui3LeftTree.xml", "java/test/jmri/util/swing/xml/Gui3Menus.xml", "java/test/jmri/util/swing/xml/Gui3MainToolBar.xml");
    f1.setSize(new java.awt.Dimension(500, 500));
    f1.setVisible(true);
    Assert.assertNotNull("found main frame", f1);
    // Find the button that loads the license
    AbstractButtonFinder finder = new AbstractButtonFinder("License");
    JButton button = (JButton) finder.find(f1, 0);
    Assert.assertNotNull("License button found", button);
    // Click it to load license
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
    // Find the button that opens a sample panel
    AbstractButtonFinder samplefinder = new AbstractButtonFinder("Sample");
    JButton samplebutton = (JButton) samplefinder.find(f1, 0);
    Assert.assertNotNull("Sample button found", samplebutton);
    // Click it to load new pane over license
    getHelper().enterClickAndLeave(new MouseEventData(this, samplebutton));
    // Find the button on new panel
    finder = new AbstractButtonFinder("Next1");
    JButton next1button = (JButton) finder.find(f1, 0);
    Assert.assertNotNull("Next1 button found", next1button);
    // Click it to load new window with Next2
    getHelper().enterClickAndLeave(new MouseEventData(this, next1button));
    // nobody disposed yet
    Assert.assertEquals("no panes disposed", 0, SamplePane.disposed.size());
    // Find the Next2 button on new panel
    finder = new AbstractButtonFinder("Next2");
    JButton next2button = (JButton) finder.find(f1, 0);
    Assert.assertNotNull("Next2 button found", next2button);
    // Click sample to reload 0 pane over 1 pane
    getHelper().enterClickAndLeave(new MouseEventData(this, samplebutton));
    // Find the button on restored panel
    finder = new AbstractButtonFinder("Next1");
    button = (JButton) finder.find(f1, 0);
    Assert.assertEquals("found same pane", next1button, button);
    // Find the button to open a pane in lower window
    finder = new AbstractButtonFinder("Extend1");
    JButton extendButton = (JButton) finder.find(f1, 0);
    Assert.assertNotNull("Extend1 button found", extendButton);
    // Press it
    getHelper().enterClickAndLeave(new MouseEventData(this, extendButton));
    // Both Close1 and Close3 should be present
    finder = new AbstractButtonFinder("Close1");
    button = (JButton) finder.find(f1, 0);
    Assert.assertNotNull("Closee1 button found", button);
    finder = new AbstractButtonFinder("Close3");
    button = (JButton) finder.find(f1, 0);
    Assert.assertNotNull("Close3 button found", button);
    // nobody disposed yet
    Assert.assertEquals("no panes disposed", 0, SamplePane.disposed.size());
    // Close entire frame directly
    TestHelper.disposeWindow(f1, this);
    // Now they're disposed
    Assert.assertEquals("panes disposed", 3, SamplePane.disposed.size());
}
Also used : AbstractButtonFinder(junit.extensions.jfcunit.finder.AbstractButtonFinder) JFrame(javax.swing.JFrame) JButton(javax.swing.JButton) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData)

Aggregations

MouseEventData (junit.extensions.jfcunit.eventdata.MouseEventData)23 AbstractButtonFinder (junit.extensions.jfcunit.finder.AbstractButtonFinder)14 JButton (javax.swing.JButton)11 DialogFinder (junit.extensions.jfcunit.finder.DialogFinder)8 JDialog (javax.swing.JDialog)7 PanelEditor (jmri.jmrit.display.panelEditor.PanelEditor)7 JComponent (javax.swing.JComponent)6 Turnout (jmri.Turnout)5 Sensor (jmri.Sensor)4 NamedIcon (jmri.jmrit.catalog.NamedIcon)4 JFrame (javax.swing.JFrame)3 JTextField (javax.swing.JTextField)3 NamedComponentFinder (junit.extensions.jfcunit.finder.NamedComponentFinder)3 JCheckBox (javax.swing.JCheckBox)2 JComboBox (javax.swing.JComboBox)2 JmriJFrame (jmri.util.JmriJFrame)2 File (java.io.File)1 JRadioButton (javax.swing.JRadioButton)1 Block (jmri.Block)1 BlockManager (jmri.BlockManager)1