Search in sources :

Example 1 with DialogFinder

use of junit.extensions.jfcunit.finder.DialogFinder in project ACS by ACS-Community.

the class AddToDeployTreeTest method testPortValidation.

public void testPortValidation() throws Exception {
    JDialog dialog;
    AbstractButtonFinder buttonFinder = new AbstractButtonFinder("Add to View");
    // { m_ignoreVisiblity || comp.isShowing() }
    buttonFinder.setIgnoreVisibility(true);
    JButton addButton = (JButton) buttonFinder.find(panel, 0);
    assertNotNull("Could not find the Add button", addButton);
    buttonFinder.setText("Full Refresh");
    JButton refreshButton = (JButton) buttonFinder.find(panel, 0);
    assertNotNull("Could not find the Refresh button", refreshButton);
    ComponentFinder componentFinder = new ComponentFinder(JTextField.class);
    // { m_ignoreVisiblity || comp.isShowing() }
    componentFinder.setIgnoreVisibility(true);
    JTextField hostField = (JTextField) componentFinder.find(panel, 0);
    assertNotNull("Could not find the host field", hostField);
    assertEquals("host field is empty", "", hostField.getText());
    JTextField portField = (JTextField) componentFinder.find(panel, 0);
    assertNotNull("Could not find the port field", portField);
    assertEquals("port field is empty", "", portField.getText());
    getHelper().sendString(new StringEventData(this, hostField, "testhost"));
    getHelper().sendString(new StringEventData(this, portField, "2"));
    getHelper().enterClickAndLeave(new MouseEventData(this, addButton));
    DialogFinder dFinder = new DialogFinder(null);
    dFinder.setWait(2);
    List<Object> showingDialogs = dFinder.findAll();
    assertEquals("Number of dialogs showing is wrong", 1, showingDialogs.size());
    dialog = (JDialog) showingDialogs.get(0);
    assertEquals("Wrong dialog showing up", "Message", dialog.getTitle());
    TestHelper.disposeWindow(dialog, this);
}
Also used : ComponentFinder(junit.extensions.jfcunit.finder.ComponentFinder) StringEventData(junit.extensions.jfcunit.eventdata.StringEventData) AbstractButtonFinder(junit.extensions.jfcunit.finder.AbstractButtonFinder) JButton(javax.swing.JButton) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData) JTextField(javax.swing.JTextField) DialogFinder(junit.extensions.jfcunit.finder.DialogFinder) JDialog(javax.swing.JDialog)

Example 2 with DialogFinder

use of junit.extensions.jfcunit.finder.DialogFinder in project JMRI by JMRI.

the class ImageIndexEditorTest method findContainer.

