use of org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarServiceDataFactoryImplTest method testIslandGtfs.
@Test
public void testIslandGtfs() throws IOException {
GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
GtfsTestData.readGtfs(dao, GtfsTestData.getIslandGtfs(), "26");
CalendarServiceDataFactoryImpl factory = new CalendarServiceDataFactoryImpl();
factory.setGtfsDao(dao);
CalendarServiceData data = factory.createData();
TimeZone tzExpected = TimeZone.getTimeZone("America/Los_Angeles");
TimeZone tzActual = data.getTimeZoneForAgencyId("26");
assertEquals(tzExpected, tzActual);
Set<AgencyAndId> serviceIds = data.getServiceIds();
assertEquals(6, serviceIds.size());
assertTrue(serviceIds.contains(new AgencyAndId("26", "23")));
assertTrue(serviceIds.contains(new AgencyAndId("26", "24")));
assertTrue(serviceIds.contains(new AgencyAndId("26", "25")));
assertTrue(serviceIds.contains(new AgencyAndId("26", "26")));
assertTrue(serviceIds.contains(new AgencyAndId("26", "27")));
assertTrue(serviceIds.contains(new AgencyAndId("26", "28")));
AgencyAndId serviceId = new AgencyAndId("26", "23");
List<ServiceDate> serviceDates = data.getServiceDatesForServiceId(serviceId);
assertEquals(239, serviceDates.size());
assertEquals(new ServiceDate(2008, 10, 27), serviceDates.get(0));
assertEquals(new ServiceDate(2008, 10, 28), serviceDates.get(1));
assertEquals(new ServiceDate(2009, 9, 24), serviceDates.get(serviceDates.size() - 2));
assertEquals(new ServiceDate(2009, 9, 25), serviceDates.get(serviceDates.size() - 1));
serviceIds = data.getServiceIdsForDate(new ServiceDate(2008, 01, 02));
assertEquals(1, serviceIds.size());
assertTrue(serviceIds.contains(new AgencyAndId("26", "25")));
serviceIds = data.getServiceIdsForDate(new ServiceDate(2008, 1, 5));
assertEquals(1, serviceIds.size());
assertTrue(serviceIds.contains(new AgencyAndId("26", "26")));
serviceIds = data.getServiceIdsForDate(new ServiceDate(2008, 5, 31));
assertEquals(2, serviceIds.size());
assertTrue(serviceIds.contains(new AgencyAndId("26", "26")));
assertTrue(serviceIds.contains(new AgencyAndId("26", "27")));
serviceIds = data.getServiceIdsForDate(new ServiceDate(2009, 1, 1));
assertEquals(0, serviceIds.size());
List<Date> dates = data.getDatesForLocalizedServiceId(new LocalizedServiceId(new AgencyAndId("26", "23"), tzExpected));
assertEquals(DateSupport.date("2008-10-27 00:00 Pacific Daylight Time"), dates.get(0));
assertEquals(DateSupport.date("2008-10-28 00:00 Pacific Daylight Time"), dates.get(1));
assertEquals(DateSupport.date("2009-09-24 00:00 Pacific Daylight Time"), dates.get(dates.size() - 2));
assertEquals(DateSupport.date("2009-09-25 00:00 Pacific Daylight Time"), dates.get(dates.size() - 1));
}
use of org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarServiceImplTest method test.
@Test
public void test() throws IOException {
GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
GtfsTestData.readGtfs(dao, GtfsTestData.getIslandGtfs(), "26");
CalendarServiceDataFactoryImpl factory = new CalendarServiceDataFactoryImpl();
factory.setGtfsDao(dao);
CalendarServiceData data = factory.createData();
CalendarServiceImpl service = new CalendarServiceImpl();
service.setData(data);
ServiceDate from = new ServiceDate(2008, 10, 27);
ServiceDate to = new ServiceDate(2009, 9, 27);
Set<ServiceDate> toExclude = new HashSet<ServiceDate>();
toExclude.add(new ServiceDate(2009, 1, 1));
// 23,1,1,1,1,1,0,0,20081027,20090927
Set<ServiceDate> dates = service.getServiceDatesForServiceId(new AgencyAndId("26", "23"));
assertEquals(239, dates.size());
Date fromDate = from.getAsDate();
Date toDate = to.getAsDate();
Calendar c = Calendar.getInstance();
c.setTime(fromDate);
while (c.getTime().compareTo(toDate) <= 0) {
ServiceDate day = new ServiceDate(c);
int dow = c.get(Calendar.DAY_OF_WEEK);
if (!(dow == Calendar.SATURDAY || dow == Calendar.SUNDAY || toExclude.contains(day))) {
assertTrue(dates.contains(day));
}
c.add(Calendar.DAY_OF_YEAR, 1);
}
}
use of org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl in project onebusaway-gtfs-modules by OneBusAway.
the class TranslationServiceImplTest method testTranslations.
@Test
public void testTranslations() throws IOException {
String agencyId = "agency";
GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
GtfsTestData.readGtfs(dao, GtfsTestData.getTestAgencyGtfs(), agencyId);
TranslationServiceImpl ts = new TranslationServiceImpl();
ts.setData(TranslationServiceDataFactoryImpl.createData(dao));
Agency agency = dao.getAgencyForId(agencyId);
assertEquals("Fake Agency Spanish", ts.getTranslatedEntity("es", Agency.class, agency).getName());
assertEquals("Fake Agency French", ts.getTranslatedEntity("fr", Agency.class, agency).getName());
Stop stop = dao.getStopForId(aid("A"));
assertEquals("A Spanish", ts.getTranslatedEntity("es", Stop.class, stop).getName());
assertEquals("A French", ts.getTranslatedEntity("fr", Stop.class, stop).getName());
Route route = dao.getRouteForId(aid("3"));
assertEquals("3 Spanish", ts.getTranslatedEntity("es", Route.class, route).getLongName());
assertEquals("3 French", ts.getTranslatedEntity("fr", Route.class, route).getLongName());
Trip trip3 = dao.getTripForId(aid("3.1"));
assertEquals("headsign Spanish", ts.getTranslatedEntity("es", Trip.class, trip3).getTripHeadsign());
assertEquals("headsign French", ts.getTranslatedEntity("fr", Trip.class, trip3).getTripHeadsign());
Trip trip4 = dao.getTripForId(aid("4.3"));
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip4);
StopTime st1 = stopTimes.get(0);
StopTime st2 = stopTimes.get(1);
assertEquals("to G Spanish", ts.getTranslatedEntity("es", StopTime.class, st1).getStopHeadsign());
assertEquals("to H Spanish", ts.getTranslatedEntity("es", StopTime.class, st2).getStopHeadsign());
assertEquals("to G French", ts.getTranslatedEntity("fr", StopTime.class, st1).getStopHeadsign());
assertEquals("to H French", ts.getTranslatedEntity("fr", StopTime.class, st2).getStopHeadsign());
FeedInfo feedInfo = dao.getAllFeedInfos().iterator().next();
assertEquals("Fake Feed Publisher Spanish", ts.getTranslatedEntity("es", FeedInfo.class, feedInfo).getPublisherName());
assertEquals("http://fake.example.es", ts.getTranslatedEntity("es", FeedInfo.class, feedInfo).getPublisherUrl());
assertEquals("Fake Feed Publisher French", ts.getTranslatedEntity("fr", FeedInfo.class, feedInfo).getPublisherName());
assertEquals("http://fake.example.fr", ts.getTranslatedEntity("fr", FeedInfo.class, feedInfo).getPublisherUrl());
// Check default translations
assertEquals("Fake Agency", ts.getTranslatedEntity("en", Agency.class, agency).getName());
assertEquals("A", ts.getTranslatedEntity("en", Stop.class, stop).getName());
assertEquals("3", ts.getTranslatedEntity("en", Route.class, route).getLongName());
assertEquals("headsign", ts.getTranslatedEntity("en", Trip.class, trip3).getTripHeadsign());
assertEquals("to G", ts.getTranslatedEntity("en", StopTime.class, st1).getStopHeadsign());
assertEquals("to H", ts.getTranslatedEntity("en", StopTime.class, st2).getStopHeadsign());
assertEquals("Fake Feed Publisher", ts.getTranslatedEntity("en", FeedInfo.class, feedInfo).getPublisherName());
assertEquals("http://fake.example.com", ts.getTranslatedEntity("en", FeedInfo.class, feedInfo).getPublisherUrl());
}
use of org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl in project onebusaway-gtfs-modules by OneBusAway.
the class MockGtfs method read.
public GtfsMutableRelationalDao read(GtfsReader reader) throws IOException {
reader.setInputLocation(_path);
GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
reader.setEntityStore(dao);
try {
reader.run();
} finally {
reader.close();
}
return dao;
}
Aggregations