Search in sources :

Example 31 with RouteLocation

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

the class TrainTest method testCaboose.

public void testCaboose() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    EngineManager emanager = EngineManager.instance();
    CarManager cmanager = CarManager.instance();
    CarTypes ct = CarTypes.instance();
    EngineTypes et = EngineTypes.instance();
    // register the car and engine types used
    ct.addName("Boxcar");
    ct.addName("Caboose");
    ct.addName("Flat");
    et.addName("Diesel");
    // place two engines in a consist
    Consist con1 = emanager.newConsist("C1");
    Engine e1 = emanager.newEngine("UP", "1");
    e1.setModel("GP40");
    e1.setConsist(con1);
    Engine e2 = emanager.newEngine("SP", "2");
    e2.setModel("GP40");
    e2.setConsist(con1);
    // Set up three cabooses and six box cars
    Car c1 = cmanager.newCar("UP", "1");
    c1.setTypeName("Caboose");
    c1.setLength("32");
    c1.setMoves(10);
    c1.setCaboose(true);
    Car c2 = cmanager.newCar("SP", "2");
    c2.setTypeName("Caboose");
    c2.setLength("30");
    c2.setMoves(5);
    c2.setCaboose(true);
    Car c3 = cmanager.newCar("NH", "3");
    c3.setTypeName("Caboose");
    c3.setLength("33");
    c3.setCaboose(true);
    Car c4 = cmanager.newCar("UP", "4");
    c4.setTypeName("Boxcar");
    c4.setLength("40");
    c4.setMoves(16);
    c4.setFred(true);
    Car c5 = cmanager.newCar("SP", "5");
    c5.setTypeName("Boxcar");
    c5.setLength("40");
    c5.setMoves(8);
    c5.setFred(true);
    Car c6 = cmanager.newCar("NH", "6");
    c6.setTypeName("Boxcar");
    c6.setLength("40");
    c6.setMoves(2);
    c6.setFred(true);
    Car c7 = cmanager.newCar("UP", "7");
    c7.setTypeName("Flat");
    c7.setLength("40");
    c7.setMoves(5);
    Car c8 = cmanager.newCar("SP", "8");
    c8.setTypeName("Boxcar");
    c8.setLength("40");
    c8.setMoves(4);
    Car c9 = cmanager.newCar("NH", "9");
    c9.setTypeName("Boxcar");
    c9.setLength("40");
    c9.setMoves(3);
    Car c10 = cmanager.newCar("NH", "10");
    c10.setTypeName("Boxcar");
    c10.setLength("40");
    c10.setMoves(10);
    Car c11 = cmanager.newCar("SP", "11");
    c11.setTypeName("Boxcar");
    c11.setLength("40");
    c11.setMoves(3);
    // Create 3 locations
    Location loc1 = lmanager.newLocation("Harvard");
    Track loc1trk1 = loc1.addTrack("Harvard Yard", Track.YARD);
    loc1trk1.setLength(1000);
    Location loc2 = lmanager.newLocation("Arlington");
    Track loc2trk1 = loc2.addTrack("Arlington Yard", Track.YARD);
    loc2trk1.setLength(1000);
    Location loc3 = lmanager.newLocation("Boston");
    Track loc3trk1 = loc3.addTrack("Boston Yard", Track.YARD);
    loc3trk1.setLength(1000);
    loc3trk1.deleteTypeName("Diesel");
    Track loc3trk2 = loc3.addTrack("Boston Engine Yard", Track.YARD);
    loc3trk2.setLength(200);
    loc3trk2.deleteTypeName("Boxcar");
    loc3trk2.deleteTypeName("Flat");
    loc3trk2.deleteTypeName("Caboose");
    // Create route with 3 location
    Route rte1 = rmanager.newRoute("Route 2 Boston");
    RouteLocation rl1 = rte1.addLocation(loc1);
    RouteLocation rl2 = rte1.addLocation(loc2);
    // set the train icon coordinates
    rl2.setTrainIconX(75);
    rl2.setTrainIconY(150);
    RouteLocation rl3 = rte1.addLocation(loc3);
    // set the train icon coordinates
    rl3.setTrainIconX(125);
    rl3.setTrainIconY(150);
    // Create train
    Train train1 = tmanager.newTrain("HTB");
    train1.setRoute(rte1);
    // Place cars
    Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(loc2, loc2trk1));
    Assert.assertEquals("Place c11", Track.OKAY, c11.setLocation(loc2, loc2trk1));
    // Place engines
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(loc1, loc1trk1));
    // no requirements, so no caboose or FRED or engines
    train1.build();
    Assert.assertEquals("Train 1 After Build 1", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 1", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 1", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 1", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 1", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 1", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 1", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 1", "Boston Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 1", "Arlington Yard", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 1", "Boston Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 1", "Boston Yard", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 1", "Boston Yard", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 1", "", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 1", "", e2.getDestinationTrackName());
    // no engines, so the caboose with least moves should be used
    train1.setRequirements(Train.CABOOSE);
    // don't allow pickups at second location Arlington
    rl2.setPickUpAllowed(false);
    train1.build();
    Assert.assertEquals("Train 1 After Build 2", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 2", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 2", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 2", "Boston Yard", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 2", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 2", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 2", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 2", "Boston Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 2", "Boston Yard", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 2", "Arlington Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 2", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 2", "", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 2", "", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 2", "", e2.getDestinationTrackName());
    // there's a caboose c1 that matches lead engine
    train1.setNumberEngines("2");
    train1.build();
    Assert.assertEquals("Train 1 After Build 3", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 3", "Boston Yard", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 3", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 3", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 3", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 3", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 3", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 3", "Boston Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 3", "Boston Yard", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 3", "Arlington Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 3", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 3", "", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 3", "Boston Engine Yard", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 3", "Boston Engine Yard", e2.getDestinationTrackName());
    // should default to the caboose with the least moves
    e1.setRoadName("X");
    // allow pickups at Arlington
    rl2.setPickUpAllowed(true);
    train1.build();
    Assert.assertEquals("Train 1 After Build 4", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 4", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 4", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 4", "Boston Yard", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 4", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 4", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 4", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 4", "Boston Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 4", "Boston Yard", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 4", "Arlington Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 4", "Boston Yard", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 4", "Boston Yard", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 4", "Boston Engine Yard", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 4", "Boston Engine Yard", e2.getDestinationTrackName());
    // don't allow drops at Boston, caboose and engines should still drop there
    rl3.setDropAllowed(false);
    // should not take NH caboose
    e1.setRoadName("NH");
    // now require a SP caboose
    train1.setCabooseRoad("SP");
    train1.build();
    Assert.assertEquals("Train 1 After Build 5", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 5", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 5", "Boston Yard", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 5", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 5", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 5", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 5", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 5", "Arlington Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 5", "Arlington Yard", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 5", "Arlington Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 5", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 5", "", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 5", "Boston Engine Yard", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 5", "Boston Engine Yard", e2.getDestinationTrackName());
    // allow drops at Boston
    rl3.setDropAllowed(true);
    // should take car with FRED and road SP
    train1.setRequirements(Train.FRED);
    train1.build();
    Assert.assertEquals("Train 1 After Build 6", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 6", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 6", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 6", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 6", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 6", "Boston Yard", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 6", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 6", "Boston Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 6", "Boston Yard", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 6", "Arlington Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 6", "Boston Yard", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 6", "Boston Yard", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 6", "Boston Engine Yard", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 6", "Boston Engine Yard", e2.getDestinationTrackName());
    // should take car with FRED least number of moves
    train1.setCabooseRoad("");
    train1.build();
    Assert.assertEquals("Train 1 After Build 7", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 7", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 7", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 7", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 7", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 7", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 7", "Boston Yard", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 7", "Boston Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 7", "Boston Yard", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 7", "Arlington Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 7", "Boston Yard", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 7", "Boston Yard", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 7", "Boston Engine Yard", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 7", "Boston Engine Yard", e2.getDestinationTrackName());
    // now exclude road NH, engine road is NH and should be rejected
    train1.addRoadName("NH");
    train1.setRoadOption(Train.EXCLUDE_ROADS);
    train1.build();
    Assert.assertEquals("Train 1 After Build 7a", false, train1.isBuilt());
    // now override by setting a road for the engine
    train1.setEngineRoad("NH");
    train1.build();
    Assert.assertEquals("Train 1 After Build 8", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 8", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 8", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 8", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 8", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 8", "Boston Yard", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 8", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 8", "Boston Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 8", "Arlington Yard", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 8", "", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 8", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 8", "Boston Yard", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 8", "Boston Engine Yard", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 8", "Boston Engine Yard", e2.getDestinationTrackName());
    // now only include NH
    train1.setRoadOption(Train.INCLUDE_ROADS);
    train1.build();
    Assert.assertEquals("Train 1 After Build 9", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 9", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 9", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 9", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 9", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 9", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 9", "Boston Yard", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 9", "", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 9", "", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 9", "Arlington Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 9", "Boston Yard", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 9", "", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 9", "Boston Engine Yard", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 9", "Boston Engine Yard", e2.getDestinationTrackName());
    // don't allow boxcar, car with FRED required, build should fail
    loc3.deleteTypeName("Boxcar");
    train1.build();
    Assert.assertEquals("Train 1 After Build 9a", false, train1.isBuilt());
    loc3.addTypeName("Boxcar");
    // add staging
    Track loc1trk2 = loc1.addTrack("Harvard Staging", Track.STAGING);
    loc1trk2.setLength(1000);
    // now depart staging, must take all cars in staging
    // there are nine cars departing staging
    rl1.setMaxCarMoves(9);
    // Place cars
    Assert.assertEquals("Move c1", Track.OKAY, c1.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Move c2", Track.OKAY, c2.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Move c3", Track.OKAY, c3.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Move c4", Track.OKAY, c4.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Move c5", Track.OKAY, c5.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Move c6", Track.OKAY, c6.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Move c7", Track.OKAY, c7.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Move c8", Track.OKAY, c8.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Move c9", Track.OKAY, c9.setLocation(loc1, loc1trk2));
    // Place engines
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(loc1, loc1trk2));
    // program requires only staging at any location, so we don't test with yard
    loc1.deleteTrack(loc1trk1);
    // All engines and cars in staging must move! Cabooses and cars with FRED to terminal
    train1.setNumberEngines("0");
    train1.build();
    // train only accepted engine and cars with NH road therefore build should fail
    Assert.assertEquals("Train 1 After Build from staging", false, train1.isBuilt());
    // try again but now accept all roads
    train1.setRoadOption(Train.ALL_ROADS);
    train1.build();
    Assert.assertEquals("Train 1 After Build 10", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 10", "Boston Yard", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 10", "Boston Yard", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 10", "Boston Yard", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 10", "Boston Yard", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 10", "Boston Yard", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 10", "Boston Yard", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 10", "Arlington Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 10", "Arlington Yard", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 10", "Arlington Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 10", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 10", "Boston Yard", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 10", "Boston Engine Yard", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 10", "Boston Engine Yard", e2.getDestinationTrackName());
    // exclude road NH
    train1.setRoadOption(Train.EXCLUDE_ROADS);
    train1.build();
    // should fail since there are NH roads in staging
    Assert.assertEquals("Train 1 After Build 11", false, train1.isBuilt());
    // reduce Boston moves to 6, to force non caboose and FRED cars to Arlington
    rl3.setMaxCarMoves(6);
    train1.setRoadOption(Train.ALL_ROADS);
    train1.build();
    Assert.assertEquals("Train 1 After Build 12", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 12", "Boston Yard", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 12", "Boston Yard", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 12", "Boston Yard", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 12", "Boston Yard", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 12", "Boston Yard", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 12", "Boston Yard", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 12", "Arlington Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 12", "Arlington Yard", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 12", "Arlington Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 12", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 12", "", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 12", "Boston Engine Yard", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 12", "Boston Engine Yard", e2.getDestinationTrackName());
    // Reduce Arlington to only two moves, this should cause train build to fail
    rl2.setMaxCarMoves(2);
    train1.build();
    Assert.assertEquals("Train 1 After Build 13", false, train1.isBuilt());
    // restore number of moves
    rl2.setMaxCarMoves(7);
    rl3.setMaxCarMoves(7);
    // don't allow drops at Boston
    rl3.setDropAllowed(false);
    train1.build();
    Assert.assertEquals("Train 1 After Build 14", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 14", "Boston Yard", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 14", "Boston Yard", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 14", "Boston Yard", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 14", "Boston Yard", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 14", "Boston Yard", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 14", "Boston Yard", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 14", "Arlington Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 14", "Arlington Yard", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 14", "Arlington Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 14", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 14", "", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 14", "Boston Engine Yard", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 14", "Boston Engine Yard", e2.getDestinationTrackName());
    // Reduce Arlington to only two moves, this should cause train build to fail
    rl2.setMaxCarMoves(2);
    train1.build();
    Assert.assertEquals("Train 1 After Build 15", false, train1.isBuilt());
    // Don't allow cabooses at Boston, should cause build failure
    rl2.setMaxCarMoves(7);
    loc3.deleteTypeName("Caboose");
    train1.build();
    Assert.assertEquals("Train 1 After Build 16", false, train1.isBuilt());
    // Don't allow boxcars, should also cause build failure
    loc3.addTypeName("Caboose");
    loc3.deleteTypeName("Boxcar");
    train1.setRequirements(Train.NO_CABOOSE_OR_FRED);
    train1.build();
    Assert.assertEquals("Train 1 After Build 17", false, train1.isBuilt());
    // allow the three road names we're testing
    loc3.addTypeName("Boxcar");
    loc3trk1.addRoadName("NH");
    loc3trk1.addRoadName("SP");
    loc3trk1.addRoadName("UP");
    loc3trk1.setRoadOption(Track.INCLUDE_ROADS);
    loc3trk2.addRoadName("NH");
    loc3trk2.addRoadName("SP");
    loc3trk2.addRoadName("UP");
    loc3trk2.setRoadOption(Track.INCLUDE_ROADS);
    train1.build();
    Assert.assertEquals("Train 1 After Build 18", true, train1.isBuilt());
    // now remove type Diesel, this should cause a failure
    loc3trk2.deleteTypeName("Diesel");
    train1.build();
    Assert.assertEquals("Train 1 After Build 19", false, train1.isBuilt());
    // now restore type Diesel
    loc3trk2.addTypeName("Diesel");
    train1.build();
    Assert.assertEquals("Train 1 After Build 20", true, train1.isBuilt());
    // Set the track length too short missing one set of couplers
    loc3trk2.setLength(Integer.parseInt(e1.getLength()) + Integer.parseInt(e2.getLength()) + Engine.COUPLER);
    train1.build();
    Assert.assertEquals("Train 1 After Build 20.1", false, train1.isBuilt());
    // restore track length
    loc3trk2.setLength(Integer.parseInt(e1.getLength()) + Integer.parseInt(e2.getLength()) + 2 * Engine.COUPLER);
    train1.build();
    Assert.assertEquals("Train 1 After Build 20.2", true, train1.isBuilt());
    // change lead engine road name, should cause build failure since Boston only
    // accepts NH, SP, and UP.
    // reset engine road requirements, was "NH"
    train1.setEngineRoad("");
    // was "NH"
    e1.setRoadName("X");
    train1.build();
    Assert.assertEquals("Train 1 After Build 21", false, train1.isBuilt());
    e1.setRoadName("UP");
    // this test that a caboose fails
    loc3trk1.deleteRoadName("NH");
    train1.build();
    Assert.assertEquals("Train 1 After Build 22", false, train1.isBuilt());
    loc3trk1.addRoadName("NH");
    // this test that a car with FRED fails
    c6.setRoadName("X");
    train1.build();
    Assert.assertEquals("Train 1 After Build 23", false, train1.isBuilt());
    loc3trk1.addRoadName("X");
    // this test that an ordinary car must move
    loc2trk1.deleteTypeName("Flat");
    train1.build();
    Assert.assertEquals("Train 1 After Build 24", false, train1.isBuilt());
    // restore
    loc2trk1.addTypeName("Flat");
    train1.build();
    Assert.assertEquals("Train 1 After Build 25", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 25", "Boston Yard", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 25", "Boston Yard", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 25", "Boston Yard", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 25", "Boston Yard", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 25", "Boston Yard", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 25", "Boston Yard", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 25", "Arlington Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 25", "Arlington Yard", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 25", "Arlington Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 25", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 25", "", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 25", "Boston Engine Yard", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 25", "Boston Engine Yard", e2.getDestinationTrackName());
    train1.reset();
    // send caboose SP 2 from staging to track that will not service it
    loc3trk2.addTypeName("Caboose");
    loc3trk2.setLength(200);
    c2.setDestination(loc3, loc3trk2);
    loc3trk2.deleteTypeName("Caboose");
    train1.build();
    Assert.assertEquals("Train 1 After Build with caboose bad destination", false, train1.isBuilt());
    c2.setDestination(null, null);
    train1.build();
    train1.move();
    train1.move();
    train1.move();
    // check final locations
    Assert.assertEquals("c1 location 24", "Boston Yard", c1.getTrackName());
    Assert.assertEquals("c2 location 24", "Boston Yard", c2.getTrackName());
    Assert.assertEquals("c3 location 24", "Boston Yard", c3.getTrackName());
    Assert.assertEquals("c4 location 24", "Boston Yard", c4.getTrackName());
    Assert.assertEquals("c5 location 24", "Boston Yard", c5.getTrackName());
    Assert.assertEquals("c6 location 24", "Boston Yard", c6.getTrackName());
    Assert.assertEquals("c7 location 24", "Arlington Yard", c7.getTrackName());
    Assert.assertEquals("c8 location 24", "Arlington Yard", c8.getTrackName());
    Assert.assertEquals("c9 location 24", "Arlington Yard", c9.getTrackName());
    Assert.assertEquals("c10 location 24", "Arlington Yard", c10.getTrackName());
    Assert.assertEquals("c11 location 24", "Arlington Yard", c11.getTrackName());
    Assert.assertEquals("e1 location 24", "Boston Engine Yard", e1.getTrackName());
    Assert.assertEquals("e2 location 24", "Boston Engine Yard", e2.getTrackName());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) EngineTypes(jmri.jmrit.operations.rollingstock.engines.EngineTypes) EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Car(jmri.jmrit.operations.rollingstock.cars.Car) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) 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)

Example 32 with RouteLocation

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

the class TrainTest method testAutoEnginesGrade.

public void testAutoEnginesGrade() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    EngineManager emanager = EngineManager.instance();
    // This test uses the maximum length of a train in route
    Setup.setMaxTrainLength(1000);
    Setup.setMaxNumberEngines(6);
    Train train = tmanager.newTrain("AutoEngineTest");
    train.setNumberEngines(Train.AUTO);
    Route route = rmanager.newRoute("AutoEngineTest");
    train.setRoute(route);
    Location A = lmanager.newLocation("A");
    Location B = lmanager.newLocation("B");
    Location C = lmanager.newLocation("C");
    Track At = A.addTrack("track", Track.SPUR);
    Track Bt = B.addTrack("track", Track.SPUR);
    Track Ct = C.addTrack("track", Track.SPUR);
    At.setLength(300);
    Bt.setLength(300);
    Ct.setLength(300);
    RouteLocation rA = route.addLocation(A);
    RouteLocation rB = route.addLocation(B);
    RouteLocation rC = route.addLocation(C);
    rA.setMaxCarMoves(12);
    rB.setMaxCarMoves(12);
    rC.setMaxCarMoves(12);
    // 2.5% grade!
    rB.setGrade(2.5);
    Engine e1 = emanager.newEngine("E", "1");
    e1.setModel("GP40");
    Engine e2 = emanager.newEngine("E", "2");
    e2.setModel("GP40");
    Engine e3 = emanager.newEngine("E", "3");
    e3.setModel("GP40");
    Engine e4 = emanager.newEngine("E", "4");
    e4.setModel("GP40");
    e1.setLocation(A, At);
    e2.setLocation(A, At);
    e3.setLocation(A, At);
    e4.setLocation(A, At);
    Consist c = emanager.newConsist("c");
    e1.setConsist(c);
    e2.setConsist(c);
    // train should require four engines
    train.build();
    Assert.assertFalse("Train should not build, needs four engines, only two", train.isBuilt());
    e3.setConsist(c);
    train.build();
    Assert.assertFalse("Train should not build, needs four engines, only three", train.isBuilt());
    e4.setConsist(c);
    train.build();
    Assert.assertTrue("Train should build, four engines available", train.isBuilt());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) Track(jmri.jmrit.operations.locations.Track) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 33 with RouteLocation

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

the class TrainTest method testTrainBuildOptions.

public void testTrainBuildOptions() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    EngineManager emanager = EngineManager.instance();
    CarManager cmanager = CarManager.instance();
    CarTypes ct = CarTypes.instance();
    EngineTypes et = EngineTypes.instance();
    // register the car and engine types used
    ct.addName("Boxcar");
    ct.addName("Caboose");
    ct.addName("Flat");
    et.addName("Diesel");
    // create 2 consists and a single engine for testing
    Consist con1 = emanager.newConsist("C1");
    Engine e1 = emanager.newEngine("UP", "1");
    e1.setModel("GP30");
    e1.setOwner("AT");
    e1.setBuilt("1957");
    e1.setConsist(con1);
    e1.setMoves(5);
    Engine e2 = emanager.newEngine("SP", "2");
    e2.setModel("GP30");
    e2.setOwner("AT");
    e2.setBuilt("1957");
    e2.setConsist(con1);
    e2.setMoves(5);
    // one engine
    Engine e3 = emanager.newEngine("SP", "3");
    e3.setModel("GP40");
    e3.setOwner("DAB");
    e3.setBuilt("1957");
    Consist con2 = emanager.newConsist("C2");
    Engine e4 = emanager.newEngine("UP", "10");
    e4.setModel("GP40");
    e4.setOwner("DAB");
    e4.setBuilt("1944");
    e4.setConsist(con2);
    e4.setMoves(20);
    Engine e5 = emanager.newEngine("SP", "20");
    e5.setModel("GP40");
    e5.setOwner("DAB");
    e5.setBuilt("1944");
    e5.setConsist(con2);
    e5.setMoves(20);
    // 3 engine consist
    Consist con3 = emanager.newConsist("C3");
    Engine e6 = emanager.newEngine("UP", "100");
    e6.setModel("GP40");
    e6.setOwner("DAB");
    e6.setBuilt("1944");
    e6.setConsist(con3);
    e6.setMoves(2);
    Engine e7 = emanager.newEngine("SP", "200");
    e7.setModel("GP40");
    e7.setOwner("DAB");
    e7.setBuilt("1944");
    e7.setConsist(con3);
    e7.setMoves(2);
    Engine e8 = emanager.newEngine("SP", "300");
    e8.setModel("GP40");
    e8.setOwner("DAB");
    e8.setBuilt("1944");
    e8.setConsist(con3);
    e8.setMoves(2);
    // Set up three cabooses and six box cars
    Car c1 = cmanager.newCar("PU", "1");
    c1.setTypeName("Caboose");
    c1.setLength("32");
    c1.setMoves(10);
    c1.setOwner("AT");
    c1.setBuilt("1943");
    c1.setCaboose(true);
    Car c2 = cmanager.newCar("SP", "2");
    c2.setTypeName("Caboose");
    c2.setLength("30");
    c2.setMoves(5);
    c2.setOwner("DAB");
    c2.setBuilt("1957");
    c2.setCaboose(true);
    Car c3 = cmanager.newCar("UP", "3");
    c3.setTypeName("Caboose");
    c3.setLength("33");
    c3.setMoves(0);
    c3.setOwner("DAB");
    c3.setBuilt("1944");
    c3.setCaboose(true);
    Car c4 = cmanager.newCar("UP", "4");
    c4.setTypeName("Boxcar");
    c4.setLength("40");
    c4.setMoves(16);
    c4.setOwner("DAB");
    c4.setBuilt("1958");
    c4.setFred(true);
    Car c5 = cmanager.newCar("SP", "5");
    c5.setTypeName("Boxcar");
    c5.setLength("40");
    c5.setMoves(8);
    c5.setOwner("DAB");
    c5.setBuilt("1958");
    c5.setFred(true);
    Car c6 = cmanager.newCar("NH", "6");
    c6.setTypeName("Boxcar");
    c6.setLength("40");
    c6.setMoves(2);
    c6.setOwner("DAB");
    c6.setBuilt("1958");
    c6.setFred(true);
    Car c7 = cmanager.newCar("UP", "7");
    c7.setTypeName("Flat");
    c7.setLength("40");
    c7.setMoves(5);
    c7.setOwner("DAB");
    c7.setBuilt("1958");
    Car c8 = cmanager.newCar("SP", "8");
    c8.setTypeName("Boxcar");
    c8.setLength("40");
    c8.setMoves(4);
    c8.setOwner("DAB");
    c8.setBuilt("1958");
    Car c9 = cmanager.newCar("NH", "9");
    c9.setTypeName("Boxcar");
    c9.setLength("40");
    c9.setMoves(3);
    c9.setOwner("DAB");
    c9.setBuilt("1944");
    Car c10 = cmanager.newCar("NH", "10");
    c10.setTypeName("Boxcar");
    c10.setLength("40");
    c10.setMoves(10);
    c10.setOwner("DAB");
    c10.setBuilt("1958");
    Car c11 = cmanager.newCar("SP", "11");
    c11.setTypeName("Boxcar");
    c11.setLength("40");
    c11.setMoves(3);
    c11.setOwner("DAB");
    c11.setBuilt("1958");
    // Create 5 locations
    Location loc1 = lmanager.newLocation("Harvard");
    Track loc1trk1 = loc1.addTrack("Harvard Yard", Track.YARD);
    loc1trk1.setLength(1000);
    Track loc1trk2 = loc1.addTrack("Harvard Yard 2", Track.YARD);
    loc1trk2.setLength(1000);
    Location loc2 = lmanager.newLocation("Arlington");
    Track loc2trk1 = loc2.addTrack("Arlington Yard", Track.YARD);
    loc2trk1.setLength(1000);
    Location loc3 = lmanager.newLocation("Boston");
    Track loc3trk1 = loc3.addTrack("Boston Yard", Track.YARD);
    loc3trk1.setLength(1000);
    Track loc3trk2 = loc3.addTrack("Boston Yard 2", Track.YARD);
    loc3trk2.setLength(1000);
    Location loc4 = lmanager.newLocation("Chelmsford");
    Track loc4trk1 = loc4.addTrack("Chelmsford Yard", Track.YARD);
    loc4trk1.setLength(1000);
    Track loc4trk2 = loc4.addTrack("Chelmsford Yard 2", Track.YARD);
    loc4trk2.setLength(1000);
    Location loc5 = lmanager.newLocation("Westford");
    Track loc5trk1 = loc5.addTrack("Westford Yard", Track.YARD);
    loc5trk1.setLength(1000);
    Track loc5trk2 = loc5.addTrack("Westford Yard 2", Track.YARD);
    loc5trk2.setLength(1000);
    // Create route with 4 location
    // set default to 7 moves per location
    Setup.setCarMoves(7);
    Route rte1 = rmanager.newRoute("Route 2 Westford");
    rte1.addLocation(loc1);
    RouteLocation rl2 = rte1.addLocation(loc2);
    // set the train icon coordinates
    rl2.setTrainIconX(175);
    rl2.setTrainIconY(150);
    RouteLocation rl3 = rte1.addLocation(loc3);
    // set the train icon coordinates
    rl3.setTrainIconX(25);
    rl3.setTrainIconY(175);
    RouteLocation rl4 = rte1.addLocation(loc4);
    // set the train icon coordinates
    rl4.setTrainIconX(75);
    rl4.setTrainIconY(175);
    // don't allow pickup or drops at Arlington
    rl2.setDropAllowed(false);
    rl2.setPickUpAllowed(false);
    // Create train
    Train train1 = tmanager.newTrain("Harvard to Chelmsford");
    train1.setRoute(rte1);
    // train skips Boston
    train1.addTrainSkipsLocation(rl3.getId());
    // Place cars
    Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(loc2, loc2trk1));
    Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(loc5, loc5trk1));
    Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(loc2, loc2trk1));
    Assert.assertEquals("Place c11", Track.OKAY, c11.setLocation(loc2, loc2trk1));
    // set c9 destination not part of train's route
    Assert.assertEquals("Destination c9", Track.OKAY, c9.setDestination(loc5, loc5trk1));
    // Place engines
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place e3", Track.OKAY, e3.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place e5", Track.OKAY, e5.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place e6", Track.OKAY, e6.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place e7", Track.OKAY, e7.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place e8", Track.OKAY, e8.setLocation(loc1, loc1trk1));
    train1.setRequirements(Train.CABOOSE);
    train1.setNumberEngines("2");
    train1.setOwnerOption(Train.ALL_OWNERS);
    train1.build();
    Assert.assertEquals("Train 1 After Build 1", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 1", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 1", "Chelmsford Yard 2", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 1", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 1", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 1", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 1", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 1", "Chelmsford Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 1", "Chelmsford Yard 2", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 1", "Westford Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 1", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 1", "", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 1", "Chelmsford Yard", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 1", "Chelmsford Yard", e2.getDestinationTrackName());
    Assert.assertEquals("e3 destination 1", "", e3.getDestinationTrackName());
    Assert.assertEquals("e4 destination 1", "", e4.getDestinationTrackName());
    Assert.assertEquals("e5 destination 1", "", e5.getDestinationTrackName());
    Assert.assertEquals("e6 destination 1", "", e6.getDestinationTrackName());
    Assert.assertEquals("e7 destination 1", "", e7.getDestinationTrackName());
    Assert.assertEquals("e8 destination 1", "", e8.getDestinationTrackName());
    // Allow c9 to be used
    // set c9 destination Chelmsford
    Assert.assertEquals("Destination c9", Track.OKAY, c9.setDestination(loc4, null));
    // check that train direction and track direction feature works properly
    loc1trk2.setTrainDirections(Location.SOUTH);
    train1.build();
    Assert.assertEquals("Train 1 After Build test track direction", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 1a", "Chelmsford Yard", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 1a", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 1a", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 1a", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 1a", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 1a", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 1a", "Chelmsford Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 1a", "Chelmsford Yard 2", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 1a", "Chelmsford Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 1a", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 1a", "", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 1a", "Chelmsford Yard 2", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 1a", "Chelmsford Yard 2", e2.getDestinationTrackName());
    Assert.assertEquals("e3 destination 1a", "", e3.getDestinationTrackName());
    Assert.assertEquals("e4 destination 1a", "", e4.getDestinationTrackName());
    Assert.assertEquals("e5 destination 1a", "", e5.getDestinationTrackName());
    Assert.assertEquals("e6 destination 1a", "", e6.getDestinationTrackName());
    Assert.assertEquals("e7 destination 1a", "", e7.getDestinationTrackName());
    Assert.assertEquals("e8 destination 1a", "", e8.getDestinationTrackName());
    loc1trk2.setTrainDirections(Location.NORTH);
    train1.addOwnerName("DAB");
    train1.setOwnerOption(Train.INCLUDE_OWNERS);
    train1.build();
    Assert.assertEquals("Train 1 After Build 2", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 2", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 2", "Chelmsford Yard", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 2", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 2", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 2", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 2", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 2", "Chelmsford Yard", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 2", "Chelmsford Yard 2", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 2", "Chelmsford Yard", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 2", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 2", "", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 2", "", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 2", "", e2.getDestinationTrackName());
    Assert.assertEquals("e3 destination 2", "", e3.getDestinationTrackName());
    Assert.assertEquals("e4 destination 2", "Chelmsford Yard 2", e4.getDestinationTrackName());
    Assert.assertEquals("e5 destination 2", "Chelmsford Yard 2", e5.getDestinationTrackName());
    Assert.assertEquals("e6 destination 2", "", e6.getDestinationTrackName());
    Assert.assertEquals("e7 destination 2", "", e7.getDestinationTrackName());
    Assert.assertEquals("e8 destination 2", "", e8.getDestinationTrackName());
    // test that build fails if Diesel type is not allowed
    train1.deleteTypeName("Diesel");
    train1.build();
    Assert.assertEquals("Train 1 After Build 3", false, train1.isBuilt());
    // restore type Diesel and allow all owners
    train1.addTypeName("Diesel");
    train1.setOwnerOption(Train.ALL_OWNERS);
    train1.build();
    Assert.assertEquals("Train 1 After Build 4", true, train1.isBuilt());
    // Only allow rolling stock built after 1956
    train1.setBuiltStartYear("1956");
    train1.build();
    Assert.assertEquals("Train 1 After Build 5", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 5", "", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 5", "Chelmsford Yard", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 5", "", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 5", "", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 5", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 5", "", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 5", "Chelmsford Yard 2", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 5", "Chelmsford Yard", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 5", "", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 5", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 5", "", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 5", "Chelmsford Yard 2", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 5", "Chelmsford Yard 2", e2.getDestinationTrackName());
    Assert.assertEquals("e3 destination 5", "", e3.getDestinationTrackName());
    Assert.assertEquals("e4 destination 5", "", e4.getDestinationTrackName());
    Assert.assertEquals("e5 destination 5", "", e5.getDestinationTrackName());
    Assert.assertEquals("e6 destination 5", "", e6.getDestinationTrackName());
    Assert.assertEquals("e7 destination 5", "", e7.getDestinationTrackName());
    Assert.assertEquals("e8 destination 5", "", e8.getDestinationTrackName());
    train1.reset();
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) EngineTypes(jmri.jmrit.operations.rollingstock.engines.EngineTypes) EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) CarTypes(jmri.jmrit.operations.rollingstock.cars.CarTypes) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Car(jmri.jmrit.operations.rollingstock.cars.Car) Consist(jmri.jmrit.operations.rollingstock.engines.Consist) CarManager(jmri.jmrit.operations.rollingstock.cars.CarManager) 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)

Example 34 with RouteLocation

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

the class XmlTest method testXMLCreate.

/**
     * Test train XML create, read, and backup support. Originally written as
     * three separate tests, now one large test as of 8/29/2013
     *
     * @throws JDOMException
     * @throws IOException
     */
public void testXMLCreate() throws JDOMException, IOException {
    // confirm that file name has been modified
    Assert.assertEquals("test file name", "OperationsJUnitTestTrainRoster.xml", TrainManagerXml.instance().getOperationsFileName());
    RouteManager rmanager = RouteManager.instance();
    Route A = rmanager.newRoute("A");
    Route B = rmanager.newRoute("B");
    Route C = rmanager.newRoute("C");
    Assert.assertEquals("no locations in route A", 0, A.getLocationsBySequenceList().size());
    Assert.assertEquals("no locations in route B", 0, B.getLocationsBySequenceList().size());
    Assert.assertEquals("no locations in route C", 0, C.getLocationsBySequenceList().size());
    LocationManager lmanager = LocationManager.instance();
    Location Arlington = lmanager.newLocation("Arlington");
    Location Westford = lmanager.newLocation("Westford");
    Location Bedford = lmanager.newLocation("Bedford");
    RouteLocation startA = A.addLocation(Westford);
    // set the train icon coordinates
    startA.setTrainIconX(125);
    startA.setTrainIconY(175);
    RouteLocation startB = B.addLocation(Arlington);
    // set the train icon coordinates
    startB.setTrainIconX(175);
    startB.setTrainIconY(175);
    RouteLocation startC = C.addLocation(Bedford);
    // set the train icon coordinates
    startC.setTrainIconX(25);
    startC.setTrainIconY(200);
    RouteLocation midC = C.addLocation(Arlington);
    RouteLocation endC = C.addLocation(Westford);
    TrainManager manager = TrainManager.instance();
    List<Train> temptrainList = manager.getTrainsByIdList();
    Assert.assertEquals("Starting Number of Trains", 0, temptrainList.size());
    Train t1 = manager.newTrain("Test Number 1");
    Train t2 = manager.newTrain("Test Number 2");
    Train t3 = manager.newTrain("Test Number 3");
    temptrainList = manager.getTrainsByIdList();
    Assert.assertEquals("New Number of Trains", 3, temptrainList.size());
    EngineManager eManager = EngineManager.instance();
    Engine e1 = eManager.newEngine("UP", "1");
    Engine e2 = eManager.newEngine("UP", "2");
    Engine e3 = eManager.newEngine("UP", "3");
    // save in backup file
    t3.setBuildEnabled(true);
    t3.setBuildFailed(false);
    t3.setBuildTrainNormalEnabled(false);
    t3.setBuilt(true);
    t3.setBuiltEndYear("1950");
    t3.setBuiltStartYear("1925");
    t3.setCabooseRoad("t3 X caboose road");
    t3.setComment("t3 X comment");
    t3.setDescription("t3 X description");
    t3.setEngineModel("t3 X engine model");
    t3.setEngineRoad("t3 X engine road");
    t3.setLeadEngine(e1);
    t3.setLoadOption("t3 X load option");
    t3.setManifestLogoURL("t3 X pathName");
    t3.setNumberEngines("7");
    t3.setOwnerOption("t3 X owner option");
    t3.setRailroadName("t3 X railroad name");
    t3.setRequirements(Train.CABOOSE);
    t3.setRoadOption("t3 X raod option");
    t3.setRoute(B);
    t3.setStatusCode(Train.CODE_UNKNOWN);
    TrainManagerXml.instance().writeOperationsFile();
    // Add some more trains and write file again
    // so we can test the backup facility
    Train t4 = manager.newTrain("Test Number 4");
    Train t5 = manager.newTrain("Test Number 5");
    Train t6 = manager.newTrain("Test Number 6");
    Assert.assertNotNull("train 1", t1);
    Assert.assertNotNull("train 2", t2);
    Assert.assertNotNull("train 3", t3);
    Assert.assertNotNull("train 4", t4);
    Assert.assertNotNull("train 5", t5);
    Assert.assertNotNull("train 6", t6);
    t1.setBuildEnabled(true);
    t1.setBuildFailed(true);
    t1.setBuildTrainNormalEnabled(true);
    t1.setBuilt(false);
    t1.setBuiltEndYear("1956");
    t1.setBuiltStartYear("1932");
    t1.setCabooseRoad("t1 caboose road");
    t1.setComment("t1 comment");
    t1.setCurrentLocation(startC);
    t1.setDepartureTime("1", "35");
    t1.setDescription("t1 description");
    t1.setEngineModel("t1 engine model");
    t1.setEngineRoad("t1 engine road");
    t1.setLeadEngine(e1);
    t1.setLoadOption("t1 load option");
    t1.setManifestLogoURL("t1 pathName");
    t1.setNumberEngines("1");
    t1.setOwnerOption("t1 owner option");
    t1.setRailroadName("t1 railroad name");
    t1.setRequirements(Train.NO_CABOOSE_OR_FRED);
    t1.setRoadOption("t1 raod option");
    t1.setRoute(C);
    t1.setSecondLegCabooseRoad("t1 second leg caboose road");
    t1.setSecondLegEndLocation(midC);
    t1.setSecondLegEngineModel("t1 second leg engine model");
    t1.setSecondLegEngineRoad("t1 second leg engine road");
    t1.setSecondLegNumberEngines("5");
    t1.setSecondLegOptions(Train.ADD_CABOOSE);
    t1.setSecondLegStartLocation(endC);
    t1.setSendCarsToTerminalEnabled(true);
    t1.setStatusCode(Train.CODE_UNKNOWN);
    t1.setSwitchListStatus(Train.PRINTED);
    t1.setThirdLegCabooseRoad("t1 third leg caboose road");
    t1.setThirdLegEndLocation(startC);
    t1.setThirdLegEngineModel("t1 third leg engine model");
    t1.setThirdLegEngineRoad("t1 third leg engine road");
    t1.setThirdLegNumberEngines("3");
    t1.setThirdLegOptions(Train.HELPER_ENGINES);
    t1.setThirdLegStartLocation(midC);
    t1.addTrainSkipsLocation(midC.getId());
    t3.setBuildEnabled(false);
    t3.setBuildFailed(true);
    t3.setBuildTrainNormalEnabled(false);
    t3.setBuilt(false);
    t3.setBuiltEndYear("1955");
    t3.setBuiltStartYear("1931");
    t3.setCabooseRoad("t3 caboose road");
    t3.setComment("t3 comment");
    t3.setCurrentLocation(startA);
    t3.setDepartureTime("4", "55");
    t3.setDescription("t3 description");
    t3.setEngineModel("t3 engine model");
    t3.setEngineRoad("t3 engine road");
    t3.setLeadEngine(e2);
    t3.setLoadOption("t3 load option");
    t3.setManifestLogoURL("t3 pathName");
    t3.setNumberEngines("1");
    t3.setOwnerOption("t3 owner option");
    t3.setRailroadName("t3 railroad name");
    t3.setRequirements(Train.NO_CABOOSE_OR_FRED);
    t3.setRoadOption("t3 raod option");
    t3.setRoute(A);
    t3.setStatusCode(Train.CODE_UNKNOWN);
    t5.setBuildEnabled(true);
    t5.setBuildFailed(false);
    t5.setBuildTrainNormalEnabled(false);
    t5.setBuilt(true);
    t5.setBuiltEndYear("1954");
    t5.setBuiltStartYear("1930");
    t5.setCabooseRoad("t5 caboose road");
    t5.setComment("t5 comment");
    t5.setCurrentLocation(startB);
    t5.setDepartureTime("23", "15");
    t5.setDescription("t5 description");
    t5.setEngineModel("t5 engine model");
    t5.setEngineRoad("t5 engine road");
    t5.setLeadEngine(e3);
    t5.setLoadOption("t5 load option");
    t5.setManifestLogoURL("t5 pathName");
    t5.setNumberEngines("1");
    t5.setOwnerOption("t5 owner option");
    t5.setRailroadName("t5 railroad name");
    t5.setRequirements(Train.NO_CABOOSE_OR_FRED);
    t5.setRoadOption("t5 raod option");
    t5.setRoute(B);
    t5.setStatusCode(Train.CODE_UNKNOWN);
    TrainManagerXml.instance().writeOperationsFile();
    // perform data check before dispose
    Assert.assertEquals("t1 build", true, t1.isBuildEnabled());
    Assert.assertEquals("t1 build failed", true, t1.getBuildFailed());
    Assert.assertEquals("t1 build normal", true, t1.isBuildTrainNormalEnabled());
    Assert.assertEquals("t1 built", false, t1.isBuilt());
    Assert.assertEquals("t1 built end year", "1956", t1.getBuiltEndYear());
    Assert.assertEquals("t1 built start year", "1932", t1.getBuiltStartYear());
    Assert.assertEquals("t1 caboose roadr", "t1 caboose road", t1.getCabooseRoad());
    Assert.assertEquals("t1 comment", "t1 comment", t1.getComment());
    Assert.assertEquals("t1 current location name", "Bedford", t1.getCurrentLocationName());
    Assert.assertEquals("t1 departure hour", "01", t1.getDepartureTimeHour());
    Assert.assertEquals("t1 departure minute", "35", t1.getDepartureTimeMinute());
    Assert.assertEquals("t1 engine model", "t1 engine model", t1.getEngineModel());
    Assert.assertEquals("t1 engine road", "t1 engine road", t1.getEngineRoad());
    Assert.assertNotNull("t1 has a lead engine", t1.getLeadEngine());
    Assert.assertEquals("t1 lead engine number", "1", t1.getLeadEngine().getNumber());
    Assert.assertEquals("t1 load option", "t1 load option", t1.getLoadOption());
    Assert.assertEquals("t1 path name", "t1 pathName", t1.getManifestLogoURL());
    Assert.assertEquals("t1 number of engines", "1", t1.getNumberEngines());
    Assert.assertEquals("t1 Owner option", "t1 owner option", t1.getOwnerOption());
    Assert.assertEquals("t1 railroad name", "t1 railroad name", t1.getRailroadName());
    Assert.assertEquals("t1 requirements", Train.NO_CABOOSE_OR_FRED, t1.getRequirements());
    Assert.assertEquals("t1 road option", "t1 raod option", t1.getRoadOption());
    Assert.assertEquals("t1 route", C, t1.getRoute());
    Assert.assertEquals("t1 second leg caboose road", "t1 second leg caboose road", t1.getSecondLegCabooseRoad());
    Assert.assertEquals("t1 second leg end location", midC, t1.getSecondLegEndLocation());
    Assert.assertEquals("t1 second leg engine model", "t1 second leg engine model", t1.getSecondLegEngineModel());
    Assert.assertEquals("t1 second leg engine road", "t1 second leg engine road", t1.getSecondLegEngineRoad());
    Assert.assertEquals("t1 second leg number of engines", "5", t1.getSecondLegNumberEngines());
    Assert.assertEquals("t1 second leg options", Train.ADD_CABOOSE, t1.getSecondLegOptions());
    Assert.assertEquals("t1 second leg start location", endC, t1.getSecondLegStartLocation());
    Assert.assertEquals("t1 send cars to terminal", true, t1.isSendCarsToTerminalEnabled());
    Assert.assertEquals("t1 status", Train.UNKNOWN, t1.getStatus());
    Assert.assertEquals("t1 switch list status", Train.PRINTED, t1.getSwitchListStatus());
    Assert.assertEquals("t1 third leg caboose road", "t1 third leg caboose road", t1.getThirdLegCabooseRoad());
    Assert.assertEquals("t1 third leg end location", startC, t1.getThirdLegEndLocation());
    Assert.assertEquals("t1 third leg engine model", "t1 third leg engine model", t1.getThirdLegEngineModel());
    Assert.assertEquals("t1 third leg engine road", "t1 third leg engine road", t1.getThirdLegEngineRoad());
    Assert.assertEquals("t1 third leg number of engines", "3", t1.getThirdLegNumberEngines());
    Assert.assertEquals("t1 third leg options", Train.HELPER_ENGINES, t1.getThirdLegOptions());
    Assert.assertEquals("t1 third leg start location", midC, t1.getThirdLegStartLocation());
    Assert.assertEquals("t1 skips location", false, t1.skipsLocation(startC.getId()));
    Assert.assertEquals("t1 skips location", true, t1.skipsLocation(midC.getId()));
    Assert.assertEquals("t1 skips location", false, t1.skipsLocation(endC.getId()));
    Assert.assertEquals("t3 build", false, t3.isBuildEnabled());
    Assert.assertEquals("t3 build failed", true, t3.getBuildFailed());
    Assert.assertEquals("t3 build normal", false, t3.isBuildTrainNormalEnabled());
    Assert.assertEquals("t3 built", false, t3.isBuilt());
    Assert.assertEquals("t3 built end year", "1955", t3.getBuiltEndYear());
    Assert.assertEquals("t3 built start year", "1931", t3.getBuiltStartYear());
    Assert.assertEquals("t3 caboose roadr", "t3 caboose road", t3.getCabooseRoad());
    Assert.assertEquals("t3 comment", "t3 comment", t3.getComment());
    Assert.assertEquals("t3 current location name", "Westford", t3.getCurrentLocationName());
    Assert.assertEquals("t3 departure hour", "04", t3.getDepartureTimeHour());
    Assert.assertEquals("t3 departure minute", "55", t3.getDepartureTimeMinute());
    Assert.assertEquals("t3 engine model", "t3 engine model", t3.getEngineModel());
    Assert.assertEquals("t3 engine road", "t3 engine road", t3.getEngineRoad());
    Assert.assertEquals("t3 lead engine number", "2", t3.getLeadEngine().getNumber());
    Assert.assertEquals("t3 load option", "t3 load option", t3.getLoadOption());
    Assert.assertEquals("t3 path name", "t3 pathName", t3.getManifestLogoURL());
    Assert.assertEquals("t3 number of engines", "1", t3.getNumberEngines());
    Assert.assertEquals("t3 Owner option", "t3 owner option", t3.getOwnerOption());
    Assert.assertEquals("t3 railroad name", "t3 railroad name", t3.getRailroadName());
    Assert.assertEquals("t3 requirements", Train.NO_CABOOSE_OR_FRED, t3.getRequirements());
    Assert.assertEquals("t3 road option", "t3 raod option", t3.getRoadOption());
    Assert.assertEquals("t3 route", A, t3.getRoute());
    // test second leg defaults
    Assert.assertEquals("t3 second leg caboose road", "", t3.getSecondLegCabooseRoad());
    Assert.assertEquals("t3 second leg end location", null, t3.getSecondLegEndLocation());
    Assert.assertEquals("t3 second leg engine model", "", t3.getSecondLegEngineModel());
    Assert.assertEquals("t3 second leg engine road", "", t3.getSecondLegEngineRoad());
    Assert.assertEquals("t3 second leg number of engines", "0", t3.getSecondLegNumberEngines());
    Assert.assertEquals("t3 second leg options", Train.NO_CABOOSE_OR_FRED, t3.getSecondLegOptions());
    Assert.assertEquals("t3 second leg start location", null, t3.getSecondLegStartLocation());
    Assert.assertEquals("t3 send cars to terminal", false, t3.isSendCarsToTerminalEnabled());
    Assert.assertEquals("t3 status", Train.UNKNOWN, t3.getStatus());
    Assert.assertEquals("t3 switch list status", Train.UNKNOWN, t3.getSwitchListStatus());
    // test third leg defaults
    Assert.assertEquals("t3 third leg caboose road", "", t3.getThirdLegCabooseRoad());
    Assert.assertEquals("t3 third leg end location", null, t3.getThirdLegEndLocation());
    Assert.assertEquals("t3 third leg engine model", "", t3.getThirdLegEngineModel());
    Assert.assertEquals("t3 third leg engine road", "", t3.getThirdLegEngineRoad());
    Assert.assertEquals("t3 third leg number of engines", "0", t3.getThirdLegNumberEngines());
    Assert.assertEquals("t3 third leg options", Train.NO_CABOOSE_OR_FRED, t3.getThirdLegOptions());
    Assert.assertEquals("t3 third leg start location", null, t3.getThirdLegStartLocation());
    Assert.assertEquals("t5 build", true, t5.isBuildEnabled());
    Assert.assertEquals("t5 build failed", false, t5.getBuildFailed());
    Assert.assertEquals("t5 built", true, t5.isBuilt());
    Assert.assertEquals("t5 built end year", "1954", t5.getBuiltEndYear());
    Assert.assertEquals("t5 built start year", "1930", t5.getBuiltStartYear());
    Assert.assertEquals("t5 caboose roadr", "t5 caboose road", t5.getCabooseRoad());
    Assert.assertEquals("t5 comment", "t5 comment", t5.getComment());
    Assert.assertEquals("t5 current location name", "Arlington", t5.getCurrentLocationName());
    Assert.assertEquals("t5 departure hour", "23", t5.getDepartureTimeHour());
    Assert.assertEquals("t5 departure minute", "15", t5.getDepartureTimeMinute());
    Assert.assertEquals("t5 engine model", "t5 engine model", t5.getEngineModel());
    Assert.assertEquals("t5 engine road", "t5 engine road", t5.getEngineRoad());
    Assert.assertEquals("t5 lead engine number", "3", t5.getLeadEngine().getNumber());
    Assert.assertEquals("t5 load option", "t5 load option", t5.getLoadOption());
    Assert.assertEquals("t5 path name", "t5 pathName", t5.getManifestLogoURL());
    Assert.assertEquals("t5 number of engines", "1", t5.getNumberEngines());
    Assert.assertEquals("t5 Owner option", "t5 owner option", t5.getOwnerOption());
    Assert.assertEquals("t5 railroad name", "t5 railroad name", t5.getRailroadName());
    Assert.assertEquals("t5 requirements", Train.NO_CABOOSE_OR_FRED, t5.getRequirements());
    Assert.assertEquals("t5 road option", "t5 raod option", t5.getRoadOption());
    Assert.assertEquals("t5 route", B, t5.getRoute());
    Assert.assertEquals("t5 status", Train.UNKNOWN, t5.getStatus());
    // clear all trains
    manager.dispose();
    // prevent swing access when loading train icon
    Setup.setPanelName("");
    manager = TrainManager.instance();
    temptrainList = manager.getTrainsByIdList();
    Assert.assertEquals("Starting Number of Trains", 0, temptrainList.size());
    // confirm that none of the trains exist
    t1 = manager.getTrainByName("Test Number 1");
    t2 = manager.getTrainByName("Test Number 2");
    t3 = manager.getTrainByName("Test Number 3");
    t4 = manager.getTrainByName("Test Number 4");
    t5 = manager.getTrainByName("Test Number 5");
    t6 = manager.getTrainByName("Test Number 6");
    Assert.assertNull("train 1", t1);
    Assert.assertNull("train 2", t2);
    Assert.assertNull("train 3", t3);
    Assert.assertNull("train 4", t4);
    Assert.assertNull("train 5", t5);
    Assert.assertNull("train 6", t6);
    // now reload train data from file
    TrainManagerXml.instance().readFile(TrainManagerXml.instance().getDefaultOperationsFilename());
    temptrainList = manager.getTrainsByIdList();
    Assert.assertEquals("Number of Trains", 6, temptrainList.size());
    t1 = manager.getTrainByName("Test Number 1");
    t2 = manager.getTrainByName("Test Number 2");
    t3 = manager.getTrainByName("Test Number 3");
    t4 = manager.getTrainByName("Test Number 4");
    t5 = manager.getTrainByName("Test Number 5");
    t6 = manager.getTrainByName("Test Number 6");
    Assert.assertNotNull("train 1", t1);
    Assert.assertNotNull("train 2", t2);
    Assert.assertNotNull("train 3", t3);
    Assert.assertNotNull("train 4", t4);
    Assert.assertNotNull("train 5", t5);
    Assert.assertNotNull("train 6", t6);
    Assert.assertEquals("t1 build", true, t1.isBuildEnabled());
    Assert.assertEquals("t1 build failed", true, t1.getBuildFailed());
    Assert.assertEquals("t1 build normal", true, t1.isBuildTrainNormalEnabled());
    Assert.assertEquals("t1 built", false, t1.isBuilt());
    Assert.assertEquals("t1 built end year", "1956", t1.getBuiltEndYear());
    Assert.assertEquals("t1 built start year", "1932", t1.getBuiltStartYear());
    Assert.assertEquals("t1 caboose roadr", "t1 caboose road", t1.getCabooseRoad());
    Assert.assertEquals("t1 comment", "t1 comment", t1.getComment());
    Assert.assertEquals("t1 current location name", "Bedford", t1.getCurrentLocationName());
    Assert.assertEquals("t1 departure hour", "01", t1.getDepartureTimeHour());
    Assert.assertEquals("t1 departure minute", "35", t1.getDepartureTimeMinute());
    Assert.assertEquals("t1 engine model", "t1 engine model", t1.getEngineModel());
    Assert.assertEquals("t1 engine road", "t1 engine road", t1.getEngineRoad());
    Assert.assertNotNull("t1 has a lead engine", t1.getLeadEngine());
    Assert.assertEquals("t1 lead engine number", "1", t1.getLeadEngine().getNumber());
    Assert.assertEquals("t1 load option", "t1 load option", t1.getLoadOption());
    Assert.assertEquals("t1 path name", "t1 pathName", t1.getManifestLogoURL());
    Assert.assertEquals("t1 number of engines", "1", t1.getNumberEngines());
    Assert.assertEquals("t1 Owner option", "t1 owner option", t1.getOwnerOption());
    Assert.assertEquals("t1 railroad name", "t1 railroad name", t1.getRailroadName());
    Assert.assertEquals("t1 requirements", Train.NO_CABOOSE_OR_FRED, t1.getRequirements());
    Assert.assertEquals("t1 road option", "t1 raod option", t1.getRoadOption());
    Assert.assertEquals("t1 route", C, t1.getRoute());
    Assert.assertEquals("t1 second leg caboose road", "t1 second leg caboose road", t1.getSecondLegCabooseRoad());
    Assert.assertEquals("t1 second leg end location", midC, t1.getSecondLegEndLocation());
    Assert.assertEquals("t1 second leg engine model", "t1 second leg engine model", t1.getSecondLegEngineModel());
    Assert.assertEquals("t1 second leg engine road", "t1 second leg engine road", t1.getSecondLegEngineRoad());
    Assert.assertEquals("t1 second leg number of engines", "5", t1.getSecondLegNumberEngines());
    Assert.assertEquals("t1 second leg options", Train.ADD_CABOOSE, t1.getSecondLegOptions());
    Assert.assertEquals("t1 second leg start location", endC, t1.getSecondLegStartLocation());
    Assert.assertEquals("t1 send cars to terminal", true, t1.isSendCarsToTerminalEnabled());
    Assert.assertEquals("t1 status", Train.UNKNOWN, t1.getStatus());
    Assert.assertEquals("t1 switch list status", Train.PRINTED, t1.getSwitchListStatus());
    Assert.assertEquals("t1 third leg caboose road", "t1 third leg caboose road", t1.getThirdLegCabooseRoad());
    Assert.assertEquals("t1 third leg end location", startC, t1.getThirdLegEndLocation());
    Assert.assertEquals("t1 third leg engine model", "t1 third leg engine model", t1.getThirdLegEngineModel());
    Assert.assertEquals("t1 third leg engine road", "t1 third leg engine road", t1.getThirdLegEngineRoad());
    Assert.assertEquals("t1 third leg number of engines", "3", t1.getThirdLegNumberEngines());
    Assert.assertEquals("t1 third leg options", Train.HELPER_ENGINES, t1.getThirdLegOptions());
    Assert.assertEquals("t1 third leg start location", midC, t1.getThirdLegStartLocation());
    Assert.assertEquals("t1 skips location", false, t1.skipsLocation(startC.getId()));
    Assert.assertEquals("t1 skips location", true, t1.skipsLocation(midC.getId()));
    Assert.assertEquals("t1 skips location", false, t1.skipsLocation(endC.getId()));
    Assert.assertEquals("t3 build", false, t3.isBuildEnabled());
    Assert.assertEquals("t3 build failed", true, t3.getBuildFailed());
    Assert.assertEquals("t3 build normal", false, t3.isBuildTrainNormalEnabled());
    Assert.assertEquals("t3 built", false, t3.isBuilt());
    Assert.assertEquals("t3 built end year", "1955", t3.getBuiltEndYear());
    Assert.assertEquals("t3 built start year", "1931", t3.getBuiltStartYear());
    Assert.assertEquals("t3 caboose roadr", "t3 caboose road", t3.getCabooseRoad());
    Assert.assertEquals("t3 comment", "t3 comment", t3.getComment());
    Assert.assertEquals("t3 current location name", "Westford", t3.getCurrentLocationName());
    Assert.assertEquals("t3 departure hour", "04", t3.getDepartureTimeHour());
    Assert.assertEquals("t3 departure minute", "55", t3.getDepartureTimeMinute());
    Assert.assertEquals("t3 engine model", "t3 engine model", t3.getEngineModel());
    Assert.assertEquals("t3 engine road", "t3 engine road", t3.getEngineRoad());
    Assert.assertEquals("t3 lead engine number", "2", t3.getLeadEngine().getNumber());
    Assert.assertEquals("t3 load option", "t3 load option", t3.getLoadOption());
    Assert.assertEquals("t3 path name", "t3 pathName", t3.getManifestLogoURL());
    Assert.assertEquals("t3 number of engines", "1", t3.getNumberEngines());
    Assert.assertEquals("t3 Owner option", "t3 owner option", t3.getOwnerOption());
    Assert.assertEquals("t3 railroad name", "t3 railroad name", t3.getRailroadName());
    Assert.assertEquals("t3 requirements", Train.NO_CABOOSE_OR_FRED, t3.getRequirements());
    Assert.assertEquals("t3 road option", "t3 raod option", t3.getRoadOption());
    Assert.assertEquals("t3 route", A, t3.getRoute());
    // test second leg defaults
    Assert.assertEquals("t3 second leg caboose road", "", t3.getSecondLegCabooseRoad());
    Assert.assertEquals("t3 second leg end location", null, t3.getSecondLegEndLocation());
    Assert.assertEquals("t3 second leg engine model", "", t3.getSecondLegEngineModel());
    Assert.assertEquals("t3 second leg engine road", "", t3.getSecondLegEngineRoad());
    Assert.assertEquals("t3 second leg number of engines", "0", t3.getSecondLegNumberEngines());
    Assert.assertEquals("t3 second leg options", Train.NO_CABOOSE_OR_FRED, t3.getSecondLegOptions());
    Assert.assertEquals("t3 second leg start location", null, t3.getSecondLegStartLocation());
    Assert.assertEquals("t3 send cars to terminal", false, t3.isSendCarsToTerminalEnabled());
    Assert.assertEquals("t3 status", Train.UNKNOWN, t3.getStatus());
    Assert.assertEquals("t3 switch list status", Train.UNKNOWN, t3.getSwitchListStatus());
    // test third leg defaults
    Assert.assertEquals("t3 third leg caboose road", "", t3.getThirdLegCabooseRoad());
    Assert.assertEquals("t3 third leg end location", null, t3.getThirdLegEndLocation());
    Assert.assertEquals("t3 third leg engine model", "", t3.getThirdLegEngineModel());
    Assert.assertEquals("t3 third leg engine road", "", t3.getThirdLegEngineRoad());
    Assert.assertEquals("t3 third leg number of engines", "0", t3.getThirdLegNumberEngines());
    Assert.assertEquals("t3 third leg options", Train.NO_CABOOSE_OR_FRED, t3.getThirdLegOptions());
    Assert.assertEquals("t3 third leg start location", null, t3.getThirdLegStartLocation());
    Assert.assertEquals("t5 build", true, t5.isBuildEnabled());
    Assert.assertEquals("t5 build failed", false, t5.getBuildFailed());
    Assert.assertEquals("t5 built", true, t5.isBuilt());
    Assert.assertEquals("t5 built end year", "1954", t5.getBuiltEndYear());
    Assert.assertEquals("t5 built start year", "1930", t5.getBuiltStartYear());
    Assert.assertEquals("t5 caboose roadr", "t5 caboose road", t5.getCabooseRoad());
    Assert.assertEquals("t5 comment", "t5 comment", t5.getComment());
    Assert.assertEquals("t5 current location name", "Arlington", t5.getCurrentLocationName());
    Assert.assertEquals("t5 departure hour", "23", t5.getDepartureTimeHour());
    Assert.assertEquals("t5 departure minute", "15", t5.getDepartureTimeMinute());
    Assert.assertEquals("t5 engine model", "t5 engine model", t5.getEngineModel());
    Assert.assertEquals("t5 engine road", "t5 engine road", t5.getEngineRoad());
    Assert.assertEquals("t5 lead engine number", "3", t5.getLeadEngine().getNumber());
    Assert.assertEquals("t5 load option", "t5 load option", t5.getLoadOption());
    Assert.assertEquals("t5 path name", "t5 pathName", t5.getManifestLogoURL());
    Assert.assertEquals("t5 number of engines", "1", t5.getNumberEngines());
    Assert.assertEquals("t5 Owner option", "t5 owner option", t5.getOwnerOption());
    Assert.assertEquals("t5 railroad name", "t5 railroad name", t5.getRailroadName());
    Assert.assertEquals("t5 requirements", Train.NO_CABOOSE_OR_FRED, t5.getRequirements());
    Assert.assertEquals("t5 road option", "t5 raod option", t5.getRoadOption());
    Assert.assertEquals("t5 route", B, t5.getRoute());
    Assert.assertEquals("t5 status", Train.UNKNOWN, t5.getStatus());
    // now test the train backup file
    manager.dispose();
    manager = TrainManager.instance();
    temptrainList = manager.getTrainsByIdList();
    Assert.assertEquals("Starting Number of Trains", 0, temptrainList.size());
    // set file name to backup
    TrainManagerXml.instance().setOperationsFileName("OperationsJUnitTestTrainRoster.xml.bak");
    TrainManagerXml.instance().readFile(TrainManagerXml.instance().getDefaultOperationsFilename());
    // restore file name
    TrainManagerXml.instance().setOperationsFileName("OperationsJUnitTestTrainRoster.xml");
    temptrainList = manager.getTrainsByIdList();
    Assert.assertEquals("Number of Trains", 3, temptrainList.size());
    t1 = manager.getTrainByName("Test Number 1");
    t2 = manager.getTrainByName("Test Number 2");
    t3 = manager.getTrainByName("Test Number 3");
    t4 = manager.getTrainByName("Test Number 4");
    t5 = manager.getTrainByName("Test Number 5");
    t6 = manager.getTrainByName("Test Number 6");
    Assert.assertNotNull("train 1", t1);
    Assert.assertNotNull("train 2", t2);
    Assert.assertNotNull("train 3", t3);
    Assert.assertNull("train 4", t4);
    Assert.assertNull("train 5", t5);
    Assert.assertNull("train 6", t6);
    Assert.assertEquals("t3 build", true, t3.isBuildEnabled());
    Assert.assertEquals("t3 build failed", false, t3.getBuildFailed());
    Assert.assertEquals("t3 built", true, t3.isBuilt());
    Assert.assertEquals("t3 built end year", "1950", t3.getBuiltEndYear());
    Assert.assertEquals("t3 built start year", "1925", t3.getBuiltStartYear());
    Assert.assertEquals("t3 caboose roadr", "t3 X caboose road", t3.getCabooseRoad());
    Assert.assertEquals("t3 comment", "t3 X comment", t3.getComment());
    Assert.assertEquals("t3 engine model", "t3 X engine model", t3.getEngineModel());
    Assert.assertEquals("t3 engine road", "t3 X engine road", t3.getEngineRoad());
    Assert.assertEquals("t3 load option", "t3 X load option", t3.getLoadOption());
    Assert.assertEquals("t3 path name", "t3 X pathName", t3.getManifestLogoURL());
    Assert.assertEquals("t3 number of engines", "7", t3.getNumberEngines());
    Assert.assertEquals("t3 Owner option", "t3 X owner option", t3.getOwnerOption());
    Assert.assertEquals("t3 railroad name", "t3 X railroad name", t3.getRailroadName());
    Assert.assertEquals("t3 requirements", Train.CABOOSE, t3.getRequirements());
    Assert.assertEquals("t3 raod option", "t3 X raod option", t3.getRoadOption());
    Assert.assertEquals("t3 status", Train.UNKNOWN, t3.getStatus());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) EngineManager(jmri.jmrit.operations.rollingstock.engines.EngineManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Example 35 with RouteLocation

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

the class TrainBuilderTest method testAutoHP.

public void testAutoHP() {
    Assert.assertEquals("confirm default of 1 HPT", 1, Setup.getHorsePowerPerTon());
    EngineTypes et = new EngineTypes();
    et.addName("Diesel");
    // create 5 locations with tracks        
    Location harvard = lmanager.newLocation("Harvard");
    Track loc1trk1 = harvard.addTrack("Harvard Yard 1", Track.YARD);
    loc1trk1.setLength(1000);
    Track loc1trk2 = harvard.addTrack("Harvard Yard 2", Track.YARD);
    loc1trk2.setLength(1000);
    Location arlington = lmanager.newLocation("Arlington");
    Track loc2trk1 = arlington.addTrack("Arlington Siding", Track.YARD);
    loc2trk1.setLength(1000);
    Location boston = lmanager.newLocation("Boston");
    Track loc3trk1 = boston.addTrack("Boston Yard 1", Track.YARD);
    loc3trk1.setLength(1000);
    Track loc3trk2 = boston.addTrack("Boston Yard 2", Track.YARD);
    loc3trk2.setLength(1000);
    Location chelmsford = lmanager.newLocation("Chelmsford");
    Track loc4trk1 = chelmsford.addTrack("Chelmsford Yard 1", Track.YARD);
    loc4trk1.setLength(1000);
    Track loc4trk2 = chelmsford.addTrack("Chelmsford Yard 2", Track.YARD);
    loc4trk2.setLength(1000);
    Location westford = lmanager.newLocation("Westford");
    Track loc5trk1 = westford.addTrack("Westford Yard", Track.YARD);
    loc5trk1.setLength(1000);
    Engine e1 = emanager.newEngine("UP", "1");
    e1.setModel("GP30-200");
    e1.setHp("200");
    e1.setTypeName("Diesel");
    e1.setLength("50");
    e1.setWeightTons("100");
    e1.setMoves(20);
    Engine e2 = emanager.newEngine("SP", "2");
    e2.setModel("GP30-400");
    e2.setHp("400");
    e2.setTypeName("Diesel");
    e2.setLength("50");
    e2.setWeightTons("110");
    e2.setMoves(15);
    Engine e3 = emanager.newEngine("SP", "3");
    e3.setModel("GP40-800");
    e3.setHp("800");
    e3.setTypeName("Diesel");
    e3.setLength("50");
    e3.setWeightTons("120");
    e3.setMoves(10);
    Engine e4 = emanager.newEngine("UP", "10");
    e4.setModel("GP40-1600");
    e4.setHp("1600");
    e4.setTypeName("Diesel");
    e4.setLength("50");
    e4.setWeightTons("130");
    e4.setMoves(5);
    // Place engines
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(harvard, loc1trk1));
    Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(harvard, loc1trk1));
    Assert.assertEquals("Place e3", Track.OKAY, e3.setLocation(harvard, loc1trk1));
    Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(harvard, loc1trk1));
    Route rte1 = rmanager.newRoute("Route Harvard to Westford");
    rte1.addLocation(harvard);
    RouteLocation rlArlington = rte1.addLocation(arlington);
    rte1.addLocation(boston);
    rte1.addLocation(chelmsford);
    rte1.addLocation(westford);
    // add grade to route
    rlArlington.setGrade(1.0);
    // Create train
    Train train1 = tmanager.newTrain("TestAutoHP");
    train1.setRoute(rte1);
    // send all car pulls to terminal
    train1.setSendCarsToTerminalEnabled(true);
    // use autoHP
    train1.setBuildConsistEnabled(true);
    train1.setNumberEngines(Train.AUTO_HPT);
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should build", true, train1.isBuilt());
    // confirm that the specified engines were assigned to the train
    Assert.assertEquals("e1 not assigned to train", null, e1.getDestination());
    Assert.assertEquals("e2 assigned to train, train only needs 400 HP", westford, e2.getDestination());
    Assert.assertEquals("e3 not assigned to train", null, e3.getDestination());
    Assert.assertEquals("e4 not assigned to train", null, e4.getDestination());
    // now increase the train's weight
    Car c1 = cmanager.newCar("UP", "43");
    c1.setTypeName("Boxcar");
    c1.setLength("40");
    // 400 tons loaded
    c1.setWeightTons("400");
    c1.setLoadName(CarLoads.instance().getDefaultLoadName());
    Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(harvard, loc1trk1));
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should build", true, train1.isBuilt());
    // confirm that the specified engines were assigned to the train
    Assert.assertEquals("e1 not assigned to train", null, e1.getDestination());
    Assert.assertEquals("e2 not assigned to train", null, e2.getDestination());
    Assert.assertEquals("e3 not assigned to train", null, e3.getDestination());
    Assert.assertEquals("e4 assigned to train, train needs 1600 HP", westford, e4.getDestination());
    // now increase the train's weight
    Car c2 = cmanager.newCar("UP", "123");
    c2.setTypeName("Boxcar");
    c2.setLength("40");
    // 200 tons loaded
    c2.setWeightTons("200");
    c2.setLoadName(CarLoads.instance().getDefaultLoadName());
    Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(arlington, loc2trk1));
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should build", true, train1.isBuilt());
    // confirm that the specified engines were assigned to the train
    Assert.assertEquals("e1 not assigned to train", null, e1.getDestination());
    Assert.assertEquals("e2 not assigned to train", null, e2.getDestination());
    Assert.assertEquals("e3 assigned to train", westford, e3.getDestination());
    Assert.assertEquals("e4 assigned to train", westford, e4.getDestination());
}
Also used : EngineTypes(jmri.jmrit.operations.rollingstock.engines.EngineTypes) Car(jmri.jmrit.operations.rollingstock.cars.Car) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Track(jmri.jmrit.operations.locations.Track) Engine(jmri.jmrit.operations.rollingstock.engines.Engine) Route(jmri.jmrit.operations.routes.Route) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

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