Search in sources :

Example 86 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation 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
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) Car(jmri.jmrit.operations.rollingstock.cars.Car) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Train(jmri.jmrit.operations.trains.Train) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) TrainManager(jmri.jmrit.operations.trains.TrainManager) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 87 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class OperationsCarRouterTest method testRoutingWithSchedulesLocal.

/* This test confirms that schedules can be linked together.
     * Note that there are schedules at Essex that are still active
     * but not reachable because the Clinton to Danbury train is
     * removed as part of this test.
     * has 5 tracks, 3 sidings, yard, and an interchange track.
     *  
     */
public void testRoutingWithSchedulesLocal() {
    TrainManager tmanager = TrainManager.instance();
    CarManager cmanager = CarManager.instance();
    LocationManager lmanager = LocationManager.instance();
    loadLocationsTrainsAndCars();
    List<Train> trains = tmanager.getTrainsByNameList();
    Assert.assertEquals("confirm number of trains", 7, trains.size());
    Car c3 = cmanager.getByRoadAndNumber("BA", "3");
    Car c4 = cmanager.getByRoadAndNumber("BB", "4");
    Car c5 = cmanager.getByRoadAndNumber("BC", "5");
    Car c6 = cmanager.getByRoadAndNumber("BD", "6");
    Car c7 = cmanager.getByRoadAndNumber("BA", "7");
    Car c8 = cmanager.getByRoadAndNumber("BB", "8");
    Car c9 = cmanager.getByRoadAndNumber("BC", "9");
    // c3 (BA 3) is a Boxcar
    c3.setLoadName("Cardboard");
    // c4 (BB 4) is a Flat
    c4.setLoadName("Trucks");
    // c5 (BC 5) is a Boxcar
    c5.setLoadName(CarLoads.instance().getDefaultEmptyName());
    // c6 (BD 6) is a Boxcar
    c6.setLoadName(CarLoads.instance().getDefaultEmptyName());
    // c7 (7) is a Boxcar
    c7.setLoadName(CarLoads.instance().getDefaultEmptyName());
    // c8 (8) is a Boxcar
    c8.setLoadName("Trucks");
    // c9 (9) is a Boxcar
    c9.setLoadName(CarLoads.instance().getDefaultEmptyName());
    Location Acton = lmanager.getLocationByName("Acton MA");
    Location Bedford = lmanager.getLocationByName("Bedford MA");
    Location Clinton = lmanager.getLocationByName("Clinton MA");
    Track CS1 = Clinton.getTrackByName("Clinton Siding 1", Track.SPUR);
    Track AS1 = Acton.getTrackByName("Acton Siding 1", Track.SPUR);
    AS1.setTrainDirections(Track.NORTH + Track.SOUTH);
    Track AS2 = Acton.getTrackByName("Acton Siding 2", Track.SPUR);
    Track AS3 = Acton.addTrack("Acton Siding 3", Track.SPUR);
    AS3.setLength(300);
    Track AY = Acton.getTrackByName("Acton Yard", Track.YARD);
    Track AI = Acton.getTrackByName("Acton Interchange", Track.INTERCHANGE);
    // create schedules
    ScheduleManager scheduleManager = ScheduleManager.instance();
    Schedule schA = scheduleManager.newSchedule("Schedule Action");
    ScheduleItem schAItem1 = schA.addItem("Boxcar");
    schAItem1.setReceiveLoadName("Cardboard");
    schAItem1.setShipLoadName("Scrap");
    ScheduleItem schAItem2 = schA.addItem("Gon");
    schAItem2.setReceiveLoadName("Trucks");
    schAItem2.setShipLoadName("Tires");
    schAItem2.setDestination(Bedford);
    ScheduleItem schAItem3 = schA.addItem("Boxcar");
    schAItem3.setReceiveLoadName("Trucks");
    schAItem3.setShipLoadName("Wire");
    schAItem3.setDestination(Clinton);
    schAItem3.setDestinationTrack(CS1);
    ScheduleItem schAItem4 = schA.addItem("Flat");
    schAItem4.setReceiveLoadName("Trucks");
    schAItem4.setShipLoadName("Coils");
    schAItem4.setDestination(Bedford);
    ScheduleItem schAItem5 = schA.addItem("Flat");
    schAItem5.setReceiveLoadName("Coils");
    schAItem5.setShipLoadName("Trucks");
    schAItem5.setDestination(Bedford);
    ScheduleItem schAItem6 = schA.addItem("Boxcar");
    schAItem6.setReceiveLoadName("Scrap");
    schAItem6.setShipLoadName("E");
    ScheduleItem schAItem7 = schA.addItem("Boxcar");
    schAItem7.setReceiveLoadName("Wire");
    schAItem7.setShipLoadName("L");
    // add schedules to tracks
    AS1.setScheduleId(schA.getId());
    AS1.setScheduleMode(Track.SEQUENTIAL);
    AS2.setScheduleId(schA.getId());
    AS2.setScheduleMode(Track.SEQUENTIAL);
    AS3.setScheduleId(schA.getId());
    // put Action Siding 3 into match mode
    AS3.setScheduleMode(Track.MATCH);
    // place cars
    Assert.assertEquals("Place car", Track.OKAY, c3.setLocation(Acton, AS1));
    Assert.assertEquals("Place car", Track.OKAY, c4.setLocation(Acton, AS1));
    Assert.assertEquals("Place car", Track.OKAY, c5.setLocation(Acton, AS2));
    Assert.assertEquals("Place car", Track.OKAY, c6.setLocation(Acton, AS2));
    Assert.assertEquals("Place car", Track.OKAY, c7.setLocation(Acton, AS3));
    Assert.assertEquals("Place car", Track.OKAY, c8.setLocation(Acton, AY));
    Assert.assertEquals("Place car", Track.OKAY, c9.setLocation(Acton, AI));
    // Build train
    Train ActonToBedfordTrain = tmanager.getTrainByName("Acton to Bedford");
    Route ActonToBeford = ActonToBedfordTrain.getRoute();
    RouteLocation rl = ActonToBeford.getDepartsRouteLocation();
    RouteLocation rd = ActonToBeford.getLastLocationByName("Bedford MA");
    // increase the number of moves so all cars are used
    rl.setMaxCarMoves(10);
    rd.setMaxCarMoves(10);
    // kill the Clinton to Danbury train
    Train ClintonToDanburyTrain = tmanager.getTrainByName("Clinton to Danbury");
    tmanager.deregister(ClintonToDanburyTrain);
    ActonToBedfordTrain.build();
    Assert.assertTrue("Acton train built", ActonToBedfordTrain.isBuilt());
    // check cars
    Assert.assertEquals("Car BA 3 destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Car BA 3 destination track", "Acton Siding 2", c3.getDestinationTrackName());
    Assert.assertEquals("Car BA 3 final destination", "", c3.getFinalDestinationName());
    Assert.assertEquals("Car BA 3 final destination track", "", c3.getFinalDestinationTrackName());
    Assert.assertEquals("Car BA 3 load", "Cardboard", c3.getLoadName());
    Assert.assertEquals("Car BA 3 next load", "Scrap", c3.getNextLoadName());
    Assert.assertEquals("Car BB 4 destination", "Acton MA", c4.getDestinationName());
    Assert.assertEquals("Car BB 4 destination track", "Acton Siding 3", c4.getDestinationTrackName());
    Assert.assertEquals("Car BB 4 final destination", "Bedford MA", c4.getFinalDestinationName());
    Assert.assertEquals("Car BB 4 final destination track", "", c4.getFinalDestinationTrackName());
    Assert.assertEquals("Car BB 4 load", "Trucks", c4.getLoadName());
    Assert.assertEquals("Car BB 4 next load", "Coils", c4.getNextLoadName());
    Assert.assertEquals("Car BC 5 destination", "Bedford MA", c5.getDestinationName());
    Assert.assertEquals("Car BC 5 destination track", "Bedford Siding 1", c5.getDestinationTrackName());
    Assert.assertEquals("Car BC 5 final destination", "", c5.getFinalDestinationName());
    Assert.assertEquals("Car BC 5 final destination track", "", c5.getFinalDestinationTrackName());
    Assert.assertEquals("Car BC 5 load", "E", c5.getLoadName());
    Assert.assertEquals("Car BC 5 next load", "", c5.getNextLoadName());
    Assert.assertEquals("Car BD 6 destination", "Bedford MA", c6.getDestinationName());
    Assert.assertEquals("Car BD 6 destination track", "Bedford Siding 2", c6.getDestinationTrackName());
    Assert.assertEquals("Car BD 6 final destination", "", c6.getFinalDestinationName());
    Assert.assertEquals("Car BD 6 final destination track", "", c6.getFinalDestinationTrackName());
    Assert.assertEquals("Car BD 6 load", "E", c6.getLoadName());
    Assert.assertEquals("Car BD 6 next load", "", c6.getNextLoadName());
    Assert.assertEquals("Car BA 7 destination", "Bedford MA", c7.getDestinationName());
    Assert.assertEquals("Car BA 7 destination track", "Bedford Yard", c7.getDestinationTrackName());
    Assert.assertEquals("Car BA 7 final destination", "", c7.getFinalDestinationName());
    Assert.assertEquals("Car BA 7 final destination track", "", c7.getFinalDestinationTrackName());
    Assert.assertEquals("Car BA 7 load", "E", c7.getLoadName());
    Assert.assertEquals("Car BA 7 next load", "", c7.getNextLoadName());
    Assert.assertEquals("Car BB 8 destination", "Acton MA", c8.getDestinationName());
    Assert.assertEquals("Car BB 8 destination track", "Acton Siding 3", c8.getDestinationTrackName());
    Assert.assertEquals("Car BB 8 final destination", "Clinton MA", c8.getFinalDestinationName());
    Assert.assertEquals("Car BB 8 final destination track", "Clinton Siding 1", c8.getFinalDestinationTrackName());
    Assert.assertEquals("Car BB 8 load", "Trucks", c8.getLoadName());
    Assert.assertEquals("Car BB 8 next load", "Wire", c8.getNextLoadName());
    Assert.assertEquals("Car BC 9 destination", "Bedford MA", c9.getDestinationName());
    Assert.assertEquals("Car BC 9 destination track", "Bedford Interchange", c9.getDestinationTrackName());
    Assert.assertEquals("Car BC 9 final destination", "", c9.getFinalDestinationName());
    Assert.assertEquals("Car BC 9 final destination track", "", c9.getFinalDestinationTrackName());
    Assert.assertEquals("Car BC 9 load", "E", c9.getLoadName());
    Assert.assertEquals("Car BC 9 next load", "", c9.getNextLoadName());
    ActonToBedfordTrain.terminate();
    // Build train
    Train BedfordToActonTrain = tmanager.newTrain("BedfordToActonToBedford");
    Route BedfordToActon = RouteManager.instance().newRoute("BedfordToActonToBedford");
    RouteLocation rlB2 = BedfordToActon.addLocation(Bedford);
    RouteLocation rlA2 = BedfordToActon.addLocation(Acton);
    RouteLocation rlB3 = BedfordToActon.addLocation(Bedford);
    // increase the number of moves so all cars are used
    rlB2.setMaxCarMoves(10);
    rlA2.setMaxCarMoves(10);
    rlB3.setMaxCarMoves(10);
    BedfordToActonTrain.setRoute(BedfordToActon);
    BedfordToActonTrain.build();
    // check cars
    Assert.assertEquals("Car BA 3 destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("Car BA 3 destination track", "Acton Siding 3", c3.getDestinationTrackName());
    Assert.assertEquals("Car BA 3 final destination", "", c3.getFinalDestinationName());
    Assert.assertEquals("Car BA 3 final destination track", "", c3.getFinalDestinationTrackName());
    Assert.assertEquals("Car BA 3 load", "Scrap", c3.getLoadName());
    Assert.assertEquals("Car BA 3 next load", "E", c3.getNextLoadName());
    Assert.assertEquals("Car BB 4 destination", "Bedford MA", c4.getDestinationName());
    Assert.assertEquals("Car BB 4 destination track", "Bedford Yard", c4.getDestinationTrackName());
    Assert.assertEquals("Car BB 4 final destination", "", c4.getFinalDestinationName());
    Assert.assertEquals("Car BB 4 final destination track", "", c4.getFinalDestinationTrackName());
    Assert.assertEquals("Car BB 4 load", "Coils", c4.getLoadName());
    Assert.assertEquals("Car BB 4 next load", "", c4.getNextLoadName());
    Assert.assertEquals("Car BC 5 destination", "Acton MA", c5.getDestinationName());
    Assert.assertEquals("Car BC 5 destination track", "Acton Yard", c5.getDestinationTrackName());
    Assert.assertEquals("Car BC 5 final destination", "", c5.getFinalDestinationName());
    Assert.assertEquals("Car BC 5 final destination track", "", c5.getFinalDestinationTrackName());
    Assert.assertEquals("Car BC 5 load", "L", c5.getLoadName());
    Assert.assertEquals("Car BC 5 next load", "", c5.getNextLoadName());
    Assert.assertEquals("Car BD 6 destination", "Acton MA", c6.getDestinationName());
    Assert.assertEquals("Car BD 6 destination track", "Acton Interchange", c6.getDestinationTrackName());
    Assert.assertEquals("Car BD 6 final destination", "", c6.getFinalDestinationName());
    Assert.assertEquals("Car BD 6 final destination track", "", c6.getFinalDestinationTrackName());
    Assert.assertEquals("Car BD 6 load", "L", c6.getLoadName());
    Assert.assertEquals("Car BD 6 next load", "", c6.getNextLoadName());
    Assert.assertEquals("Car BA 7 destination", "Acton MA", c7.getDestinationName());
    Assert.assertEquals("Car BA 7 destination track", "Acton Yard", c7.getDestinationTrackName());
    Assert.assertEquals("Car BA 7 final destination", "", c7.getFinalDestinationName());
    Assert.assertEquals("Car BA 7 final destination track", "", c7.getFinalDestinationTrackName());
    Assert.assertEquals("Car BA 7 load", "E", c7.getLoadName());
    Assert.assertEquals("Car BA 7 next load", "", c7.getNextLoadName());
    Assert.assertEquals("Car BB 8 destination", "Bedford MA", c8.getDestinationName());
    Assert.assertEquals("Car BB 8 destination track", "Bedford Interchange", c8.getDestinationTrackName());
    Assert.assertEquals("Car BB 8 final destination", "Clinton MA", c8.getFinalDestinationName());
    Assert.assertEquals("Car BB 8 final destination track", "Clinton Siding 1", c8.getFinalDestinationTrackName());
    Assert.assertEquals("Car BB 8 load", "Wire", c8.getLoadName());
    Assert.assertEquals("Car BB 8 next load", "", c8.getNextLoadName());
    Assert.assertEquals("Car BC 9 destination", "Acton MA", c9.getDestinationName());
    Assert.assertEquals("Car BC 9 destination track", "Acton Interchange", c9.getDestinationTrackName());
    Assert.assertEquals("Car BC 9 final destination", "", c9.getFinalDestinationName());
    Assert.assertEquals("Car BC 9 final destination track", "", c9.getFinalDestinationTrackName());
    Assert.assertEquals("Car BC 9 load", "E", c9.getLoadName());
    Assert.assertEquals("Car BC 9 next load", "", c9.getNextLoadName());
    BedfordToActonTrain.terminate();
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) ScheduleManager(jmri.jmrit.operations.locations.schedules.ScheduleManager) ScheduleItem(jmri.jmrit.operations.locations.schedules.ScheduleItem) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) TrainManager(jmri.jmrit.operations.trains.TrainManager) Car(jmri.jmrit.operations.rollingstock.cars.Car) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) Schedule(jmri.jmrit.operations.locations.schedules.Schedule) Train(jmri.jmrit.operations.trains.Train) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 88 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class OperationsCarRouterTest method testRoutingWithTrains.

