GtfsReader extends CsvEntityReader { public GenericMutableDao getEntityStore() { return _entityStore; } GtfsReader(); void setLastModifiedTime(Long lastModifiedTime); Long getLastModfiedTime(); List<Agency> getAgencies(); void setAgencies(List<Agency> agencies); void setDefaultAgencyId(String feedId); String getDefaultAgencyId(); void addAgencyIdMapping(String fromAgencyId, String toAgencyId); GtfsReaderContext getGtfsReaderContext(); GenericMutableDao getEntityStore(); void setEntityStore(GenericMutableDao entityStore); List<Class<?>> getEntityClasses(); void setEntityClasses(List<Class<?>> entityClasses); void setOverwriteDuplicates(boolean overwriteDuplicates); void run(); void run(CsvInputSource source); static final String KEY_CONTEXT; }
@Test public void testAgency() throws CsvEntityIOException, IOException { GtfsReader reader = new GtfsReader(); StringBuilder b = new StringBuilder(); b.append("agency_id,agency_name,agency_url,agency_timezone,agency_fare_url,agency_lang,agency_phone\n"); b.append("1,Agency,http: reader.readEntities(Agency.class, new StringReader(b.toString())); Agency agency = reader.getEntityStore().getEntityForId(Agency.class, "1"); assertEquals("1", agency.getId()); assertEquals("Agency", agency.getName()); assertEquals("http: assertEquals("Amercia/Los_Angeles", agency.getTimezone()); assertEquals("http: assertEquals("en", agency.getLang()); assertEquals("800-555-BUS1", agency.getPhone()); }
@Test public void testFeedInfo() throws CsvEntityIOException, IOException { GtfsReader reader = new GtfsReader(); StringBuilder b = new StringBuilder(); b.append("feed_publisher_name,feed_publisher_url,feed_lang,feed_start_date,feed_end_date,feed_version\n"); b.append("Test,http: reader.readEntities(FeedInfo.class, new StringReader(b.toString())); FeedInfo feedInfo = reader.getEntityStore().getEntityForId(FeedInfo.class, "1"); assertEquals("Test", feedInfo.getPublisherName()); assertEquals("http: assertEquals("en", feedInfo.getLang()); assertEquals(new ServiceDate(2011, 9, 28), feedInfo.getStartDate()); assertEquals(new ServiceDate(2012, 1, 31), feedInfo.getEndDate()); assertEquals("1.0", feedInfo.getVersion()); b = new StringBuilder(); b.append("feed_publisher_name\n"); b.append("Test\n"); try { reader.readEntities(FeedInfo.class, new StringReader(b.toString())); fail(); } catch (CsvEntityIOException ex) { MissingRequiredFieldException ex2 = (MissingRequiredFieldException) ex.getCause(); assertEquals(FeedInfo.class, ex2.getEntityType()); assertEquals("feed_publisher_url", ex2.getFieldName()); } b = new StringBuilder(); b.append("feed_publisher_name,feed_publisher_url\n"); b.append("Test,http: try { reader.readEntities(FeedInfo.class, new StringReader(b.toString())); fail(); } catch (CsvEntityIOException ex) { MissingRequiredFieldException ex2 = (MissingRequiredFieldException) ex.getCause(); assertEquals(FeedInfo.class, ex2.getEntityType()); assertEquals("feed_lang", ex2.getFieldName()); } b = new StringBuilder(); b.append("feed_publisher_name,feed_publisher_url,feed_lang,feed_start_date\n"); b.append("Test,http: try { reader.readEntities(FeedInfo.class, new StringReader(b.toString())); fail(); } catch (CsvEntityIOException ex) { InvalidValueEntityException ex2 = (InvalidValueEntityException) ex.getCause(); assertEquals(FeedInfo.class, ex2.getEntityType()); assertEquals("feed_start_date", ex2.getFieldName()); assertEquals("2011XX01", ex2.getFieldValue()); } b = new StringBuilder(); b.append("feed_publisher_name,feed_publisher_url,feed_lang,feed_end_date\n"); b.append("Test,http: try { reader.readEntities(FeedInfo.class, new StringReader(b.toString())); fail(); } catch (CsvEntityIOException ex) { InvalidValueEntityException ex2 = (InvalidValueEntityException) ex.getCause(); assertEquals(FeedInfo.class, ex2.getEntityType()); assertEquals("feed_end_date", ex2.getFieldName()); assertEquals("2011XX01", ex2.getFieldValue()); } }