use of org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl 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());
}
use of org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl 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());
}
use of org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl in project onebusaway-gtfs-modules by OneBusAway.
the class PropertyMethodResolverImplTest method before.
@Before
public void before() {
_dao = new GtfsRelationalDaoImpl();
_schemaCache = new EntitySchemaCache();
_resolver = new PropertyMethodResolverImpl(_dao, _schemaCache);
}
use of org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsWriterTest method testWriteUtf8.
@Test
public void testWriteUtf8() throws IOException {
GtfsWriter writer = new GtfsWriter();
writer.setOutputLocation(_tmpDirectory);
Agency agency = new Agency();
agency.setId("åå");
agency.setLang("en");
agency.setName("Büs Operación");
agency.setPhone("¡555!");
agency.setEmail("userå@example.com");
agency.setTimezone("America/Los_Angeles");
agency.setUrl("http://agency.com/");
writer.handleEntity(agency);
writer.close();
GtfsReader reader = new GtfsReader();
reader.setInputLocation(_tmpDirectory);
GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
reader.setEntityStore(dao);
reader.readEntities(Agency.class);
Agency agency2 = dao.getAgencyForId("åå");
assertEquals("åå", agency2.getId());
assertEquals("en", agency2.getLang());
assertEquals("Büs Operación", agency2.getName());
assertEquals("¡555!", agency2.getPhone());
assertEquals("userå@example.com", agency2.getEmail());
assertEquals("America/Los_Angeles", agency2.getTimezone());
assertEquals("http://agency.com/", agency2.getUrl());
}
use of org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl in project onebusaway-gtfs-modules by OneBusAway.
the class ExtensionsTest method testExtensionWrite.
@Test
public void testExtensionWrite() throws IOException {
DefaultEntitySchemaFactory factory = GtfsEntitySchemaFactory.createEntitySchemaFactory();
factory.addExtension(Stop.class, StopExtension.class);
{
MockGtfs gtfs = MockGtfs.create();
gtfs.putMinimal();
gtfs.putStops(2, "label=a,b");
GtfsReader reader = new GtfsReader();
reader.setEntitySchemaFactory(factory);
GtfsMutableRelationalDao dao = gtfs.read(reader);
Stop stop = dao.getStopForId(new AgencyAndId("a0", "s0"));
StopExtension extension = stop.getExtension(StopExtension.class);
assertEquals("a", extension.getLabel());
GtfsWriter writer = new GtfsWriter();
writer.setEntitySchemaFactory(factory);
writer.setOutputLocation(_tmpDirectory);
writer.run(dao);
writer.close();
}
{
GtfsReader reader2 = new GtfsReader();
reader2.setEntitySchemaFactory(factory);
reader2.setInputLocation(_tmpDirectory);
GtfsRelationalDaoImpl dao2 = new GtfsRelationalDaoImpl();
reader2.setDefaultAgencyId("a0");
reader2.setEntityStore(dao2);
reader2.readEntities(Stop.class);
Stop stop2 = dao2.getStopForId(new AgencyAndId("a0", "s0"));
StopExtension extension2 = stop2.getExtension(StopExtension.class);
assertEquals("a", extension2.getLabel());
}
}
Aggregations