package jmri.jmrit.operations.locations; import java.util.List; import org.junit.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jmri.InstanceManager; import jmri.jmrit.operations.OperationsTestCase; import jmri.jmrit.operations.locations.schedules.*; import jmri.jmrit.operations.rollingstock.cars.*; /** * Tests for the Operations Locations class Last manually cross-checked on * 20090131 *
* Still to do: ScheduleItem: XML read/write Schedule: Register, List, XML * read/write Track: AcceptsDropTrain, AcceptsDropRoute Track: * AcceptsPickupTrain, AcceptsPickupRoute Track: CheckScheduleValid Track: XML * read/write Location: Track support <-- I am here Location: XML read/write * * @author Bob Coleman Copyright (C) 2008, 2009 */ public class LocationTest extends OperationsTestCase { // test Location Class (part one) // test Location creation @Test public void testCreate() { Location l = new Location("Test id", "Test Name"); Assert.assertEquals("Location id", "Test id", l.getId()); Assert.assertEquals("Location Name", "Test Name", l.getName()); l.setName("New Test Name"); Assert.assertEquals("New Location Name", "New Test Name", l.getName()); l.setComment("Test Location Comment"); Assert.assertEquals("Location Comment", "Test Location Comment", l.getCommentWithColor()); } // test Location public constants @Test public void testLocationConstants() { Location l = new Location("Test id", "Test Name"); Assert.assertEquals("Location id", "Test id", l.getId()); Assert.assertEquals("Location Name", "Test Name", l.getName()); Assert.assertEquals("Location Constant NORMAL", "1", Location.NORMAL); Assert.assertEquals("Location Constant STAGING", "2", Location.STAGING); Assert.assertEquals("Location Constant EAST", 1, Location.EAST); Assert.assertEquals("Location Constant WEST", 2, Location.WEST); Assert.assertEquals("Location Constant NORTH", 4, Location.NORTH); Assert.assertEquals("Location Constant SOUTH", 8, Location.SOUTH); Assert.assertEquals("Location Constant YARDLISTLENGTH_CHANGED_PROPERTY", "trackListLength", Location.TRACK_LISTLENGTH_CHANGED_PROPERTY); Assert.assertEquals("Location Constant TYPES_CHANGED_PROPERTY", "locationTypes", Location.TYPES_CHANGED_PROPERTY); Assert.assertEquals("Location Constant TRAINDIRECTION_CHANGED_PROPERTY", "locationTrainDirection", Location.TRAIN_DIRECTION_CHANGED_PROPERTY); Assert.assertEquals("Location Constant LENGTH_CHANGED_PROPERTY", "locationTrackLengths", Location.LENGTH_CHANGED_PROPERTY); Assert.assertEquals("Location Constant USEDLENGTH_CHANGED_PROPERTY", "locationUsedLength", Location.USEDLENGTH_CHANGED_PROPERTY); Assert.assertEquals("Location Constant NAME_CHANGED_PROPERTY", "locationName", Location.NAME_CHANGED_PROPERTY); Assert.assertEquals("Location Constant SWITCHLIST_CHANGED_PROPERTY", "switchList", Location.SWITCHLIST_CHANGED_PROPERTY); Assert.assertEquals("Location Constant DISPOSE_CHANGED_PROPERTY", "locationDispose", Location.DISPOSE_CHANGED_PROPERTY); } // test Locations class (part two) // test length attributes @Test public void testLengthAttributes() { Location l = new Location("Test id", "Test Name"); Assert.assertEquals("Location id", "Test id", l.getId()); Assert.assertEquals("Location Name", "Test Name", l.getName()); l.setLength(400); Assert.assertEquals("Location Length", 400, l.getLength()); l.setUsedLength(200); Assert.assertEquals("Location Used Length", 200, l.getUsedLength()); } // test direction attributes @Test public void testDirectionAttributes() { Location l = new Location("Test id", "Test Name"); Assert.assertEquals("Location id", "Test id", l.getId()); Assert.assertEquals("Location Name", "Test Name", l.getName()); l.setTrainDirections(Location.NORTH); Assert.assertEquals("Location Direction North", Location.NORTH, l.getTrainDirections()); l.setTrainDirections(Location.SOUTH); Assert.assertEquals("Location Direction South", Location.SOUTH, l.getTrainDirections()); l.setTrainDirections(Location.EAST); Assert.assertEquals("Location Direction East", Location.EAST, l.getTrainDirections()); l.setTrainDirections(Location.WEST); Assert.assertEquals("Location Direction West", Location.WEST, l.getTrainDirections()); l.setTrainDirections(Location.NORTH + Location.SOUTH); Assert.assertEquals("Location Direction North+South", Location.NORTH + Location.SOUTH, l.getTrainDirections()); l.setTrainDirections(Location.EAST + Location.WEST); Assert.assertEquals("Location Direction East+West", Location.EAST + Location.WEST, l.getTrainDirections()); l.setTrainDirections(Location.NORTH + Location.SOUTH + Location.EAST + Location.WEST); Assert.assertEquals("Location Direction North+South+East+West", Location.NORTH + Location.SOUTH + Location.EAST + Location.WEST, l.getTrainDirections()); } // test car attributes @Test public void testCarAttributes() { Location l = new Location("Test id", "Test Name"); Assert.assertEquals("Location id", "Test id", l.getId()); Assert.assertEquals("Location Name", "Test Name", l.getName()); l.setNumberRS(8); Assert.assertEquals("Location Number of Cars", 8, l.getNumberRS()); } // test switchlist attributes @Test public void testSwitchlistAttributes() { Location l = new Location("Test id", "Test Name"); Assert.assertEquals("Location id", "Test id", l.getId()); Assert.assertEquals("Location Name", "Test Name", l.getName()); l.setSwitchListEnabled(true); Assert.assertEquals("Location Switch List True", true, l.isSwitchListEnabled()); l.setSwitchListEnabled(false); Assert.assertEquals("Location Switch List True", false, l.isSwitchListEnabled()); } // test typename support @Test public void testTypeNameSupport() { // use LocationManager to allow replace car type to work properly Location l = InstanceManager.getDefault(LocationManager.class).newLocation("Test Name"); Assert.assertEquals("Location Name", "Test Name", l.getName()); Assert.assertEquals("Location Accepts Type Name undefined", false, l.acceptsTypeName("TestTypeName")); // l.addTypeName("TestTypeName"); // Assert.assertEquals("Location Accepts Type Name defined", false, l.acceptsTypeName("TestTypeName")); // now add to car types CarTypes ct = InstanceManager.getDefault(CarTypes.class); ct.addName("TestTypeName"); l.addTypeName("TestTypeName"); Assert.assertEquals("Location Accepts Type Name defined", true, l.acceptsTypeName("TestTypeName")); l.deleteTypeName("TestTypeName"); Assert.assertEquals("Location Accepts Type Name undefined2", false, l.acceptsTypeName("TestTypeName")); ct.addName("Baggage"); ct.addName("BoxCar"); ct.addName(Bundle.getMessage("Caboose")); ct.addName("Coal"); ct.addName("Engine"); ct.addName("Hopper"); ct.addName("MOW"); ct.addName("Passenger"); ct.addName("Reefer"); ct.addName("Stock"); ct.addName("Tank Oil"); l.addTypeName("Baggage"); l.addTypeName("BoxCar"); l.addTypeName(Bundle.getMessage("Caboose")); l.addTypeName("Coal"); l.addTypeName("Engine"); l.addTypeName("Hopper"); l.addTypeName("MOW"); l.addTypeName("Passenger"); l.addTypeName("Reefer"); l.addTypeName("Stock"); l.addTypeName("Tank Oil"); Track t = l.addTrack("new track", Track.SPUR); Assert.assertEquals("Location Accepts Type Name BoxCar", true, l.acceptsTypeName("BoxCar")); Assert.assertEquals("Location Accepts Type Name boxCar", false, l.acceptsTypeName("boxCar")); Assert.assertEquals("Location Accepts Type Name MOW", true, l.acceptsTypeName("MOW")); Assert.assertEquals("Location Accepts Type Name Caboose", true, l.acceptsTypeName(Bundle.getMessage("Caboose"))); Assert.assertEquals("Location Accepts Type Name BoxCar", true, l.acceptsTypeName("BoxCar")); Assert.assertEquals("Location Accepts Type Name undefined3", false, l.acceptsTypeName("TestTypeName")); Assert.assertEquals("Track Accepts Type Name BoxCar", true, t.isTypeNameAccepted("BoxCar")); Assert.assertEquals("Track Accepts Type Name boxCar", false, t.isTypeNameAccepted("boxCar")); Assert.assertEquals("Track Accepts Type Name MOW", true, t.isTypeNameAccepted("MOW")); Assert.assertEquals("Track Accepts Type Name Caboose", true, t.isTypeNameAccepted(Bundle.getMessage("Caboose"))); Assert.assertEquals("Track Accepts Type Name undefined3", false, t.isTypeNameAccepted("undefined")); t.addTypeName("Baggage"); t.addTypeName("BoxCar"); t.addTypeName(Bundle.getMessage("Caboose")); t.addTypeName("Coal"); t.addTypeName("Engine"); t.addTypeName("Hopper"); t.addTypeName("MOW"); t.addTypeName("Passenger"); t.addTypeName("Reefer"); t.addTypeName("Stock"); t.addTypeName("Tank Oil"); Assert.assertEquals("Track Accepts Type Name BoxCar", true, t.isTypeNameAccepted("BoxCar")); Assert.assertEquals("Track Accepts Type Name boxCar", false, t.isTypeNameAccepted("boxCar")); Assert.assertEquals("Track Accepts Type Name MOW", true, t.isTypeNameAccepted("MOW")); Assert.assertEquals("Track Accepts Type Name Caboose", true, t.isTypeNameAccepted(Bundle.getMessage("Caboose"))); Assert.assertEquals("Track Accepts Type Name BoxCar", true, t.isTypeNameAccepted("BoxCar")); Assert.assertEquals("Track Accepts Type Name undefined3", false, t.isTypeNameAccepted("undefined")); // test replace // also test replace type in schedules ScheduleManager sm = InstanceManager.getDefault(ScheduleManager.class); Schedule s = sm.newSchedule("newest schedule"); ScheduleItem i1 = s.addItem("BoxCar"); ScheduleItem i2 = s.addItem(Bundle.getMessage("Caboose")); Assert.assertEquals("ScheudleItem i1 Type BoxCar", "BoxCar", i1.getTypeName()); Assert.assertEquals("ScheudleItem i2 Type Caboose", Bundle.getMessage("Caboose"), i2.getTypeName()); ct.replaceName("BoxCar", "boxcar"); Assert.assertFalse("Location Does Not Accepts Type Name BoxCar", l.acceptsTypeName("BoxCar")); Assert.assertTrue("Location Accepts Type Name boxcar", l.acceptsTypeName("boxcar")); Assert.assertFalse("Track Does Not Accepts Type Name BoxCar", l.acceptsTypeName("BoxCar")); Assert.assertTrue("Track Accepts Type Name boxcar", t.isTypeNameAccepted("boxcar")); Assert.assertEquals("ScheudleItem i1 Type boxcar", "boxcar", i1.getTypeName()); Assert.assertEquals("Check ScheudleItem i2 Type Caboose", Bundle.getMessage("Caboose"), i2.getTypeName()); // remove all schedules sm.dispose(); } @Test public void testRoadNameSupport() { // use LocationManager to allow replace car road to work properly Location l = InstanceManager.getDefault(LocationManager.class).newLocation("Test Name 2"); Assert.assertEquals("Location Name", "Test Name 2", l.getName()); Track t = l.addTrack("new track", Track.SPUR); Assert.assertEquals("Location", l, t.getLocation()); t.setRoadOption(Track.INCLUDE_ROADS); t.addRoadName("Test Road Name"); t.addRoadName("Test Road Name 2"); ScheduleManager sm = InstanceManager.getDefault(ScheduleManager.class); Schedule s = sm.newSchedule("test schedule"); ScheduleItem i1 = s.addItem("BoxCar"); ScheduleItem i2 = s.addItem("BoxCar"); i1.setRoadName("Test Road Name"); i2.setRoadName("Test Road Name 2"); Assert.assertTrue("track should accept road Test Road Name", t.isRoadNameAccepted("Test Road Name")); Assert.assertTrue("track should accept road Test Road Name 2", t.isRoadNameAccepted("Test Road Name 2")); Assert.assertFalse("track should Not accept road New Test Road Name", t.isRoadNameAccepted("New Test Road Name")); Assert.assertEquals("ScheudleItem i1 Road Test Road Name", "Test Road Name", i1.getRoadName()); Assert.assertEquals("ScheudleItem i2 Road Test Road Name", "Test Road Name 2", i2.getRoadName()); CarRoads cr = InstanceManager.getDefault(CarRoads.class); cr.replaceName("Test Road Name", "New Test Road Name"); Assert.assertFalse("track should Not accept road Test Road Name", t.isRoadNameAccepted("Test Road Name")); Assert.assertTrue("track should accept road Test Road Name 2", t.isRoadNameAccepted("Test Road Name 2")); Assert.assertTrue("track should accept road New Test Road Name", t.isRoadNameAccepted("New Test Road Name")); Assert.assertEquals("ScheudleItem i1 Road Test Road Name", "New Test Road Name", i1.getRoadName()); Assert.assertEquals("Check ScheudleItem i2 Road Test Road Name", "Test Road Name 2", i2.getRoadName()); // remove all schedules sm.dispose(); } // test pickup support @Test public void testPickUpSupport() { Location l = new Location("Test id", "Test Name"); Assert.assertEquals("Location id", "Test id", l.getId()); Assert.assertEquals("Location Name", "Test Name", l.getName()); Assert.assertEquals("Location Pick Ups Start Condition", 0, l.getPickupRS()); l.addPickupRS(); Assert.assertEquals("Location Pick Up 1", 1, l.getPickupRS()); l.addPickupRS(); Assert.assertEquals("Location Pick Up second", 2, l.getPickupRS()); l.deletePickupRS(); Assert.assertEquals("Location Delete Pick Up", 1, l.getPickupRS()); l.deletePickupRS(); Assert.assertEquals("Location Delete Pick Up second", 0, l.getPickupRS()); } // test drop support @Test public void testDropSupport() { Location l = new Location("Test id", "Test Name"); Assert.assertEquals("Location id", "Test id", l.getId()); Assert.assertEquals("Location Name", "Test Name", l.getName()); Assert.assertEquals("Location Drop Start Condition", 0, l.getPickupRS()); l.addDropRS(); Assert.assertEquals("Location Drop 1", 1, l.getDropRS()); l.addDropRS(); Assert.assertEquals("Location Drop second", 2, l.getDropRS()); l.deleteDropRS(); Assert.assertEquals("Location Delete Drop", 1, l.getDropRS()); l.deleteDropRS(); Assert.assertEquals("Location Delete Drop second", 0, l.getDropRS()); } // test car support @Test public void testCarSupport() { Location l = new Location("Test id", "Test Name"); Assert.assertEquals("Location id", "Test id", l.getId()); Assert.assertEquals("Location Name", "Test Name", l.getName()); Assert.assertEquals("Location Used Length", 0, l.getUsedLength()); Assert.assertEquals("Location Number of Cars", 0, l.getNumberRS()); Car c1 = new Car("TESTROAD", "TESTNUMBER1"); c1.setLength("40"); l.addRS(c1); Assert.assertEquals("Location Number of Cars", 1, l.getNumberRS()); Assert.assertEquals("Location Used Length one car", 44, l.getUsedLength()); // Drawbar length is 4 Car c2 = new Car("TESTROAD", "TESTNUMBER2"); c2.setLength("33"); l.addRS(c2); Assert.assertEquals("Location Number of Cars", 2, l.getNumberRS()); Assert.assertEquals("Location Used Length one car", 40 + 4 + 33 + 4, l.getUsedLength()); // Drawbar length is 4 Car c3 = new Car("TESTROAD", "TESTNUMBER3"); c3.setLength("50"); l.addRS(c3); Assert.assertEquals("Location Number of Cars", 3, l.getNumberRS()); Assert.assertEquals("Location Used Length one car", 40 + 4 + 33 + 4 + 50 + 4, l.getUsedLength()); // Drawbar // length is // 4 l.deleteRS(c2); Assert.assertEquals("Location Number of Cars", 2, l.getNumberRS()); Assert.assertEquals("Location Used Length one car", 40 + 4 + 50 + 4, l.getUsedLength()); // Drawbar length is 4 l.deleteRS(c1); Assert.assertEquals("Location Number of Cars", 1, l.getNumberRS()); Assert.assertEquals("Location Used Length one car", 50 + 4, l.getUsedLength()); // Drawbar length is 4 l.deleteRS(c3); Assert.assertEquals("Location Number of Cars", 0, l.getNumberRS()); Assert.assertEquals("Location Used Length one car", 0, l.getUsedLength()); // Drawbar length is 4 } // test car duplicates support @Test public void testCarDuplicatesSupport() { Location l = new Location("Test id", "Test Name"); Assert.assertEquals("Location id", "Test id", l.getId()); Assert.assertEquals("Location Name", "Test Name", l.getName()); Assert.assertEquals("Location Used Length", 0, l.getUsedLength()); Assert.assertEquals("Location Number of Cars", 0, l.getNumberRS()); Car c1 = new Car("TESTROAD", "TESTNUMBER1"); c1.setLength("40"); l.addRS(c1); Assert.assertEquals("Location Number of Cars", 1, l.getNumberRS()); Assert.assertEquals("Location Used Length one car", 44, l.getUsedLength()); // Drawbar length is 4 Car c2 = new Car("TESTROAD", "TESTNUMBER2"); c2.setLength("33"); l.addRS(c2); Assert.assertEquals("Location Number of Cars", 2, l.getNumberRS()); Assert.assertEquals("Location Used Length one car", 40 + 4 + 33 + 4, l.getUsedLength()); // Drawbar length is 4 l.addRS(c1); Assert.assertEquals("Location Number of Cars", 3, l.getNumberRS()); Assert.assertEquals("Location Used Length one car", 40 + 4 + 33 + 4 + 40 + 4, l.getUsedLength()); // Drawbar // length is // 4 } // test track priority @Test public void testTrackPriority() { LocationManager locMan = new LocationManager(); Location l = locMan.newLocation("TestPriority Location"); Track t1 = l.addTrack("Yard 1", Track.YARD); Track t2 = l.addTrack("Yard 2", Track.YARD); Track t3 = l.addTrack("Spur 1", Track.SPUR); Track t4 = l.addTrack("Spur 2", Track.SPUR); Track t5 = l.addTrack("Interchange 1", Track.INTERCHANGE); Track t6 = l.addTrack("Interchange 2", Track.INTERCHANGE); Track t7 = l.addTrack("Interchange 3", Track.INTERCHANGE); // set the priority bias t1.setMoves(12); t2.setMoves(14); t3.setMoves(18); // lowest priority t4.setMoves(11); t5.setMoves(10); // highest priority t6.setMoves(16); t7.setMoves(15); // get all tracks ids List