use of jmri.jmrit.operations.routes.RouteManager in project JMRI by JMRI.
the class TrainTest method testRouteLocationsBuild.
public void testRouteLocationsBuild() {
TrainManager tmanager = TrainManager.instance();
RouteManager rmanager = RouteManager.instance();
LocationManager lmanager = LocationManager.instance();
Train train = tmanager.newTrain("Test");
// exercise manifest build
train.setRailroadName("Working Railroad");
train.setComment("One Hard Working Train");
// now add a route that doesn't have any locations
Route route = rmanager.newRoute("TestRoute");
train.setRoute(route);
// now add a location to the route
Location depart = lmanager.newLocation("depart");
RouteLocation rl = route.addLocation(depart);
train.build();
Assert.assertTrue("Train should build", train.isBuilt());
Assert.assertEquals("Train built", Train.CODE_PARTIAL_BUILT, train.getStatusCode());
// delete location
lmanager.deregister(depart);
train.build();
Assert.assertFalse("Train should not build, location deleted", train.isBuilt());
Assert.assertEquals("Train build failed", Train.CODE_BUILD_FAILED, train.getStatusCode());
// recreate location
depart = lmanager.newLocation("depart");
train.build();
Assert.assertFalse("Train should not build, location recreated, but not part of route", train.isBuilt());
route.deleteLocation(rl);
route.addLocation(depart);
train.build();
Assert.assertTrue("Train should build, route repaired", train.isBuilt());
Location terminate = lmanager.newLocation("terminate");
rl = route.addLocation(terminate);
train.build();
Assert.assertTrue("Train should build, route has two locations", train.isBuilt());
// delete terminal location
lmanager.deregister(terminate);
train.build();
Assert.assertFalse("Train should not build, terminal location deleted", train.isBuilt());
route.deleteLocation(rl);
terminate = lmanager.newLocation("terminate");
rl = route.addLocation(terminate);
train.build();
Assert.assertTrue("Train should build, route has been repaired", train.isBuilt());
Location middle = lmanager.newLocation("middle");
// staging tracks in the middle of the route are ignored
middle.addTrack("staging in the middle", Track.STAGING);
// next 5 lines exercise manifest build messages
Setup.setPrintLocationCommentsEnabled(true);
middle.setComment("Middle comment");
// put location in middle of route
rl = route.addLocation(middle, 2);
rl.setDepartureTime("12:30");
rl.setComment("This location has a departure time");
train.build();
Assert.assertTrue("Train should build, three location route", train.isBuilt());
// delete location in the middle
lmanager.deregister(middle);
train.build();
Assert.assertFalse("Train should not build, middle location deleted", train.isBuilt());
// remove the middle location from the route
route.deleteLocation(rl);
train.build();
Assert.assertTrue("Train should build, two location route", train.isBuilt());
}
use of jmri.jmrit.operations.routes.RouteManager in project JMRI by JMRI.
the class TrainTest method testBuildRequiresCars.
public void testBuildRequiresCars() {
TrainManager tmanager = TrainManager.instance();
RouteManager rmanager = RouteManager.instance();
LocationManager lmanager = LocationManager.instance();
Train train = tmanager.newTrain("Test");
// exercise manifest build
train.setRailroadName("Working Railroad");
train.setComment("One Hard Working Train");
// now add a route that doesn't have any locations
Route route = rmanager.newRoute("TestRoute");
train.setRoute(route);
// now add locations to the route
Location depart = lmanager.newLocation("depart");
route.addLocation(depart);
Location terminate = lmanager.newLocation("terminate");
route.addLocation(terminate);
Location middle = lmanager.newLocation("middle");
// put location in middle of route
route.addLocation(middle, 2);
// Build option require cars
Control.fullTrainOnly = true;
train.build();
Assert.assertFalse("Train should not build, requires cars", train.isBuilt());
// restore control
Control.fullTrainOnly = false;
train.build();
Assert.assertTrue("Train should build, build doesn't require cars", train.isBuilt());
}
use of jmri.jmrit.operations.routes.RouteManager in project JMRI by JMRI.
the class TrainTest method testAutoEnginesBuildFailNoEngines.
public void testAutoEnginesBuildFailNoEngines() {
TrainManager tmanager = TrainManager.instance();
RouteManager rmanager = RouteManager.instance();
LocationManager lmanager = LocationManager.instance();
// This test uses the maximum length of a train in route
Setup.setMaxTrainLength(1000);
Train train = tmanager.newTrain("AutoEngineTest");
train.setNumberEngines(Train.AUTO);
Route route = rmanager.newRoute("AutoEngineTest");
train.setRoute(route);
Location A = lmanager.newLocation("A");
Location B = lmanager.newLocation("B");
Location C = lmanager.newLocation("C");
Track At = A.addTrack("track", Track.SPUR);
Track Bt = B.addTrack("track", Track.SPUR);
Track Ct = C.addTrack("track", Track.SPUR);
At.setLength(300);
Bt.setLength(300);
Ct.setLength(300);
RouteLocation rA = route.addLocation(A);
RouteLocation rB = route.addLocation(B);
RouteLocation rC = route.addLocation(C);
rA.setMaxCarMoves(5);
rB.setMaxCarMoves(5);
rC.setMaxCarMoves(5);
// Auto Engines calculates the number of engines based on requested moves in the route
train.build();
Assert.assertFalse("Train should not build, no engines", train.isBuilt());
}
use of jmri.jmrit.operations.routes.RouteManager in project JMRI by JMRI.
the class TrainTest method testRouteLocationBuild.
public void testRouteLocationBuild() {
TrainManager tmanager = TrainManager.instance();
RouteManager rmanager = RouteManager.instance();
Train train = tmanager.newTrain("Test");
// exercise manifest build
train.setRailroadName("Working Railroad");
train.setComment("One Hard Working Train");
// now add a route that doesn't have any locations
Route route = rmanager.newRoute("TestRoute");
train.setRoute(route);
train.build();
Assert.assertFalse("Train should not build, no route locations", train.isBuilt());
Assert.assertEquals("Train build failed", Train.CODE_BUILD_FAILED, train.getStatusCode());
}
use of jmri.jmrit.operations.routes.RouteManager 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
}
Aggregations