Search in sources :

Example 16 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class SignalGroupTableActionTest method testAdd.

@Test
public void testAdd() throws Exception {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    // create a signal mast
    SignalMast sm = new jmri.implementation.VirtualSignalMast("IF$vsm:AAR-1946:CPL($0002)", "VM1");
    // create a Turnout
    Turnout it1 = InstanceManager.turnoutManagerInstance().provideTurnout("IT1");
    // create a signal head
    SignalHead sh = new jmri.implementation.SingleTurnoutSignalHead("IH1", new jmri.NamedBeanHandle<Turnout>("IT1", it1), SignalHead.LUNAR, // on state + off state
    SignalHead.DARK);
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(sh);
    // open Signal Group Table
    SignalGroupTableAction _sGroupTable;
    _sGroupTable = new SignalGroupTableAction();
    Assert.assertNotNull("found SignalGroupTable frame", _sGroupTable);
    _sGroupTable.addPressed(null);
    JFrame af = JFrameOperator.waitJFrame(Bundle.getMessage("AddSignalGroup"), true, true);
    Assert.assertNotNull("found Add frame", af);
    // create a new signal group
    _sGroupTable._userName.setText("TestGroup");
    Assert.assertEquals("user name", "TestGroup", _sGroupTable._userName.getText());
    _sGroupTable._systemName.setText("R1");
    Assert.assertEquals("system name", "R1", _sGroupTable._systemName.getText());
    _sGroupTable.mainSignalComboBox.setSelectedBeanByName("VM1");
    SignalGroup g = _sGroupTable.checkNamesOK();
    _sGroupTable.setValidSignalMastAspects();
    // add the head to the group:
    g.addSignalHead(sh);
    // NPE when bypassing the GUI to open an Edit Head pane: was fixed by registering sh in SignalHeadManager (line 63)
    // open Edit head pane
    SignalGroupSubTableAction editSignalHead = new SignalGroupSubTableAction();
    editSignalHead.editHead(g, "IH1");
    // close edit head pane
    editSignalHead.cancelSubPressed(null);
    // calling updatePressed() complains about duplicate group name
    _sGroupTable.cancelPressed(null);
    // clean up
    af.dispose();
    g.dispose();
    _sGroupTable.dispose();
    sh.dispose();
}
Also used : SignalGroup(jmri.SignalGroup) JFrame(javax.swing.JFrame) SignalMast(jmri.SignalMast) SignalHead(jmri.SignalHead) Turnout(jmri.Turnout) Test(org.junit.Test)

Example 17 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class TurnoutTableActionTest method testAddAndInvoke.

/**
     * Check Turnout Table GUI, menus and graphic state presentation.
     * @since 4.7.4
     */
