Search in sources :

Example 26 with GtfsMutableRelationalDao

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

the class CalendarExtensionStrategyTest method testCalendarDateExtension.

@Test
public void testCalendarDateExtension() throws IOException {
    _gtfs.putCalendarDates("sid0=20121217,20121218,20121219,20121220,20121221," + "20121224,20121225,20121226,20121227,20121228", "sid1=20121222,20121223,20121229,20121230");
    GtfsMutableRelationalDao dao = _gtfs.read();
    ServiceDate endDate = new ServiceDate(2013, 01, 06);
    _strategy.setEndDate(endDate);
    _strategy.run(_context, dao);
    CalendarService service = CalendarServiceDataFactoryImpl.createService(dao);
    {
        Set<ServiceDate> dates = service.getServiceDatesForServiceId(new AgencyAndId("a0", "sid0"));
        assertEquals(15, dates.size());
        assertTrue(dates.contains(new ServiceDate(2012, 12, 31)));
        assertTrue(dates.contains(new ServiceDate(2013, 01, 01)));
        assertTrue(dates.contains(new ServiceDate(2013, 01, 02)));
        assertTrue(dates.contains(new ServiceDate(2013, 01, 03)));
        assertTrue(dates.contains(new ServiceDate(2013, 01, 04)));
    }
    {
        Set<ServiceDate> dates = service.getServiceDatesForServiceId(new AgencyAndId("a0", "sid1"));
        assertEquals(6, dates.size());
        assertTrue(dates.contains(new ServiceDate(2013, 01, 05)));
        assertTrue(dates.contains(new ServiceDate(2013, 01, 06)));
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Set(java.util.Set) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService) Test(org.junit.Test)

Example 27 with GtfsMutableRelationalDao

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

the class CalendarExtensionStrategyTest method testCalendarExtension.

@Test
public void testCalendarExtension() throws IOException {
    _gtfs.putCalendars(2, "start_date=20120630,20120731", "end_date=20121224,20121231", "mask=1111100,0000011");
    GtfsMutableRelationalDao dao = _gtfs.read();
    ServiceDate endDate = new ServiceDate(2013, 12, 31);
    _strategy.setEndDate(endDate);
    _strategy.run(_context, dao);
    {
        ServiceCalendar calendar = dao.getCalendarForServiceId(new AgencyAndId("a0", "sid0"));
        assertEquals(endDate, calendar.getEndDate());
    }
    {
        ServiceCalendar calendar = dao.getCalendarForServiceId(new AgencyAndId("a0", "sid1"));
        assertEquals(endDate, calendar.getEndDate());
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 28 with GtfsMutableRelationalDao

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

the class ExtensionsTest method testExtensionRead.

@Test
public void testExtensionRead() throws IOException {
    MockGtfs gtfs = MockGtfs.create();
    gtfs.putMinimal();
    gtfs.putStops(2, "label=a,b");
    DefaultEntitySchemaFactory factory = GtfsEntitySchemaFactory.createEntitySchemaFactory();
    factory.addExtension(Stop.class, StopExtension.class);
    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());
}
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) Test(org.junit.Test) GtfsWriterTest(org.onebusaway.gtfs.serialization.GtfsWriterTest)

Example 29 with GtfsMutableRelationalDao

use of org.onebusaway.gtfs.services.GtfsMutableRelationalDao 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

GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)29 Test (org.junit.Test)16 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)15 Trip (org.onebusaway.gtfs.model.Trip)9 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)7 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)7 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)5 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)5 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)4 Stop (org.onebusaway.gtfs.model.Stop)4 MockGtfs (org.onebusaway.gtfs.services.MockGtfs)4 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)4 TransformContext (org.onebusaway.gtfs_transformer.services.TransformContext)4 Collection (java.util.Collection)3 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)3 StopTime (org.onebusaway.gtfs.model.StopTime)3 HibernateGtfsFactory (org.onebusaway.gtfs.services.HibernateGtfsFactory)3 TypedEntityMatch (org.onebusaway.gtfs_transformer.match.TypedEntityMatch)3 TrimOperation (org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy.TrimOperation)3 File (java.io.File)2