/*
    public void testOpenDirectory() {
        if (GraphicsEnvironment.isHeadless()) {
            return;
        }
        jmri.util.ThreadingUtil.runOnGUIEventually(() -> {
            DirectorySearcher.instance().openDirectory();
        });
        java.awt.Container pane = findContainer(Bundle.getMessage("openDirMenu"));
        Assert.assertNotNull("FileChooser not found", pane);
        pressButton(pane, "Cancel");
    }
/*    
    public void testPreviewDialog()  throws FileNotFoundException, IOException {
        if (GraphicsEnvironment.isHeadless()) {
            return;
        }
        long time = System.currentTimeMillis();
        System.out.println("Start testPreviewDialog: time = "+time+"ms");
        jmri.util.ThreadingUtil.runOnGUIEventually(() -> {
            DirectorySearcher.instance().searchFS();
        });
        ComponentFinder finder = new ComponentFinder(JFileChooser.class);
        JUnitUtil.waitFor(() -> {
            return (JFileChooser)finder.find()!=null;
        }, "Found JFileChooser \"searchFSMenu\"");
        JFileChooser chooser = (JFileChooser) finder.find();
        Assert.assertNotNull(" JFileChooser not found", chooser);
        File file = FileUtil.getFile(FileUtil.getAbsoluteFilename("program:resources/icons"));
        Assert.assertTrue(file.getPath()+" File does not exist", file.exists());
        flushAWT();
        jmri.util.ThreadingUtil.runOnGUIEventually(() -> {
            chooser.setCurrentDirectory(file);
        });
        flushAWT();
        pressButton(chooser, "Open");
        flushAWT();
        System.out.println("Mid testPreviewDialog: elapsed time = "+ (System.currentTimeMillis()-time)+"ms");
        
        // search a few directories
        int cnt = 0;
        while (cnt<1) {     // was 5.  not enough memory on Mac test machine?
            java.awt.Container pane = findContainer(Bundle.getMessage("previewDir"));
            Assert.assertNotNull("Preview directory not found", pane);
            pressButton(pane, Bundle.getMessage("ButtonKeepLooking"));
            cnt++;
            flushAWT();
        }
        System.out.println("Mid testPreviewDialog: elapsed time = "+ (System.currentTimeMillis()-time)+"ms");

        // cancel search of more directories
        java.awt.Container pane = findContainer(Bundle.getMessage("previewDir"));
        Assert.assertNotNull("Preview Cancel not found", pane);
        pressButton(pane, Bundle.getMessage("ButtonCancel"));
        flushAWT();

        // dismiss info dialog of count of number of icons found
        pane = findContainer(Bundle.getMessage("info"));
        Assert.assertNotNull("Preview dismiss not found", pane);
        pressButton(pane, "OK");
        System.out.println("End testPreviewDialog: elapsed time = "+ (System.currentTimeMillis()-time)+"ms");
    }
*/
java.awt.Container findContainer(String title) {
    DialogFinder finder = new DialogFinder(title);
    JUnitUtil.waitFor(() -> {
        return (java.awt.Container) finder.find() != null;
    }, "Found dialog + \"title\"");
    java.awt.Container pane = (java.awt.Container) finder.find();
    return pane;
}
Also used : DialogFinder(junit.extensions.jfcunit.finder.DialogFinder)

Example 3 with DialogFinder

use of junit.extensions.jfcunit.finder.DialogFinder in project JMRI by JMRI.

the class TurnoutIconWindowTest method testLayoutEditor.

@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("TurnoutIconWindowTest.testLayoutEditor");
    JComponent jf = panel.getTargetPanel();
    TurnoutIcon icon = new TurnoutIcon(panel);
    icon.setDisplayLevel(Editor.TURNOUTS);
    Turnout sn = jmri.InstanceManager.turnoutManagerInstance().provideTurnout("IT1");
    icon.setTurnout("IT1");
    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));
}
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) Turnout(jmri.Turnout) JDialog(javax.swing.JDialog)

Example 4 with DialogFinder

use of junit.extensions.jfcunit.finder.DialogFinder in project JMRI by JMRI.

the class SensorIconWindowTest method testPanelEditor.

// DialogFinder not parameterized
@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("SensorIconWindowTest.testPanelEditor");
    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 5 with DialogFinder

use of junit.extensions.jfcunit.finder.DialogFinder 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)

Aggregations

DialogFinder (junit.extensions.jfcunit.finder.DialogFinder)10 MouseEventData (junit.extensions.jfcunit.eventdata.MouseEventData)8 JButton (javax.swing.JButton)7 JDialog (javax.swing.JDialog)7 AbstractButtonFinder (junit.extensions.jfcunit.finder.AbstractButtonFinder)7 JComponent (javax.swing.JComponent)4 NamedIcon (jmri.jmrit.catalog.NamedIcon)4 Sensor (jmri.Sensor)3 Turnout (jmri.Turnout)2 File (java.io.File)1 JRadioButton (javax.swing.JRadioButton)1 JTextField (javax.swing.JTextField)1 Block (jmri.Block)1 BlockManager (jmri.BlockManager)1 ConfigureManager (jmri.ConfigureManager)1 SensorManager (jmri.SensorManager)1 ControlPanelEditor (jmri.jmrit.display.controlPanelEditor.ControlPanelEditor)1 StringEventData (junit.extensions.jfcunit.eventdata.StringEventData)1 ComponentFinder (junit.extensions.jfcunit.finder.ComponentFinder)1