// Use trains to move cars
public void testRoutingWithTrains() {
    TrainManager tmanager = TrainManager.instance();
    CarManager cmanager = CarManager.instance();
    LocationManager lmanager = LocationManager.instance();
    loadLocationsTrainsAndCars();
    List<Train> trains = tmanager.getTrainsByNameList();
    Assert.assertEquals("confirm number of trains", 7, trains.size());
    Train ActonTrain = tmanager.getTrainByName("Acton Local");
    Train ActonToBedfordTrain = tmanager.getTrainByName("Acton to Bedford");
    Train BedfordToClintonTrain = tmanager.getTrainByName("Bedford to Clinton");
    Train ClintonToDanburyTrain = tmanager.getTrainByName("Clinton to Danbury");
    Train DanburyToEssexTrain = tmanager.getTrainByName("Danbury to Essex");
    Train EssexToFoxboroTrain = tmanager.getTrainByName("Essex to Foxboro");
    Car c3 = cmanager.getByRoadAndNumber("BA", "3");
    Car c4 = cmanager.getByRoadAndNumber("BB", "4");
    Location Acton = lmanager.getLocationByName("Acton MA");
    Track AS1 = Acton.getTrackByName("Acton Siding 1", Track.SPUR);
    // set the depart track Acton to service by local train only
    AS1.setTrainDirections(0);
    Location Essex = lmanager.getLocationByName("Essex MA");
    Track ES2 = Essex.getTrackByName("Essex Siding 2", Track.SPUR);
    Location Foxboro = lmanager.getLocationByName("Foxboro MA");
    Location Gulf = lmanager.newLocation("Gulf");
    // place cars
    Assert.assertEquals("Place car", Track.OKAY, c3.setLocation(Acton, AS1));
    Assert.assertEquals("Place car", Track.OKAY, c4.setLocation(Acton, AS1));
    // confirm cars are in Acton
    Assert.assertEquals("car's location Acton", "Acton MA", c3.getLocationName());
    Assert.assertEquals("car's location Acton", "Acton Siding 1", c3.getTrackName());
    Assert.assertEquals("car's location Acton", "Acton MA", c4.getLocationName());
    Assert.assertEquals("car's location Acton", "Acton Siding 1", c4.getTrackName());
    // set final destination Essex
    c3.setFinalDestination(Essex);
    c3.setFinalDestinationTrack(ES2);
    c3.setLoadName("L");
    c3.setReturnWhenEmptyDestination(Foxboro);
    // final destination Gulf is not reachable, so car must move
    c4.setFinalDestination(Gulf);
    ActonTrain.build();
    Assert.assertEquals("car's destination", "Acton MA", c3.getDestinationName());
    Assert.assertEquals("car's destinaton track", "Acton Interchange", c3.getDestinationTrackName());
    Assert.assertEquals("car's final destinaton", Essex, c3.getFinalDestination());
    Assert.assertEquals("car's final destinaton track", ES2, c3.getFinalDestinationTrack());
    Assert.assertEquals("car's destination", "Acton MA", c4.getDestinationName());
    Assert.assertEquals("car's destinaton track", "Acton Yard", c4.getDestinationTrackName());
    Assert.assertEquals("car's final destinaton", Gulf, c4.getFinalDestination());
    Assert.assertEquals("car's final destinaton track", null, c4.getFinalDestinationTrack());
    ActonTrain.reset();
    // check car's destinations after reset
    Assert.assertEquals("car's destination", "", c3.getDestinationName());
    Assert.assertEquals("car's destinaton track", "", c3.getDestinationTrackName());
    Assert.assertEquals("car's final destinaton", Essex, c3.getFinalDestination());
    Assert.assertEquals("car's final destinaton track", ES2, c3.getFinalDestinationTrack());
    Assert.assertEquals("car's load", "L", c3.getLoadName());
    Assert.assertEquals("car's final destinaton", Gulf, c4.getFinalDestination());
    Assert.assertEquals("car's final destinaton track", null, c4.getFinalDestinationTrack());
    ActonTrain.build();
    ActonTrain.terminate();
    // confirm cars have moved
    Assert.assertEquals("car's location Acton", "Acton MA", c3.getLocationName());
    Assert.assertEquals("car's location Acton", "Acton Interchange", c3.getTrackName());
    // as of 5/4/2011 the car's destination is set to null, but the final destination continues to exist
    Assert.assertEquals("car's destination", "", c3.getDestinationName());
    Assert.assertEquals("car's destination track", "", c3.getDestinationTrackName());
    Assert.assertEquals("car's final destinaton", Essex, c3.getFinalDestination());
    Assert.assertEquals("car's final destinaton track", ES2, c3.getFinalDestinationTrack());
    Assert.assertEquals("car's load", "L", c3.getLoadName());
    Assert.assertEquals("car's location Acton", "Acton MA", c4.getLocationName());
    Assert.assertEquals("car's location Acton", "Acton Yard", c4.getTrackName());
    Assert.assertEquals("car's destination", "", c4.getDestinationName());
    Assert.assertEquals("car's destination track", "", c4.getDestinationTrackName());
    // Place a maximum length restriction on the train
    Route route = ActonToBedfordTrain.getRoute();
    RouteLocation rlActon = route.getDepartsRouteLocation();
    rlActon.setMaxTrainLength(c3.getTotalLength());
    ActonToBedfordTrain.build();
    Assert.assertEquals("car's destination", "Bedford MA", c3.getDestinationName());
    Assert.assertEquals("car's destinaton track", "Bedford Interchange", c3.getDestinationTrackName());
    Assert.assertEquals("car's final destinaton", Essex, c3.getFinalDestination());
    Assert.assertEquals("car's final destinaton track", ES2, c3.getFinalDestinationTrack());
    Assert.assertEquals("car's destination", "", c4.getDestinationName());
    Assert.assertEquals("car's destinaton track", "", c4.getDestinationTrackName());
    Assert.assertEquals("car's final destinaton", Gulf, c4.getFinalDestination());
    Assert.assertEquals("car's final destinaton track", null, c4.getFinalDestinationTrack());
    ActonToBedfordTrain.reset();
    // restore
    rlActon.setMaxTrainLength(Setup.getMaxTrainLength());
    ActonToBedfordTrain.build();
    ActonToBedfordTrain.terminate();
    // confirm cars have moved
    Assert.assertEquals("car's location Bedford", "Bedford MA", c3.getLocationName());
    Assert.assertEquals("car's location Bedford", "Bedford Interchange", c3.getTrackName());
    Assert.assertEquals("car's destination", "", c3.getDestinationName());
    Assert.assertEquals("car's destination track", "", c3.getDestinationTrackName());
    Assert.assertEquals("car's load", "L", c3.getLoadName());
    Assert.assertEquals("car's final destinaton", Essex, c3.getFinalDestination());
    Assert.assertEquals("car's final destinaton track", ES2, c3.getFinalDestinationTrack());
    Assert.assertEquals("car's location Bedford", "Bedford MA", c4.getLocationName());
    Assert.assertEquals("car's location Bedford", "Bedford Siding 1", c4.getTrackName());
    Assert.assertEquals("car's destination", "", c4.getDestinationName());
    Assert.assertEquals("car's destination track", "", c4.getDestinationTrackName());
    BedfordToClintonTrain.build();
    BedfordToClintonTrain.terminate();
    // confirm cars have moved
    Assert.assertEquals("car's location Clinton", "Clinton MA", c3.getLocationName());
    Assert.assertEquals("car's location Clinton", "Clinton Interchange", c3.getTrackName());
    Assert.assertEquals("car's destination", "", c3.getDestinationName());
    Assert.assertEquals("car's destination track", "", c3.getDestinationTrackName());
    Assert.assertEquals("car's load", "L", c3.getLoadName());
    Assert.assertEquals("car's final destinaton", Essex, c3.getFinalDestination());
    Assert.assertEquals("car's final destinaton track", ES2, c3.getFinalDestinationTrack());
    Assert.assertEquals("car's location Clinton", "Clinton MA", c4.getLocationName());
    Assert.assertEquals("car's location Clinton", "Clinton Siding 1", c4.getTrackName());
    Assert.assertEquals("car's destination", "", c4.getDestinationName());
    Assert.assertEquals("car's destination track", "", c4.getDestinationTrackName());
    ClintonToDanburyTrain.build();
    ClintonToDanburyTrain.terminate();
    // confirm cars have moved
    Assert.assertEquals("car's location Danbury", "Danbury MA", c3.getLocationName());
    Assert.assertEquals("car's location Danbury", "Danbury Interchange", c3.getTrackName());
    Assert.assertEquals("car's destination", "", c3.getDestinationName());
    Assert.assertEquals("car's destination track", "", c3.getDestinationTrackName());
    Assert.assertEquals("car's load", "L", c3.getLoadName());
    Assert.assertEquals("car's final destinaton", Essex, c3.getFinalDestination());
    Assert.assertEquals("car's final destinaton track", ES2, c3.getFinalDestinationTrack());
    Assert.assertEquals("car's location Danbury", "Danbury MA", c4.getLocationName());
    Assert.assertEquals("car's location Danbury", "Danbury Siding 1", c4.getTrackName());
    Assert.assertEquals("car's destination", "", c4.getDestinationName());
    Assert.assertEquals("car's destination track", "", c4.getDestinationTrackName());
    DanburyToEssexTrain.build();
    DanburyToEssexTrain.terminate();
    // confirm cars have moved car has arrived at final destination Essex
    Assert.assertEquals("car's location Essex", "Essex MA", c3.getLocationName());
    Assert.assertEquals("car's location Essex", "Essex Siding 2", c3.getTrackName());
    Assert.assertEquals("car's destination", "", c3.getDestinationName());
    Assert.assertEquals("car's destination track", "", c3.getDestinationTrackName());
    Assert.assertEquals("car's load", "E", c3.getLoadName());
    // car when empty must return to Foxboro
    Assert.assertEquals("car's final destinaton", Foxboro, c3.getFinalDestination());
    Assert.assertEquals("car's final destinaton track", null, c3.getFinalDestinationTrack());
    Assert.assertEquals("car's location Essex", "Essex MA", c4.getLocationName());
    Assert.assertEquals("car's location Essex", "Essex Siding 1", c4.getTrackName());
    Assert.assertEquals("car's destination", "", c4.getDestinationName());
    Assert.assertEquals("car's destination track", "", c4.getDestinationTrackName());
    EssexToFoxboroTrain.build();
    EssexToFoxboroTrain.terminate();
    // confirm cars have moved
    Assert.assertEquals("car's location Foxboro", "Foxboro MA", c3.getLocationName());
    Assert.assertEquals("car's location Foxboro", "Foxboro Siding 1", c3.getTrackName());
    Assert.assertEquals("car's destination", "", c3.getDestinationName());
    Assert.assertEquals("car's destination track", "", c3.getDestinationTrackName());
    Assert.assertEquals("car's load", "L", c3.getLoadName());
    Assert.assertEquals("car's location Foxboro", "Foxboro MA", c4.getLocationName());
    Assert.assertEquals("car's location Foxboro", "Foxboro Siding 2", c4.getTrackName());
    Assert.assertEquals("car's destination", "", c4.getDestinationName());
    Assert.assertEquals("car's destination track", "", c4.getDestinationTrackName());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) Car(jmri.jmrit.operations.rollingstock.cars.Car) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Train(jmri.jmrit.operations.trains.Train) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) TrainManager(jmri.jmrit.operations.trains.TrainManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 89 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class OperationsCarRouterTest method loadLocationsTrainsAndCars.

private void loadLocationsTrainsAndCars() {
    LocationManager lmanager = LocationManager.instance();
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.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());
    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 a local train servicing Acton
    Train ActonTrain = tmanager.newTrain("Acton Local");
    Route routeA = rmanager.newRoute("A");
    RouteLocation rlA = routeA.addLocation(Acton);
    rlA.setMaxCarMoves(10);
    // set train icon coordinates
    rlA.setTrainIconX(25);
    rlA.setTrainIconY(250);
    ActonTrain.setRoute(routeA);
    // create a train with a route from Acton to Bedford
    Train ActonToBedfordTrain = tmanager.newTrain("Acton to Bedford");
    Route routeAB = rmanager.newRoute("AB");
    routeAB.addLocation(Acton);
    RouteLocation rlBedford = routeAB.addLocation(Bedford);
    // set train icon coordinates
    rlBedford.setTrainIconX(100);
    rlBedford.setTrainIconY(250);
    ActonToBedfordTrain.setRoute(routeAB);
    // 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);
    // 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);
    // 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);
    // 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);
    Train BedfordToActonTrain = tmanager.newTrain("BedfordToActonToBedford");
    Route BedfordToActon = RouteManager.instance().newRoute("BedfordToActonToBedford");
    RouteLocation rlB2 = BedfordToActon.addLocation(Bedford);
    RouteLocation rlA3 = BedfordToActon.addLocation(Acton);
    RouteLocation rlB3 = BedfordToActon.addLocation(Bedford);
    // increase the number of moves so all cars are used
    rlB2.setMaxCarMoves(10);
    rlA3.setMaxCarMoves(10);
    rlB3.setMaxCarMoves(10);
    BedfordToActonTrain.setRoute(BedfordToActon);
    // add cars
    Car c3 = cmanager.newCar("BA", "3");
    c3.setTypeName("Boxcar");
    c3.setLength("40");
    c3.setOwner("DAB");
    c3.setBuilt("1984");
    Car c4 = cmanager.newCar("BB", "4");
    c4.setTypeName("Flat");
    c4.setLength("40");
    c4.setOwner("AT");
    c4.setBuilt("1-86");
    c4.setMoves(2);
    Car c5 = cmanager.newCar("BC", "5");
    c5.setTypeName("Boxcar");
    c5.setLoadName("Boxes");
    c5.setLength("40");
    c5.setBuilt("2000");
    c5.setMoves(3);
    Car c6 = cmanager.newCar("BD", "6");
    c6.setTypeName("Boxcar");
    c6.setLoadName("Empty");
    c6.setLength("40");
    c6.setBuilt("2000");
    c6.setMoves(4);
    Car c7 = cmanager.newCar("BA", "7");
    c7.setTypeName("Boxcar");
    c7.setLoadName("Boxes");
    c7.setLength("4");
    c7.setBuilt("2000");
    c7.setMoves(5);
    Car c8 = cmanager.newCar("BB", "8");
    c8.setTypeName("Boxcar");
    c8.setLoadName("Empty");
    c8.setLength("4");
    c8.setBuilt("2000");
    c8.setMoves(6);
    Car c9 = cmanager.newCar("BC", "9");
    c9.setTypeName("Boxcar");
    c9.setLoadName("Empty");
    c9.setLength("4");
    c9.setBuilt("2000");
    c9.setMoves(7);
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) Car(jmri.jmrit.operations.rollingstock.cars.Car) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Train(jmri.jmrit.operations.trains.Train) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) TrainManager(jmri.jmrit.operations.trains.TrainManager) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 90 with RouteLocation

