TransformFactory { public void addModificationsFromString(String value) throws IOException, TransformSpecificationException { addModificationsFromReader(new BufferedReader(new StringReader(value))); } TransformFactory(GtfsTransformer transformer); void addEntityPackage(String entityPackage); void addModificationsFromFile(File path); void addModificationsFromString(String value); void addModificationsFromUrl(URL url); void addModificationsFromReader(BufferedReader reader);  }
@Test public void testFileMatch() throws IOException, TransformSpecificationException { _factory.addModificationsFromString("{'op':'remove', 'match':{'file':'routes.txt', 'shortName':'10'}}"); GtfsTransformStrategy transform = _transformer.getLastTransform(); assertEquals(EntitiesTransformStrategy.class, transform.getClass()); EntitiesTransformStrategy strategy = (EntitiesTransformStrategy) transform; List<MatchAndTransform> transforms = strategy.getModifications(); assertEquals(1, transforms.size()); }
@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()); }
@Test public void testReplaceValueInUpdate() throws IOException, TransformSpecificationException { _factory.addModificationsFromString("{'op':'update', " + "'match':{'file':'trips.txt'}, " + "'update':{'trip_headsign': 's/Downtown/Uptown/'}}"); GtfsTransformStrategy transform = _transformer.getLastTransform(); TransformContext context = new TransformContext(); GtfsMutableRelationalDao dao = new GtfsRelationalDaoImpl(); Trip trip = new Trip(); trip.setId(new AgencyAndId("1", "1")); trip.setTripHeadsign("Downtown Express"); dao.saveEntity(trip); transform.run(context, dao); assertEquals("Uptown Express", trip.getTripHeadsign()); }
@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()); }
@Test public void testReplaceIdInUpdateComplex() throws IOException, TransformSpecificationException { _factory.addModificationsFromString("{'op':'update', " + "'match':{'file':'trips.txt'}, " + "'update':{'trip_id': 's/^([^_]*)_([0-9]*).*/$2/'}}"); GtfsTransformStrategy transform = _transformer.getLastTransform(); TransformContext context = new TransformContext(); context.setDefaultAgencyId("2"); GtfsMutableRelationalDao dao = new GtfsRelationalDaoImpl(); Trip trip = new Trip(); trip.setId(new AgencyAndId("2", "1234-this-text-to-remove")); dao.saveEntity(trip); transform.run(context, dao); assertEquals("1234", trip.getId().getId()); }
@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()); }
@Test public void testCalendarSimplification() throws IOException, TransformSpecificationException { _factory.addModificationsFromString("{'op':'calendar_simplification'}"); GtfsTransformStrategy transform = _transformer.getLastTransform(); assertEquals(CalendarSimplicationStrategy.class, transform.getClass()); CalendarSimplicationStrategy simplification = (CalendarSimplicationStrategy) transform; assertFalse(simplification.isUndoGoogleTransitDataFeedMergeTool()); _factory.addModificationsFromString("{'op':'calendar_simplification', 'min_number_of_weeks_for_calendar_entry':10}"); simplification = (CalendarSimplicationStrategy) _transformer.getLastTransform(); assertEquals(10, simplification.getLibrary().getMinNumberOfWeeksForCalendarEntry()); _factory.addModificationsFromString("{'op':'calendar_simplification', 'day_of_the_week_inclusion_ratio':0.1}"); simplification = (CalendarSimplicationStrategy) _transformer.getLastTransform(); assertEquals(0.1, simplification.getLibrary().getDayOfTheWeekInclusionRatio(), 0.0); _factory.addModificationsFromString("{'op':'calendar_simplification', 'undo_google_transit_data_feed_merge_tool':true}"); simplification = (CalendarSimplicationStrategy) _transformer.getLastTransform(); assertTrue(simplification.isUndoGoogleTransitDataFeedMergeTool()); }