Search in sources :

Example 31 with Stop

use of org.onebusaway.gtfs.model.Stop 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)

Example 32 with Stop

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

the class GenericDaoImplTest method testSaveOrUpdate.

@Test
public void testSaveOrUpdate() {
    GenericDaoImpl impl = new GenericDaoImpl();
    AgencyAndId id = new AgencyAndId("1", "stopA");
    Stop entity = impl.getEntityForId(Stop.class, id);
    assertNull(entity);
    Stop stopA = new Stop();
    stopA.setId(id);
    impl.saveOrUpdateEntity(stopA);
    entity = impl.getEntityForId(Stop.class, id);
    assertSame(stopA, entity);
    impl.saveOrUpdateEntity(stopA);
    entity = impl.getEntityForId(Stop.class, id);
    assertSame(stopA, entity);
    Stop stopB = new Stop();
    stopB.setId(id);
    impl.saveOrUpdateEntity(stopB);
    entity = impl.getEntityForId(Stop.class, id);
    assertSame(stopB, entity);
    Collection<Stop> entities = impl.getAllEntitiesForType(Stop.class);
    assertEquals(1, entities.size());
    assertSame(stopB, entities.iterator().next());
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) Test(org.junit.Test)

Example 33 with Stop

use of org.onebusaway.gtfs.model.Stop 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 34 with Stop

use of org.onebusaway.gtfs.model.Stop 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 35 with Stop

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

the class DeferredValueConverterTest method testInteger.

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

Aggregations

Stop (org.onebusaway.gtfs.model.Stop)40 Test (org.junit.Test)29 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)24 StopTime (org.onebusaway.gtfs.model.StopTime)11 Trip (org.onebusaway.gtfs.model.Trip)11 Agency (org.onebusaway.gtfs.model.Agency)8 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)7 Route (org.onebusaway.gtfs.model.Route)6 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)6 FareAttribute (org.onebusaway.gtfs.model.FareAttribute)5 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)5 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)5 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)5 FareRule (org.onebusaway.gtfs.model.FareRule)4 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CsvEntityContextImpl (org.onebusaway.csv_entities.CsvEntityContextImpl)3 Frequency (org.onebusaway.gtfs.model.Frequency)3 Transfer (org.onebusaway.gtfs.model.Transfer)3