use of jmri.jmrit.operations.routes.RouteLocation in project JMRI by JMRI.

the class OperationsTrainsGuiTest method testTrainIcon.

@Test
public void testTrainIcon() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    EngineManager emanager = EngineManager.instance();
    EngineTypes et = EngineTypes.instance();
    // create and register a panel
    jmri.jmrit.display.panelEditor.PanelEditor editor = new jmri.jmrit.display.panelEditor.PanelEditor("Train Test Panel");
    PanelMenu.instance().addEditorPanel(editor);
    // confirm panel creation
    JmriJFrame f = JmriJFrame.getFrame("Train Test Panel");
    Assert.assertNotNull(f);
    // Place train icons on panel
    Setup.setPanelName("Train Test Panel");
    // Set terminate color to yellow
    Setup.setTrainIconColorTerminate(TrainIcon.YELLOW);
    // add engine number
    Setup.setTrainIconAppendEnabled(true);
    et.addName("Diesel");
    // Set up four engines in two consists
    Consist con1 = emanager.newConsist("C16");
    Consist con2 = emanager.newConsist("C14");
    Engine e1 = new Engine("PC", "5016");
    e1.setModel("GP40");
    e1.setConsist(con1);
    e1.setMoves(123);
    e1.setOwner("AT");
    e1.setBuilt("1990");
    Assert.assertEquals("Engine 1 Length", "59", e1.getLength());
    emanager.register(e1);
    Engine e2 = new Engine("PC", "5019");
    e2.setModel("GP40");
    e2.setConsist(con1);
    e2.setMoves(321);
    e2.setOwner("AT");
    e2.setBuilt("1990");
    Assert.assertEquals("Engine 2 Length", "59", e2.getLength());
    emanager.register(e2);
    Engine e3 = new Engine("PC", "5524");
    e3.setModel("SD45");
    e3.setConsist(con2);
    e3.setOwner("DAB");
    e3.setBuilt("1980");
    Assert.assertEquals("Engine 3 Length", "66", e3.getLength());
    emanager.register(e3);
    Engine e4 = new Engine("PC", "5559");
    e4.setModel("SD45");
    e4.setConsist(con2);
    e4.setOwner("DAB");
    e4.setBuilt("1980");
    Assert.assertEquals("Engine 4 Length", "66", e4.getLength());
    emanager.register(e4);
    // Set up a route of 3 locations: North End Staging (2 tracks),
    // North Industries (1 track), and South End Staging (2 tracks).
    Location l1 = new Location("1", "North End");
    Assert.assertEquals("Location 1 Id", "1", l1.getId());
    Assert.assertEquals("Location 1 Name", "North End", l1.getName());
    Assert.assertEquals("Location 1 Initial Length", 0, l1.getLength());
    l1.setLocationOps(Location.STAGING);
    l1.setTrainDirections(DIRECTION_ALL);
    l1.setSwitchListEnabled(true);
    lmanager.register(l1);
    Track l1s1 = new Track("1s1", "North End 1", Track.STAGING, l1);
    l1s1.setLength(300);
    Assert.assertEquals("Location 1s1 Id", "1s1", l1s1.getId());
    Assert.assertEquals("Location 1s1 Name", "North End 1", l1s1.getName());
    Assert.assertEquals("Location 1s1 LocType", "Staging", l1s1.getTrackType());
    Assert.assertEquals("Location 1s1 Length", 300, l1s1.getLength());
    l1s1.setTrainDirections(DIRECTION_ALL);
    l1s1.setRoadOption(Track.ALL_ROADS);
    l1s1.setDropOption(Track.ANY);
    l1s1.setPickupOption(Track.ANY);
    Track l1s2 = new Track("1s2", "North End 2", Track.STAGING, l1);
    l1s2.setLength(400);
    Assert.assertEquals("Location 1s2 Id", "1s2", l1s2.getId());
    Assert.assertEquals("Location 1s2 Name", "North End 2", l1s2.getName());
    Assert.assertEquals("Location 1s2 LocType", "Staging", l1s2.getTrackType());
    Assert.assertEquals("Location 1s2 Length", 400, l1s2.getLength());
    l1s2.setTrainDirections(DIRECTION_ALL);
    l1s2.setRoadOption(Track.ALL_ROADS);
    l1s2.setDropOption(Track.ANY);
    l1s2.setPickupOption(Track.ANY);
    l1.addTrack("North End 1", Track.STAGING);
    l1.addTrack("North End 2", Track.STAGING);
    List<Track> templist1 = l1.getTrackByNameList(null);
    for (int i = 0; i < templist1.size(); i++) {
        if (i == 0) {
            Assert.assertEquals("RL 1 Staging 1 Name", "North End 1", templist1.get(i).getName());
        }
        if (i == 1) {
            Assert.assertEquals("RL 1 Staging 2 Name", "North End 2", templist1.get(i).getName());
        }
    }
    l1.register(l1s1);
    l1.register(l1s2);
    Assert.assertEquals("Location 1 Length", 700, l1.getLength());
    Location l2 = new Location("2", "North Industries");
    Assert.assertEquals("Location 2 Id", "2", l2.getId());
    Assert.assertEquals("Location 2 Name", "North Industries", l2.getName());
    l2.setLocationOps(Location.NORMAL);
    l2.setTrainDirections(DIRECTION_ALL);
    l2.setSwitchListEnabled(true);
    lmanager.register(l2);
    Track l2s1 = new Track("2s1", "NI Yard", Track.YARD, l2);
    l2s1.setLength(432);
    Assert.assertEquals("Location 2s1 Id", "2s1", l2s1.getId());
    Assert.assertEquals("Location 2s1 Name", "NI Yard", l2s1.getName());
    Assert.assertEquals("Location 2s1 LocType", Track.YARD, l2s1.getTrackType());
    Assert.assertEquals("Location 2s1 Length", 432, l2s1.getLength());
    l2s1.setTrainDirections(DIRECTION_ALL);
    l2.register(l2s1);
    Assert.assertEquals("Location 2 Length", 432, l2.getLength());
    Location l3 = new Location("3", "South End");
    Assert.assertEquals("Location 3 Id", "3", l3.getId());
    Assert.assertEquals("Location 3 Name", "South End", l3.getName());
    Assert.assertEquals("Location 3 Initial Length", 0, l3.getLength());
    l3.setLocationOps(Location.STAGING);
    l3.setTrainDirections(DIRECTION_ALL);
    l3.setSwitchListEnabled(true);
    lmanager.register(l3);
    Track l3s1 = new Track("3s1", "South End 1", Track.STAGING, l3);
    l3s1.setLength(300);
    Assert.assertEquals("Location 3s1 Id", "3s1", l3s1.getId());
    Assert.assertEquals("Location 3s1 Name", "South End 1", l3s1.getName());
    Assert.assertEquals("Location 3s1 LocType", "Staging", l3s1.getTrackType());
    Assert.assertEquals("Location 3s1 Length", 300, l3s1.getLength());
    l3s1.setTrainDirections(DIRECTION_ALL);
    l3s1.setRoadOption(Track.ALL_ROADS);
    l3s1.setDropOption(Track.ANY);
    l3s1.setPickupOption(Track.ANY);
    Track l3s2 = new Track("3s2", "South End 2", Track.STAGING, l3);
    l3s2.setLength(401);
    Assert.assertEquals("Location 3s2 Id", "3s2", l3s2.getId());
    Assert.assertEquals("Location 3s2 Name", "South End 2", l3s2.getName());
    Assert.assertEquals("Location 3s2 LocType", "Staging", l3s2.getTrackType());
    Assert.assertEquals("Location 3s2 Length", 401, l3s2.getLength());
    l3s2.setTrainDirections(DIRECTION_ALL);
    l3s2.setRoadOption(Track.ALL_ROADS);
    l3s2.setDropOption(Track.ANY);
    l3s2.setPickupOption(Track.ANY);
    l3.addTrack("South End 1", Track.STAGING);
    l3.addTrack("South End 2", Track.STAGING);
    List<Track> templist3 = l3.getTrackByNameList(null);
    for (int i = 0; i < templist3.size(); i++) {
        if (i == 0) {
            Assert.assertEquals("RL 3 Staging 1 Name", "South End 1", templist3.get(i).getName());
        }
        if (i == 1) {
            Assert.assertEquals("RL 3 Staging 2 Name", "South End 2", templist3.get(i).getName());
        }
    }
    l3.register(l3s1);
    l3.register(l3s2);
    Assert.assertEquals("Location 3 Length", 701, l3.getLength());
    // Place Engines on Staging tracks
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(l1, l1s1));
    Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(l1, l1s1));
    Assert.assertEquals("Place e3", Track.OKAY, e3.setLocation(l1, l1s2));
    Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(l1, l1s2));
    // Define the route.
    Route r1 = new Route("1", "Southbound Main Route");
    Assert.assertEquals("Route Id", "1", r1.getId());
    Assert.assertEquals("Route Name", "Southbound Main Route", r1.getName());
    RouteLocation rl1 = new RouteLocation("1r1", l1);
    rl1.setSequenceId(1);
    rl1.setTrainDirection(RouteLocation.SOUTH);
    rl1.setMaxCarMoves(5);
    rl1.setMaxTrainLength(1000);
    // set the train icon coordinates
    rl1.setTrainIconX(25);
    rl1.setTrainIconY(25);
    Assert.assertEquals("Route Location 1 Id", "1r1", rl1.getId());
    Assert.assertEquals("Route Location 1 Name", "North End", rl1.getName());
    RouteLocation rl2 = new RouteLocation("1r2", l2);
    rl2.setSequenceId(2);
    rl2.setTrainDirection(RouteLocation.SOUTH);
    // test for only 1 pickup and 1 drop
    rl2.setMaxCarMoves(2);
    rl2.setMaxTrainLength(1000);
    // set the train icon coordinates
    rl2.setTrainIconX(75);
    rl2.setTrainIconY(25);
    Assert.assertEquals("Route Location 2 Id", "1r2", rl2.getId());
    Assert.assertEquals("Route Location 2 Name", "North Industries", rl2.getName());
    RouteLocation rl3 = new RouteLocation("1r3", l3);
    rl3.setSequenceId(3);
    rl3.setTrainDirection(RouteLocation.SOUTH);
    rl3.setMaxCarMoves(5);
    rl3.setMaxTrainLength(1000);
    // set the train icon coordinates
    rl3.setTrainIconX(125);
    rl3.setTrainIconY(35);
    Assert.assertEquals("Route Location 3 Id", "1r3", rl3.getId());
    Assert.assertEquals("Route Location 3 Name", "South End", rl3.getName());
    r1.register(rl1);
    r1.register(rl2);
    r1.register(rl3);
    rmanager.register(r1);
    // Finally ready to define the trains.
    Train train1 = new Train("1", "STF");
    Assert.assertEquals("Train Id", "1", train1.getId());
    Assert.assertEquals("Train Name", "STF", train1.getName());
    train1.setRoute(r1);
    tmanager.register(train1);
    Train train2 = new Train("2", "SFF");
    Assert.assertEquals("Train Id", "2", train2.getId());
    Assert.assertEquals("Train Name", "SFF", train2.getName());
    train2.setRoute(r1);
    tmanager.register(train2);
    // Last minute checks.
    Assert.assertEquals("Train 1 Departs Name", "North End", train1.getTrainDepartsName());
    Assert.assertEquals("Train 1 Route Departs Name", "North End", train1.getTrainDepartsRouteLocation().getName());
    Assert.assertEquals("Train 1 Terminates Name", "South End", train1.getTrainTerminatesName());
    Assert.assertEquals("Train 1 Route Terminates Name", "South End", train1.getTrainTerminatesRouteLocation().getName());
    Assert.assertEquals("Train 1 Next Location Name", "", train1.getNextLocationName());
    Assert.assertEquals("Train 1 Route Name", "Southbound Main Route", train1.getRoute().getName());
    Assert.assertEquals("Train 2 Departs Name", "North End", train2.getTrainDepartsName());
    Assert.assertEquals("Train 2 Route Departs Name", "North End", train2.getTrainDepartsRouteLocation().getName());
    Assert.assertEquals("Train 2 Terminates Name", "South End", train2.getTrainTerminatesName());
    Assert.assertEquals("Train 2 Route Terminates Name", "South End", train2.getTrainTerminatesRouteLocation().getName());
    Assert.assertEquals("Train 2 Next Location Name", "", train2.getNextLocationName());
    Assert.assertEquals("Train 2 Route Name", "Southbound Main Route", train2.getRoute().getName());
    // disable build messages
    tmanager.setBuildMessagesEnabled(false);
    // disable build reports
    tmanager.setBuildReportEnabled(false);
    train1.build();
    train2.build();
    Assert.assertEquals("Train 1 after build", true, train1.isBuilt());
    Assert.assertEquals("Train 2 after build", true, train2.isBuilt());
    // check train icon location and name
    TrainIcon ti1 = train1.getTrainIcon();
    Assert.assertNotNull("Train 1 icon exists", ti1);
    Assert.assertEquals("Train 1 icon text", "STF 5016", ti1.getText());
    TrainIcon ti2 = train2.getTrainIcon();
    Assert.assertNotNull("Train 2 icon exists", ti2);
    Assert.assertEquals("Train 2 icon text", "SFF 5524", ti2.getText());
    // icon uses TrainIconAnimation 2 pixels every 3 mSec
    // X=0 to X=25 25/2 * 3 = 38 mSec
    // Y=0 to Y=25 25/2 * 3 = 38 mSec
    // need to wait for icon to finish moving
    jmri.util.JUnitUtil.waitFor(() -> (ti2.getX() == 25 && ti2.getY() == 25), "Train 2 Move 0");
    Assert.assertEquals("Train 1 icon X", 25, ti1.getX());
    Assert.assertEquals("Train 1 icon Y", 25, ti1.getY());
    Assert.assertEquals("Train 2 icon X", 25, ti2.getX());
    Assert.assertEquals("Train 2 icon Y", 25, ti2.getY());
    // move the trains
    train1.move();
    // icon uses TrainIconAnimation 2 pixels every 3 mSec
    // need to wait for icon to finish moving
    jmri.util.JUnitUtil.waitFor(() -> (ti1.getX() == 75 && ti1.getY() == 25), "Train 1 Move");
    Assert.assertEquals("Train 1 icon X", 75, ti1.getX());
    Assert.assertEquals("Train 1 icon Y", 25, ti1.getY());
    // train 2 shouldn't move
    Assert.assertEquals("Train 2 icon X", 25, ti2.getX());
    Assert.assertEquals("Train 2 icon Y", 25, ti2.getY());
    train2.move();
    // need to wait for icon to finish moving
    jmri.util.JUnitUtil.waitFor(() -> (ti2.getX() == 75 && ti2.getY() == 25), "Train 2 Move");
    Assert.assertEquals("Train 1 icon X", 75, ti1.getX());
    Assert.assertEquals("Train 1 icon Y", 25, ti1.getY());
    Assert.assertEquals("Train 2 icon X", 75, ti2.getX());
    Assert.assertEquals("Train 2 icon Y", 25, ti2.getY());
    train2.move();
    // need to wait for icon to finish moving
    jmri.util.JUnitUtil.waitFor(() -> (ti2.getX() == 125 && ti2.getY() == 35), "Train 2 Move 2");
    Assert.assertEquals("Train 1 icon X", 75, ti1.getX());
    Assert.assertEquals("Train 1 icon Y", 25, ti1.getY());
    Assert.assertEquals("Train 2 icon X", 125, ti2.getX());
    Assert.assertEquals("Train 2 icon Y", 35, ti2.getY());
    editor.getTargetFrame().dispose();
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) EngineTypes(jmri.jmrit.operations.rollingstock.engines.EngineTypes) EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) JmriJFrame(jmri.util.JmriJFrame) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location) Test(org.junit.Test)

Aggregations

RouteLocation (jmri.jmrit.operations.routes.RouteLocation)118 Route (jmri.jmrit.operations.routes.Route)64 Location (jmri.jmrit.operations.locations.Location)55 Track (jmri.jmrit.operations.locations.Track)52 Car (jmri.jmrit.operations.rollingstock.cars.Car)48 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)33 LocationManager (jmri.jmrit.operations.locations.LocationManager)21 RouteManager (jmri.jmrit.operations.routes.RouteManager)20 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)17 Train (jmri.jmrit.operations.trains.Train)16 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)13 ArrayList (java.util.ArrayList)12 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)12 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)12 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)11 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)8 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)6 IOException (java.io.IOException)6 TrainManager (jmri.jmrit.operations.trains.TrainManager)6 JCheckBox (javax.swing.JCheckBox)5