Search in sources :

Example 6 with DefaultEntitySchemaFactory

use of org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory 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 7 with DefaultEntitySchemaFactory

use of org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory 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 8 with DefaultEntitySchemaFactory

use of org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory in project onebusaway-gtfs-modules by OneBusAway.

the class LatLonFieldMappingFactoryTest method buildFieldMapping.

private FieldMapping buildFieldMapping() {
    LatLonFieldMappingFactory factory = new LatLonFieldMappingFactory();
    DefaultEntitySchemaFactory schemaFactory = GtfsEntitySchemaFactory.createEntitySchemaFactory();
    return factory.createFieldMapping(schemaFactory, Stop.class, "stop_lat", "lat", Double.TYPE, true);
}
Also used : DefaultEntitySchemaFactory(org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory)

Aggregations

DefaultEntitySchemaFactory (org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory)8 Test (org.junit.Test)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 HashMap (java.util.HashMap)2 CsvEntityContext (org.onebusaway.csv_entities.CsvEntityContext)2 CsvEntityContextImpl (org.onebusaway.csv_entities.CsvEntityContextImpl)2 BeanWrapper (org.onebusaway.csv_entities.schema.BeanWrapper)2 FieldMapping (org.onebusaway.csv_entities.schema.FieldMapping)2 Stop (org.onebusaway.gtfs.model.Stop)2 GtfsReader (org.onebusaway.gtfs.serialization.GtfsReader)2 GtfsWriterTest (org.onebusaway.gtfs.serialization.GtfsWriterTest)2 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)2 MockGtfs (org.onebusaway.gtfs.services.MockGtfs)2 PropertyMethod (org.onebusaway.collections.beans.PropertyMethod)1 EntitySchema (org.onebusaway.csv_entities.schema.EntitySchema)1 EntitySchemaFactoryHelper (org.onebusaway.csv_entities.schema.EntitySchemaFactoryHelper)1 CsvEntityMappingBean (org.onebusaway.csv_entities.schema.beans.CsvEntityMappingBean)1 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)1 Route (org.onebusaway.gtfs.model.Route)1 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)1