use of org.onebusaway.gtfs_transformer.services.TransformContext in project onebusaway-gtfs-modules by OneBusAway.
the class TransformFactoryTest method testPathInUpdate.
@Test
public void testPathInUpdate() throws IOException, TransformSpecificationException {
_factory.addModificationsFromString("{'op':'update', " + "'match':{'file':'trips.txt'}, " + "'update':{'trip_headsign': 'path(route.longName)'}}");
GtfsTransformStrategy transform = _transformer.getLastTransform();
TransformContext context = new TransformContext();
GtfsMutableRelationalDao dao = new GtfsRelationalDaoImpl();
Route route = new Route();
route.setLongName("long cat");
Trip trip = new Trip();
trip.setId(new AgencyAndId("1", "1"));
trip.setRoute(route);
dao.saveEntity(trip);
transform.run(context, dao);
assertEquals("long cat", trip.getTripHeadsign());
}
use of org.onebusaway.gtfs_transformer.services.TransformContext in project onebusaway-gtfs-modules by OneBusAway.
the class LastStopToHeadsignStrategyTest method test.
@Test
public void test() {
LastStopToHeadsignStrategy _strategy = new LastStopToHeadsignStrategy();
AgencyAndId tripId = new AgencyAndId();
tripId.setId("1.1");
tripId.setAgencyId("agency");
Trip trip = _dao.getTripForId(tripId);
Assert.assertNotSame("C", trip.getTripHeadsign());
_strategy.run(new TransformContext(), _dao);
trip = _dao.getTripForId(tripId);
Assert.assertEquals("C", trip.getTripHeadsign());
}
use of org.onebusaway.gtfs_transformer.services.TransformContext in project onebusaway-gtfs-modules by OneBusAway.
the class RemoveNonRevenueStopsStrategyTest method testExcludeTerminals.
@Test
public void testExcludeTerminals() throws IOException {
RemoveNonRevenueStopsExcludingTerminalsStrategy _strategy = new RemoveNonRevenueStopsExcludingTerminalsStrategy();
_gtfs.putAgencies(1);
_gtfs.putStops(3);
_gtfs.putRoutes(1);
_gtfs.putCalendars(1, "start_date=20120903", "end_date=20121016", "mask=1111100");
_gtfs.putTrips(1, "r0", "sid0");
_gtfs.putLines("stop_times.txt", "trip_id,stop_id,stop_sequence,arrival_time,departure_time,drop_off_type,pickup_type", "t0,s0,0,01:00:00,01:05:00,1,1", "t0,s1,1,01:30:00,01:30:00,0,0", "t0,s2,2,02:30:00,02:30:00,1,1", "t0,s0,3,03:00:00,03:00:00,0,0", "t0,s2,4,03:30:00,03:30:00,1,1");
GtfsMutableRelationalDao dao = _gtfs.read();
_strategy.run(new TransformContext(), dao);
Trip trip = dao.getTripForId(_gtfs.id("t0"));
assertEquals("sid0", trip.getServiceId().getId());
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
assertEquals(4, stopTimes.size());
assertEquals(1, stopTimes.get(3).getPickupType());
assertEquals(0, stopTimes.get(2).getPickupType());
assertEquals(1, stopTimes.get(0).getPickupType());
}
use of org.onebusaway.gtfs_transformer.services.TransformContext in project onebusaway-gtfs-modules by OneBusAway.
the class ShiftNegativeStopTimesUpdateStrategyTest method test.
@Test
public void test() throws IOException {
_gtfs.putAgencies(1);
_gtfs.putStops(3);
_gtfs.putRoutes(1);
_gtfs.putCalendars(1, "start_date=20120903", "end_date=20121016", "mask=1111100");
_gtfs.putTrips(1, "r0", "sid0");
_gtfs.putLines("stop_times.txt", "trip_id,stop_id,stop_sequence,arrival_time,departure_time", "t0,s0,0,-01:00:00,-01:05:00", "t0,s1,1,-01:30:00,-01:30:00", "t0,s2,2,00:30:00,00:30:00");
GtfsMutableRelationalDao dao = _gtfs.read();
_strategy.run(new TransformContext(), dao);
Trip trip = dao.getTripForId(_gtfs.id("t0"));
assertEquals("sid0 -1", trip.getServiceId().getId());
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
assertEquals(3, stopTimes.size());
{
StopTime stopTime = stopTimes.get(0);
assertEquals(stopTime.getArrivalTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:00:00"));
assertEquals(stopTime.getDepartureTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:05:00"));
}
{
StopTime stopTime = stopTimes.get(1);
assertEquals(stopTime.getArrivalTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:30:00"));
assertEquals(stopTime.getDepartureTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:30:00"));
}
{
StopTime stopTime = stopTimes.get(2);
assertEquals(stopTime.getArrivalTime(), StopTimeFieldMappingFactory.getStringAsSeconds("24:30:00"));
assertEquals(stopTime.getDepartureTime(), StopTimeFieldMappingFactory.getStringAsSeconds("24:30:00"));
}
ServiceCalendar c = dao.getCalendarForServiceId(trip.getServiceId());
assertEquals(c.getStartDate(), new ServiceDate(2012, 9, 2));
assertEquals(c.getEndDate(), new ServiceDate(2012, 10, 15));
assertEquals(1, c.getMonday());
assertEquals(1, c.getTuesday());
assertEquals(1, c.getWednesday());
assertEquals(1, c.getThursday());
assertEquals(0, c.getFriday());
assertEquals(0, c.getSaturday());
assertEquals(1, c.getSunday());
}
use of org.onebusaway.gtfs_transformer.services.TransformContext in project onebusaway-gtfs-modules by OneBusAway.
the class TransformFactoryTest method testReplaceIdInUpdate.
@Test
public void testReplaceIdInUpdate() throws IOException, TransformSpecificationException {
_factory.addModificationsFromString("{'op':'update', " + "'match':{'file':'trips.txt'}, " + "'update':{'trip_id': 's/^1_([0-9]*).*/$1/'}}");
GtfsTransformStrategy transform = _transformer.getLastTransform();
TransformContext context = new TransformContext();
context.setDefaultAgencyId("1");
GtfsMutableRelationalDao dao = new GtfsRelationalDaoImpl();
Trip trip = new Trip();
trip.setId(new AgencyAndId("1", "1234-this-text-to-remove"));
dao.saveEntity(trip);
transform.run(context, dao);
assertEquals("1234", trip.getId().getId());
}
Aggregations