Search in sources :

Example 1 with ComponentFinder

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

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

the class NXFrameTest method getRadioButtons.

// For types from DialogFinder().findAll(..)
@SuppressWarnings("unchecked")
private static List<JRadioButton> getRadioButtons(java.awt.Container frame) {
    ComponentFinder finder = new ComponentFinder(JRadioButton.class);
    List<JRadioButton> list = finder.findAll(frame);
    Assert.assertNotNull("JRadioButton list not found", list);
    return list;
}
Also used : ComponentFinder(junit.extensions.jfcunit.finder.ComponentFinder) JRadioButton(javax.swing.JRadioButton)

Example 3 with ComponentFinder

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

the class NXFrameTest method confirmJOptionPane.

// For types from DialogFinder().findAll(..)
@SuppressWarnings("unchecked")
private void confirmJOptionPane(java.awt.Container frame, String title, String message, String buttonLabel) {
    ComponentFinder finder = new ComponentFinder(JOptionPane.class);
    JOptionPane pane;
    if (frame == null) {
        pane = (JOptionPane) finder.find();
        Assert.assertNotNull(title + " JOptionPane not found", pane);
    } else {
        List<JOptionPane> list = finder.findAll(frame);
        Assert.assertNotNull(title + " JOptionPane not found", list);
        Assert.assertTrue(title + " JOptionPane not found", list.size() == 1);
        //          java.util.Iterator iter = list.iterator();
        pane = list.get(0);
    }
    if (message != null) {
        Assert.assertEquals(title + " JOptionPane message", message, pane.getMessage());
    }
    pressButton(pane, buttonLabel);
}
Also used : ComponentFinder(junit.extensions.jfcunit.finder.ComponentFinder) JOptionPane(javax.swing.JOptionPane)

Example 4 with ComponentFinder

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

the class MemoryIconTest method getColor.

int[] getColor(String frameName, String label, int x, int y, int n) {
    // Find window by name
    JmriJFrame frame = JmriJFrame.getFrame(frameName);
    Assert.assertNotNull("frame: " + frameName, frame);
    // find label within that
    ComponentFinder finder = new ComponentFinder(MemoryIcon.class);
    // FIXME: finder.findAll returns an untyped list, so we have issues with casting
    @SuppressWarnings("rawtypes") java.util.List list = finder.findAll(frame);
    Assert.assertNotNull("list: " + frameName, list);
    Assert.assertTrue("length: " + frameName + ": " + list.size(), list.size() > 0);
    // find a point in mid-center of memory icon - location choosen by
    // looking at v4.0.1 on Mac
    Point p = SwingUtilities.convertPoint(((JComponent) list.get(0)), x, y, frame);
    // check pixel color (from http://stackoverflow.com/questions/13307962/how-to-get-the-color-of-a-point-in-a-jpanel )
    BufferedImage image = new BufferedImage(400, 300, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D g2 = image.createGraphics();
    frame.paint(g2);
    // display a sweep of color
    int[] colors = new int[n];
    for (int i = 0; i < n; i++) {
        int color = image.getRGB(p.x + i, p.y);
        //System.err.println(" "+i+" "+String.format("0x%8s", Integer.toHexString(color)).replace(' ', '0'));
        colors[i] = color;
    }
    g2.dispose();
    return colors;
}
Also used : ComponentFinder(junit.extensions.jfcunit.finder.ComponentFinder) JmriJFrame(jmri.util.JmriJFrame) JComponent(javax.swing.JComponent) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Aggregations

ComponentFinder (junit.extensions.jfcunit.finder.ComponentFinder)4 Graphics2D (java.awt.Graphics2D)1 Point (java.awt.Point)1 BufferedImage (java.awt.image.BufferedImage)1 JButton (javax.swing.JButton)1 JComponent (javax.swing.JComponent)1 JDialog (javax.swing.JDialog)1 JOptionPane (javax.swing.JOptionPane)1 JRadioButton (javax.swing.JRadioButton)1 JTextField (javax.swing.JTextField)1 JmriJFrame (jmri.util.JmriJFrame)1 MouseEventData (junit.extensions.jfcunit.eventdata.MouseEventData)1 StringEventData (junit.extensions.jfcunit.eventdata.StringEventData)1 AbstractButtonFinder (junit.extensions.jfcunit.finder.AbstractButtonFinder)1 DialogFinder (junit.extensions.jfcunit.finder.DialogFinder)1