use of jmri.jmrit.operations.locations.Location 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());
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class TrainBuilderTest method testCarOrderFIFO.
public void testCarOrderFIFO() {
TrainBuilder tb = new TrainBuilder();
// start by creating a track
Location A = lmanager.newLocation("A");
Track interchangeTrack = A.addTrack("track", Track.INTERCHANGE);
interchangeTrack.setLength(1000);
interchangeTrack.setServiceOrder(Track.FIFO);
java.util.Calendar cal = java.util.Calendar.getInstance();
java.util.Date date = cal.getTime();
// and placing 3 cars on the track.
Car a = cmanager.newCar("ABC", "123");
a.setTypeName("Boxcar");
a.setLength("50");
a.setLastDate(date);
a.setLocation(A, interchangeTrack);
cal.add(java.util.Calendar.MINUTE, 2);
date = cal.getTime();
Car b = cmanager.newCar("ABC", "321");
b.setTypeName("Boxcar");
b.setLength("50");
b.setLastDate(date);
b.setLocation(A, interchangeTrack);
cal.add(java.util.Calendar.MINUTE, 2);
date = cal.getTime();
Car c = cmanager.newCar("ABC", "111");
c.setTypeName("Boxcar");
c.setLength("50");
c.setLastDate(date);
c.setLocation(A, interchangeTrack);
// NOTE: this test uses reflection to test a private method.
java.lang.reflect.Method getCarOrderMethod = null;
try {
getCarOrderMethod = tb.getClass().getDeclaredMethod("getCarOrder", Car.class);
} catch (java.lang.NoSuchMethodException nsm) {
Assert.fail("Could not find method getCarOrder in TrackBuilder class: ");
}
// override the default permissions.
Assert.assertNotNull(getCarOrderMethod);
getCarOrderMethod.setAccessible(true);
// and set the car list up.
tb._carList = new java.util.ArrayList<Car>();
tb._carList.add(a);
tb._carList.add(b);
tb._carList.add(c);
try {
// FIFO order should always return 123.
Car d = (Car) getCarOrderMethod.invoke(tb, a);
Assert.assertEquals("FIFO Order, 123 first", a, d);
d = (Car) getCarOrderMethod.invoke(tb, b);
Assert.assertEquals("FIFO Order, 123 second", a, d);
d = (Car) getCarOrderMethod.invoke(tb, c);
Assert.assertEquals("FIFO Order, 123 third", a, d);
} catch (java.lang.IllegalAccessException iae) {
Assert.fail("Could not access method getCarOrder in TrackBuilder class");
} catch (java.lang.reflect.InvocationTargetException ite) {
Throwable cause = ite.getCause();
Assert.fail("getCarOrder executon failed reason: " + cause.getMessage());
}
}
use of jmri.jmrit.operations.locations.Location 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());
}
use of jmri.jmrit.operations.locations.Location 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());
}
use of jmri.jmrit.operations.locations.Location in project JMRI by JMRI.
the class ScheduleEditFrameGuiTest method testScheduleComboBoxes.
@Test
public void testScheduleComboBoxes() {
LocationManager lm = LocationManager.instance();
Location l = lm.newLocation("new test location");
Track t = l.addTrack("track 1", Track.SPUR);
ScheduleManager sm = ScheduleManager.instance();
// clear out any previous schedules
sm.dispose();
sm = ScheduleManager.instance();
Schedule s1 = sm.newSchedule("new schedule");
Schedule s2 = sm.newSchedule("newer schedule");
ScheduleItem i1 = s1.addItem("BoxCar");
i1.setRoadName("new road");
i1.setReceiveLoadName("new load");
i1.setShipLoadName("new ship load");
ScheduleItem i2 = s1.addItem("Caboose");
i2.setRoadName("road");
i2.setReceiveLoadName("load");
i2.setShipLoadName("ship load");
Assert.assertEquals("1 First schedule name", "new schedule", s1.getName());
Assert.assertEquals("1 First schedule name", "newer schedule", s2.getName());
List<Schedule> names = sm.getSchedulesByNameList();
Assert.assertEquals("There should be 2 schedules", 2, names.size());
Schedule sch1 = names.get(0);
Schedule sch2 = names.get(1);
Assert.assertEquals("2 First schedule name", "new schedule", sch1.getName());
Assert.assertEquals("2 First schedule name", "newer schedule", sch2.getName());
Assert.assertEquals("Schedule 1", sch1, sm.getScheduleByName("new schedule"));
Assert.assertEquals("Schedule 2", sch2, sm.getScheduleByName("newer schedule"));
JComboBox<Schedule> box = sm.getComboBox();
Assert.assertEquals("3 First schedule name", null, box.getItemAt(0));
Assert.assertEquals("3 First schedule name", sch1, box.getItemAt(1));
Assert.assertEquals("3 First schedule name", sch2, box.getItemAt(2));
JComboBox<LocationTrackPair> box2 = sm.getSpursByScheduleComboBox(s1);
Assert.assertEquals("First siding name", null, box2.getItemAt(0));
// now add a schedule to siding
t.setScheduleId(sch1.getId());
JComboBox<LocationTrackPair> box3 = sm.getSpursByScheduleComboBox(s1);
LocationTrackPair ltp = box3.getItemAt(0);
Assert.assertEquals("Location track pair location", l, ltp.getLocation());
Assert.assertEquals("Location track pair track", t, ltp.getTrack());
// remove all schedules
sm.dispose();
names = sm.getSchedulesByNameList();
Assert.assertEquals("There should be no schedules", 0, names.size());
}
Aggregations