Search in sources :

Example 91 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsTransformerTest method testUpdateAnyRoute.

@Test
public void testUpdateAnyRoute() throws Exception {
    GtfsRelationalDao dao = transform("{'op':'update', " + "'match':{'file':'routes.txt', 'any(trips.trip_headsign)':'Outbound'}, " + "'update':{'route_long_name':'Outbound'}}");
    assertEquals("Outbound", dao.getRouteForId(new AgencyAndId("a0", "r1")).getLongName());
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Example 92 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsTransformerTest method testUpdateCalendarCollection.

@Test
public void testUpdateCalendarCollection() throws Exception {
    GtfsRelationalDao dao = transform("{'op':'update', 'match':{'collection':'calendar', 'service_id':'sid1'}, 'update':{'service_id':'WEEK'}}");
    assertNotNull(dao.getCalendarForServiceId(new AgencyAndId("a0", "WEEK")));
    assertEquals(new AgencyAndId("a0", "WEEK"), dao.getTripForId(new AgencyAndId("a0", "t1")).getServiceId());
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Example 93 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.

the class DeferredValueConverterTest method testAgencAndId_DefaultAgencyId.

@Test
public void testAgencAndId_DefaultAgencyId() {
    Object value = convert(new Stop(), "id", "123");
    assertEquals(new AgencyAndId("1", "123"), value);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) Test(org.junit.Test)

Example 94 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsReaderTest method testCsvParser.

@Test
public void testCsvParser() throws CsvEntityIOException, IOException {
    GtfsReader reader = new GtfsReader();
    reader.setDefaultAgencyId("1");
    Agency agency = new Agency();
    agency.setId("1");
    reader.setAgencies(Arrays.asList(agency));
    StringBuilder b = new StringBuilder();
    b.append("agency_id,route_id,route_short_name,route_long_name,route_type\n");
    b.append("        1,    R-10,              10,   \"Ten, Ten\",3\n");
    reader.readEntities(Route.class, new StringReader(b.toString()));
    Route route = reader.getEntityStore().getEntityForId(Route.class, new AgencyAndId("1", "R-10"));
    assertEquals("Ten, Ten", route.getLongName());
}
Also used : Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StringReader(java.io.StringReader) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 95 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsReaderTest method testCaltrain.

@Test
public void testCaltrain() throws IOException, ParseException {
    File resourcePath = GtfsTestData.getCaltrainGtfs();
    String agencyId = "Caltrain";
    GtfsDao entityStore = processFeed(resourcePath, agencyId, false);
    Collection<Agency> agencies = entityStore.getAllAgencies();
    assertEquals(1, agencies.size());
    Agency agency = entityStore.getAgencyForId(agencyId);
    assertNotNull(agency);
    assertEquals("Caltrain", agency.getName());
    assertEquals("http://www.caltrain.com", agency.getUrl());
    assertEquals("America/Los_Angeles", agency.getTimezone());
    assertNull(agency.getPhone());
    assertNull(agency.getLang());
    Collection<Route> routes = entityStore.getAllRoutes();
    assertEquals(3, routes.size());
    AgencyAndId routeBulletId = new AgencyAndId(agencyId, "ct_bullet");
    Route routeBullet = entityStore.getRouteForId(routeBulletId);
    assertEquals(routeBulletId, routeBullet.getId());
    assertEquals(agency, routeBullet.getAgency());
    assertNull(routeBullet.getShortName());
    assertEquals("Bullet", routeBullet.getLongName());
    assertNull(routeBullet.getDesc());
    assertEquals(2, routeBullet.getType());
    assertNull(routeBullet.getUrl());
    assertNull(routeBullet.getColor());
    assertEquals("ff0000", routeBullet.getTextColor());
    Route routeLocal = entityStore.getRouteForId(new AgencyAndId(agencyId, "ct_local"));
    Collection<Stop> stops = entityStore.getAllStops();
    assertEquals(31, stops.size());
    AgencyAndId stopAId = new AgencyAndId(agencyId, "San Francisco Caltrain");
    Stop stopA = entityStore.getStopForId(stopAId);
    assertEquals(stopAId, stopA.getId());
    assertNull(stopA.getCode());
    assertEquals("700 4th Street, San Francisco", stopA.getDesc());
    assertEquals(37.7764393371, stopA.getLat(), 0.000001);
    assertEquals(-122.394322993, stopA.getLon(), 0.000001);
    assertEquals(0, stopA.getLocationType());
    assertEquals("San Francisco Caltrain", stopA.getName());
    assertEquals("1", stopA.getZoneId());
    assertNull(stopA.getUrl());
    AgencyAndId stopBId = new AgencyAndId(agencyId, "Gilroy Caltrain");
    Stop stopB = entityStore.getStopForId(stopBId);
    assertEquals(stopBId, stopB.getId());
    assertNull(stopB.getCode());
    assertEquals("7150 Monterey Street, Gilroy", stopB.getDesc());
    assertEquals(37.003084, stopB.getLat(), 0.000001);
    assertEquals(-121.567091, stopB.getLon(), 0.000001);
    assertEquals(0, stopB.getLocationType());
    assertEquals("Gilroy Caltrain", stopB.getName());
    assertEquals("6", stopB.getZoneId());
    assertNull(stopB.getUrl());
    Collection<Trip> trips = entityStore.getAllTrips();
    assertEquals(260, trips.size());
    AgencyAndId tripAId = new AgencyAndId(agencyId, "10101272009");
    Trip tripA = entityStore.getTripForId(tripAId);
    assertEquals(tripAId, tripA.getId());
    assertNull(tripA.getBlockId());
    assertEquals("0", tripA.getDirectionId());
    assertEquals(routeLocal, tripA.getRoute());
    assertEquals(new AgencyAndId(agencyId, "WD01272009"), tripA.getServiceId());
    assertEquals(new AgencyAndId(agencyId, "cal_sj_sf"), tripA.getShapeId());
    assertEquals("San Jose to San Francisco", tripA.getTripHeadsign());
    Collection<StopTime> stopTimes = entityStore.getAllStopTimes();
    assertEquals(4712, stopTimes.size());
    StopTime stopTimeA = stopTimes.iterator().next();
    assertEquals(entityStore.getTripForId(new AgencyAndId(agencyId, "10101272009")), stopTimeA.getTrip());
    assertEquals(21120, stopTimeA.getArrivalTime());
    assertEquals(21120, stopTimeA.getDepartureTime());
    assertEquals(entityStore.getStopForId(new AgencyAndId(agencyId, "22nd Street Caltrain")), stopTimeA.getStop());
    assertEquals(21, stopTimeA.getStopSequence());
    assertNull(stopTimeA.getStopHeadsign());
    assertEquals(0, stopTimeA.getPickupType());
    assertEquals(0, stopTimeA.getDropOffType());
    assertFalse(stopTimeA.isShapeDistTraveledSet());
    Collection<ShapePoint> shapePoints = entityStore.getAllShapePoints();
    assertEquals(2677, shapePoints.size());
    AgencyAndId shapeId = new AgencyAndId(agencyId, "cal_sf_gil");
    ShapePoint shapePointA = getShapePoint(shapePoints, shapeId, 1);
    assertEquals(shapeId, shapePointA.getShapeId());
    assertEquals(1, shapePointA.getSequence());
    assertEquals(37.776439059278346, shapePointA.getLat(), 0.0);
    assertEquals(-122.39441156387329, shapePointA.getLon(), 0.0);
    assertFalse(shapePointA.isDistTraveledSet());
    Collection<ServiceCalendar> calendars = entityStore.getAllCalendars();
    assertEquals(6, calendars.size());
    ServiceCalendar calendarA = entityStore.getCalendarForId(new Integer(1));
    assertEquals(new Integer(1), calendarA.getId());
    assertEquals(new AgencyAndId(agencyId, "SN01272009"), calendarA.getServiceId());
    assertEquals(new ServiceDate(2009, 3, 2), calendarA.getStartDate());
    assertEquals(new ServiceDate(2019, 3, 2), calendarA.getEndDate());
    assertEquals(0, calendarA.getMonday());
    assertEquals(0, calendarA.getTuesday());
    assertEquals(0, calendarA.getWednesday());
    assertEquals(0, calendarA.getThursday());
    assertEquals(0, calendarA.getFriday());
    assertEquals(1, calendarA.getSaturday());
    assertEquals(1, calendarA.getSunday());
    Collection<ServiceCalendarDate> calendarDates = entityStore.getAllCalendarDates();
    assertEquals(10, calendarDates.size());
    ServiceCalendarDate cd = entityStore.getCalendarDateForId(new Integer(1));
    assertEquals(new Integer(1), cd.getId());
    assertEquals(new AgencyAndId(agencyId, "SN01272009"), cd.getServiceId());
    assertEquals(new ServiceDate(2009, 5, 25), cd.getDate());
    assertEquals(1, cd.getExceptionType());
    Collection<FareAttribute> fareAttributes = entityStore.getAllFareAttributes();
    assertEquals(6, fareAttributes.size());
    AgencyAndId fareId = new AgencyAndId(agencyId, "OW_1");
    FareAttribute fareAttribute = entityStore.getFareAttributeForId(fareId);
    assertEquals(fareId, fareAttribute.getId());
    assertEquals(2.50, fareAttribute.getPrice(), 0.0);
    assertEquals("USD", fareAttribute.getCurrencyType());
    assertEquals(1, fareAttribute.getPaymentMethod());
    assertFalse(fareAttribute.isTransfersSet());
    assertFalse(fareAttribute.isTransferDurationSet());
    Collection<FareRule> fareRules = entityStore.getAllFareRules();
    assertEquals(36, fareRules.size());
    List<FareRule> fareRuleMatches = GtfsTestData.grep(fareRules, "fare", fareAttribute);
    assertEquals(6, fareRuleMatches.size());
    fareRuleMatches = GtfsTestData.grep(fareRuleMatches, "originId", "1");
    assertEquals(1, fareRuleMatches.size());
    FareRule fareRule = fareRuleMatches.get(0);
    assertEquals(fareAttribute, fareRule.getFare());
    assertEquals("1", fareRule.getOriginId());
    assertEquals("1", fareRule.getDestinationId());
    assertNull(fareRule.getRoute());
    assertNull(fareRule.getContainsId());
}
Also used : FareAttribute(org.onebusaway.gtfs.model.FareAttribute) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) GtfsDao(org.onebusaway.gtfs.services.GtfsDao) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) FareRule(org.onebusaway.gtfs.model.FareRule) File(java.io.File) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Aggregations

AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)102 Test (org.junit.Test)63 Trip (org.onebusaway.gtfs.model.Trip)37 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)25 Stop (org.onebusaway.gtfs.model.Stop)24 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)17 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)16 ArrayList (java.util.ArrayList)15 Route (org.onebusaway.gtfs.model.Route)15 StopTime (org.onebusaway.gtfs.model.StopTime)15 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)15 Agency (org.onebusaway.gtfs.model.Agency)13 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)12 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)11 HashSet (java.util.HashSet)10 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)10 List (java.util.List)9 Frequency (org.onebusaway.gtfs.model.Frequency)9 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)7 Set (java.util.Set)6