@Test
public void testAddAndInvoke() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    // show table
    a.actionPerformed(null);
    // create 2 turnouts and see if they exist
    Turnout it1 = InstanceManager.turnoutManagerInstance().provideTurnout("IT1");
    Turnout it2 = InstanceManager.turnoutManagerInstance().provideTurnout("IT2");
    it1.setCommandedState(Turnout.THROWN);
    it2.setCommandedState(Turnout.CLOSED);
    // set graphic state column display preference to false, read by createModel()
    InstanceManager.getDefault(GuiLafPreferencesManager.class).setGraphicTableState(false);
    TurnoutTableAction _tTable;
    _tTable = new TurnoutTableAction();
    Assert.assertNotNull("found TurnoutTable frame", _tTable);
    // prevent there are 2 menubars with the same name
    _tTable.dispose();
    // set to true, use icons
    InstanceManager.getDefault(GuiLafPreferencesManager.class).setGraphicTableState(true);
    TurnoutTableAction _t1Table;
    _t1Table = new TurnoutTableAction();
    Assert.assertNotNull("found TurnoutTable1 frame", _t1Table);
    JFrame t1Frame = JFrameOperator.waitJFrame(Bundle.getMessage("TitleTurnoutTable"), true, true);
    // test Add pane
    _t1Table.addPressed(null);
    JFrame af = JFrameOperator.waitJFrame(Bundle.getMessage("TitleAddTurnout"), true, true);
    Assert.assertNotNull("found Add frame", af);
    // close Add pane
    _t1Table.cancelPressed(null);
    // more Turnout Add pane tests are in TurnoutTableWindowTest
    // Open Automation pane to test Automation menu
    jmri.jmrit.turnoutoperations.TurnoutOperationFrame tof = new jmri.jmrit.turnoutoperations.TurnoutOperationFrame(null);
    // create dialog (bypassing menu)
    // TODO I18N using Bundle
    JDialogOperator am = new JDialogOperator("Turnout Operation Editor");
    Assert.assertNotNull("found Automation menu dialog", am);
    // close pane
    JButtonOperator jbo = new JButtonOperator(am, "OK");
    // instead of .push();
    jbo.pushNoBlock();
    // Open Speed pane to test Speed menu, which displays a JOptionPane
    //System.out.println("Speed pane started at " + java.time.LocalTime.now()); // debug
    // method 1: open as method
    //_t1Table.setDefaultSpeeds(null); // create dialog (bypassing menu, but is not found)
    //_t1Table.setDefaultSpeeds(t1Frame); // create dialog by frame (bypassing menu, but is also not found)
    //        JFrameOperator main = new JFrameOperator(Bundle.getMessage("TitleTurnoutTable")); // create dialog (through menu)
    // method 2: Alternatively, used GUI menu to open Speeds pane:
    // pushMenuNoBlock is used, because dialog is modal
    //        JMenuBarOperator mainbar = new JMenuBarOperator(main);
    //        mainbar.pushMenuNoBlock("Speeds"); // stops at top level
    //        JMenuOperator jmo = new JMenuOperator(mainbar, "Speeds");
    //        JPopupMenu jpm = jmo.getPopupMenu();
    //        JMenuItem firstMenuItem = (JMenuItem)jpm.getComponent(0); // first item is [Defaults...]
    //        JMenuItemOperator jmio = new JMenuItemOperator(firstMenuItem);
    //        jmio.pushNoBlock();
    // wait for Speeds dialog
    // for Jemmy to work, we need the Turnout Speeds pane inside a JDialog
    // TODO activate test when we manage to find pane:
    //        JDialogOperator as = new JDialogOperator(Bundle.getMessage("TurnoutGlobalSpeedMessageTitle"));
    //        Assert.assertNotNull("found Speeds menu dialog", as);
    //System.out.println("Speed pane found at " + java.time.LocalTime.now()); // debug
    // close pane
    //        JButtonOperator jbs = new JButtonOperator(as, "OK");
    //        jbs.pushNoBlock();
    // clean up
    af.dispose();
    am.dispose();
    //as.dispose(); // uncomment when test is Speeds menu activated
    tof.dispose();
    _t1Table.dispose();
}
Also used : JButtonOperator(org.netbeans.jemmy.operators.JButtonOperator) GuiLafPreferencesManager(apps.gui.GuiLafPreferencesManager) JDialogOperator(org.netbeans.jemmy.operators.JDialogOperator) JFrame(javax.swing.JFrame) Turnout(jmri.Turnout) Test(org.junit.Test)

Example 18 with Turnout

use of jmri.Turnout 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"));
}
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) JCheckBox(javax.swing.JCheckBox) AbstractButtonFinder(junit.extensions.jfcunit.finder.AbstractButtonFinder) JmriJFrame(jmri.util.JmriJFrame) Turnout(jmri.Turnout)

Example 19 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class LogixTableActionTest method setUp.

