use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class ScheduleManagerTest method testScheduleManager.
public void testScheduleManager() {
LocationManager lm = LocationManager.instance();
Location l = lm.newLocation("new test location");
Track t = l.addTrack("track 1", Track.SPUR);
ScheduleManager sm = ScheduleManager.instance();
// clear out any previous schedules
sm.dispose();
sm = ScheduleManager.instance();
Schedule s1 = sm.newSchedule("new schedule");
Schedule s2 = sm.newSchedule("newer schedule");
ScheduleItem i1 = s1.addItem("BoxCar");
i1.setRoadName("new road");
i1.setReceiveLoadName("new load");
i1.setShipLoadName("new ship load");
ScheduleItem i2 = s1.addItem("Caboose");
i2.setRoadName("road");
i2.setReceiveLoadName("load");
i2.setShipLoadName("ship load");
Assert.assertEquals("1 First schedule name", "new schedule", s1.getName());
Assert.assertEquals("1 First schedule name", "newer schedule", s2.getName());
List<Schedule> names = sm.getSchedulesByNameList();
Assert.assertEquals("There should be 2 schedules", 2, names.size());
Schedule sch1 = names.get(0);
Schedule sch2 = names.get(1);
Assert.assertEquals("2 First schedule name", "new schedule", sch1.getName());
Assert.assertEquals("2 First schedule name", "newer schedule", sch2.getName());
Assert.assertEquals("Schedule 1", sch1, sm.getScheduleByName("new schedule"));
Assert.assertEquals("Schedule 2", sch2, sm.getScheduleByName("newer schedule"));
// Remove references to swing
// JComboBox box = sm.getComboBox();
// Assert.assertEquals("3 First schedule name", "", box.getItemAt(0));
// Assert.assertEquals("3 First schedule name", sch1, box.getItemAt(1));
// Assert.assertEquals("3 First schedule name", sch2, box.getItemAt(2));
//
// JComboBox box2 = sm.getSidingsByScheduleComboBox(s1);
// Assert.assertEquals("First siding name", null, box2.getItemAt(0));
// now add a schedule to siding
t.setScheduleId(sch1.getId());
// JComboBox box3 = sm.getSidingsByScheduleComboBox(s1);
// LocationTrackPair ltp = (LocationTrackPair)box3.getItemAt(0);
// Assert.assertEquals("Location track pair location", l, ltp.getLocation());
// Assert.assertEquals("Location track pair track", t, ltp.getTrack());
Assert.assertEquals("1 Schedule Item 1 type", "BoxCar", i1.getTypeName());
Assert.assertEquals("1 Schedule Item 1 road", "new road", i1.getRoadName());
Assert.assertEquals("1 Schedule Item 1 load", "new load", i1.getReceiveLoadName());
Assert.assertEquals("1 Schedule Item 1 ship", "new ship load", i1.getShipLoadName());
Assert.assertEquals("1 Schedule Item 2 type", "Caboose", i2.getTypeName());
Assert.assertEquals("1 Schedule Item 2 road", "road", i2.getRoadName());
Assert.assertEquals("1 Schedule Item 2 load", "load", i2.getReceiveLoadName());
Assert.assertEquals("1 Schedule Item 2 ship", "ship load", i2.getShipLoadName());
sm.replaceRoad("new road", "replaced road");
Assert.assertEquals("2 Schedule Item 1 type", "BoxCar", i1.getTypeName());
Assert.assertEquals("2 Schedule Item 1 road", "replaced road", i1.getRoadName());
Assert.assertEquals("2 Schedule Item 1 load", "new load", i1.getReceiveLoadName());
Assert.assertEquals("2 Schedule Item 1 ship", "new ship load", i1.getShipLoadName());
Assert.assertEquals("2 Schedule Item 2 type", "Caboose", i2.getTypeName());
Assert.assertEquals("2 Schedule Item 2 road", "road", i2.getRoadName());
Assert.assertEquals("2 Schedule Item 2 load", "load", i2.getReceiveLoadName());
Assert.assertEquals("2 Schedule Item 2 ship", "ship load", i2.getShipLoadName());
sm.replaceType("BoxCar", "replaced car type");
Assert.assertEquals("3 Schedule Item 1 type", "replaced car type", i1.getTypeName());
Assert.assertEquals("3 Schedule Item 1 road", "replaced road", i1.getRoadName());
Assert.assertEquals("3 Schedule Item 1 load", "new load", i1.getReceiveLoadName());
Assert.assertEquals("3 Schedule Item 1 ship", "new ship load", i1.getShipLoadName());
Assert.assertEquals("3 Schedule Item 2 type", "Caboose", i2.getTypeName());
Assert.assertEquals("3 Schedule Item 2 road", "road", i2.getRoadName());
Assert.assertEquals("3 Schedule Item 2 load", "load", i2.getReceiveLoadName());
Assert.assertEquals("3 Schedule Item 2 ship", "ship load", i2.getShipLoadName());
sm.replaceType("Caboose", "BoxCar");
Assert.assertEquals("4 Schedule Item 1 type", "replaced car type", i1.getTypeName());
Assert.assertEquals("4 Schedule Item 1 road", "replaced road", i1.getRoadName());
Assert.assertEquals("4 Schedule Item 1 load", "new load", i1.getReceiveLoadName());
Assert.assertEquals("4 Schedule Item 1 ship", "new ship load", i1.getShipLoadName());
Assert.assertEquals("4 Schedule Item 2 type", "BoxCar", i2.getTypeName());
Assert.assertEquals("4 Schedule Item 2 road", "road", i2.getRoadName());
Assert.assertEquals("4 Schedule Item 2 load", "load", i2.getReceiveLoadName());
Assert.assertEquals("4 Schedule Item 2 ship", "ship load", i2.getShipLoadName());
sm.replaceLoad("BoxCar", "load", "new load");
Assert.assertEquals("5 Schedule Item 1 type", "replaced car type", i1.getTypeName());
Assert.assertEquals("5 Schedule Item 1 road", "replaced road", i1.getRoadName());
Assert.assertEquals("5 Schedule Item 1 load", "new load", i1.getReceiveLoadName());
Assert.assertEquals("5 Schedule Item 1 ship", "new ship load", i1.getShipLoadName());
Assert.assertEquals("5 Schedule Item 2 type", "BoxCar", i2.getTypeName());
Assert.assertEquals("5 Schedule Item 2 road", "road", i2.getRoadName());
Assert.assertEquals("5 Schedule Item 2 load", "new load", i2.getReceiveLoadName());
Assert.assertEquals("5 Schedule Item 2 ship", "ship load", i2.getShipLoadName());
sm.replaceLoad("BoxCar", "new load", "next load");
Assert.assertEquals("6 Schedule Item 1 type", "replaced car type", i1.getTypeName());
Assert.assertEquals("6 Schedule Item 1 road", "replaced road", i1.getRoadName());
Assert.assertEquals("6 Schedule Item 1 load", "new load", i1.getReceiveLoadName());
Assert.assertEquals("6 Schedule Item 1 ship", "new ship load", i1.getShipLoadName());
Assert.assertEquals("6 Schedule Item 2 type", "BoxCar", i2.getTypeName());
Assert.assertEquals("6 Schedule Item 2 road", "road", i2.getRoadName());
Assert.assertEquals("6 Schedule Item 2 load", "next load", i2.getReceiveLoadName());
Assert.assertEquals("6 Schedule Item 2 ship", "ship load", i2.getShipLoadName());
// remove all schedules
sm.dispose();
names = sm.getSchedulesByNameList();
Assert.assertEquals("There should be no schedules", 0, names.size());
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class ScheduleEditFrameGuiTest method testScheduleEditFrame.
@Test
public void testScheduleEditFrame() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
LocationManager lManager = LocationManager.instance();
Location l2 = lManager.newLocation("Test Loc C");
l2.setLength(1003);
Location l = lManager.getLocationByName("Test Loc C");
Assert.assertNotNull("Location exists", l);
Track t = l.addTrack("3rd siding track", Track.SPUR);
Assert.assertNotNull("Track exists", t);
ScheduleEditFrame f = new ScheduleEditFrame(null, t);
f.setTitle("Test Schedule Frame");
f.scheduleNameTextField.setText("Test Schedule A");
f.commentTextField.setText("Test Comment");
enterClickAndLeave(f.addScheduleButton);
// was the schedule created?
ScheduleManager m = ScheduleManager.instance();
Schedule s = m.getScheduleByName("Test Schedule A");
Assert.assertNotNull("Test Schedule A exists", s);
// now add some car types to the schedule
f.typeBox.setSelectedItem("Boxcar");
enterClickAndLeave(f.addTypeButton);
f.typeBox.setSelectedItem("Flatcar");
enterClickAndLeave(f.addTypeButton);
f.typeBox.setSelectedItem("Coilcar");
enterClickAndLeave(f.addTypeButton);
// put Tank Food at start of list
f.typeBox.setSelectedItem("Tank Food");
enterClickAndLeave(f.addLocAtTop);
enterClickAndLeave(f.addTypeButton);
enterClickAndLeave(f.saveScheduleButton);
List<ScheduleItem> list = s.getItemsBySequenceList();
Assert.assertEquals("number of items", 4, list.size());
ScheduleItem si = list.get(0);
Assert.assertEquals("1st type", "Tank Food", si.getTypeName());
si = list.get(1);
Assert.assertEquals("2nd type", "Boxcar", si.getTypeName());
si = list.get(2);
Assert.assertEquals("3rd type", "Flatcar", si.getTypeName());
si = list.get(3);
Assert.assertEquals("3rd type", "Coilcar", si.getTypeName());
enterClickAndLeave(f.deleteScheduleButton);
// Yes to pop up
pressDialogButton(f, Bundle.getMessage("DeleteSchedule?"), "Yes");
s = m.getScheduleByName("Test Schedule A");
Assert.assertNull("Test Schedule A exists", s);
f.dispose();
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class ScheduleEditFrameGuiTest method loadLocations.
private void loadLocations() {
// create 5 locations
LocationManager lManager = LocationManager.instance();
Location l1 = lManager.newLocation("Test Loc E");
l1.setLength(1001);
Location l2 = lManager.newLocation("Test Loc D");
l2.setLength(1002);
Location l3 = lManager.newLocation("Test Loc C");
l3.setLength(1003);
Location l4 = lManager.newLocation("Test Loc B");
l4.setLength(1004);
Location l5 = lManager.newLocation("Test Loc A");
l5.setLength(1005);
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class OperationsRollingStockTest method testRollingStockLocation.
// test RollingStock location and track
public void testRollingStockLocation() {
RollingStock rs1 = new RollingStock("TESTROAD", "TESTNUMBER1");
/* Rolling Stock needs a valid type */
rs1.setTypeName("TESTTYPE");
/* Type needs to be in CarTypes or EngineTypes */
CarTypes.instance().addName("TESTTYPE");
Assert.assertEquals("RollingStock Road", "TESTROAD", rs1.getRoadName());
Assert.assertEquals("RollingStock Number", "TESTNUMBER1", rs1.getNumber());
Assert.assertEquals("RollingStock Type", "TESTTYPE", rs1.getTypeName());
/* Rolling Stock not placed on layout yet */
Assert.assertEquals("RollingStock null Location Name", "", rs1.getLocationName());
Assert.assertEquals("RollingStock null Location Id", "", rs1.getLocationId());
Assert.assertEquals("RollingStock null Track Name", "", rs1.getTrackName());
Assert.assertEquals("RollingStock null Track Id", "", rs1.getTrackId());
Assert.assertEquals("RollingStock car length", "0", rs1.getLength());
String testresult;
/* Place Rolling Stock on layout */
Location testlocation1 = new Location("Loc1", "Test Town");
Track testtrack1 = testlocation1.addTrack("Testees Office", Track.SPUR);
testtrack1.deleteTypeName("TESTTYPE");
testresult = rs1.setLocation(testlocation1, testtrack1);
Assert.assertEquals("RollingStock null Set Location", "type (TESTTYPE)", testresult);
/* type needs to be valid for Track */
testtrack1.addTypeName("TESTTYPE");
testlocation1.deleteTypeName("TESTTYPE");
testresult = rs1.setLocation(testlocation1, testtrack1);
Assert.assertEquals("RollingStock null Set Location Track type", "type (TESTTYPE)", testresult);
/* type needs to be valid for Location */
testlocation1.addTypeName("TESTTYPE");
rs1.setLength("");
testresult = rs1.setLocation(testlocation1, testtrack1);
Assert.assertEquals("RollingStock null Set Location type", "rolling stock length ()", testresult);
/* track needs to have a defined length */
rs1.setLength("41");
testresult = rs1.setLocation(testlocation1, testtrack1);
Assert.assertTrue("status message starts with capacity", testresult.startsWith(Track.CAPACITY));
/* track needs to be long enough */
testtrack1.setLength(40);
testresult = rs1.setLocation(testlocation1, testtrack1);
Assert.assertTrue("status message starts with capacity", testresult.startsWith(Track.CAPACITY));
/* track needs to be long enough */
// rs length + Coupler == 4
testtrack1.setLength(44);
rs1.setLength("40");
testresult = rs1.setLocation(testlocation1, testtrack1);
Assert.assertEquals("RollingStock null Set Length match", "okay", testresult);
/* track needs to accept road */
testtrack1.setRoadOption(Track.INCLUDE_ROADS);
testresult = rs1.setLocation(testlocation1, testtrack1);
Assert.assertEquals("RollingStock null Set includeroads", "road (TESTROAD)", testresult);
/* track needs to accept road */
testtrack1.setRoadOption(Track.INCLUDE_ROADS);
testtrack1.addRoadName("TESTROAD");
testresult = rs1.setLocation(testlocation1, testtrack1);
Assert.assertEquals("RollingStock Set includeroads", "okay", testresult);
/* track needs to accept road */
testtrack1.setRoadOption(Track.EXCLUDE_ROADS);
testresult = rs1.setLocation(testlocation1, testtrack1);
Assert.assertEquals("RollingStock Set excluderoads", "road (TESTROAD)", testresult);
/* track needs to accept road */
testtrack1.setRoadOption(Track.ALL_ROADS);
testresult = rs1.setLocation(testlocation1, testtrack1);
Assert.assertEquals("RollingStock Set allroads", "okay", testresult);
/* track needs to accept road */
testtrack1.setRoadOption(Track.EXCLUDE_ROADS);
testtrack1.deleteRoadName("TESTROAD");
testresult = rs1.setLocation(testlocation1, testtrack1);
Assert.assertEquals("RollingStock Set null excluderoads", "okay", testresult);
// Normally logged message
jmri.util.JUnitAppender.assertErrorMessage("Loco (TESTROAD TESTNUMBER1) length () is not valid");
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class PoolTrackGuiTest method testSelectPoolAndSaveTrack.
@Test
public void testSelectPoolAndSaveTrack() throws Exception {
if (GraphicsEnvironment.isHeadless()) {
// can't use Assume in TestCase subclasses
return;
}
// This should change the pool track property of the Track under test.
Location l = new Location("LOC1", "Location One");
l.addPool("Pool 1");
Pool desiredPool = l.addPool("Pool 2");
l.addPool("Pool 3");
Assert.assertEquals("Pool count", 3, l.getPoolsByNameList().size());
Track t = new Track("ID1", "TestTrack1", "Siding", l);
Assert.assertEquals("Initial Track Pool", null, t.getPool());
PoolTrackFrame f = new PoolTrackFrame(t);
f.setTitle("Test Pool Track Select Pool and Save Frame");
f.initComponents();
f.comboBoxPools.setSelectedItem(desiredPool);
Assert.assertEquals("ComboBox selection", desiredPool, f.comboBoxPools.getSelectedItem());
// Now click the Save button and the Track should be updated with the selected Pool
enterClickAndLeave(f.saveButton);
Assert.assertEquals("Updated Track Pool", desiredPool, t.getPool());
f.setVisible(true);
// close window
f.dispose();
}
Aggregations