Search in sources :

Example 21 with GtfsRelationalDaoImpl

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());
}
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 22 with GtfsRelationalDaoImpl

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());
}
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 23 with GtfsRelationalDaoImpl

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);
}
Also used : EntitySchemaCache(org.onebusaway.gtfs_transformer.deferred.EntitySchemaCache) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Before(org.junit.Before)

Example 24 with GtfsRelationalDaoImpl

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());
}
Also used : Agency(org.onebusaway.gtfs.model.Agency) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Test(org.junit.Test)

Example 25 with GtfsRelationalDaoImpl

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());
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) MockGtfs(org.onebusaway.gtfs.services.MockGtfs) DefaultEntitySchemaFactory(org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) GtfsWriter(org.onebusaway.gtfs.serialization.GtfsWriter) Test(org.junit.Test) GtfsWriterTest(org.onebusaway.gtfs.serialization.GtfsWriterTest)

Aggregations

GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)34 Test (org.junit.Test)19 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)13 Agency (org.onebusaway.gtfs.model.Agency)10 Trip (org.onebusaway.gtfs.model.Trip)9 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)8 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)7 CalendarServiceData (org.onebusaway.gtfs.model.calendar.CalendarServiceData)6 File (java.io.File)5 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)5 GtfsTransformStrategy (org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy)5 TransformContext (org.onebusaway.gtfs_transformer.services.TransformContext)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Before (org.junit.Before)4 Route (org.onebusaway.gtfs.model.Route)3 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)3 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)3 Stop (org.onebusaway.gtfs.model.Stop)3 IOException (java.io.IOException)2