Search in sources :

Example 11 with LocationManager

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

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

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

the class TrainTest method testRouteLocationsBuild.

public void testRouteLocationsBuild() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    Train train = tmanager.newTrain("Test");
    // exercise manifest build
    train.setRailroadName("Working Railroad");
    train.setComment("One Hard Working Train");
    // now add a route that doesn't have any locations
    Route route = rmanager.newRoute("TestRoute");
    train.setRoute(route);
    // now add a location to the route
    Location depart = lmanager.newLocation("depart");
    RouteLocation rl = route.addLocation(depart);
    train.build();
    Assert.assertTrue("Train should build", train.isBuilt());
    Assert.assertEquals("Train built", Train.CODE_PARTIAL_BUILT, train.getStatusCode());
    // delete location
    lmanager.deregister(depart);
    train.build();
    Assert.assertFalse("Train should not build, location deleted", train.isBuilt());
    Assert.assertEquals("Train build failed", Train.CODE_BUILD_FAILED, train.getStatusCode());
    // recreate location
    depart = lmanager.newLocation("depart");
    train.build();
    Assert.assertFalse("Train should not build, location recreated, but not part of route", train.isBuilt());
    route.deleteLocation(rl);
    route.addLocation(depart);
    train.build();
    Assert.assertTrue("Train should build, route repaired", train.isBuilt());
    Location terminate = lmanager.newLocation("terminate");
    rl = route.addLocation(terminate);
    train.build();
    Assert.assertTrue("Train should build, route has two locations", train.isBuilt());
    // delete terminal location
    lmanager.deregister(terminate);
    train.build();
    Assert.assertFalse("Train should not build, terminal location deleted", train.isBuilt());
    route.deleteLocation(rl);
    terminate = lmanager.newLocation("terminate");
    rl = route.addLocation(terminate);
    train.build();
    Assert.assertTrue("Train should build, route has been repaired", train.isBuilt());
    Location middle = lmanager.newLocation("middle");
    // staging tracks in the middle of the route are ignored
    middle.addTrack("staging in the middle", Track.STAGING);
    // next 5 lines exercise manifest build messages
    Setup.setPrintLocationCommentsEnabled(true);
    middle.setComment("Middle comment");
    // put location in middle of route
    rl = route.addLocation(middle, 2);
    rl.setDepartureTime("12:30");
    rl.setComment("This location has a departure time");
    train.build();
    Assert.assertTrue("Train should build, three location route", train.isBuilt());
    // delete location in the middle
    lmanager.deregister(middle);
    train.build();
    Assert.assertFalse("Train should not build, middle location deleted", train.isBuilt());
    // remove the middle location from the route
    route.deleteLocation(rl);
    train.build();
    Assert.assertTrue("Train should build, two location route", train.isBuilt());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) 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 14 with LocationManager

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

the class TrainTest method testBuildRequiresCars.

public void testBuildRequiresCars() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    Train train = tmanager.newTrain("Test");
    // exercise manifest build
    train.setRailroadName("Working Railroad");
    train.setComment("One Hard Working Train");
    // now add a route that doesn't have any locations
    Route route = rmanager.newRoute("TestRoute");
    train.setRoute(route);
    // now add locations to the route
    Location depart = lmanager.newLocation("depart");
    route.addLocation(depart);
    Location terminate = lmanager.newLocation("terminate");
    route.addLocation(terminate);
    Location middle = lmanager.newLocation("middle");
    // put location in middle of route
    route.addLocation(middle, 2);
    // Build option require cars
    Control.fullTrainOnly = true;
    train.build();
    Assert.assertFalse("Train should not build, requires cars", train.isBuilt());
    // restore control
    Control.fullTrainOnly = false;
    train.build();
    Assert.assertTrue("Train should build, build doesn't require cars", train.isBuilt());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) 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 15 with LocationManager

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

the class TrainTest method testAutoEnginesBuildFailNoEngines.

public void testAutoEnginesBuildFailNoEngines() {
    TrainManager tmanager = TrainManager.instance();
    RouteManager rmanager = RouteManager.instance();
    LocationManager lmanager = LocationManager.instance();
    // This test uses the maximum length of a train in route
    Setup.setMaxTrainLength(1000);
    Train train = tmanager.newTrain("AutoEngineTest");
    train.setNumberEngines(Train.AUTO);
    Route route = rmanager.newRoute("AutoEngineTest");
    train.setRoute(route);
    Location A = lmanager.newLocation("A");
    Location B = lmanager.newLocation("B");
    Location C = lmanager.newLocation("C");
    Track At = A.addTrack("track", Track.SPUR);
    Track Bt = B.addTrack("track", Track.SPUR);
    Track Ct = C.addTrack("track", Track.SPUR);
    At.setLength(300);
    Bt.setLength(300);
    Ct.setLength(300);
    RouteLocation rA = route.addLocation(A);
    RouteLocation rB = route.addLocation(B);
    RouteLocation rC = route.addLocation(C);
    rA.setMaxCarMoves(5);
    rB.setMaxCarMoves(5);
    rC.setMaxCarMoves(5);
    // Auto Engines calculates the number of engines based on requested moves in the route
    train.build();
    Assert.assertFalse("Train should not build, no engines", train.isBuilt());
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Route(jmri.jmrit.operations.routes.Route) Track(jmri.jmrit.operations.locations.Track) RouteManager(jmri.jmrit.operations.routes.RouteManager) RouteLocation(jmri.jmrit.operations.routes.RouteLocation) Location(jmri.jmrit.operations.locations.Location)

Aggregations

LocationManager (jmri.jmrit.operations.locations.LocationManager)45 Location (jmri.jmrit.operations.locations.Location)43 Track (jmri.jmrit.operations.locations.Track)33 RouteLocation (jmri.jmrit.operations.routes.RouteLocation)28 Route (jmri.jmrit.operations.routes.Route)23 RouteManager (jmri.jmrit.operations.routes.RouteManager)21 Car (jmri.jmrit.operations.rollingstock.cars.Car)18 CarManager (jmri.jmrit.operations.rollingstock.cars.CarManager)18 Engine (jmri.jmrit.operations.rollingstock.engines.Engine)13 EngineManager (jmri.jmrit.operations.rollingstock.engines.EngineManager)13 CarTypes (jmri.jmrit.operations.rollingstock.cars.CarTypes)12 Consist (jmri.jmrit.operations.rollingstock.engines.Consist)10 Train (jmri.jmrit.operations.trains.Train)9 TrainManager (jmri.jmrit.operations.trains.TrainManager)9 Schedule (jmri.jmrit.operations.locations.schedules.Schedule)7 ScheduleItem (jmri.jmrit.operations.locations.schedules.ScheduleItem)7 ScheduleManager (jmri.jmrit.operations.locations.schedules.ScheduleManager)7 Test (org.junit.Test)7 CarRoads (jmri.jmrit.operations.rollingstock.cars.CarRoads)6 EngineTypes (jmri.jmrit.operations.rollingstock.engines.EngineTypes)6