use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class TrainEditFrame method dispose.
@Override
public void dispose() {
LocationManager.instance().removePropertyChangeListener(this);
EngineTypes.instance().removePropertyChangeListener(this);
EngineModels.instance().removePropertyChangeListener(this);
CarTypes.instance().removePropertyChangeListener(this);
CarRoads.instance().removePropertyChangeListener(this);
routeManager.removePropertyChangeListener(this);
for (Frame frame : children) {
frame.dispose();
}
if (_train != null) {
_train.removePropertyChangeListener(this);
Route route = _train.getRoute();
if (route != null) {
route.removePropertyChangeListener(this);
for (RouteLocation rl : route.getLocationsBySequenceList()) {
Location loc = rl.getLocation();
if (loc != null) {
loc.removePropertyChangeListener(this);
}
}
}
}
super.dispose();
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class PrintTrainAction method printTrain.
protected void printTrain(HardcopyWriter writer, Train train) {
try {
String s = Bundle.getMessage("Name") + ": " + train.getName() + NEW_LINE;
writer.write(s);
s = Bundle.getMessage("Description") + ": " + train.getDescription() + NEW_LINE;
writer.write(s);
s = Bundle.getMessage("Departs") + ": " + train.getTrainDepartsName() + NEW_LINE;
writer.write(s);
s = Bundle.getMessage("DepartTime") + ": " + train.getDepartureTime() + NEW_LINE;
writer.write(s);
s = Bundle.getMessage("Terminates") + ": " + train.getTrainTerminatesName() + NEW_LINE;
writer.write(s);
s = NEW_LINE;
writer.write(s);
s = Bundle.getMessage("Route") + ": " + train.getTrainRouteName() + NEW_LINE;
writer.write(s);
Route route = train.getRoute();
if (route != null) {
for (RouteLocation rl : route.getLocationsBySequenceList()) {
s = TAB + rl.getName() + NEW_LINE;
writer.write(s);
}
}
if (!train.getComment().equals(Train.NONE)) {
s = Bundle.getMessage("Comment") + ": " + train.getComment() + NEW_LINE;
writer.write(s);
}
} catch (IOException we) {
log.error("Error printing train report");
}
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class OperationsCarRouterTest method testCarRouting.
/**
* Test car routing. First set of tests confirm proper operation of just one
* location. The next set of tests confirms operation using one train and
* two locations. When this test was written, routing up to 5 trains and 6
* locations was supported.
*
*/
public void testCarRouting() {
// now load up the managers
TrainManager tmanager = TrainManager.instance();
RouteManager rmanager = RouteManager.instance();
LocationManager lmanager = LocationManager.instance();
Router router = Router.instance();
CarManager cmanager = CarManager.instance();
CarTypes ct = CarTypes.instance();
// register the car and engine types used
ct.addName("Boxcar");
ct.addName("Caboose");
ct.addName("Flat");
// create 6 locations and tracks
Location Acton = lmanager.newLocation("Acton MA");
Assert.assertEquals("Location 1 Name", "Acton MA", Acton.getName());
Assert.assertEquals("Location 1 Initial Length", 0, Acton.getLength());
Track AS1 = Acton.addTrack("Acton Siding 1", Track.SPUR);
AS1.setLength(300);
Assert.assertEquals("Location AS1 Name", "Acton Siding 1", AS1.getName());
Assert.assertEquals("Location AS1 Length", 300, AS1.getLength());
Track AS2 = Acton.addTrack("Acton Siding 2", Track.SPUR);
AS2.setLength(300);
Assert.assertEquals("Location AS2 Name", "Acton Siding 2", AS2.getName());
Assert.assertEquals("Location AS2 Length", 300, AS2.getLength());
Track AY = Acton.addTrack("Acton Yard", Track.YARD);
AY.setLength(400);
Assert.assertEquals("Location AY Name", "Acton Yard", AY.getName());
Assert.assertEquals("Location AY Length", 400, AY.getLength());
Track AI = Acton.addTrack("Acton Interchange", Track.INTERCHANGE);
AI.setLength(500);
Assert.assertEquals("Track AI Name", "Acton Interchange", AI.getName());
Assert.assertEquals("Track AI Length", 500, AI.getLength());
Assert.assertEquals("Track AI Train Directions", DIRECTION_ALL, AI.getTrainDirections());
// add a second interchange track
Track AI2 = Acton.addTrack("Acton Interchange 2", Track.INTERCHANGE);
AI2.setLength(500);
// bias tracks
AI2.setMoves(100);
Assert.assertEquals("Track AI2 Name", "Acton Interchange 2", AI2.getName());
Assert.assertEquals("Track AI2 Length", 500, AI2.getLength());
Assert.assertEquals("Track AI2 Train Directions", DIRECTION_ALL, AI2.getTrainDirections());
Location Bedford = lmanager.newLocation("Bedford MA");
Assert.assertEquals("Location 1 Name", "Bedford MA", Bedford.getName());
Assert.assertEquals("Location 1 Initial Length", 0, Bedford.getLength());
Track BS1 = Bedford.addTrack("Bedford Siding 1", Track.SPUR);
BS1.setLength(300);
Assert.assertEquals("Location BS1 Name", "Bedford Siding 1", BS1.getName());
Assert.assertEquals("Location BS1 Length", 300, BS1.getLength());
Track BS2 = Bedford.addTrack("Bedford Siding 2", Track.SPUR);
BS2.setLength(300);
Assert.assertEquals("Location BS2 Name", "Bedford Siding 2", BS2.getName());
Assert.assertEquals("Location BS2 Length", 300, BS2.getLength());
Track BY = Bedford.addTrack("Bedford Yard", Track.YARD);
BY.setLength(400);
Assert.assertEquals("Location BY Name", "Bedford Yard", BY.getName());
Assert.assertEquals("Location BY Length", 400, BY.getLength());
Track BI = Bedford.addTrack("Bedford Interchange", Track.INTERCHANGE);
BI.setLength(500);
Assert.assertEquals("Track BI Name", "Bedford Interchange", BI.getName());
Assert.assertEquals("Track BI Length", 500, BI.getLength());
Location Clinton = lmanager.newLocation("Clinton MA");
Assert.assertEquals("Location 1 Name", "Clinton MA", Clinton.getName());
Assert.assertEquals("Location 1 Initial Length", 0, Clinton.getLength());
Track CS1 = Clinton.addTrack("Clinton Siding 1", Track.SPUR);
CS1.setLength(300);
Assert.assertEquals("Location CS1 Name", "Clinton Siding 1", CS1.getName());
Assert.assertEquals("Location CS1 Length", 300, CS1.getLength());
Track CS2 = Clinton.addTrack("Clinton Siding 2", Track.SPUR);
CS2.setLength(300);
Assert.assertEquals("Location CS2 Name", "Clinton Siding 2", CS2.getName());
Assert.assertEquals("Location CS2 Length", 300, BS2.getLength());
Track CY = Clinton.addTrack("Clinton Yard", Track.YARD);
CY.setLength(400);
Assert.assertEquals("Location CY Name", "Clinton Yard", CY.getName());
Assert.assertEquals("Location CY Length", 400, CY.getLength());
Track CI = Clinton.addTrack("Clinton Interchange", Track.INTERCHANGE);
CI.setLength(500);
Assert.assertEquals("Track CI Name", "Clinton Interchange", CI.getName());
Assert.assertEquals("Track CI Length", 500, CI.getLength());
Location Danbury = lmanager.newLocation("Danbury MA");
Track DS1 = Danbury.addTrack("Danbury Siding 1", Track.SPUR);
DS1.setLength(300);
Track DS2 = Danbury.addTrack("Danbury Siding 2", Track.SPUR);
DS2.setLength(300);
Track DY = Danbury.addTrack("Danbury Yard", Track.YARD);
DY.setLength(400);
Track DI = Danbury.addTrack("Danbury Interchange", Track.INTERCHANGE);
DI.setLength(500);
Location Essex = lmanager.newLocation("Essex MA");
Track ES1 = Essex.addTrack("Essex Siding 1", Track.SPUR);
ES1.setLength(300);
Track ES2 = Essex.addTrack("Essex Siding 2", Track.SPUR);
ES2.setLength(300);
Track EY = Essex.addTrack("Essex Yard", Track.YARD);
EY.setLength(400);
Track EI = Essex.addTrack("Essex Interchange", Track.INTERCHANGE);
EI.setLength(500);
Location Foxboro = lmanager.newLocation("Foxboro MA");
Track FS1 = Foxboro.addTrack("Foxboro Siding 1", Track.SPUR);
FS1.setLength(300);
Track FS2 = Foxboro.addTrack("Foxboro Siding 2", Track.SPUR);
FS2.setLength(300);
Track FY = Foxboro.addTrack("Foxboro Yard", Track.YARD);
FY.setLength(400);
Track FI = Foxboro.addTrack("Foxboro Interchange", Track.INTERCHANGE);
FI.setLength(500);
// create 2 cars
Car c3 = cmanager.newCar("BA", "3");
c3.setTypeName("Boxcar");
c3.setLength("40");
c3.setOwner("DAB");
c3.setBuilt("1984");
Assert.assertEquals("Box Car 3 Length", "40", c3.getLength());
Car c4 = cmanager.newCar("BB", "4");
c4.setTypeName("Flat");
c4.setLength("40");
c4.setOwner("AT");
c4.setBuilt("1-86");
Assert.assertEquals("Box Car 4 Length", "40", c4.getLength());
Assert.assertEquals("place car at BI", Track.OKAY, c3.setLocation(Acton, AS1));
Assert.assertFalse("Try routing no final destination", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("place car at Acton", Track.OKAY, c4.setLocation(Acton, AS1));
Assert.assertFalse("Try routing no final destination", router.setDestination(c4, null, null));
Assert.assertEquals("Check car's destination", "", c4.getDestinationName());
// test disable routing
Setup.setCarRoutingEnabled(false);
c3.setFinalDestination(Bedford);
Assert.assertFalse("Test router disabled", router.setDestination(c3, null, null));
Assert.assertEquals("Router status", Router.STATUS_ROUTER_DISABLED, router.getStatus());
Setup.setCarRoutingEnabled(true);
// first try car routing with just one location
c3.setFinalDestination(Acton);
Assert.assertFalse("Try routing final destination equal to current", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Router status", Router.STATUS_CAR_AT_DESINATION, router.getStatus());
// now try with next track not equal to current
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
Assert.assertFalse("Try routing final track not equal to current", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
// now try with next track equal to current
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS1);
Assert.assertFalse("Try routing final track equal to current", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Router status", Router.STATUS_CAR_AT_DESINATION, router.getStatus());
// create a local train servicing Acton
Train ActonTrain = tmanager.newTrain("Acton Local");
Route routeA = rmanager.newRoute("A");
RouteLocation rlA = routeA.addLocation(Acton);
// set train icon coordinates
rlA.setTrainIconX(25);
rlA.setTrainIconY(250);
ActonTrain.setRoute(routeA);
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
Assert.assertTrue("Try routing final track with Acton Local", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Siding 2", c3.getDestinationTrackName());
Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
// specify the Acton train
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
Assert.assertTrue("Try routing final track with Acton Local", router.setDestination(c3, ActonTrain, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Siding 2", c3.getDestinationTrackName());
Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
// Set the track length to be less the length of c3
AS2.setLength(c3.getTotalLength() - 1);
// clear previous destination
c3.setDestination(null, null);
// local move, alternate or yard track option should be ignored
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
Assert.assertTrue("Try routing final track with Acton Local", router.setDestination(c3, ActonTrain, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
Assert.assertTrue("Should report that the issue was track length", router.getStatus().startsWith(Track.CAPACITY));
// restore track length
AS2.setLength(300);
// don't allow train to service boxcars
ActonTrain.deleteTypeName("Boxcar");
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
Assert.assertFalse("Try routing with train that doesn't service Boxcar", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
// try the car type Flat
// clear previous destination
c4.setDestination(null, null);
c4.setFinalDestination(Acton);
c4.setFinalDestinationTrack(AS2);
Assert.assertTrue("Try routing with train that service Flat", router.setDestination(c4, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c4.getDestinationName());
Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
// now allow Boxcar again
ActonTrain.addTypeName("Boxcar");
Assert.assertTrue("Try routing with train that does service Boxcar", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
// don't allow train to service boxcars with road name BA
ActonTrain.addRoadName("BA");
ActonTrain.setRoadOption(Train.EXCLUDE_ROADS);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
Assert.assertFalse("Try routing with train that doesn't service road name BA", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
// try the car road name BB
// clear previous destination
c4.setDestination(null, null);
c4.setFinalDestination(Acton);
c4.setFinalDestinationTrack(AS2);
Assert.assertTrue("Try routing with train that services road BB", router.setDestination(c4, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c4.getDestinationName());
Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
// now try again but allow road name
ActonTrain.setRoadOption(Train.ALL_ROADS);
Assert.assertTrue("Try routing with train that does service road name BA", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
// don't service cars built before 1985
ActonTrain.setBuiltStartYear("1985");
ActonTrain.setBuiltEndYear("2010");
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
Assert.assertFalse("Try routing with train that doesn't service car built before 1985", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
// try the car built after 1985
// clear previous destination
c4.setDestination(null, null);
c4.setFinalDestination(Acton);
c4.setFinalDestinationTrack(AS2);
Assert.assertTrue("Try routing with train that services car built after 1985", router.setDestination(c4, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c4.getDestinationName());
Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
// car was built in 1984 should work
ActonTrain.setBuiltStartYear("1983");
Assert.assertTrue("Try routing with train that doesn't service car built before 1983", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
// try car loads
c3.setLoadName("Tools");
ActonTrain.addLoadName("Tools");
ActonTrain.setLoadOption(Train.EXCLUDE_LOADS);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
Assert.assertFalse("Try routing with train that doesn't service load Tools", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
// try the car load "E"
// clear previous destination
c4.setDestination(null, null);
c4.setFinalDestination(Acton);
c4.setFinalDestinationTrack(AS2);
Assert.assertTrue("Try routing with train that services load E", router.setDestination(c4, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c4.getDestinationName());
ActonTrain.setLoadOption(Train.ALL_LOADS);
Assert.assertTrue("Try routing with train that that does service load Tools", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
// now test by modifying the route
rlA.setPickUpAllowed(false);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
Assert.assertFalse("Try routing with train that doesn't pickup cars", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
rlA.setPickUpAllowed(true);
Assert.assertTrue("Try routing with train that that can pickup cars", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
rlA.setDropAllowed(false);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
Assert.assertFalse("Try routing with train that doesn't drop cars", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
rlA.setDropAllowed(true);
Assert.assertTrue("Try routing with train that that can drop cars", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
rlA.setMaxCarMoves(0);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
Assert.assertFalse("Try routing with train that doesn't service location", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
rlA.setMaxCarMoves(10);
Assert.assertTrue("Try routing with train that does service location", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
// test train depart direction
Assert.assertEquals("check default direction", Track.NORTH, rlA.getTrainDirection());
// set the depart location Acton to service by South bound trains only
Acton.setTrainDirections(Track.SOUTH);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
Assert.assertTrue("Try routing with local train that departs north, location south", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Acton.setTrainDirections(Track.NORTH);
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
Assert.assertTrue("Try routing with local train that departs north, location north", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
// set the depart track Acton to service by local train only
AS1.setTrainDirections(0);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
Assert.assertTrue("Try routing with local only", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
AS1.setTrainDirections(Track.NORTH);
Assert.assertTrue("Try routing with local train that departs north, track north", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
// test arrival directions
// set the arrival track Acton to service by local trains only
AS2.setTrainDirections(0);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
// now specify the actual track
c3.setFinalDestinationTrack(AS2);
Assert.assertTrue("Try routing with local train", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
AS2.setTrainDirections(Track.NORTH);
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
// now specify the actual track
c3.setFinalDestinationTrack(AS2);
Assert.assertTrue("Try routing with train that departs north, track north", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
// add a second local train
// create a local train servicing Acton
Route routeA2 = rmanager.newRoute("A2");
RouteLocation rlA2 = routeA2.addLocation(Acton);
// set train icon coordinates
rlA2.setTrainIconX(25);
rlA2.setTrainIconY(250);
Train ActonTrain2 = tmanager.newTrain("Acton Local 2");
ActonTrain2.setRoute(routeA2);
// try routing with this train
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
Assert.assertTrue("Try routing final track with Acton Local", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Siding 2", c3.getDestinationTrackName());
// don't allow Acton Local 2 to service boxcars
ActonTrain2.deleteTypeName("Boxcar");
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Acton);
c3.setFinalDestinationTrack(AS2);
// Should be able to route using Acton Local, but destination should not be set
Assert.assertTrue("Try routing with train that doesn't service Boxcar", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Router status", Router.STATUS_NOT_THIS_TRAIN, router.getStatus());
// Two locations one train testing begins
// set next destination Bedford
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
c3.setFinalDestinationTrack(null);
// should fail no train!
Assert.assertFalse("Try routing with final destination", router.setDestination(c3, null, null));
// create a train with a route from Acton to Bedford
Train ActonToBedfordTrain = tmanager.newTrain("Acton to Bedford");
Route routeAB = rmanager.newRoute("AB");
RouteLocation rlActon = routeAB.addLocation(Acton);
RouteLocation rlBedford = routeAB.addLocation(Bedford);
// set train icon coordinates
rlBedford.setTrainIconX(100);
rlBedford.setTrainIconY(250);
ActonToBedfordTrain.setRoute(routeAB);
// should work
Assert.assertTrue("Try routing with final destination and train", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
// try specific train
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
c3.setFinalDestinationTrack(null);
Assert.assertTrue("Try routing with final destination and train", router.setDestination(c3, ActonToBedfordTrain, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
// don't allow train to service boxcars
ActonToBedfordTrain.deleteTypeName("Boxcar");
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
Assert.assertFalse("Try routing with train that doesn't service Boxcar", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
// try the car type Flat
// clear previous destination
c4.setDestination(null, null);
c4.setFinalDestination(Bedford);
c4.setFinalDestinationTrack(null);
Assert.assertTrue("Try routing with train that service Flat", router.setDestination(c4, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c4.getDestinationName());
// now allow Boxcar again
ActonToBedfordTrain.addTypeName("Boxcar");
Assert.assertTrue("Try routing with train that does service Boxcar", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
// don't allow train to service boxcars with road name BA
ActonToBedfordTrain.addRoadName("BA");
ActonToBedfordTrain.setRoadOption(Train.EXCLUDE_ROADS);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
Assert.assertFalse("Try routing with train that doesn't service road name BA", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
// try the car road name BB
// clear previous destination
c4.setDestination(null, null);
c4.setFinalDestination(Bedford);
Assert.assertTrue("Try routing with train that services road BB", router.setDestination(c4, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c4.getDestinationName());
// now try again but allow road name
ActonToBedfordTrain.setRoadOption(Train.ALL_ROADS);
Assert.assertTrue("Try routing with train that does service road name BA", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
// don't service cars built before 1985
ActonToBedfordTrain.setBuiltStartYear("1985");
ActonToBedfordTrain.setBuiltEndYear("2010");
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
Assert.assertFalse("Try routing with train that doesn't service car built before 1985", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
// try the car built after 1985
// clear previous destination
c4.setDestination(null, null);
c4.setFinalDestination(Bedford);
Assert.assertTrue("Try routing with train that services car built after 1985", router.setDestination(c4, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c4.getDestinationName());
// car was built in 1984 should work
ActonToBedfordTrain.setBuiltStartYear("1983");
Assert.assertTrue("Try routing with train that doesn't service car built before 1983", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
// try car loads
c3.setLoadName("Tools");
ActonToBedfordTrain.addLoadName("Tools");
ActonToBedfordTrain.setLoadOption(Train.EXCLUDE_LOADS);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
Assert.assertFalse("Try routing with train that doesn't service load Tools", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
// try the car load "E"
// clear previous destination
c4.setDestination(null, null);
c4.setFinalDestination(Bedford);
Assert.assertTrue("Try routing with train that services load E", router.setDestination(c4, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c4.getDestinationName());
ActonToBedfordTrain.setLoadOption(Train.ALL_LOADS);
Assert.assertTrue("Try routing with train that that does service load Tools", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
// don't allow Bedford to service Flat
// clear previous destination
c4.setDestination(null, null);
c4.setFinalDestination(Bedford);
Bedford.deleteTypeName("Flat");
Assert.assertFalse("Try routing with Bedford that does not service Flat", router.setDestination(c4, null, null));
Assert.assertEquals("Check car's destination", "", c4.getDestinationName());
Assert.assertTrue("Router status", router.getStatus().startsWith(Track.TYPE));
// restore Bedford can service Flat
Bedford.addTypeName("Flat");
// now test by modifying the route
rlActon.setPickUpAllowed(false);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
Assert.assertFalse("Try routing with train that doesn't pickup cars", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
rlActon.setPickUpAllowed(true);
Assert.assertTrue("Try routing with train that that can pickup cars", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
rlBedford.setDropAllowed(false);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
Assert.assertFalse("Try routing with train that doesn't drop cars", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
rlBedford.setDropAllowed(true);
Assert.assertTrue("Try routing with train that that can drop cars", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
rlBedford.setMaxCarMoves(0);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
Assert.assertFalse("Try routing with train that doesn't service destination", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
rlBedford.setMaxCarMoves(5);
Assert.assertTrue("Try routing with train that does service destination", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
rlActon.setMaxCarMoves(0);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
Assert.assertFalse("Try routing with train that doesn't service location", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
rlActon.setMaxCarMoves(5);
Assert.assertTrue("Try routing with train that does service location", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
// test train depart direction
Assert.assertEquals("check default direction", Track.NORTH, rlActon.getTrainDirection());
// set the depart location Acton to service by South bound trains only
Acton.setTrainDirections(Track.SOUTH);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
// remove the Action local by not allowing train to service boxcars
ActonTrain.deleteTypeName("Boxcar");
Assert.assertFalse("Try routing with train that departs north, location south", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Acton.setTrainDirections(Track.NORTH);
Assert.assertTrue("Try routing with train that departs north, location north", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
// set the depart track Acton to service by South bound trains only
AS1.setTrainDirections(Track.SOUTH);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
Assert.assertFalse("Try routing with train that departs north, track south", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
AS1.setTrainDirections(Track.NORTH);
Assert.assertTrue("Try routing with train that departs north, track north", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
// test arrival directions
// set the arrival location Bedford to service by South bound trains only
Bedford.setTrainDirections(Track.SOUTH);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
Assert.assertFalse("Try routing with train that arrives north, destination south", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Bedford.setTrainDirections(Track.NORTH);
Assert.assertTrue("Try routing with train that arrives north, destination north", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
// set the depart track Acton to service by South bound trains only
BS1.setTrainDirections(Track.SOUTH);
// and the next destination for the car
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
Assert.assertTrue("Try routing with train that arrives north, but no final track", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
// clear previous destination
c3.setDestination(null, null);
// the final destination for the car
c3.setFinalDestination(Bedford);
// now specify the actual track
c3.setFinalDestinationTrack(BS1);
Assert.assertFalse("Try routing with train that arrives north, now with track", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
BS1.setTrainDirections(Track.NORTH);
Assert.assertTrue("Try routing with train that departs north, track north", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
Setup.setOnlyActiveTrainsEnabled(true);
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
Assert.assertTrue("Try routing only active trains", router.setDestination(c3, null, null));
// now deselect the Action to Bedford train
ActonToBedfordTrain.setBuildEnabled(false);
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
Assert.assertFalse("Try routing only active trains, Action to Beford deselected", router.setDestination(c3, null, null));
Assert.assertEquals("Router status", Router.STATUS_NOT_ABLE, router.getStatus());
Setup.setOnlyActiveTrainsEnabled(false);
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
Assert.assertTrue("Try routing, only active trains deselected", router.setDestination(c3, null, null));
// test yard and alternate track options
BS1.setLength(c3.getTotalLength());
// c4 is the same length as c3, so the track is now full
Assert.assertEquals("Use up all of the space for BS1", Track.OKAY, c4.setLocation(Bedford, BS1));
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
c3.setFinalDestinationTrack(BS1);
Assert.assertTrue("Test search for yard", router.setDestination(c3, null, null));
Assert.assertEquals("Destination", "Bedford MA", c3.getDestinationName());
Assert.assertEquals("Destination track should be yard", "Bedford Yard", c3.getDestinationTrackName());
// the car was sent to a yard track because the spur was full
Assert.assertTrue("Should be reporting length issue", router.getStatus().startsWith(Track.LENGTH));
// remove yard type
BY.setTrackType(Track.SPUR);
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
c3.setFinalDestinationTrack(BS1);
Assert.assertTrue("Test search for yard that doesn't exist", router.setDestination(c3, null, null));
Assert.assertEquals("Destination", "", c3.getDestinationName());
Assert.assertTrue("Should be reporting length issue", router.getStatus().startsWith(Track.LENGTH));
// restore yard type
BY.setTrackType(Track.YARD);
// test alternate track option
BS1.setAlternateTrack(BS2);
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Bedford);
c3.setFinalDestinationTrack(BS1);
Assert.assertTrue("Test use alternate", router.setDestination(c3, null, null));
Assert.assertEquals("Destination", "Bedford MA", c3.getDestinationName());
Assert.assertEquals("Destination track should be siding", "Bedford Siding 2", c3.getDestinationTrackName());
// the car was sent to the alternate track because the spur was full
Assert.assertTrue("Should be reporting length issue", router.getStatus().startsWith(Track.LENGTH));
// restore track length and remove alternate
BS1.setLength(300);
BS1.setAlternateTrack(null);
// One train tests complete. Start two train testing.
// Force first move to be by local train
AS1.setTrainDirections(0);
// restore the local
ActonTrain.addTypeName("Boxcar");
// clear previous destination
c3.setDestination(null, null);
// the final destination for the car
c3.setFinalDestination(Bedford);
// now specify the actual track
c3.setFinalDestinationTrack(BS1);
Assert.assertTrue("Try routing two trains via interchange", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
// don't allow use of interchange track
AI.setDropOption(Track.TRAINS);
// clear previous destination
c3.setDestination(null, null);
// the final destination for the car
c3.setFinalDestination(Bedford);
// now specify the actual track
c3.setFinalDestinationTrack(BS1);
Assert.assertTrue("Try routing two trains via interchange", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Interchange 2", c3.getDestinationTrackName());
AI2.setDropOption(Track.TRAINS);
// clear previous destination
c3.setDestination(null, null);
// the final destination for the car
c3.setFinalDestination(Bedford);
// now specify the actual track
c3.setFinalDestinationTrack(BS1);
Assert.assertTrue("Try routing two trains via yard", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Yard", c3.getDestinationTrackName());
// allow use of interchange track
AI.setDropOption(Track.ANY);
AI2.setDropOption(Track.ANY);
// clear previous destination
c3.setDestination(null, null);
// the final destination for the car
c3.setFinalDestination(Bedford);
c3.setFinalDestinationTrack(BS1);
// allow Boxcars
ActonTrain2.addTypeName("Boxcar");
Assert.assertTrue("Try routing two trains", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
// test to see if second interchange track used if first is full
AI.setLength(c3.getTotalLength() - 1);
// clear previous destination
c3.setDestination(null, null);
// the final destination for the car
c3.setFinalDestination(Bedford);
c3.setFinalDestinationTrack(BS1);
Assert.assertTrue("Try routing two trains to interchange track 2", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Interchange 2", c3.getDestinationTrackName());
Assert.assertEquals("Router status", Track.OKAY, router.getStatus());
// use yard track if interchange tracks are full
AI2.setLength(c3.getTotalLength() - 1);
// clear previous destination
c3.setDestination(null, null);
// the final destination for the car
c3.setFinalDestination(Bedford);
c3.setFinalDestinationTrack(BS1);
Assert.assertTrue("Try routing two trains to yard track", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Yard", c3.getDestinationTrackName());
// disable using yard tracks for routing
Setup.setCarRoutingViaYardsEnabled(false);
// clear previous destination
c3.setDestination(null, null);
// the final destination for the car
c3.setFinalDestination(Bedford);
c3.setFinalDestinationTrack(BS1);
router.setDestination(c3, ActonTrain2, null);
Assert.assertFalse("Try routing two trains to yard track", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
// restore track length
AI.setLength(500);
AI2.setLength(500);
Setup.setCarRoutingViaYardsEnabled(true);
// don't allow train 2 to service boxcars with road name BA
ActonTrain2.addRoadName("BA");
ActonTrain2.setRoadOption(Train.EXCLUDE_ROADS);
// clear previous destination
c3.setDestination(null, null);
// the final destination for the car
c3.setFinalDestination(Bedford);
c3.setFinalDestinationTrack(BS1);
// routing should work using train 1, destination and track should not be set
Assert.assertTrue("Try routing two trains via yard", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
// two train testing done!
// now try up to 5 trains to route car
// set final destination Clinton
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Clinton);
c3.setFinalDestinationTrack(null);
// should fail no train!
Assert.assertFalse("Try routing with final destination", router.setDestination(c3, null, null));
// create a train with a route from Bedford to Clinton
Train BedfordToClintonTrain = tmanager.newTrain("Bedford to Clinton");
Route routeBC = rmanager.newRoute("BC");
routeBC.addLocation(Bedford);
RouteLocation rlchelmsford = routeBC.addLocation(Clinton);
// set train icon coordinates
rlchelmsford.setTrainIconX(175);
rlchelmsford.setTrainIconY(250);
BedfordToClintonTrain.setRoute(routeBC);
// should work
Assert.assertTrue("Try routing with final destination and train", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
// allow train 2 to service boxcars with road name BA
ActonTrain2.setRoadOption(Train.ALL_ROADS);
// try with train 2
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Clinton);
// routing should work using train 2
Assert.assertTrue("Try routing three trains", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Clinton);
// test to see if second interchange track used if first is full
AI.setLength(c3.getTotalLength() - 1);
// clear previous destination
c3.setDestination(null, null);
// the final destination for the car
c3.setFinalDestination(Clinton);
Assert.assertTrue("Try routing three trains to interchange track 2", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Interchange 2", c3.getDestinationTrackName());
// use yard track if interchange tracks are full
AI2.setLength(c3.getTotalLength() - 1);
// clear previous destination
c3.setDestination(null, null);
// the final destination for the car
c3.setFinalDestination(Clinton);
Assert.assertTrue("Try routing three trains to yard track", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Yard", c3.getDestinationTrackName());
// disable the use of yard tracks for routing
Setup.setCarRoutingViaYardsEnabled(false);
// clear previous destination
c3.setDestination(null, null);
// the final destination for the car
c3.setFinalDestination(Clinton);
// both interchange tracks are too short, so there isn't a route
Assert.assertFalse("Try routing three trains to yard track, option disabled", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
// Try again with an interchange track that is long enough for car c3.
AI.setLength(c3.getTotalLength());
Assert.assertEquals("c4 consumes all of the interchange track", Track.OKAY, c4.setLocation(AI.getLocation(), AI));
// Track AI is long enough, but c4 is consuming all of the track, but there is a route!
Assert.assertTrue("Try routing three trains to yard track, option disabled", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
// restore track length
AI.setLength(500);
AI2.setLength(500);
Setup.setCarRoutingViaYardsEnabled(true);
// clear previous destination
c3.setDestination(null, null);
// the final destination for the car
c3.setFinalDestination(Clinton);
// don't allow train 2 to service cars built before 1985
ActonTrain2.setBuiltStartYear("1985");
ActonTrain2.setBuiltEndYear("2010");
// routing should work using train 1, but destinations and track should not be set
Assert.assertTrue("Try routing three trains", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
// allow car to be serviced
// car was built in 1984 should work
ActonTrain2.setBuiltStartYear("1983");
// set final destination Danbury
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Danbury);
// should fail no train!
Assert.assertFalse("Try routing with final destination", router.setDestination(c3, null, null));
// create a train with a route from Clinton to Danbury
Train ClintonToDanburyTrain = tmanager.newTrain("Clinton to Danbury");
Route routeCD = rmanager.newRoute("CD");
routeCD.addLocation(Clinton);
RouteLocation rlDanbury = routeCD.addLocation(Danbury);
// set train icon coordinates
rlDanbury.setTrainIconX(250);
rlDanbury.setTrainIconY(250);
ClintonToDanburyTrain.setRoute(routeCD);
// should work
Assert.assertTrue("Try routing with final destination and train", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
// clear previous destination
c3.setDestination(null, null);
// the final destination for the car
c3.setFinalDestination(Danbury);
// routing should work using train 2
Assert.assertTrue("Try routing four trains", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
// clear previous destination
c3.setDestination(null, null);
// the final destination for the car
c3.setFinalDestination(Danbury);
// don't allow train 2 to service cars with load Tools
ActonTrain2.addLoadName("Tools");
ActonTrain2.setLoadOption(Train.EXCLUDE_LOADS);
// routing should work using train 1, but destinations and track should not be set
Assert.assertTrue("Try routing four trains", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
// restore train 2
ActonTrain2.setLoadOption(Train.ALL_LOADS);
// set final destination Essex
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Essex);
// should fail no train!
Assert.assertFalse("Try routing with final destination", router.setDestination(c3, null, null));
// create a train with a route from Danbury to Essex
Train DanburyToEssexTrain = tmanager.newTrain("Danbury to Essex");
Route routeDE = rmanager.newRoute("DE");
RouteLocation rlDanbury2 = routeDE.addLocation(Danbury);
RouteLocation rlEssex = routeDE.addLocation(Essex);
// set the number of car moves to 8 for a later test
rlDanbury2.setMaxCarMoves(8);
rlEssex.setMaxCarMoves(8);
// set train icon coordinates
rlEssex.setTrainIconX(25);
rlEssex.setTrainIconY(275);
DanburyToEssexTrain.setRoute(routeDE);
// should work
Assert.assertTrue("Try routing with final destination and train", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
// routing should work using train 2
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Essex);
Assert.assertTrue("Try routing five trains", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Acton Interchange", c3.getDestinationTrackName());
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Essex);
// don't allow train 2 to pickup
rlA2.setPickUpAllowed(false);
// routing should work using train 1, but destinations and track should not be set
Assert.assertTrue("Try routing five trains", router.setDestination(c3, ActonTrain2, null));
Assert.assertEquals("Check car's destination", "", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "", c3.getDestinationTrackName());
Assert.assertEquals("Check status", Router.STATUS_NOT_THIS_TRAIN, router.getStatus());
// set final destination Foxboro
// clear previous destination
c3.setDestination(null, null);
c3.setFinalDestination(Foxboro);
// should fail no train!
Assert.assertFalse("Try routing with final destination", router.setDestination(c3, null, null));
// create a train with a route from Essex to Foxboro
Train EssexToFoxboroTrain = tmanager.newTrain("Essex to Foxboro");
Route routeEF = rmanager.newRoute("EF");
routeEF.addLocation(Essex);
RouteLocation rlFoxboro = routeEF.addLocation(Foxboro);
// set train icon coordinates
rlFoxboro.setTrainIconX(100);
rlFoxboro.setTrainIconY(275);
EssexToFoxboroTrain.setRoute(routeEF);
// 6th train should fail! Only 5 trains supported
Assert.assertFalse("Try routing with final destination and train", router.setDestination(c3, null, null));
Assert.assertFalse("Try routing with final destination and train", router.setDestination(c3, ActonTrain, null));
Assert.assertFalse("Try routing with final destination and train", router.setDestination(c3, ActonTrain2, null));
// get rid of the local train
AS1.setTrainDirections(Track.NORTH);
// now should work!
Assert.assertTrue("Try routing with final destination and train", router.setDestination(c3, null, null));
Assert.assertEquals("Check car's destination", "Bedford MA", c3.getDestinationName());
Assert.assertEquals("Check car's destination track", "Bedford Interchange", c3.getDestinationTrackName());
// require local train for next test
AS1.setTrainDirections(0);
//TODO test restrict location by car type
//TODO test restrict tracks by type road, load
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class OperationsCarRouterTest method testRoutingWithSchedulesLocal.
/* This test confirms that schedules can be linked together.
* Note that there are schedules at Essex that are still active
* but not reachable because the Clinton to Danbury train is
* removed as part of this test.
* has 5 tracks, 3 sidings, yard, and an interchange track.
*
*/
public void testRoutingWithSchedulesLocal() {
TrainManager tmanager = TrainManager.instance();
CarManager cmanager = CarManager.instance();
LocationManager lmanager = LocationManager.instance();
loadLocationsTrainsAndCars();
List<Train> trains = tmanager.getTrainsByNameList();
Assert.assertEquals("confirm number of trains", 7, trains.size());
Car c3 = cmanager.getByRoadAndNumber("BA", "3");
Car c4 = cmanager.getByRoadAndNumber("BB", "4");
Car c5 = cmanager.getByRoadAndNumber("BC", "5");
Car c6 = cmanager.getByRoadAndNumber("BD", "6");
Car c7 = cmanager.getByRoadAndNumber("BA", "7");
Car c8 = cmanager.getByRoadAndNumber("BB", "8");
Car c9 = cmanager.getByRoadAndNumber("BC", "9");
// c3 (BA 3) is a Boxcar
c3.setLoadName("Cardboard");
// c4 (BB 4) is a Flat
c4.setLoadName("Trucks");
// c5 (BC 5) is a Boxcar
c5.setLoadName(CarLoads.instance().getDefaultEmptyName());
// c6 (BD 6) is a Boxcar
c6.setLoadName(CarLoads.instance().getDefaultEmptyName());
// c7 (7) is a Boxcar
c7.setLoadName(CarLoads.instance().getDefaultEmptyName());
// c8 (8) is a Boxcar
c8.setLoadName("Trucks");
// c9 (9) is a Boxcar
c9.setLoadName(CarLoads.instance().getDefaultEmptyName());
Location Acton = lmanager.getLocationByName("Acton MA");
Location Bedford = lmanager.getLocationByName("Bedford MA");
Location Clinton = lmanager.getLocationByName("Clinton MA");
Track CS1 = Clinton.getTrackByName("Clinton Siding 1", Track.SPUR);
Track AS1 = Acton.getTrackByName("Acton Siding 1", Track.SPUR);
AS1.setTrainDirections(Track.NORTH + Track.SOUTH);
Track AS2 = Acton.getTrackByName("Acton Siding 2", Track.SPUR);
Track AS3 = Acton.addTrack("Acton Siding 3", Track.SPUR);
AS3.setLength(300);
Track AY = Acton.getTrackByName("Acton Yard", Track.YARD);
Track AI = Acton.getTrackByName("Acton Interchange", Track.INTERCHANGE);
// create schedules
ScheduleManager scheduleManager = ScheduleManager.instance();
Schedule schA = scheduleManager.newSchedule("Schedule Action");
ScheduleItem schAItem1 = schA.addItem("Boxcar");
schAItem1.setReceiveLoadName("Cardboard");
schAItem1.setShipLoadName("Scrap");
ScheduleItem schAItem2 = schA.addItem("Gon");
schAItem2.setReceiveLoadName("Trucks");
schAItem2.setShipLoadName("Tires");
schAItem2.setDestination(Bedford);
ScheduleItem schAItem3 = schA.addItem("Boxcar");
schAItem3.setReceiveLoadName("Trucks");
schAItem3.setShipLoadName("Wire");
schAItem3.setDestination(Clinton);
schAItem3.setDestinationTrack(CS1);
ScheduleItem schAItem4 = schA.addItem("Flat");
schAItem4.setReceiveLoadName("Trucks");
schAItem4.setShipLoadName("Coils");
schAItem4.setDestination(Bedford);
ScheduleItem schAItem5 = schA.addItem("Flat");
schAItem5.setReceiveLoadName("Coils");
schAItem5.setShipLoadName("Trucks");
schAItem5.setDestination(Bedford);
ScheduleItem schAItem6 = schA.addItem("Boxcar");
schAItem6.setReceiveLoadName("Scrap");
schAItem6.setShipLoadName("E");
ScheduleItem schAItem7 = schA.addItem("Boxcar");
schAItem7.setReceiveLoadName("Wire");
schAItem7.setShipLoadName("L");
// add schedules to tracks
AS1.setScheduleId(schA.getId());
AS1.setScheduleMode(Track.SEQUENTIAL);
AS2.setScheduleId(schA.getId());
AS2.setScheduleMode(Track.SEQUENTIAL);
AS3.setScheduleId(schA.getId());
// put Action Siding 3 into match mode
AS3.setScheduleMode(Track.MATCH);
// place cars
Assert.assertEquals("Place car", Track.OKAY, c3.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c4.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c5.setLocation(Acton, AS2));
Assert.assertEquals("Place car", Track.OKAY, c6.setLocation(Acton, AS2));
Assert.assertEquals("Place car", Track.OKAY, c7.setLocation(Acton, AS3));
Assert.assertEquals("Place car", Track.OKAY, c8.setLocation(Acton, AY));
Assert.assertEquals("Place car", Track.OKAY, c9.setLocation(Acton, AI));
// Build train
Train ActonToBedfordTrain = tmanager.getTrainByName("Acton to Bedford");
Route ActonToBeford = ActonToBedfordTrain.getRoute();
RouteLocation rl = ActonToBeford.getDepartsRouteLocation();
RouteLocation rd = ActonToBeford.getLastLocationByName("Bedford MA");
// increase the number of moves so all cars are used
rl.setMaxCarMoves(10);
rd.setMaxCarMoves(10);
// kill the Clinton to Danbury train
Train ClintonToDanburyTrain = tmanager.getTrainByName("Clinton to Danbury");
tmanager.deregister(ClintonToDanburyTrain);
ActonToBedfordTrain.build();
Assert.assertTrue("Acton train built", ActonToBedfordTrain.isBuilt());
// check cars
Assert.assertEquals("Car BA 3 destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "Acton Siding 2", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BA 3 load", "Cardboard", c3.getLoadName());
Assert.assertEquals("Car BA 3 next load", "Scrap", c3.getNextLoadName());
Assert.assertEquals("Car BB 4 destination", "Acton MA", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "Acton Siding 3", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Bedford MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "", c4.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 load", "Trucks", c4.getLoadName());
Assert.assertEquals("Car BB 4 next load", "Coils", c4.getNextLoadName());
Assert.assertEquals("Car BC 5 destination", "Bedford MA", c5.getDestinationName());
Assert.assertEquals("Car BC 5 destination track", "Bedford Siding 1", c5.getDestinationTrackName());
Assert.assertEquals("Car BC 5 final destination", "", c5.getFinalDestinationName());
Assert.assertEquals("Car BC 5 final destination track", "", c5.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 5 load", "E", c5.getLoadName());
Assert.assertEquals("Car BC 5 next load", "", c5.getNextLoadName());
Assert.assertEquals("Car BD 6 destination", "Bedford MA", c6.getDestinationName());
Assert.assertEquals("Car BD 6 destination track", "Bedford Siding 2", c6.getDestinationTrackName());
Assert.assertEquals("Car BD 6 final destination", "", c6.getFinalDestinationName());
Assert.assertEquals("Car BD 6 final destination track", "", c6.getFinalDestinationTrackName());
Assert.assertEquals("Car BD 6 load", "E", c6.getLoadName());
Assert.assertEquals("Car BD 6 next load", "", c6.getNextLoadName());
Assert.assertEquals("Car BA 7 destination", "Bedford MA", c7.getDestinationName());
Assert.assertEquals("Car BA 7 destination track", "Bedford Yard", c7.getDestinationTrackName());
Assert.assertEquals("Car BA 7 final destination", "", c7.getFinalDestinationName());
Assert.assertEquals("Car BA 7 final destination track", "", c7.getFinalDestinationTrackName());
Assert.assertEquals("Car BA 7 load", "E", c7.getLoadName());
Assert.assertEquals("Car BA 7 next load", "", c7.getNextLoadName());
Assert.assertEquals("Car BB 8 destination", "Acton MA", c8.getDestinationName());
Assert.assertEquals("Car BB 8 destination track", "Acton Siding 3", c8.getDestinationTrackName());
Assert.assertEquals("Car BB 8 final destination", "Clinton MA", c8.getFinalDestinationName());
Assert.assertEquals("Car BB 8 final destination track", "Clinton Siding 1", c8.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 8 load", "Trucks", c8.getLoadName());
Assert.assertEquals("Car BB 8 next load", "Wire", c8.getNextLoadName());
Assert.assertEquals("Car BC 9 destination", "Bedford MA", c9.getDestinationName());
Assert.assertEquals("Car BC 9 destination track", "Bedford Interchange", c9.getDestinationTrackName());
Assert.assertEquals("Car BC 9 final destination", "", c9.getFinalDestinationName());
Assert.assertEquals("Car BC 9 final destination track", "", c9.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 9 load", "E", c9.getLoadName());
Assert.assertEquals("Car BC 9 next load", "", c9.getNextLoadName());
ActonToBedfordTrain.terminate();
// Build train
Train BedfordToActonTrain = tmanager.newTrain("BedfordToActonToBedford");
Route BedfordToActon = RouteManager.instance().newRoute("BedfordToActonToBedford");
RouteLocation rlB2 = BedfordToActon.addLocation(Bedford);
RouteLocation rlA2 = BedfordToActon.addLocation(Acton);
RouteLocation rlB3 = BedfordToActon.addLocation(Bedford);
// increase the number of moves so all cars are used
rlB2.setMaxCarMoves(10);
rlA2.setMaxCarMoves(10);
rlB3.setMaxCarMoves(10);
BedfordToActonTrain.setRoute(BedfordToActon);
BedfordToActonTrain.build();
// check cars
Assert.assertEquals("Car BA 3 destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "Acton Siding 3", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BA 3 load", "Scrap", c3.getLoadName());
Assert.assertEquals("Car BA 3 next load", "E", c3.getNextLoadName());
Assert.assertEquals("Car BB 4 destination", "Bedford MA", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "Bedford Yard", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "", c4.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 load", "Coils", c4.getLoadName());
Assert.assertEquals("Car BB 4 next load", "", c4.getNextLoadName());
Assert.assertEquals("Car BC 5 destination", "Acton MA", c5.getDestinationName());
Assert.assertEquals("Car BC 5 destination track", "Acton Yard", c5.getDestinationTrackName());
Assert.assertEquals("Car BC 5 final destination", "", c5.getFinalDestinationName());
Assert.assertEquals("Car BC 5 final destination track", "", c5.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 5 load", "L", c5.getLoadName());
Assert.assertEquals("Car BC 5 next load", "", c5.getNextLoadName());
Assert.assertEquals("Car BD 6 destination", "Acton MA", c6.getDestinationName());
Assert.assertEquals("Car BD 6 destination track", "Acton Interchange", c6.getDestinationTrackName());
Assert.assertEquals("Car BD 6 final destination", "", c6.getFinalDestinationName());
Assert.assertEquals("Car BD 6 final destination track", "", c6.getFinalDestinationTrackName());
Assert.assertEquals("Car BD 6 load", "L", c6.getLoadName());
Assert.assertEquals("Car BD 6 next load", "", c6.getNextLoadName());
Assert.assertEquals("Car BA 7 destination", "Acton MA", c7.getDestinationName());
Assert.assertEquals("Car BA 7 destination track", "Acton Yard", c7.getDestinationTrackName());
Assert.assertEquals("Car BA 7 final destination", "", c7.getFinalDestinationName());
Assert.assertEquals("Car BA 7 final destination track", "", c7.getFinalDestinationTrackName());
Assert.assertEquals("Car BA 7 load", "E", c7.getLoadName());
Assert.assertEquals("Car BA 7 next load", "", c7.getNextLoadName());
Assert.assertEquals("Car BB 8 destination", "Bedford MA", c8.getDestinationName());
Assert.assertEquals("Car BB 8 destination track", "Bedford Interchange", c8.getDestinationTrackName());
Assert.assertEquals("Car BB 8 final destination", "Clinton MA", c8.getFinalDestinationName());
Assert.assertEquals("Car BB 8 final destination track", "Clinton Siding 1", c8.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 8 load", "Wire", c8.getLoadName());
Assert.assertEquals("Car BB 8 next load", "", c8.getNextLoadName());
Assert.assertEquals("Car BC 9 destination", "Acton MA", c9.getDestinationName());
Assert.assertEquals("Car BC 9 destination track", "Acton Interchange", c9.getDestinationTrackName());
Assert.assertEquals("Car BC 9 final destination", "", c9.getFinalDestinationName());
Assert.assertEquals("Car BC 9 final destination track", "", c9.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 9 load", "E", c9.getLoadName());
Assert.assertEquals("Car BC 9 next load", "", c9.getNextLoadName());
BedfordToActonTrain.terminate();
}
use of jmri.jmrit.operations.routes.Route in project JMRI by JMRI.
the class OperationsCarRouterTest method testRoutingWithTrains.
// Use trains to move cars
public void testRoutingWithTrains() {
TrainManager tmanager = TrainManager.instance();
CarManager cmanager = CarManager.instance();
LocationManager lmanager = LocationManager.instance();
loadLocationsTrainsAndCars();
List<Train> trains = tmanager.getTrainsByNameList();
Assert.assertEquals("confirm number of trains", 7, trains.size());
Train ActonTrain = tmanager.getTrainByName("Acton Local");
Train ActonToBedfordTrain = tmanager.getTrainByName("Acton to Bedford");
Train BedfordToClintonTrain = tmanager.getTrainByName("Bedford to Clinton");
Train ClintonToDanburyTrain = tmanager.getTrainByName("Clinton to Danbury");
Train DanburyToEssexTrain = tmanager.getTrainByName("Danbury to Essex");
Train EssexToFoxboroTrain = tmanager.getTrainByName("Essex to Foxboro");
Car c3 = cmanager.getByRoadAndNumber("BA", "3");
Car c4 = cmanager.getByRoadAndNumber("BB", "4");
Location Acton = lmanager.getLocationByName("Acton MA");
Track AS1 = Acton.getTrackByName("Acton Siding 1", Track.SPUR);
// set the depart track Acton to service by local train only
AS1.setTrainDirections(0);
Location Essex = lmanager.getLocationByName("Essex MA");
Track ES2 = Essex.getTrackByName("Essex Siding 2", Track.SPUR);
Location Foxboro = lmanager.getLocationByName("Foxboro MA");
Location Gulf = lmanager.newLocation("Gulf");
// place cars
Assert.assertEquals("Place car", Track.OKAY, c3.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c4.setLocation(Acton, AS1));
// confirm cars are in Acton
Assert.assertEquals("car's location Acton", "Acton MA", c3.getLocationName());
Assert.assertEquals("car's location Acton", "Acton Siding 1", c3.getTrackName());
Assert.assertEquals("car's location Acton", "Acton MA", c4.getLocationName());
Assert.assertEquals("car's location Acton", "Acton Siding 1", c4.getTrackName());
// set final destination Essex
c3.setFinalDestination(Essex);
c3.setFinalDestinationTrack(ES2);
c3.setLoadName("L");
c3.setReturnWhenEmptyDestination(Foxboro);
// final destination Gulf is not reachable, so car must move
c4.setFinalDestination(Gulf);
ActonTrain.build();
Assert.assertEquals("car's destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("car's destinaton track", "Acton Interchange", c3.getDestinationTrackName());
Assert.assertEquals("car's final destinaton", Essex, c3.getFinalDestination());
Assert.assertEquals("car's final destinaton track", ES2, c3.getFinalDestinationTrack());
Assert.assertEquals("car's destination", "Acton MA", c4.getDestinationName());
Assert.assertEquals("car's destinaton track", "Acton Yard", c4.getDestinationTrackName());
Assert.assertEquals("car's final destinaton", Gulf, c4.getFinalDestination());
Assert.assertEquals("car's final destinaton track", null, c4.getFinalDestinationTrack());
ActonTrain.reset();
// check car's destinations after reset
Assert.assertEquals("car's destination", "", c3.getDestinationName());
Assert.assertEquals("car's destinaton track", "", c3.getDestinationTrackName());
Assert.assertEquals("car's final destinaton", Essex, c3.getFinalDestination());
Assert.assertEquals("car's final destinaton track", ES2, c3.getFinalDestinationTrack());
Assert.assertEquals("car's load", "L", c3.getLoadName());
Assert.assertEquals("car's final destinaton", Gulf, c4.getFinalDestination());
Assert.assertEquals("car's final destinaton track", null, c4.getFinalDestinationTrack());
ActonTrain.build();
ActonTrain.terminate();
// confirm cars have moved
Assert.assertEquals("car's location Acton", "Acton MA", c3.getLocationName());
Assert.assertEquals("car's location Acton", "Acton Interchange", c3.getTrackName());
// as of 5/4/2011 the car's destination is set to null, but the final destination continues to exist
Assert.assertEquals("car's destination", "", c3.getDestinationName());
Assert.assertEquals("car's destination track", "", c3.getDestinationTrackName());
Assert.assertEquals("car's final destinaton", Essex, c3.getFinalDestination());
Assert.assertEquals("car's final destinaton track", ES2, c3.getFinalDestinationTrack());
Assert.assertEquals("car's load", "L", c3.getLoadName());
Assert.assertEquals("car's location Acton", "Acton MA", c4.getLocationName());
Assert.assertEquals("car's location Acton", "Acton Yard", c4.getTrackName());
Assert.assertEquals("car's destination", "", c4.getDestinationName());
Assert.assertEquals("car's destination track", "", c4.getDestinationTrackName());
// Place a maximum length restriction on the train
Route route = ActonToBedfordTrain.getRoute();
RouteLocation rlActon = route.getDepartsRouteLocation();
rlActon.setMaxTrainLength(c3.getTotalLength());
ActonToBedfordTrain.build();
Assert.assertEquals("car's destination", "Bedford MA", c3.getDestinationName());
Assert.assertEquals("car's destinaton track", "Bedford Interchange", c3.getDestinationTrackName());
Assert.assertEquals("car's final destinaton", Essex, c3.getFinalDestination());
Assert.assertEquals("car's final destinaton track", ES2, c3.getFinalDestinationTrack());
Assert.assertEquals("car's destination", "", c4.getDestinationName());
Assert.assertEquals("car's destinaton track", "", c4.getDestinationTrackName());
Assert.assertEquals("car's final destinaton", Gulf, c4.getFinalDestination());
Assert.assertEquals("car's final destinaton track", null, c4.getFinalDestinationTrack());
ActonToBedfordTrain.reset();
// restore
rlActon.setMaxTrainLength(Setup.getMaxTrainLength());
ActonToBedfordTrain.build();
ActonToBedfordTrain.terminate();
// confirm cars have moved
Assert.assertEquals("car's location Bedford", "Bedford MA", c3.getLocationName());
Assert.assertEquals("car's location Bedford", "Bedford Interchange", c3.getTrackName());
Assert.assertEquals("car's destination", "", c3.getDestinationName());
Assert.assertEquals("car's destination track", "", c3.getDestinationTrackName());
Assert.assertEquals("car's load", "L", c3.getLoadName());
Assert.assertEquals("car's final destinaton", Essex, c3.getFinalDestination());
Assert.assertEquals("car's final destinaton track", ES2, c3.getFinalDestinationTrack());
Assert.assertEquals("car's location Bedford", "Bedford MA", c4.getLocationName());
Assert.assertEquals("car's location Bedford", "Bedford Siding 1", c4.getTrackName());
Assert.assertEquals("car's destination", "", c4.getDestinationName());
Assert.assertEquals("car's destination track", "", c4.getDestinationTrackName());
BedfordToClintonTrain.build();
BedfordToClintonTrain.terminate();
// confirm cars have moved
Assert.assertEquals("car's location Clinton", "Clinton MA", c3.getLocationName());
Assert.assertEquals("car's location Clinton", "Clinton Interchange", c3.getTrackName());
Assert.assertEquals("car's destination", "", c3.getDestinationName());
Assert.assertEquals("car's destination track", "", c3.getDestinationTrackName());
Assert.assertEquals("car's load", "L", c3.getLoadName());
Assert.assertEquals("car's final destinaton", Essex, c3.getFinalDestination());
Assert.assertEquals("car's final destinaton track", ES2, c3.getFinalDestinationTrack());
Assert.assertEquals("car's location Clinton", "Clinton MA", c4.getLocationName());
Assert.assertEquals("car's location Clinton", "Clinton Siding 1", c4.getTrackName());
Assert.assertEquals("car's destination", "", c4.getDestinationName());
Assert.assertEquals("car's destination track", "", c4.getDestinationTrackName());
ClintonToDanburyTrain.build();
ClintonToDanburyTrain.terminate();
// confirm cars have moved
Assert.assertEquals("car's location Danbury", "Danbury MA", c3.getLocationName());
Assert.assertEquals("car's location Danbury", "Danbury Interchange", c3.getTrackName());
Assert.assertEquals("car's destination", "", c3.getDestinationName());
Assert.assertEquals("car's destination track", "", c3.getDestinationTrackName());
Assert.assertEquals("car's load", "L", c3.getLoadName());
Assert.assertEquals("car's final destinaton", Essex, c3.getFinalDestination());
Assert.assertEquals("car's final destinaton track", ES2, c3.getFinalDestinationTrack());
Assert.assertEquals("car's location Danbury", "Danbury MA", c4.getLocationName());
Assert.assertEquals("car's location Danbury", "Danbury Siding 1", c4.getTrackName());
Assert.assertEquals("car's destination", "", c4.getDestinationName());
Assert.assertEquals("car's destination track", "", c4.getDestinationTrackName());
DanburyToEssexTrain.build();
DanburyToEssexTrain.terminate();
// confirm cars have moved car has arrived at final destination Essex
Assert.assertEquals("car's location Essex", "Essex MA", c3.getLocationName());
Assert.assertEquals("car's location Essex", "Essex Siding 2", c3.getTrackName());
Assert.assertEquals("car's destination", "", c3.getDestinationName());
Assert.assertEquals("car's destination track", "", c3.getDestinationTrackName());
Assert.assertEquals("car's load", "E", c3.getLoadName());
// car when empty must return to Foxboro
Assert.assertEquals("car's final destinaton", Foxboro, c3.getFinalDestination());
Assert.assertEquals("car's final destinaton track", null, c3.getFinalDestinationTrack());
Assert.assertEquals("car's location Essex", "Essex MA", c4.getLocationName());
Assert.assertEquals("car's location Essex", "Essex Siding 1", c4.getTrackName());
Assert.assertEquals("car's destination", "", c4.getDestinationName());
Assert.assertEquals("car's destination track", "", c4.getDestinationTrackName());
EssexToFoxboroTrain.build();
EssexToFoxboroTrain.terminate();
// confirm cars have moved
Assert.assertEquals("car's location Foxboro", "Foxboro MA", c3.getLocationName());
Assert.assertEquals("car's location Foxboro", "Foxboro Siding 1", c3.getTrackName());
Assert.assertEquals("car's destination", "", c3.getDestinationName());
Assert.assertEquals("car's destination track", "", c3.getDestinationTrackName());
Assert.assertEquals("car's load", "L", c3.getLoadName());
Assert.assertEquals("car's location Foxboro", "Foxboro MA", c4.getLocationName());
Assert.assertEquals("car's location Foxboro", "Foxboro Siding 2", c4.getTrackName());
Assert.assertEquals("car's destination", "", c4.getDestinationName());
Assert.assertEquals("car's destination track", "", c4.getDestinationTrackName());
}
Aggregations