use of jmri.jmrit.operations.locations.schedules.ScheduleItem in project JMRI by JMRI.
the class XmlTest method testXMLCreate.
/**
* Test location Xml create and read support. Originally this was three test
* that had to run in the order specified. Now changed on 8/29/2013 to be
* one long test.
*
* @throws Exception
*/
public void testXMLCreate() throws Exception {
LocationManager manager = LocationManager.instance();
manager.dispose();
// dispose kills instance, so reload manager
manager = LocationManager.instance();
// now load locations
List<Location> locationList = manager.getLocationsByIdList();
Assert.assertEquals("Starting Number of Locations", 0, locationList.size());
Location l1 = manager.newLocation("Test Location 2");
Location l2 = manager.newLocation("Test Location 1");
Location l3 = manager.newLocation("Test Location 3");
Track t1 = l1.addTrack("A Yard", Track.YARD);
Track t2 = l1.addTrack("A Siding", Track.SPUR);
Track t3 = l2.addTrack("An Interchange", Track.INTERCHANGE);
Track t4 = l3.addTrack("A Stage", Track.STAGING);
t1.addRoadName("Track 1 Road");
t1.setRoadOption(Track.INCLUDE_ROADS);
t2.addTypeName("Track 2 Type");
t3.addRoadName("Track 3 Road");
t3.setRoadOption(Track.EXCLUDE_ROADS);
t4.addTypeName("Track 4 Type");
// test pool features
Pool pool = l1.addPool("Test Pool");
t1.setPool(pool);
t1.setMinimumLength(321);
t2.setPool(pool);
t2.setMinimumLength(123);
CarTypes ct = CarTypes.instance();
ct.addName("Boxcar");
ct.addName("boxCar");
ct.addName("BoxCar");
ct.addName("Track 2 Type");
ct.addName("Track 4 Type");
// also test schedules
ScheduleManager sm = ScheduleManager.instance();
Schedule s1 = sm.newSchedule("Schedule 1 Name");
s1.setComment("Schedule 1 Comment");
ScheduleItem s1i1 = s1.addItem("Boxcar");
s1i1.setRoadName("Schedule 1 Item 1 Road");
s1i1.setReceiveLoadName("Schedule 1 Item 1 Load");
s1i1.setShipLoadName("Schedule 1 Item 1 Ship");
s1i1.setCount(321);
s1i1.setDestination(l1);
s1i1.setDestinationTrack(t2);
s1i1.setComment("Schedule 1 Item 1 Comment");
ScheduleItem s1i2 = s1.addItem("boxcar");
s1i2.setRoadName("Schedule 1 Item 2 Road");
s1i2.setReceiveLoadName("Schedule 1 Item 2 Load");
s1i2.setShipLoadName("Schedule 1 Item 2 Ship");
s1i2.setCount(222);
s1i2.setDestination(l2);
s1i2.setDestinationTrack(t3);
s1i2.setComment("Schedule 1 Item 2 Comment");
Schedule s2 = sm.newSchedule("Schedule 2 Name");
s2.setComment("Schedule 2 Comment");
ScheduleItem s2i1 = s2.addItem("BoxCar");
s2i1.setRoadName("Schedule 2 Item 1 Road");
s2i1.setReceiveLoadName("Schedule 2 Item 1 Load");
s2i1.setShipLoadName("Schedule 2 Item 1 Ship");
s2i1.setCount(123);
s2i1.setComment("Schedule 2 Item 1 Comment");
// test schedule and alternate track features
t2.setScheduleId(s1.getId());
t2.setAlternateTrack(t1);
t2.setReservationFactor(33);
t2.setScheduleMode(Track.MATCH);
t2.setScheduleCount(2);
locationList = manager.getLocationsByIdList();
Assert.assertEquals("New Location by Id 1", "Test Location 2", locationList.get(0).getName());
Assert.assertEquals("New Location by Id 2", "Test Location 1", locationList.get(1).getName());
Assert.assertEquals("New Location by Id 3", "Test Location 3", locationList.get(2).getName());
Assert.assertEquals("New Location by Name 1", "Test Location 1", manager.getLocationByName("Test Location 1").getName());
Assert.assertEquals("New Location by Name 2", "Test Location 2", manager.getLocationByName("Test Location 2").getName());
Assert.assertEquals("New Location by Name 3", "Test Location 3", manager.getLocationByName("Test Location 3").getName());
manager.getLocationByName("Test Location 1").setComment("Test Location 1 Comment");
manager.getLocationByName("Test Location 1").setLocationOps(Location.NORMAL);
manager.getLocationByName("Test Location 1").setSwitchListEnabled(true);
manager.getLocationByName("Test Location 1").setTrainDirections(Location.EAST);
manager.getLocationByName("Test Location 1").addTypeName("Baggage");
manager.getLocationByName("Test Location 1").addTypeName("BoxCar");
manager.getLocationByName("Test Location 1").addTypeName("Caboose");
manager.getLocationByName("Test Location 1").addTypeName("Coal");
manager.getLocationByName("Test Location 1").addTypeName("Engine");
manager.getLocationByName("Test Location 1").addTypeName("Hopper");
manager.getLocationByName("Test Location 2").setComment("Test Location 2 Comment");
manager.getLocationByName("Test Location 2").setLocationOps(Location.NORMAL);
manager.getLocationByName("Test Location 2").setSwitchListEnabled(false);
manager.getLocationByName("Test Location 2").setTrainDirections(Location.WEST);
manager.getLocationByName("Test Location 2").addTypeName("Baggage");
manager.getLocationByName("Test Location 2").addTypeName("Boxcar");
manager.getLocationByName("Test Location 2").addTypeName("Caboose");
manager.getLocationByName("Test Location 2").addTypeName("Coal");
manager.getLocationByName("Test Location 2").addTypeName("Engine");
manager.getLocationByName("Test Location 2").addTypeName("Hopper");
manager.getLocationByName("Test Location 2").addTypeName("Track 2 Type");
manager.getLocationByName("Test Location 3").setComment("Test Location 3 Comment");
manager.getLocationByName("Test Location 3").setLocationOps(Location.STAGING);
manager.getLocationByName("Test Location 3").setSwitchListEnabled(true);
manager.getLocationByName("Test Location 3").setTrainDirections(Location.EAST + Location.WEST + Location.NORTH);
manager.getLocationByName("Test Location 3").addTypeName("Baggage");
manager.getLocationByName("Test Location 3").addTypeName("boxCar");
manager.getLocationByName("Test Location 3").addTypeName("Caboose");
manager.getLocationByName("Test Location 3").addTypeName("Coal");
manager.getLocationByName("Test Location 3").addTypeName("Engine");
manager.getLocationByName("Test Location 3").addTypeName("Hopper");
manager.getLocationByName("Test Location 3").addTypeName("Track 4 Type");
locationList = manager.getLocationsByIdList();
Assert.assertEquals("New Number of Locations", 3, locationList.size());
for (int i = 0; i < locationList.size(); i++) {
Location loc = locationList.get(i);
String locname = loc.getName();
if (i == 0) {
Assert.assertEquals("New Location by Id List 1", "Test Location 2", locname);
}
if (i == 1) {
Assert.assertEquals("New Location by Id List 2", "Test Location 1", locname);
}
if (i == 2) {
Assert.assertEquals("New Location by Id List 3", "Test Location 3", locname);
}
}
List<Location> locationListByName = manager.getLocationsByNameList();
Assert.assertEquals("New Number of Locations", 3, locationList.size());
for (int i = 0; i < locationListByName.size(); i++) {
Location loc = locationListByName.get(i);
String locname = loc.getName();
if (i == 0) {
Assert.assertEquals("New Location by Name List 1", "Test Location 1", locname);
}
if (i == 1) {
Assert.assertEquals("New Location by Name List 2", "Test Location 2", locname);
}
if (i == 2) {
Assert.assertEquals("New Location by Name List 3", "Test Location 3", locname);
}
}
LocationManagerXml.instance().writeOperationsFile();
manager.newLocation("Test Location 4");
manager.newLocation("Test Location 5");
manager.newLocation("Test Location 6");
manager.getLocationByName("Test Location 2").setComment("Test Location 2 Changed Comment");
LocationManagerXml.instance().writeOperationsFile();
locationList = manager.getLocationsByIdList();
Assert.assertEquals("Number of Locations", 6, locationList.size());
// Revert the main xml file back to the backup file.
LocationManagerXml.instance().revertBackupFile("temp" + File.separator + OperationsSetupXml.getOperationsDirectoryName() + File.separator + LocationManagerXml.instance().getOperationsFileName());
// Need to dispose of the LocationManager's list and hash table
manager.dispose();
// delete all schedules
ScheduleManager.instance().dispose();
ct.addName("Boxcar");
ct.addName("boxCar");
ct.addName("BoxCar");
ct.addName("Track 2 Type");
ct.addName("Track 4 Type");
// The dispose has removed all locations from the Manager.
manager = LocationManager.instance();
locationListByName = manager.getLocationsByNameList();
Assert.assertEquals("Starting Number of Locations", 0, locationListByName.size());
// Need to force a re-read of the xml file.
LocationManagerXml.instance().readFile("temp" + File.separator + OperationsSetupXml.getOperationsDirectoryName() + File.separator + LocationManagerXml.instance().getOperationsFileName());
// check locations
locationListByName = manager.getLocationsByNameList();
Assert.assertEquals("Starting Number of Locations", 3, locationListByName.size());
for (int i = 0; i < locationListByName.size(); i++) {
Location loc = locationListByName.get(i);
if (i == 0) {
Assert.assertEquals("New Location by Name List 1", "Test Location 1", loc.getName());
Assert.assertEquals("Location 1 operations", Location.NORMAL, loc.getLocationOps());
Assert.assertEquals("Location 1 direction", Location.EAST, loc.getTrainDirections());
Assert.assertEquals("Location 1 comment", "Test Location 1 Comment", loc.getComment());
Assert.assertEquals("Location 1 switchList", true, loc.isSwitchListEnabled());
Assert.assertEquals("Location 1 car type", true, loc.acceptsTypeName("BoxCar"));
Assert.assertEquals("Location 1 car type", false, loc.acceptsTypeName("boxCar"));
Assert.assertEquals("Location 1 car type", true, loc.acceptsTypeName("Boxcar"));
List<Track> list = loc.getTrackByNameList(null);
Assert.assertEquals("Location 1 has n tracks", 1, list.size());
Track t = list.get(0);
Assert.assertEquals("Location 1 first track name", "An Interchange", t.getName());
Assert.assertEquals("Location 1 track road option", Track.EXCLUDE_ROADS, t.getRoadOption());
Assert.assertEquals("Location 1 track road", true, t.acceptsRoadName("Track 1 Road"));
Assert.assertEquals("Location 1 track road", false, t.acceptsRoadName("Track 3 Road"));
Assert.assertNull("Location 1 track pool", t.getPool());
}
if (i == 1) {
Assert.assertEquals("New Location by Name List 2", "Test Location 2", loc.getName());
Assert.assertEquals("Location 2 operations", Location.NORMAL, loc.getLocationOps());
Assert.assertEquals("Location 2 direction", Location.WEST, loc.getTrainDirections());
Assert.assertEquals("Location 2 comment", "Test Location 2 Comment", loc.getComment());
Assert.assertEquals("Location 2 switchList", false, loc.isSwitchListEnabled());
Assert.assertEquals("Location 2 car type", true, loc.acceptsTypeName("Boxcar"));
Assert.assertEquals("Location 2 car type", false, loc.acceptsTypeName("boxCar"));
Assert.assertEquals("Location 2 car type", false, loc.acceptsTypeName("BoxCar"));
List<Track> list = loc.getTrackByNameList(null);
Assert.assertEquals("Location 2 has n tracks", 2, list.size());
Track t = list.get(0);
Assert.assertEquals("Location 2 first track name", "A Siding", t.getName());
Assert.assertEquals("Location 2 track 1 road option", Track.ALL_ROADS, t.getRoadOption());
Assert.assertEquals("Location 2 track 1 road", true, t.acceptsRoadName("Track 1 Road"));
Assert.assertEquals("Location 2 track 1 road", true, t.acceptsRoadName("Track 3 Road"));
Assert.assertEquals("Location 2 track 1 type", true, t.acceptsTypeName("Track 2 Type"));
Assert.assertEquals("Location 2 track 1 type", false, t.acceptsTypeName("Track 4 Type"));
Assert.assertNotNull("Location 2 track 1 pool exists", t.getPool());
Assert.assertEquals("Location 2 track 1 pool name", "Test Pool", t.getPool().getName());
Assert.assertEquals("Location 2 track 1 pool name", "Test Pool", t.getPoolName());
Assert.assertEquals("Location 2 track 1 min track length", 123, t.getMinimumLength());
Assert.assertNotNull("Location 2 track 1 schedule", t.getSchedule());
Assert.assertEquals("Location 2 track 1 schedule name", "Schedule 1 Name", t.getSchedule().getName());
Assert.assertEquals("Location 2 track 1 schedule name", "Schedule 1 Name", t.getScheduleName());
Assert.assertNotNull("Location 2 track 1 alternate track", t.getAlternateTrack());
Assert.assertEquals("Location 2 track 1 alternate track name", "A Yard", t.getAlternateTrack().getName());
Assert.assertEquals("Location 2 track 1 schedule mode", Track.MATCH, t.getScheduleMode());
Assert.assertEquals("Location 2 track 1 reservation factor", 33, t.getReservationFactor());
Assert.assertEquals("Location 2 track 1 schedule count", 2, t.getScheduleCount());
t = list.get(1);
Assert.assertEquals("Location 2 2nd track name", "A Yard", t.getName());
Assert.assertEquals("Location 2 track 2 road option", Track.INCLUDE_ROADS, t.getRoadOption());
Assert.assertEquals("Location 2 track 2 road", true, t.acceptsRoadName("Track 1 Road"));
Assert.assertEquals("Location 2 track 2 road", false, t.acceptsRoadName("Track 3 Road"));
Assert.assertEquals("Location 2 track 2 type", false, t.acceptsTypeName("Track 2 Type"));
Assert.assertEquals("Location 2 track 2 type", false, t.acceptsTypeName("Track 4 Type"));
Assert.assertNotNull("Location 2 track 2 pool exists", t.getPool());
Assert.assertEquals("Location 2 track 2 pool name", "Test Pool", t.getPool().getName());
Assert.assertEquals("Location 2 track 2 min track length", 321, t.getMinimumLength());
}
if (i == 2) {
Assert.assertEquals("New Location by Name List 3", "Test Location 3", loc.getName());
Assert.assertEquals("Location 3 operations", Location.STAGING, loc.getLocationOps());
Assert.assertEquals("Location 3 direction", Location.EAST + Location.WEST + Location.NORTH, loc.getTrainDirections());
Assert.assertEquals("Location 3 comment", "Test Location 3 Comment", loc.getComment());
Assert.assertEquals("Location 3 switchList", true, loc.isSwitchListEnabled());
Assert.assertEquals("Location 3 car type", true, loc.acceptsTypeName("boxCar"));
Assert.assertEquals("Location 3 car type", false, loc.acceptsTypeName("BoxCar"));
Assert.assertEquals("Location 3 car type", true, loc.acceptsTypeName("Boxcar"));
List<Track> list = loc.getTrackByNameList(null);
Assert.assertEquals("Location 3 has n tracks", 1, list.size());
Track t = list.get(0);
Assert.assertEquals("Location 3 first track name", "A Stage", t.getName());
Assert.assertEquals("Location 3 track 1 road option", Track.ALL_ROADS, t.getRoadOption());
Assert.assertEquals("Location 3 track 1 road", true, t.acceptsRoadName("Track 1 Road"));
Assert.assertEquals("Location 3 track 1 road", true, t.acceptsRoadName("Track 3 Road"));
Assert.assertEquals("Location 3 track type", false, t.acceptsTypeName("Track 2 Type"));
Assert.assertEquals("Location 3 track type", true, t.acceptsTypeName("Track 4 Type"));
Assert.assertNull("Location 3 track pool", t.getPool());
}
}
// check Schedules
sm = ScheduleManager.instance();
List<Schedule> list = sm.getSchedulesByNameList();
Assert.assertEquals("There should be 2 schedules", 2, list.size());
s1 = list.get(0);
s2 = list.get(1);
Assert.assertEquals("Schedule 1 name", "Schedule 1 Name", s1.getName());
Assert.assertEquals("Schedule 2 name", "Schedule 2 Name", s2.getName());
Assert.assertEquals("Schedule 1 comment", "Schedule 1 Comment", s1.getComment());
Assert.assertEquals("Schedule 2 comment", "Schedule 2 Comment", s2.getComment());
List<ScheduleItem> s1items = s1.getItemsBySequenceList();
Assert.assertEquals("There should be 2 items", 2, s1items.size());
ScheduleItem si1 = s1items.get(0);
Assert.assertEquals("Item 1 type", "Boxcar", si1.getTypeName());
Assert.assertEquals("Item 1 load", "Schedule 1 Item 1 Load", si1.getReceiveLoadName());
Assert.assertEquals("Item 1 ship", "Schedule 1 Item 1 Ship", si1.getShipLoadName());
Assert.assertEquals("Item 1 type", "Schedule 1 Item 1 Comment", si1.getComment());
Assert.assertEquals("Item 1 road", "Schedule 1 Item 1 Road", si1.getRoadName());
Assert.assertEquals("Item 1 count", 321, si1.getCount());
Assert.assertEquals("Item 1 destination", "Test Location 2", si1.getDestinationName());
Assert.assertEquals("Item 1 track", "A Siding", si1.getDestinationTrackName());
ScheduleItem si2 = s1items.get(1);
Assert.assertEquals("Item 2 type", "boxcar", si2.getTypeName());
Assert.assertEquals("Item 2 load", "Schedule 1 Item 2 Load", si2.getReceiveLoadName());
Assert.assertEquals("Item 2 ship", "Schedule 1 Item 2 Ship", si2.getShipLoadName());
Assert.assertEquals("Item 2 type", "Schedule 1 Item 2 Comment", si2.getComment());
Assert.assertEquals("Item 2 road", "Schedule 1 Item 2 Road", si2.getRoadName());
Assert.assertEquals("Item 2 count", 222, si2.getCount());
Assert.assertEquals("Item 2 destination", "Test Location 1", si2.getDestinationName());
Assert.assertEquals("Item 2 track", "An Interchange", si2.getDestinationTrackName());
List<ScheduleItem> s2items = s2.getItemsBySequenceList();
Assert.assertEquals("There should be 1 items", 1, s2items.size());
ScheduleItem si3 = s2items.get(0);
Assert.assertEquals("Item 3 type", "BoxCar", si3.getTypeName());
Assert.assertEquals("Item 3 load", "Schedule 2 Item 1 Load", si3.getReceiveLoadName());
Assert.assertEquals("Item 3 ship", "Schedule 2 Item 1 Ship", si3.getShipLoadName());
Assert.assertEquals("Item 3 type", "Schedule 2 Item 1 Comment", si3.getComment());
Assert.assertEquals("Item 3 type", "Schedule 2 Item 1 Road", si3.getRoadName());
Assert.assertEquals("Item 3 count", 123, si3.getCount());
Assert.assertEquals("Item 3 destination", "", si3.getDestinationName());
Assert.assertEquals("Item 3 track", "", si3.getDestinationTrackName());
// delete all locations
manager.dispose();
// delete all schedules
sm.dispose();
// clear out the file
LocationManagerXml.instance().writeOperationsFile();
}
use of jmri.jmrit.operations.locations.schedules.ScheduleItem in project JMRI by JMRI.
the class LocationTest method testTypeNameSupport.
// test typename support
public void testTypeNameSupport() {
// use LocationManager to allow replace car type to work properly
Location l = LocationManager.instance().newLocation("Test Name");
Assert.assertEquals("Location Name", "Test Name", l.getName());
Assert.assertEquals("Location Accepts Type Name undefined", false, l.acceptsTypeName("TestTypeName"));
// l.addTypeName("TestTypeName");
// Assert.assertEquals("Location Accepts Type Name defined", false, l.acceptsTypeName("TestTypeName"));
// now add to car types
CarTypes ct = CarTypes.instance();
ct.addName("TestTypeName");
l.addTypeName("TestTypeName");
Assert.assertEquals("Location Accepts Type Name defined", true, l.acceptsTypeName("TestTypeName"));
l.deleteTypeName("TestTypeName");
Assert.assertEquals("Location Accepts Type Name undefined2", false, l.acceptsTypeName("TestTypeName"));
ct.addName("Baggage");
ct.addName("BoxCar");
ct.addName("Caboose");
ct.addName("Coal");
ct.addName("Engine");
ct.addName("Hopper");
ct.addName("MOW");
ct.addName("Passenger");
ct.addName("Reefer");
ct.addName("Stock");
ct.addName("Tank Oil");
l.addTypeName("Baggage");
l.addTypeName("BoxCar");
l.addTypeName("Caboose");
l.addTypeName("Coal");
l.addTypeName("Engine");
l.addTypeName("Hopper");
l.addTypeName("MOW");
l.addTypeName("Passenger");
l.addTypeName("Reefer");
l.addTypeName("Stock");
l.addTypeName("Tank Oil");
Track t = l.addTrack("new track", Track.SPUR);
Assert.assertEquals("Location Accepts Type Name BoxCar", true, l.acceptsTypeName("BoxCar"));
Assert.assertEquals("Location Accepts Type Name boxCar", false, l.acceptsTypeName("boxCar"));
Assert.assertEquals("Location Accepts Type Name MOW", true, l.acceptsTypeName("MOW"));
Assert.assertEquals("Location Accepts Type Name Caboose", true, l.acceptsTypeName("Caboose"));
Assert.assertEquals("Location Accepts Type Name BoxCar", true, l.acceptsTypeName("BoxCar"));
Assert.assertEquals("Location Accepts Type Name undefined3", false, l.acceptsTypeName("TestTypeName"));
Assert.assertEquals("Track Accepts Type Name BoxCar", true, t.acceptsTypeName("BoxCar"));
Assert.assertEquals("Track Accepts Type Name boxCar", false, t.acceptsTypeName("boxCar"));
Assert.assertEquals("Track Accepts Type Name MOW", true, t.acceptsTypeName("MOW"));
Assert.assertEquals("Track Accepts Type Name Caboose", true, t.acceptsTypeName("Caboose"));
Assert.assertEquals("Track Accepts Type Name undefined3", false, t.acceptsTypeName("undefined"));
t.addTypeName("Baggage");
t.addTypeName("BoxCar");
t.addTypeName("Caboose");
t.addTypeName("Coal");
t.addTypeName("Engine");
t.addTypeName("Hopper");
t.addTypeName("MOW");
t.addTypeName("Passenger");
t.addTypeName("Reefer");
t.addTypeName("Stock");
t.addTypeName("Tank Oil");
Assert.assertEquals("Track Accepts Type Name BoxCar", true, t.acceptsTypeName("BoxCar"));
Assert.assertEquals("Track Accepts Type Name boxCar", false, t.acceptsTypeName("boxCar"));
Assert.assertEquals("Track Accepts Type Name MOW", true, t.acceptsTypeName("MOW"));
Assert.assertEquals("Track Accepts Type Name Caboose", true, t.acceptsTypeName("Caboose"));
Assert.assertEquals("Track Accepts Type Name BoxCar", true, t.acceptsTypeName("BoxCar"));
Assert.assertEquals("Track Accepts Type Name undefined3", false, t.acceptsTypeName("undefined"));
// test replace
// also test replace type in schedules
ScheduleManager sm = ScheduleManager.instance();
Schedule s = sm.newSchedule("newest schedule");
ScheduleItem i1 = s.addItem("BoxCar");
ScheduleItem i2 = s.addItem("Caboose");
Assert.assertEquals("ScheudleItem i1 Type BoxCar", "BoxCar", i1.getTypeName());
Assert.assertEquals("ScheudleItem i2 Type Caboose", "Caboose", i2.getTypeName());
ct.replaceName("BoxCar", "boxcar");
Assert.assertFalse("Location Does Not Accepts Type Name BoxCar", l.acceptsTypeName("BoxCar"));
Assert.assertTrue("Location Accepts Type Name boxcar", l.acceptsTypeName("boxcar"));
Assert.assertFalse("Track Does Not Accepts Type Name BoxCar", l.acceptsTypeName("BoxCar"));
Assert.assertTrue("Track Accepts Type Name boxcar", t.acceptsTypeName("boxcar"));
Assert.assertEquals("ScheudleItem i1 Type boxcar", "boxcar", i1.getTypeName());
Assert.assertEquals("Check ScheudleItem i2 Type Caboose", "Caboose", i2.getTypeName());
// remove all schedules
sm.dispose();
}
use of jmri.jmrit.operations.locations.schedules.ScheduleItem in project JMRI by JMRI.
the class TrainBuilderTest method testScheduleLoads.
public void testScheduleLoads() {
ct.addName("Gon");
ct.addName("Coil Car");
ct.addName("Flat Car");
ct.addName("Boxcar");
// create schedules
Schedule sch1 = smanager.newSchedule("Schedule 1");
ScheduleItem sch1Item1 = sch1.addItem("Boxcar");
// request a UP Boxcar
sch1Item1.setRoadName("UP");
ScheduleItem sch1Item2 = sch1.addItem("Flat Car");
// request an empty car and load it with Scrap
sch1Item2.setReceiveLoadName("E");
sch1Item2.setShipLoadName("Scrap");
ScheduleItem sch1Item3 = sch1.addItem("Gon");
// request a loaded car and load it with Tin
sch1Item3.setReceiveLoadName("L");
sch1Item3.setShipLoadName("Tin");
// Allows c13 which is part of a kernel to get a new load
CarLoads.instance().addName("Gon", "Tin");
Schedule sch2 = smanager.newSchedule("Schedule 2");
ScheduleItem sch2Item1 = sch2.addItem("Coil Car");
sch2Item1.setCount(2);
sch2.addItem("Boxcar");
// Create locations used
Location loc1;
loc1 = lmanager.newLocation("New Westford");
loc1.setTrainDirections(DIRECTION_ALL);
// loc1.addTypeName("Flat Car");
Location loc2;
loc2 = lmanager.newLocation("New Chelmsford");
loc2.setTrainDirections(DIRECTION_ALL);
Location loc3;
loc3 = lmanager.newLocation("New Bedford");
loc3.setTrainDirections(DIRECTION_ALL);
Track loc1trk1;
loc1trk1 = loc1.addTrack("Westford Yard 1", Track.YARD);
loc1trk1.setTrainDirections(Track.WEST + Track.EAST);
loc1trk1.setLength(900);
// loc1trk1.addTypeName("Flat Car");
Track loc1trk2;
loc1trk2 = loc1.addTrack("Westford Yard 2", Track.YARD);
loc1trk2.setTrainDirections(Track.WEST + Track.EAST);
loc1trk2.setLength(500);
loc1trk2.deleteTypeName("Coil Car");
Track loc1trk3;
loc1trk3 = loc1.addTrack("Westford Express 3", Track.SPUR);
loc1trk3.setTrainDirections(Track.WEST + Track.EAST);
loc1trk3.setLength(300);
loc1trk3.deleteTypeName("Gon");
loc1trk3.deleteTypeName("Coil Car");
Track loc1trk4;
loc1trk4 = loc1.addTrack("Westford Express 4", Track.SPUR);
loc1trk4.setTrainDirections(Track.WEST + Track.EAST);
loc1trk4.setLength(300);
loc1trk4.deleteTypeName("Gon");
loc1trk4.deleteTypeName("Coil Car");
Track loc2trk1;
loc2trk1 = loc2.addTrack("Chelmsford Freight 1", Track.SPUR);
loc2trk1.setTrainDirections(Track.WEST + Track.EAST);
loc2trk1.setLength(900);
loc2trk1.deleteTypeName("Coil Car");
loc2trk1.setScheduleId(sch1.getId());
loc2trk1.setScheduleMode(Track.SEQUENTIAL);
// start the schedule with 2nd item Flat Car
loc2trk1.setScheduleItemId(sch1.getItemsBySequenceList().get(1).getId());
Track loc2trk2;
loc2trk2 = loc2.addTrack("Chelmsford Freight 2", Track.SPUR);
loc2trk2.setTrainDirections(Track.WEST + Track.EAST);
loc2trk2.setLength(900);
loc2trk2.deleteTypeName("Coil Car");
loc2trk2.setScheduleId(sch1.getId());
loc2trk2.setScheduleMode(Track.SEQUENTIAL);
// start the schedule with 3rd item Gon
loc2trk2.setScheduleItemId(sch1.getItemsBySequenceList().get(2).getId());
Track loc2trk3;
loc2trk3 = loc2.addTrack("Chelmsford Yard 3", Track.YARD);
loc2trk3.setTrainDirections(Track.WEST + Track.EAST);
loc2trk3.setLength(900);
loc2trk3.deleteTypeName("Gon");
loc2trk3.deleteTypeName("Coil Car");
Track loc2trk4;
loc2trk4 = loc2.addTrack("Chelmsford Freight 4", Track.SPUR);
loc2trk4.setTrainDirections(Track.WEST + Track.EAST);
loc2trk4.setLength(900);
loc2trk4.setScheduleId(sch2.getId());
loc2trk4.setScheduleMode(Track.SEQUENTIAL);
Track loc3trk1;
loc3trk1 = loc3.addTrack("Bedford Yard 1", Track.STAGING);
loc3trk1.setTrainDirections(Track.WEST + Track.EAST);
loc3trk1.setLength(900);
loc3trk1.setRemoveCustomLoadsEnabled(true);
// Create route with 2 location
Route rte1;
rte1 = rmanager.newRoute("Two Location Route");
RouteLocation rl1 = rte1.addLocation(loc1);
rl1.setTrainDirection(RouteLocation.EAST);
rl1.setMaxCarMoves(12);
// set the train icon coordinates
rl1.setTrainIconX(25);
rl1.setTrainIconY(75);
RouteLocation rl2 = rte1.addLocation(loc2);
rl2.setTrainDirection(RouteLocation.EAST);
rl2.setMaxCarMoves(12);
// set the train icon coordinates
rl2.setTrainIconX(75);
rl2.setTrainIconY(75);
// Create train
Train train1;
train1 = tmanager.newTrain("TestScheduleLoads");
train1.setRoute(rte1);
// Set up 13 cars
Car c1 = new Car("BM", "S1");
c1.setTypeName("Gon");
c1.setLength("90");
c1.setMoves(13);
c1.setLoadName("L");
cmanager.register(c1);
Car c2 = new Car("UP", "S2");
c2.setTypeName("Boxcar");
c2.setLength("80");
c2.setMoves(12);
cmanager.register(c2);
Car c3 = new Car("XP", "S3");
c3.setTypeName("Flat Car");
c3.setLength("70");
c3.setMoves(0);
c3.setLoadName("L");
// force this car to Chelmsford
c3.setDestination(loc2, null);
cmanager.register(c3);
Car c4 = new Car("PU", "S4");
c4.setTypeName("Boxcar");
c4.setLength("60");
c4.setMoves(10);
cmanager.register(c4);
// place two cars in a kernel
Kernel k1 = cmanager.newKernel("TwoCars");
Car c5 = new Car("UP", "S5");
c5.setTypeName("Gon");
c5.setLength("50");
c5.setMoves(9);
c5.setLoadName("L");
c5.setKernel(k1);
cmanager.register(c5);
Car c6 = new Car("CP", "S6");
c6.setTypeName("Boxcar");
c6.setLength("40");
c6.setMoves(8);
c6.setLoadName("L");
cmanager.register(c6);
Car c7 = new Car("UP", "S7");
c7.setTypeName("Boxcar");
c7.setLength("50");
c7.setMoves(7);
cmanager.register(c7);
Car c8 = new Car("XP", "S8");
c8.setTypeName("Gon");
c8.setLength("60");
c8.setMoves(6);
cmanager.register(c8);
Car c9 = new Car("XP", "S9");
c9.setTypeName("Flat Car");
c9.setLength("90");
c9.setMoves(5);
c9.setLoadName("E");
cmanager.register(c9);
Car c10 = new Car("CP", "S10");
c10.setTypeName("Coil Car");
c10.setLength("40");
c10.setMoves(2);
c10.setLoadName("L");
cmanager.register(c10);
Car c11 = new Car("CP", "S11");
c11.setTypeName("Coil Car");
c11.setLength("40");
c11.setMoves(3);
c11.setLoadName("Coils");
cmanager.register(c11);
Car c12 = new Car("CP", "S12");
c12.setTypeName("Coil Car");
c12.setLength("40");
c12.setMoves(4);
cmanager.register(c12);
// place car in kernel with c5
Car c13 = new Car("UP", "S13");
c13.setTypeName("Gon");
c13.setLength("50");
c13.setMoves(1);
c13.setLoadName("L");
c13.setKernel(k1);
cmanager.register(c13);
// place the cars in the yards
Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c11", Track.OKAY, c11.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c12", Track.OKAY, c12.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c13", Track.OKAY, c13.setLocation(loc1, loc1trk2));
train1.reset();
new TrainBuilder().build(train1);
// Schedule sch1 should cause c2 to be delivered to Chelmsford Freight 2
Assert.assertEquals("c2 destination", "Chelmsford Freight 2", c2.getDestinationTrackName());
Assert.assertEquals("c2 next load", "", c2.getNextLoadName());
// Schedule sch1 and sch2 should reject c3, to be delivered to Chelmsford Yard 3
Assert.assertEquals("c3 destination", "Chelmsford Yard 3", c3.getDestinationTrackName());
Assert.assertEquals("c3 next load", "", c3.getNextLoadName());
Assert.assertEquals("c4 destination", "Chelmsford Yard 3", c4.getDestinationTrackName());
// Schedule sch1 should cause c5 & c13 to be delivered to Chelmsford Freight 2
Assert.assertEquals("c5 destination", "Chelmsford Freight 2", c5.getDestinationTrackName());
Assert.assertEquals("c5 next load", "Tin", c5.getNextLoadName());
Assert.assertEquals("c6 destination", "Chelmsford Yard 3", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination", "Chelmsford Freight 4", c7.getDestinationTrackName());
Assert.assertEquals("c9 destination", "Chelmsford Freight 1", c9.getDestinationTrackName());
Assert.assertEquals("c9 next load", "Scrap", c9.getNextLoadName());
Assert.assertEquals("c10 destination", "Chelmsford Freight 4", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination", "Chelmsford Freight 4", c11.getDestinationTrackName());
// C13 is part of kernel, load will flip between E and L
Assert.assertEquals("c13 destination", "Chelmsford Freight 2", c13.getDestinationTrackName());
Assert.assertEquals("c13 next load", "Tin", c13.getNextLoadName());
// move and terminate train
train1.move();
train1.move();
train1.move();
Assert.assertEquals("c1 track", "Chelmsford Freight 1", c1.getTrackName());
Assert.assertEquals("c1 load", "Tin", c1.getLoadName());
Assert.assertEquals("c2 track", "Chelmsford Freight 2", c2.getTrackName());
Assert.assertEquals("c2 load", "L", c2.getLoadName());
Assert.assertEquals("c3 track", "Chelmsford Yard 3", c3.getTrackName());
Assert.assertEquals("c3 load", "L", c3.getLoadName());
Assert.assertEquals("c4 track", "Chelmsford Yard 3", c4.getTrackName());
Assert.assertEquals("c4 load", "E", c4.getLoadName());
Assert.assertEquals("c5 track", "Chelmsford Freight 2", c5.getTrackName());
Assert.assertEquals("c5 load", "Tin", c5.getLoadName());
Assert.assertEquals("c6 track", "Chelmsford Yard 3", c6.getTrackName());
Assert.assertEquals("c6 load", "L", c6.getLoadName());
Assert.assertEquals("c7 track", "Chelmsford Freight 4", c7.getTrackName());
Assert.assertEquals("c7 load", "L", c7.getLoadName());
Assert.assertEquals("c8 track", "Westford Yard 2", c8.getTrackName());
Assert.assertEquals("c8 load", "E", c8.getLoadName());
Assert.assertEquals("c9 track", "Chelmsford Freight 1", c9.getTrackName());
Assert.assertEquals("c9 load", "Scrap", c9.getLoadName());
Assert.assertEquals("c10 track", "Chelmsford Freight 4", c10.getTrackName());
Assert.assertEquals("c10 load", "E", c10.getLoadName());
Assert.assertEquals("c11 track", "Chelmsford Freight 4", c11.getTrackName());
Assert.assertEquals("c11 load", "E", c11.getLoadName());
Assert.assertEquals("c12 track", "Westford Yard 1", c12.getTrackName());
Assert.assertEquals("c12 load", "E", c12.getLoadName());
Assert.assertEquals("c13 track", "Chelmsford Freight 2", c13.getTrackName());
Assert.assertEquals("c13 load", "Tin", c13.getLoadName());
// create a route to staging to test remove schedule load
// Create route with 2 location
Route rte2;
rte2 = rmanager.newRoute("Chelmsford to Staging");
RouteLocation r2rl1 = rte2.addLocation(loc2);
r2rl1.setTrainDirection(RouteLocation.EAST);
r2rl1.setMaxCarMoves(12);
// set the train icon coordinates
r2rl1.setTrainIconX(125);
r2rl1.setTrainIconY(75);
RouteLocation r2rl3 = rte2.addLocation(loc3);
r2rl3.setTrainDirection(RouteLocation.EAST);
r2rl3.setMaxCarMoves(12);
// set the train icon coordinates
r2rl3.setTrainIconX(175);
r2rl3.setTrainIconY(75);
train1.setRoute(rte2);
train1.setName("Chelmsford to Bedford");
train1.reset();
new TrainBuilder().build(train1);
// move and terminate train
train1.move();
train1.move();
train1.move();
Assert.assertEquals("c1 track to staging", "Bedford Yard 1", c1.getTrackName());
Assert.assertEquals("c1 load to staging", "E", c1.getLoadName());
Assert.assertEquals("c2 track to staging", "Bedford Yard 1", c2.getTrackName());
Assert.assertEquals("c2 load to staging", "L", c2.getLoadName());
Assert.assertEquals("c3 track to staging", "Bedford Yard 1", c3.getTrackName());
Assert.assertEquals("c3 load to staging", "L", c3.getLoadName());
Assert.assertEquals("c4 track to staging", "Bedford Yard 1", c4.getTrackName());
Assert.assertEquals("c4 load to staging", "E", c4.getLoadName());
Assert.assertEquals("c5 track to staging", "Bedford Yard 1", c5.getTrackName());
Assert.assertEquals("c5 load to staging", "E", c5.getLoadName());
Assert.assertEquals("c6 track to staging", "Bedford Yard 1", c6.getTrackName());
Assert.assertEquals("c6 load to staging", "L", c6.getLoadName());
Assert.assertEquals("c7 track to staging", "Bedford Yard 1", c7.getTrackName());
Assert.assertEquals("c7 load to staging", "L", c7.getLoadName());
Assert.assertEquals("c8 track to staging", "Westford Yard 2", c8.getTrackName());
Assert.assertEquals("c8 load to staging", "E", c8.getLoadName());
Assert.assertEquals("c9 track to staging", "Bedford Yard 1", c9.getTrackName());
Assert.assertEquals("c9 load to staging", "E", c9.getLoadName());
Assert.assertEquals("c10 track to staging", "Bedford Yard 1", c10.getTrackName());
Assert.assertEquals("c10 load to staging", "E", c10.getLoadName());
Assert.assertEquals("c11 track to staging", "Bedford Yard 1", c11.getTrackName());
Assert.assertEquals("c11 load to staging", "E", c11.getLoadName());
Assert.assertEquals("c12 track to staging", "Westford Yard 1", c12.getTrackName());
Assert.assertEquals("c12 load to staging", "E", c12.getLoadName());
Assert.assertEquals("c13 track to staging", "Bedford Yard 1", c13.getTrackName());
Assert.assertEquals("c13 load to staging", "E", c13.getLoadName());
// create a route from staging to test generate schedule load
// Create route with 3 locations
Route rte3;
rte3 = rmanager.newRoute("Staging to Chelmsford");
RouteLocation r3rl1 = rte3.addLocation(loc3);
r3rl1.setTrainDirection(RouteLocation.EAST);
// there are 11 cars departing staging
r3rl1.setMaxCarMoves(11);
// set the train icon coordinates
r3rl1.setTrainIconX(25);
r3rl1.setTrainIconY(100);
RouteLocation r3rl2 = rte3.addLocation(loc2);
r3rl2.setTrainDirection(RouteLocation.EAST);
r3rl2.setMaxCarMoves(12);
RouteLocation r3rl3 = rte3.addLocation(loc1);
r3rl3.setTrainDirection(RouteLocation.EAST);
r3rl3.setMaxCarMoves(12);
// set the train icon coordinates
r3rl3.setTrainIconX(75);
r3rl3.setTrainIconY(100);
loc3trk1.setRemoveCustomLoadsEnabled(false);
// generate schedule loads
loc3trk1.setAddCustomLoadsEnabled(true);
// request these loads from staging
sch1Item1.setReceiveLoadName("Metal 1");
sch1Item2.setReceiveLoadName("Metal 2");
sch1Item3.setReceiveLoadName("Metal 3");
// Allows c13 which is part of a kernel to get a new load
CarLoads.instance().addName("Gon", "Metal 3");
train1.setRoute(rte3);
train1.setName("BCW");
train1.reset();
new TrainBuilder().build(train1);
Assert.assertEquals("Train Bedford Chelmsford Westford build status", true, train1.isBuilt());
Assert.assertEquals("c1 load from staging", "E", c1.getLoadName());
Assert.assertEquals("c2 load from staging", "L", c2.getLoadName());
Assert.assertEquals("c3 load from staging", "L", c3.getLoadName());
Assert.assertEquals("c4 load from staging", "E", c4.getLoadName());
Assert.assertEquals("c5 load from staging", "Metal 3", c5.getLoadName());
Assert.assertEquals("c6 load from staging", "L", c6.getLoadName());
Assert.assertEquals("c7 load from staging", "L", c7.getLoadName());
Assert.assertEquals("c8 load from staging", "E", c8.getLoadName());
Assert.assertEquals("c9 load from staging", "Metal 2", c9.getLoadName());
Assert.assertEquals("c9 next load from staging", "Scrap", c9.getNextLoadName());
Assert.assertEquals("c10 load from staging", "E", c10.getLoadName());
Assert.assertEquals("c11 load from staging", "E", c11.getLoadName());
Assert.assertEquals("c13 load from staging", "Metal 3", c13.getLoadName());
// move and terminate train
train1.move();
train1.move();
train1.move();
train1.move();
Assert.assertEquals("c1 track from staging terminated", "Westford Yard 1", c1.getTrackName());
Assert.assertEquals("c1 load from staging terminated", "E", c1.getLoadName());
Assert.assertEquals("c2 track from staging terminated", "Westford Yard 2", c2.getTrackName());
Assert.assertEquals("c2 load from staging terminated", "L", c2.getLoadName());
Assert.assertEquals("c3 track from staging terminated", "Westford Yard 1", c3.getTrackName());
Assert.assertEquals("c3 load from staging terminated", "L", c3.getLoadName());
Assert.assertEquals("c4 track from staging terminated", "Westford Express 4", c4.getTrackName());
Assert.assertEquals("c4 load from staging terminated", "L", c4.getLoadName());
Assert.assertEquals("c5 track from staging terminated", "Chelmsford Freight 2", c5.getTrackName());
Assert.assertEquals("c5 load from staging terminated", "Tin", c5.getLoadName());
Assert.assertEquals("c6 track from staging terminated", "Westford Express 3", c6.getTrackName());
Assert.assertEquals("c6 load from staging terminated", "E", c6.getLoadName());
Assert.assertEquals("c7 track from staging terminated", "Westford Yard 2", c7.getTrackName());
Assert.assertEquals("c7 load from staging terminated", "L", c7.getLoadName());
Assert.assertEquals("c8 track from staging terminated", "Westford Yard 2", c8.getTrackName());
Assert.assertEquals("c8 load from staging terminated", "E", c8.getLoadName());
Assert.assertEquals("c9 track from staging terminated", "Chelmsford Freight 2", c9.getTrackName());
Assert.assertEquals("c9 load from staging terminated", "Scrap", c9.getLoadName());
Assert.assertEquals("c10 track from staging terminated", "Chelmsford Freight 4", c10.getTrackName());
Assert.assertEquals("c10 load from staging terminated", "L", c10.getLoadName());
Assert.assertEquals("c11 track from staging terminated", "Westford Yard 1", c11.getTrackName());
Assert.assertEquals("c11 load from staging terminated", "E", c11.getLoadName());
Assert.assertEquals("c12 track from staging terminated", "Westford Yard 1", c12.getTrackName());
Assert.assertEquals("c12 load from staging terminated", "E", c12.getLoadName());
Assert.assertEquals("c13 track from staging terminated", "Chelmsford Freight 2", c13.getTrackName());
Assert.assertEquals("c13 load from staging terminated", "Tin", c13.getLoadName());
}
Aggregations