Search in sources :

Example 11 with TransformContext

use of org.onebusaway.gtfs_transformer.services.TransformContext in project onebusaway-gtfs-modules by OneBusAway.

the class TransformFactoryTest method testReplaceValueInUpdateRegex.

@Test
public void testReplaceValueInUpdateRegex() throws IOException, TransformSpecificationException {
    _factory.addModificationsFromString("{'op':'update', " + "'match':{'file':'trips.txt', 'trip_short_name': 'm/X41/'}, " + "'update':{'trip_headsign': 'Uptown Express'}}");
    GtfsTransformStrategy transform = _transformer.getLastTransform();
    TransformContext context = new TransformContext();
    GtfsMutableRelationalDao dao = new GtfsRelationalDaoImpl();
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("1", "1"));
    trip.setTripShortName("X41");
    trip.setTripHeadsign("Downtown Local");
    dao.saveEntity(trip);
    transform.run(context, dao);
    assertEquals("Uptown Express", trip.getTripHeadsign());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransformContext(org.onebusaway.gtfs_transformer.services.TransformContext) GtfsTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Test(org.junit.Test)

Example 12 with TransformContext

use of org.onebusaway.gtfs_transformer.services.TransformContext in project onebusaway-gtfs-modules by OneBusAway.

the class ShapeDirectionTransformStrategyTest 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.putLines("trips.txt", "trip_id,route_id,service_id,direction_id,shape_id", "t0,r0,sid0,0,shp0", "t1,r0,sid0,1,shp0");
    _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,02:30:00,02:30:00", "t1,s0,0,01:00:00,01:05:00", "t1,s1,1,01:30:00,01:30:00", "t1,s2,2,02:30:00,02:30:00");
    _gtfs.putLines("shapes.txt", "shape_id,shape_pt_sequence,shape_pt_lat,shape_pt_lon", "shp0,1,1,1", "shp0,2,2,2", "shp0,3,3,3");
    GtfsMutableRelationalDao dao = _gtfs.read();
    TransformContext tc = new TransformContext();
    tc.setDefaultAgencyId("a0");
    _strategy.setShapeId("shp0");
    _strategy.setShapeDirection("0");
    _strategy.run(tc, dao);
    UpdateLibrary.clearDaoCache(dao);
    Collection<ShapePoint> newShapePoints = dao.getShapePointsForShapeId(AgencyAndId.convertFromString("a0_shp0R"));
    assertFalse(newShapePoints.isEmpty());
    ShapePoint sp0 = newShapePoints.iterator().next();
    assertEquals(sp0.getLat(), 3, 0);
    assertEquals(sp0.getLon(), 3, 0);
    Trip t = dao.getTripForId(AgencyAndId.convertFromString("a0_t1"));
    assertEquals(t.getDirectionId(), "1");
    assertEquals(t.getShapeId().getId(), "shp0R");
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) Trip(org.onebusaway.gtfs.model.Trip) TransformContext(org.onebusaway.gtfs_transformer.services.TransformContext) Test(org.junit.Test)

Aggregations

TransformContext (org.onebusaway.gtfs_transformer.services.TransformContext)12 Test (org.junit.Test)11 Trip (org.onebusaway.gtfs.model.Trip)11 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)11 GtfsTransformStrategy (org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy)7 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)6 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)5 StopTime (org.onebusaway.gtfs.model.StopTime)3 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)2 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)2 java.io (java.io)1 URL (java.net.URL)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 SimpleDateFormat (java.text.SimpleDateFormat)1 java.util (java.util)1 ExternalServices (org.onebusaway.cloud.api.ExternalServices)1 ExternalServicesBridgeFactory (org.onebusaway.cloud.api.ExternalServicesBridgeFactory)1 CSVLibrary (org.onebusaway.csv_entities.CSVLibrary)1 CSVListener (org.onebusaway.csv_entities.CSVListener)1