use of jmri.jmrit.operations.rollingstock.cars.CarManager in project JMRI by JMRI.
the class JsonUtil method getCarsForTrain.
private ArrayNode getCarsForTrain(Locale locale, Train train) {
ArrayNode clan = mapper.createArrayNode();
CarManager carManager = CarManager.instance();
List<Car> carList = carManager.getByTrainDestinationList(train);
carList.forEach((car) -> {
//add each car's data to the carList array
clan.add(getCar(locale, car.getId()).get(DATA));
});
//return array of car data
return clan;
}
use of jmri.jmrit.operations.rollingstock.cars.CarManager in project JMRI by JMRI.
the class PrintLocationsAction method printAnalysisSelected.
private void printAnalysisSelected() throws IOException {
CarManager carManager = CarManager.instance();
List<Location> locations = manager.getLocationsByNameList();
List<RollingStock> cars = carManager.getByLocationList();
String[] carTypes = CarTypes.instance().getNames();
String s = Bundle.getMessage("TrackAnalysis") + NEW_LINE;
writer.write(s);
// print the car type being analyzed
for (String type : carTypes) {
// get the total length for a given car type
int numberOfCars = 0;
int totalTrackLength = 0;
for (RollingStock car : cars) {
if (car.getTypeName().equals(type) && car.getLocation() != null) {
numberOfCars++;
totalTrackLength += car.getTotalLength();
}
}
writer.write(MessageFormat.format(Bundle.getMessage("NumberTypeLength"), new Object[] { numberOfCars, type, totalTrackLength, Setup.getLengthUnit().toLowerCase() }) + NEW_LINE);
// don't bother reporting when the number of cars for a given type is zero
if (numberOfCars > 0) {
// spurs
writer.write(SPACE + MessageFormat.format(Bundle.getMessage("SpurTrackThatAccept"), new Object[] { type }) + NEW_LINE);
int trackLength = getTrackLengthAcceptType(locations, type, Track.SPUR);
if (trackLength > 0) {
writer.write(SPACE + MessageFormat.format(Bundle.getMessage("TotalLengthSpur"), new Object[] { type, trackLength, Setup.getLengthUnit().toLowerCase(), 100 * totalTrackLength / trackLength }) + NEW_LINE);
} else {
writer.write(SPACE + Bundle.getMessage("None") + NEW_LINE);
}
// yards
writer.write(SPACE + MessageFormat.format(Bundle.getMessage("YardTrackThatAccept"), new Object[] { type }) + NEW_LINE);
trackLength = getTrackLengthAcceptType(locations, type, Track.YARD);
if (trackLength > 0) {
writer.write(SPACE + MessageFormat.format(Bundle.getMessage("TotalLengthYard"), new Object[] { type, trackLength, Setup.getLengthUnit().toLowerCase(), 100 * totalTrackLength / trackLength }) + NEW_LINE);
} else {
writer.write(SPACE + Bundle.getMessage("None") + NEW_LINE);
}
// interchanges
writer.write(SPACE + MessageFormat.format(Bundle.getMessage("InterchangesThatAccept"), new Object[] { type }) + NEW_LINE);
trackLength = getTrackLengthAcceptType(locations, type, Track.INTERCHANGE);
if (trackLength > 0) {
writer.write(SPACE + MessageFormat.format(Bundle.getMessage("TotalLengthInterchange"), new Object[] { type, trackLength, Setup.getLengthUnit().toLowerCase(), 100 * totalTrackLength / trackLength }) + NEW_LINE);
} else {
writer.write(SPACE + Bundle.getMessage("None") + NEW_LINE);
}
// staging
if (showStaging) {
writer.write(SPACE + MessageFormat.format(Bundle.getMessage("StageTrackThatAccept"), new Object[] { type }) + NEW_LINE);
trackLength = getTrackLengthAcceptType(locations, type, Track.STAGING);
if (trackLength > 0) {
writer.write(SPACE + MessageFormat.format(Bundle.getMessage("TotalLengthStage"), new Object[] { type, trackLength, Setup.getLengthUnit().toLowerCase(), 100 * totalTrackLength / trackLength }) + NEW_LINE);
} else {
writer.write(SPACE + Bundle.getMessage("None") + NEW_LINE);
}
}
}
}
}
use of jmri.jmrit.operations.rollingstock.cars.CarManager in project JMRI by JMRI.
the class TrainCommon method addCarsLocationUnknown.
protected void addCarsLocationUnknown(PrintWriter file, boolean isManifest) {
CarManager carManager = CarManager.instance();
List<Car> cars = carManager.getCarsLocationUnknown();
if (cars.size() == 0) {
// no cars to search for!
return;
}
newLine(file);
newLine(file, Setup.getMiaComment(), isManifest);
for (Car car : cars) {
addSearchForCar(file, car);
}
}
use of jmri.jmrit.operations.rollingstock.cars.CarManager in project JMRI by JMRI.
the class JsonUtil method getCarsForTrain.
private static ArrayNode getCarsForTrain(Locale locale, Train train) {
ArrayNode clan = mapper.createArrayNode();
CarManager carManager = CarManager.instance();
List<Car> carList = carManager.getByTrainDestinationList(train);
for (Car car : carList) {
//add each car's data to the carList array
clan.add(getCar(locale, car.getId()).get(DATA));
}
//return array of car data
return clan;
}
use of jmri.jmrit.operations.rollingstock.cars.CarManager 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