use of org.onebusaway.gtfs.services.MockGtfs 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());
}
use of org.onebusaway.gtfs.services.MockGtfs 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());
}
}
Aggregations