Search in sources :

Example 71 with Location

use of jmri.jmrit.operations.locations.Location 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 72 with Location

use of jmri.jmrit.operations.locations.Location 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 73 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class TrainTest method testAggressiveBuildOption.

public void testAggressiveBuildOption() {
    Setup.setBuildAggressive(true);
    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 cars
    Car c1 = cmanager.newCar("PU", "13");
    c1.setTypeName("Caboose");
    c1.setLength("32");
    c1.setMoves(10);
    c1.setOwner("AT");
    c1.setBuilt("1943");
    c1.setCaboose(true);
    Car c2 = cmanager.newCar("SP", "23");
    c2.setTypeName("Boxcar");
    c2.setLength("30");
    c2.setMoves(5);
    c2.setOwner("DAB");
    c2.setBuilt("1957");
    Car c3 = cmanager.newCar("UP", "33");
    c3.setTypeName("Boxcar");
    c3.setLength("33");
    c3.setMoves(0);
    c3.setOwner("DAB");
    c3.setBuilt("1944");
    Car c4 = cmanager.newCar("UP", "43");
    c4.setTypeName("Boxcar");
    c4.setLength("40");
    c4.setMoves(16);
    c4.setOwner("DAB");
    c4.setBuilt("1958");
    Car c5 = cmanager.newCar("SP", "53");
    c5.setTypeName("Boxcar");
    c5.setLength("40");
    c5.setMoves(8);
    c5.setOwner("DAB");
    c5.setBuilt("1958");
    Car c6 = cmanager.newCar("NH", "63");
    c6.setTypeName("Boxcar");
    c6.setLength("40");
    c6.setMoves(2);
    c6.setOwner("DAB");
    c6.setBuilt("1958");
    Car c7 = cmanager.newCar("UP", "73");
    c7.setTypeName("Flat");
    c7.setLength("40");
    c7.setMoves(5);
    c7.setOwner("DAB");
    c7.setBuilt("1958");
    Car c8 = cmanager.newCar("SP", "83");
    c8.setTypeName("Boxcar");
    c8.setLength("40");
    c8.setMoves(4);
    c8.setOwner("DAB");
    c8.setBuilt("1958");
    Car c9 = cmanager.newCar("NH", "93");
    c9.setTypeName("Boxcar");
    c9.setLength("40");
    c9.setMoves(3);
    c9.setOwner("DAB");
    c9.setBuilt("1944");
    Car c10 = cmanager.newCar("NH", "103");
    c10.setTypeName("Boxcar");
    c10.setLength("40");
    c10.setMoves(10);
    c10.setOwner("DAB");
    c10.setBuilt("1958");
    Car c11 = cmanager.newCar("SP", "113");
    c11.setTypeName("Boxcar");
    c11.setLength("40");
    c11.setMoves(3);
    c11.setOwner("DAB");
    c11.setBuilt("1958");
    // Create 5 locations
    Location loc1 = lmanager.newLocation("New Harvard");
    Track loc1trk1 = loc1.addTrack("Harvard Yard 1", Track.YARD);
    loc1trk1.setLength(1000);
    Track loc1trk2 = loc1.addTrack("Harvard Yard 2", Track.YARD);
    loc1trk2.setLength(1000);
    Location loc2 = lmanager.newLocation("New Arlington");
    Track loc2trk1 = loc2.addTrack("Arlington Siding", Track.SPUR);
    loc2trk1.setLength(50);
    Location loc3 = lmanager.newLocation("New Boston");
    Track loc3trk1 = loc3.addTrack("Boston Yard 1", Track.YARD);
    loc3trk1.setLength(50);
    Track loc3trk2 = loc3.addTrack("Boston Yard 2", Track.YARD);
    loc3trk2.setLength(50);
    Location loc4 = lmanager.newLocation("New Chelmsford");
    Track loc4trk1 = loc4.addTrack("Chelmsford Yard 1", Track.YARD);
    loc4trk1.setLength(50);
    Track loc4trk2 = loc4.addTrack("Chelmsford Yard 2", Track.YARD);
    loc4trk2.setLength(50);
    Location loc5 = lmanager.newLocation("New Westford");
    Track loc5trk1 = loc5.addTrack("Westford Yard 1", Track.YARD);
    loc5trk1.setLength(1000);
    Track loc5trk2 = loc5.addTrack("Westford Yard 2", Track.YARD);
    loc5trk2.setLength(1000);
    // Create route with 5 location
    Route rte1 = rmanager.newRoute("Route 3 Westford");
    rte1.addLocation(loc1);
    rte1.addLocation(loc2);
    rte1.addLocation(loc3);
    rte1.addLocation(loc4);
    rte1.addLocation(loc5);
    // Create train
    Train train1 = tmanager.newTrain("Harvard to Westford Aggressive");
    train1.setRoute(rte1);
    // 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(loc1, loc1trk1));
    Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(loc1, loc1trk1));
    Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(loc3, loc3trk1));
    Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(loc3, loc3trk2));
    Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(loc4, loc4trk1));
    Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(loc4, loc4trk2));
    Assert.assertEquals("Place c11", Track.OKAY, c11.setLocation(loc1, loc1trk1));
    // 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("3");
    train1.setOwnerOption(Train.ALL_OWNERS);
    train1.build();
    Assert.assertEquals("Train 1 After Build 1", true, train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 1", "Westford Yard 2", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 1", "Westford Yard 1", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 1", "Westford Yard 2", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 1", "Boston Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 1", "Arlington Siding", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 1", "Westford Yard 2", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 1", "Westford Yard 2", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 1", "Westford Yard 1", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 1", "", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 1", "", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 1", "Westford Yard 2", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 1", "", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 1", "", 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", "Westford Yard 1", e6.getDestinationTrackName());
    Assert.assertEquals("e7 destination 1", "Westford Yard 1", e7.getDestinationTrackName());
    Assert.assertEquals("e8 destination 1", "Westford Yard 1", e8.getDestinationTrackName());
    // test departing from staging in aggressive mode
    Assert.assertTrue(train1.reset());
    loc1trk1.setTrackType(Track.STAGING);
    loc1trk2.setTrackType(Track.STAGING);
    loc1.setLocationOps(Location.STAGING);
    train1.build();
    Assert.assertFalse("Train 1 After Build from staging, eight loco on departure track", train1.isBuilt());
    // move locos to other departure track
    Assert.assertEquals("Place e1", Track.OKAY, e1.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place e2", Track.OKAY, e2.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place e3", Track.OKAY, e3.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place e4", Track.OKAY, e4.setLocation(loc1, loc1trk2));
    Assert.assertEquals("Place e5", Track.OKAY, e5.setLocation(loc1, loc1trk2));
    train1.build();
    Assert.assertTrue("Train 1 After Build from staging, three loco on departure track", train1.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 2", "Westford Yard 2", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 2", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 2", "Westford Yard 2", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 2", "Boston Yard 2", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 2", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 2", "Arlington Siding", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 2", "Westford Yard 1", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 2", "Westford Yard 2", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 2", "Westford Yard 2", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 2", "Westford Yard 1", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 2", "Chelmsford Yard 1", 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", "", e4.getDestinationTrackName());
    Assert.assertEquals("e5 destination 2", "", e5.getDestinationTrackName());
    Assert.assertEquals("e6 destination 2", "Westford Yard 1", e6.getDestinationTrackName());
    Assert.assertEquals("e7 destination 2", "Westford Yard 1", e7.getDestinationTrackName());
    Assert.assertEquals("e8 destination 2", "Westford Yard 1", e8.getDestinationTrackName());
    // test train move to a specific location
    Assert.assertFalse("Old Harvard is not part of this trains route", train1.move("Old Harvard"));
    Assert.assertFalse("Train departs New Harvard already there", train1.move("New Harvard"));
    Assert.assertTrue("Next location in train's route is New Arlington", train1.move("New Arlington"));
    Assert.assertFalse("Train is at New Arlington", train1.move("New Arlington"));
    // next location is New Boston, skip it and go directly to New Chelmsford
    Assert.assertTrue("New Chelmsford is in train's route", train1.move("New Chelmsford"));
    Assert.assertTrue("Next location in train's route is New Westford", train1.move("New Westford"));
    Assert.assertFalse("Train is at New Westford last location in train's route", train1.move("New Westford"));
    // terminate train
    train1.move();
    // now try with a train returning to staging, test alternate track feature
    // Create train
    Train train2 = tmanager.newTrain("Westford to Harvard Aggressive");
    Route rte2 = rmanager.copyRoute(rte1, "Route 4 Harvard", true);
    train2.setRoute(rte2);
    train2.setRequirements(Train.CABOOSE);
    train2.setNumberEngines("3");
    // add 2 yard tracks to siding at Arlington
    Track loc2trk2 = loc2.addTrack("Arlington Yard 1", Track.YARD);
    // only enough room for one car
    loc2trk2.setLength(50);
    Track loc2trk3 = loc2.addTrack("Arlington Alternate Track", Track.SPUR);
    // only enough room for two cars
    loc2trk3.setLength(100);
    // set the alternate for Arlington siding
    loc2trk1.setAlternateTrack(loc2trk3);
    // send cars to Arlington siding
    c3.setFinalDestination(loc2);
    c3.setFinalDestinationTrack(loc2trk1);
    c8.setFinalDestination(loc2);
    c8.setFinalDestinationTrack(loc2trk1);
    c9.setFinalDestination(loc2);
    c9.setFinalDestinationTrack(loc2trk1);
    c11.setFinalDestination(loc2);
    c11.setFinalDestinationTrack(loc2trk1);
    train2.build();
    Assert.assertTrue("Train 2 returns to staging", train2.isBuilt());
    // check destinations
    Assert.assertEquals("c1 destination 3", "Harvard Yard 1", c1.getDestinationTrackName());
    Assert.assertEquals("c2 destination 3", "", c2.getDestinationTrackName());
    Assert.assertEquals("c3 destination 3", "Arlington Alternate Track", c3.getDestinationTrackName());
    Assert.assertEquals("c4 destination 3", "Harvard Yard 1", c4.getDestinationTrackName());
    Assert.assertEquals("c5 destination 3", "", c5.getDestinationTrackName());
    Assert.assertEquals("c6 destination 3", "Harvard Yard 1", c6.getDestinationTrackName());
    Assert.assertEquals("c7 destination 3", "Chelmsford Yard 2", c7.getDestinationTrackName());
    Assert.assertEquals("c8 destination 3", "Arlington Yard 1", c8.getDestinationTrackName());
    Assert.assertEquals("c9 destination 3", "Arlington Alternate Track", c9.getDestinationTrackName());
    Assert.assertEquals("c10 destination 3", "Boston Yard 1", c10.getDestinationTrackName());
    Assert.assertEquals("c11 destination 3", "Arlington Siding", c11.getDestinationTrackName());
    Assert.assertEquals("e1 destination 3", "", e1.getDestinationTrackName());
    Assert.assertEquals("e2 destination 3", "", e2.getDestinationTrackName());
    Assert.assertEquals("e3 destination 3", "", e3.getDestinationTrackName());
    Assert.assertEquals("e4 destination 3", "", e4.getDestinationTrackName());
    Assert.assertEquals("e5 destination 3", "", e5.getDestinationTrackName());
    Assert.assertEquals("e6 destination 3", "Harvard Yard 1", e6.getDestinationTrackName());
    Assert.assertEquals("e7 destination 3", "Harvard Yard 1", e7.getDestinationTrackName());
    Assert.assertEquals("e8 destination 3", "Harvard Yard 1", e8.getDestinationTrackName());
    // check that cars on alternate track are sent to Arlington Siding
    Assert.assertEquals("next dest Arlingtion", loc2, c3.getFinalDestination());
    Assert.assertEquals("next dest track Arlingtion Siding", loc2trk1, c3.getFinalDestinationTrack());
    Assert.assertEquals("next dest Arlingtion", loc2, c8.getFinalDestination());
    Assert.assertEquals("next dest track Arlingtion Siding", loc2trk1, c8.getFinalDestinationTrack());
    Assert.assertEquals("next dest Arlingtion", loc2, c9.getFinalDestination());
    Assert.assertEquals("next dest track Arlingtion Siding", loc2trk1, c9.getFinalDestinationTrack());
    Assert.assertEquals("next dest null", null, c11.getFinalDestination());
    Assert.assertEquals("next dest track null", null, c11.getFinalDestinationTrack());
    // test train move to a an exact location
    Assert.assertFalse("Old Harvard is not part of this trains route", train2.moveToNextLocation("Old Harvard"));
    Assert.assertFalse("New Harvard is the last location in this trains route", train2.moveToNextLocation("New Harvard"));
    Assert.assertFalse("New Boston is the 3rd to last location in this trains route", train2.moveToNextLocation("New Boston"));
    Assert.assertFalse("New Westford is the current location in this trains route", train2.moveToNextLocation("New Westford"));
    Assert.assertFalse("New Arlington is the 2nd to last location in this trains route", train2.moveToNextLocation("New Arlington"));
    Assert.assertTrue("New Chelmsford is the next location in this trains route", train2.moveToNextLocation("New Chelmsford"));
    Assert.assertTrue("New Boston is the next location in this trains route", train2.moveToNextLocation("New Boston"));
    Assert.assertTrue("New Arlington is the next location in this trains route", train2.moveToNextLocation("New Arlington"));
    Assert.assertTrue("New Harvard is the next location in this trains route", train2.moveToNextLocation("New Harvard"));
    Assert.assertFalse("Train is at New Harvard", train2.moveToNextLocation("New Harvard"));
    // terminate train
    train2.move();
    // now test train returning to staging
    Setup.setStagingTrackImmediatelyAvail(false);
    rte1.addLocation(loc1);
    train1.build();
    // should fail, can't return to staging track
    Assert.assertEquals("Train 1 deaprting and returning to staging", false, train1.isBuilt());
    // change mode
    Setup.setStagingTrackImmediatelyAvail(true);
    train1.build();
    Assert.assertEquals("Train 1 deaprting and returning to staging", true, train1.isBuilt());
    train1.terminate();
    // check car locations
    Assert.assertEquals("c1 location", "Harvard Yard 1", c1.getTrackName());
    Assert.assertEquals("c2 location", "Harvard Yard 2", c2.getTrackName());
    Assert.assertEquals("c3 location", "Arlington Alternate Track", c3.getTrackName());
    Assert.assertEquals("c4 location", "Boston Yard 2", c4.getTrackName());
    Assert.assertEquals("c5 location", "Harvard Yard 2", c5.getTrackName());
    Assert.assertEquals("c6 location", "Westford Yard 1", c6.getTrackName());
    Assert.assertEquals("c7 location", "Harvard Yard 1", c7.getTrackName());
    Assert.assertEquals("c8 location", "Arlington Siding", c8.getTrackName());
    Assert.assertEquals("c9 location", "Arlington Alternate Track", c9.getTrackName());
    Assert.assertEquals("c10 location", "Chelmsford Yard 1", c10.getTrackName());
    Assert.assertEquals("c11 location", "Westford Yard 2", c11.getTrackName());
    Assert.assertEquals("e1 location", "Harvard Yard 2", e1.getTrackName());
    Assert.assertEquals("e2 location", "Harvard Yard 2", e2.getTrackName());
    Assert.assertEquals("e3 location", "Harvard Yard 2", e3.getTrackName());
    Assert.assertEquals("e4 location", "Harvard Yard 2", e4.getTrackName());
    Assert.assertEquals("e5 location", "Harvard Yard 2", e5.getTrackName());
    Assert.assertEquals("e6 location", "Harvard Yard 1", e6.getTrackName());
    Assert.assertEquals("e7 location", "Harvard Yard 1", e7.getTrackName());
    Assert.assertEquals("e8 location", "Harvard Yard 1", e8.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) 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 74 with Location

use of jmri.jmrit.operations.locations.Location 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)

Example 75 with Location

use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.

the class TrainBuilderTest method testCabooseChanges.

/**
     * The program allows up to two caboose changes in a train's route.
     */
public void testCabooseChanges() {
    // test confirms the order cabooses are assigned to the train
    Setup.setBuildAggressive(true);
    // create 5 locations with tracks        
    Location harvard = lmanager.newLocation("Harvard");
    Track loc1trk1 = harvard.addTrack("Harvard Yard 1", Track.YARD);
    loc1trk1.setLength(80);
    Location arlington = lmanager.newLocation("Arlington");
    Track loc2trk1 = arlington.addTrack("Arlington Siding", Track.YARD);
    loc2trk1.setLength(80);
    Location boston = lmanager.newLocation("Boston");
    Track loc3trk1 = boston.addTrack("Boston Yard 1", Track.YARD);
    loc3trk1.setLength(80);
    Location chelmsford = lmanager.newLocation("Chelmsford");
    Track loc4trk1 = chelmsford.addTrack("Chelmsford Yard 1", Track.YARD);
    loc4trk1.setLength(80);
    Location westford = lmanager.newLocation("Westford");
    Track loc5trk1 = westford.addTrack("Westford Yard", Track.YARD);
    loc5trk1.setLength(40);
    // create and place cabooses
    Car c1 = cmanager.newCar("ABC", "1");
    c1.setTypeName("Caboose");
    c1.setLength("32");
    c1.setCaboose(true);
    Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(harvard, loc1trk1));
    Car c2 = cmanager.newCar("ABC", "2");
    c2.setTypeName("Caboose");
    c2.setLength("32");
    c2.setCaboose(true);
    Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(arlington, loc2trk1));
    Car c3 = cmanager.newCar("XYZ", "3");
    c3.setTypeName("Caboose");
    c3.setLength("32");
    c3.setCaboose(true);
    c2.setMoves(10);
    Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(arlington, loc2trk1));
    Car c4 = cmanager.newCar("ABC", "4");
    c4.setTypeName("Caboose");
    c4.setLength("32");
    c4.setCaboose(true);
    Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(chelmsford, loc4trk1));
    Car c5 = cmanager.newCar("XYZ", "5");
    c5.setTypeName("Caboose");
    c5.setLength("32");
    c5.setCaboose(true);
    c5.setMoves(10);
    Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(chelmsford, loc4trk1));
    // car with FRED at departure
    Car f1 = cmanager.newCar("CBA", "1");
    f1.setTypeName("Boxcar");
    f1.setLength("32");
    f1.setFred(true);
    Assert.assertEquals("Place f1", Track.OKAY, f1.setLocation(harvard, loc1trk1));
    Route rte1 = rmanager.newRoute("Route Harvard to Westford");
    rte1.addLocation(harvard);
    RouteLocation rlArlington = rte1.addLocation(arlington);
    rte1.addLocation(boston);
    RouteLocation rlChelmsford = rte1.addLocation(chelmsford);
    rte1.addLocation(westford);
    // Create train
    Train train1 = tmanager.newTrain("TestCabooseChanges");
    train1.setRoute(rte1);
    // depart with caboose
    train1.setRequirements(Train.CABOOSE);
    // swap out caboose at Arlington
    train1.setSecondLegOptions(Train.ADD_CABOOSE);
    train1.setSecondLegStartLocation(rlArlington);
    train1.setSecondLegCabooseRoad("XYZ");
    // swap out caboose at Chelmsford       
    train1.setThirdLegOptions(Train.ADD_CABOOSE);
    train1.setThirdLegStartLocation(rlChelmsford);
    train1.setThirdLegCabooseRoad("XYZ");
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should build", true, train1.isBuilt());
    // confirm caboose destinations
    Assert.assertEquals("Caboose is part of train", arlington, c1.getDestination());
    Assert.assertEquals("Caboose is not part of train", null, c2.getDestination());
    Assert.assertEquals("Caboose is part of train", chelmsford, c3.getDestination());
    Assert.assertEquals("Caboose is not part of train", null, c4.getDestination());
    Assert.assertEquals("Caboose is part of train", westford, c5.getDestination());
    // now test failures by removing required cabooses
    Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(null, null));
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should not build", false, train1.isBuilt());
    train1.reset();
    Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(arlington, loc2trk1));
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should build", true, train1.isBuilt());
    train1.reset();
    Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(null, null));
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should not build", false, train1.isBuilt());
    train1.reset();
    Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(chelmsford, loc4trk1));
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should build", true, train1.isBuilt());
    // now test removing caboose from train
    train1.setSecondLegOptions(Train.REMOVE_CABOOSE);
    // need room for 1st caboose at Arlington
    loc2trk1.setLength(150);
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should build", true, train1.isBuilt());
    // confirm caboose destinations
    Assert.assertEquals("Caboose is part of train", arlington, c1.getDestination());
    Assert.assertEquals("Caboose is not part of train", null, c2.getDestination());
    Assert.assertEquals("Caboose is not part of train", null, c3.getDestination());
    Assert.assertEquals("Caboose is not part of train", null, c4.getDestination());
    Assert.assertEquals("Caboose is part of train", westford, c5.getDestination());
    // now depart without a caboose, add one, then remove it, and continue to destination
    train1.setRequirements(Train.NO_CABOOSE_OR_FRED);
    train1.setSecondLegOptions(Train.ADD_CABOOSE);
    train1.setThirdLegOptions(Train.REMOVE_CABOOSE);
    // need room for caboose at Chelmsford
    loc4trk1.setLength(150);
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should build", true, train1.isBuilt());
    // confirm caboose destinations
    Assert.assertEquals("Caboose is not part of train", null, c1.getDestination());
    Assert.assertEquals("Caboose is not part of train", null, c2.getDestination());
    Assert.assertEquals("Caboose is part of train", chelmsford, c3.getDestination());
    Assert.assertEquals("Caboose is not part of train", null, c4.getDestination());
    Assert.assertEquals("Caboose is part of train", null, c5.getDestination());
    // try departing with FRED and swapping it for a caboose
    train1.setRequirements(Train.FRED);
    train1.reset();
    new TrainBuilder().build(train1);
    Assert.assertEquals("Train should build", true, train1.isBuilt());
    // confirm destinations
    Assert.assertEquals("Boxcar is part of train", arlington, f1.getDestination());
    Assert.assertEquals("Caboose is not part of train", null, c1.getDestination());
    Assert.assertEquals("Caboose is not part of train", null, c1.getDestination());
    Assert.assertEquals("Caboose is not part of train", null, c2.getDestination());
    Assert.assertEquals("Caboose is part of train", chelmsford, c3.getDestination());
    Assert.assertEquals("Caboose is not part of train", null, c4.getDestination());
    Assert.assertEquals("Caboose is part of train", null, c5.getDestination());
}
Also used : Car(jmri.jmrit.operations.rollingstock.cars.Car) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Track(jmri.jmrit.operations.locations.Track) Route(jmri.jmrit.operations.routes.Route) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Aggregations

Location (jmri.jmrit.operations.locations.Location)186 Track (jmri.jmrit.operations.locations.Track)108 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)82 Route (jmri.jmrit.operations.routes.Route)51 LocationManager (jmri.jmrit.operations.locations.LocationManager)43 Car (jmri.jmrit.operations.rollingstock.cars.Car)41 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)29 RouteManager (jmri.jmrit.operations.routes.RouteManager)21 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)20 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)19 Test (org.junit.Test)18 JCheckBox (javax.swing.JCheckBox)13 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)13 Train (jmri.jmrit.operations.trains.Train)13 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)12 Schedule (jmri.jmrit.operations.locations.schedules.Schedule)11 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)10 File (java.io.File)9 ScheduleItem (jmri.jmrit.operations.locations.schedules.ScheduleItem)9 TrainManager (jmri.jmrit.operations.trains.TrainManager)8