Search in sources :

Example 86 with AgencyAndId

use of org.onebusaway.gtfs.model.AgencyAndId 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);
    }
}
Also used : CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Calendar(java.util.Calendar) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Date(java.util.Date) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 87 with AgencyAndId

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

the class LocalizedServiceIdTest method testCompareTo.

@Test
public void testCompareTo() {
    TimeZone tzLA = TimeZone.getTimeZone("America/Los_Angeles");
    TimeZone tzNY = TimeZone.getTimeZone("America/New_York");
    LocalizedServiceId lsidA = new LocalizedServiceId(new AgencyAndId("1", "sA"), tzLA);
    LocalizedServiceId lsidB = new LocalizedServiceId(new AgencyAndId("1", "sA"), tzNY);
    LocalizedServiceId lsidC = new LocalizedServiceId(new AgencyAndId("1", "sB"), tzLA);
    LocalizedServiceId lsidD = new LocalizedServiceId(new AgencyAndId("1", "sB"), tzNY);
    LocalizedServiceId lsidE = new LocalizedServiceId(new AgencyAndId("2", "sB"), tzLA);
    assertEquals(0, lsidA.compareTo(lsidA));
    assertTrue(lsidA.compareTo(lsidB) < 0);
    assertTrue(lsidA.compareTo(lsidC) < 0);
    assertTrue(lsidA.compareTo(lsidD) < 0);
    assertTrue(lsidA.compareTo(lsidE) < 0);
    assertTrue(lsidB.compareTo(lsidA) > 0);
    assertEquals(0, lsidB.compareTo(lsidB));
    assertTrue(lsidB.compareTo(lsidC) < 0);
    assertTrue(lsidB.compareTo(lsidD) < 0);
    assertTrue(lsidB.compareTo(lsidE) < 0);
    assertTrue(lsidC.compareTo(lsidA) > 0);
    assertTrue(lsidC.compareTo(lsidB) > 0);
    assertEquals(0, lsidC.compareTo(lsidC));
    assertTrue(lsidC.compareTo(lsidD) < 0);
    assertTrue(lsidC.compareTo(lsidE) < 0);
    assertTrue(lsidD.compareTo(lsidA) > 0);
    assertTrue(lsidD.compareTo(lsidB) > 0);
    assertTrue(lsidD.compareTo(lsidC) > 0);
    assertEquals(0, lsidD.compareTo(lsidD));
    assertTrue(lsidD.compareTo(lsidE) < 0);
    assertTrue(lsidE.compareTo(lsidA) > 0);
    assertTrue(lsidE.compareTo(lsidB) > 0);
    assertTrue(lsidE.compareTo(lsidC) > 0);
    assertTrue(lsidE.compareTo(lsidD) > 0);
    assertEquals(0, lsidE.compareTo(lsidE));
}
Also used : TimeZone(java.util.TimeZone) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Example 88 with AgencyAndId

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

the class DeferredValueSupportTest method testResolveAgencyAndId_DefaultAgencyId.

@Test
public void testResolveAgencyAndId_DefaultAgencyId() {
    Stop stop = new Stop();
    BeanWrapper bean = BeanWrapperFactory.wrap(stop);
    AgencyAndId id = _support.resolveAgencyAndId(bean, "id", "1");
    assertEquals(new AgencyAndId("a0", "1"), id);
}
Also used : BeanWrapper(org.onebusaway.csv_entities.schema.BeanWrapper) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) Test(org.junit.Test)

Example 89 with AgencyAndId

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

the class PropertyMethodResolverImplTest method testTripStopTimesVirtualMethod.

@Test
public void testTripStopTimesVirtualMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("1", "t0"));
    _dao.saveEntity(trip);
    StopTime stopTime = new StopTime();
    stopTime.setTrip(trip);
    stopTime.setStop(new Stop());
    _dao.saveEntity(stopTime);
    PropertyMethod method = _resolver.getPropertyMethod(Trip.class, "stop_times");
    assertEquals(Arrays.asList(stopTime), method.invoke(trip));
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) PropertyMethod(org.onebusaway.collections.beans.PropertyMethod) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 90 with AgencyAndId

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

the class GtfsTransformerTest method testRemoveCalendarCollection.

@Test
public void testRemoveCalendarCollection() throws Exception {
    GtfsRelationalDao dao = transform("{'op':'remove', 'match':{'collection':'calendar', 'service_id':'sid1'}}");
    assertNull(dao.getCalendarForServiceId(new AgencyAndId("a0", "sid1")));
    assertNull(dao.getTripForId(new AgencyAndId("a0", "t1")));
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) 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