Search in sources :

Example 76 with Turnout

use of jmri.Turnout 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 77 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class OPathTest method testNameChange.

@Test
public void testNameChange() {
    Portal exitP = _portalMgr.providePortal("exitP");
    OBlock blk = _blkMgr.provideOBlock("OB0");
    Turnout to = _turnoutMgr.provideTurnout("turnout_1");
    OPath path = new OPath("path", blk, null, null, null);
    path.setToPortal(exitP);
    path.addSetting(new jmri.BeanSetting(to, Turnout.CLOSED));
    Assert.assertEquals("Get exit portal", exitP, path.getToPortal());
    path.setName("OtherPath");
    Assert.assertEquals("path name change", "OtherPath", path.getName());
    Assert.assertEquals("turnout unknown", Turnout.UNKNOWN, to.getCommandedState());
    path.setTurnouts(0, true, 0, false);
    Assert.assertEquals("path name change", Turnout.CLOSED, to.getCommandedState());
}
Also used : BeanSetting(jmri.BeanSetting) Turnout(jmri.Turnout) Test(org.junit.Test)

Example 78 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class OsIndicatorTest method testIntantiateLocked.

public void testIntantiateLocked() throws JmriException {
    OsIndicator os = new OsIndicator("IT12", "IS34", "IS56");
    Turnout t1 = InstanceManager.turnoutManagerInstance().provideTurnout("IT12");
    t1.setCommandedState(Turnout.CLOSED);
    Sensor s1 = InstanceManager.sensorManagerInstance().provideSensor("IS34");
    s1.setKnownState(Sensor.INACTIVE);
    Sensor s2 = InstanceManager.sensorManagerInstance().provideSensor("IS56");
    s2.setKnownState(Sensor.INACTIVE);
    Assert.assertEquals("sensor before", Sensor.INACTIVE, s1.getKnownState());
    Assert.assertEquals("lock before", Sensor.INACTIVE, s2.getKnownState());
    Assert.assertEquals("output before", Turnout.CLOSED, t1.getCommandedState());
    os.instantiate();
    Assert.assertEquals("sensor after instantiate", Sensor.INACTIVE, s1.getKnownState());
    Assert.assertEquals("lock after instantiate", Sensor.INACTIVE, s2.getKnownState());
    Assert.assertEquals("output after instantiate", Turnout.CLOSED, t1.getCommandedState());
}
Also used : Turnout(jmri.Turnout) Sensor(jmri.Sensor)

Example 79 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class OsIndicatorTest method testIntantiateNoLock.

public void testIntantiateNoLock() throws JmriException {
    OsIndicator os = new OsIndicator("IT12", "IS34", "");
    Turnout t1 = InstanceManager.turnoutManagerInstance().provideTurnout("IT12");
    t1.setCommandedState(Turnout.CLOSED);
    Sensor s1 = InstanceManager.sensorManagerInstance().provideSensor("IS34");
    s1.setKnownState(Sensor.INACTIVE);
    Assert.assertEquals("sensor before", Sensor.INACTIVE, s1.getKnownState());
    Assert.assertEquals("output before", Turnout.CLOSED, t1.getCommandedState());
    os.instantiate();
    Assert.assertEquals("sensor after instantiate", Sensor.INACTIVE, s1.getKnownState());
    Assert.assertEquals("output after instantiate", Turnout.CLOSED, t1.getCommandedState());
}
Also used : Turnout(jmri.Turnout) Sensor(jmri.Sensor)

Example 80 with Turnout

use of jmri.Turnout in project JMRI by JMRI.

the class AcelaTurnoutManagerTest method testAsAbstractFactory.

@Test
public void testAsAbstractFactory() {
    // a Turnout Manager object is created and registered in setUp.
    // ask for a Turnout, and check type
    TurnoutManager t = jmri.InstanceManager.turnoutManagerInstance();
    Turnout o = t.newTurnout("AT11", "my name");
    if (log.isDebugEnabled()) {
        log.debug("received turnout value " + o);
    }
    Assert.assertTrue(null != (AcelaTurnout) o);
    // make sure loaded into tables
    if (log.isDebugEnabled()) {
        log.debug("by system name: " + t.getBySystemName("AT11"));
    }
    if (log.isDebugEnabled()) {
        log.debug("by user name:   " + t.getByUserName("my name"));
    }
    Assert.assertTrue(null != t.getBySystemName("AT11"));
    Assert.assertTrue(null != t.getByUserName("my name"));
}
Also used : TurnoutManager(jmri.TurnoutManager) Turnout(jmri.Turnout) Test(org.junit.Test)

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