// The minimal setup for log4J
@Override
protected void setUp() throws Exception {
    apps.tests.Log4JFixture.setUp();
    super.setUp();
    JUnitUtil.resetInstanceManager();
    JUnitUtil.initDefaultUserMessagePreferences();
    JUnitUtil.initInternalTurnoutManager();
    JUnitUtil.initInternalLightManager();
    JUnitUtil.initInternalSensorManager();
    JUnitUtil.initInternalSignalHeadManager();
    _logixTable = new LogixTableAction() {

        // skip dialog box if in edit mode, just assume OK pressed
        @Override
        boolean checkEditConditional() {
            return inEditConditionalMode;
        }
    };
    // test has begun
    assertNotNull("LogixTableAction is null!", _logixTable);
    _logixTable._suppressReminder = true;
    Logix x1 = new jmri.implementation.DefaultLogix("IX01");
    assertNotNull("Logix x1 is null!", x1);
    InstanceManager.getDefault(jmri.LogixManager.class).register(x1);
    for (int i = 0; i < 10; i++) {
        Sensor s = InstanceManager.sensorManagerInstance().newSensor("IS" + i, "Sensor" + i);
        assertNotNull(i + "th Sensor is null!", s);
        Turnout t = InstanceManager.turnoutManagerInstance().newTurnout("IT" + i, "Turnout" + i);
        assertNotNull(i + "th Turnout is null!", t);
        Light l = InstanceManager.lightManagerInstance().newLight("IL" + (i), "Light" + i);
        assertNotNull(i + "th Light is null!", l);
        Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).createNewConditional("IX01C" + i, "Conditional " + i);
        assertNotNull(i + "th Conditional is null!", c);
        Memory m = InstanceManager.memoryManagerInstance().provideMemory("IMemory" + i);
        assertNotNull(i + "th Memory is null!", m);
        SignalHead sh = new jmri.implementation.VirtualSignalHead("SignalHead" + i);
        assertNotNull(i + "th SignalHead is null!", sh);
        InstanceManager.getDefault(jmri.SignalHeadManager.class).register(sh);
        Route r = new jmri.implementation.DefaultRoute("Route" + i);
        assertNotNull(i + "th Route is null!", r);
        InstanceManager.getDefault(jmri.RouteManager.class).register(r);
    }
}
Also used : Memory(jmri.Memory) SignalHead(jmri.SignalHead) Conditional(jmri.Conditional) Logix(jmri.Logix) Light(jmri.Light) Turnout(jmri.Turnout) Route(jmri.Route) Sensor(jmri.Sensor)

Example 20 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class LRouteTableActionTest method setUp.

// The minimal setup for log4J
@Override
protected void setUp() throws Exception {
    apps.tests.Log4JFixture.setUp();
    super.setUp();
    JUnitUtil.resetInstanceManager();
    jmri.util.JUnitUtil.initDefaultUserMessagePreferences();
    JUnitUtil.initInternalTurnoutManager();
    JUnitUtil.initInternalLightManager();
    JUnitUtil.initInternalSensorManager();
    JUnitUtil.initInternalSignalHeadManager();
    _lRouteTable = new LRouteTableAction("LRoute");
    // test has begun
    assertNotNull("LRouteTableAction is null!", _lRouteTable);
    _logixTable = new LogixTableAction() {

        // skip dialog box if in edit mode, just assume OK pressed
        @Override
        boolean checkEditConditional() {
            if (inEditConditionalMode) {
                return true;
            }
            return false;
        }
    };
    assertNotNull("LogixTableAction is null!", _logixTable);
    for (int i = 1; i < 20; i++) {
        Sensor s = InstanceManager.sensorManagerInstance().newSensor("IS" + i, "Sensor" + i);
        assertNotNull("Sensor is null!", s);
        Turnout t = InstanceManager.turnoutManagerInstance().newTurnout("IT" + i, "Turnout" + i);
        assertNotNull("Turnout is null!", t);
        Light l = InstanceManager.lightManagerInstance().newLight("IL" + (i), "Light" + i);
        assertNotNull(i + "th Light is null!", l);
        //            Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).createNewConditional(
        //                    "Conditional" + i, "Conditional" + i);
        //            assertNotNull(i + "th Conditional is null!", c);
        SignalHead sh = new jmri.implementation.VirtualSignalHead("SignalHead" + i);
        assertNotNull(i + "th SignalHead is null!", sh);
        InstanceManager.getDefault(jmri.SignalHeadManager.class).register(sh);
        Route r = new jmri.implementation.DefaultRoute("Route" + i);
        assertNotNull(i + "th Route is null!", r);
        InstanceManager.getDefault(jmri.RouteManager.class).register(r);
    }
}
Also used : SignalHead(jmri.SignalHead) Light(jmri.Light) Turnout(jmri.Turnout) Route(jmri.Route) Sensor(jmri.Sensor)

Aggregations

Turnout (jmri.Turnout)221 Test (org.junit.Test)63 Sensor (jmri.Sensor)26 SignalHead (jmri.SignalHead)20 Element (org.jdom2.Element)20 TurnoutManager (jmri.TurnoutManager)17 JmriException (jmri.JmriException)11 Light (jmri.Light)10 SignalMast (jmri.SignalMast)10 ActionEvent (java.awt.event.ActionEvent)9 NamedBeanHandle (jmri.NamedBeanHandle)9 JsonException (jmri.server.json.JsonException)9 ActionListener (java.awt.event.ActionListener)8 Block (jmri.Block)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 NamedBean (jmri.NamedBean)6 Route (jmri.Route)6 AbstractTurnout (jmri.implementation.AbstractTurnout)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5