Search in sources :

Example 6 with FeedInfo

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

the class TranslationServiceImplTest method testTranslations.

@Test
public void testTranslations() throws IOException {
    String agencyId = "agency";
    GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
    GtfsTestData.readGtfs(dao, GtfsTestData.getTestAgencyGtfs(), agencyId);
    TranslationServiceImpl ts = new TranslationServiceImpl();
    ts.setData(TranslationServiceDataFactoryImpl.createData(dao));
    Agency agency = dao.getAgencyForId(agencyId);
    assertEquals("Fake Agency Spanish", ts.getTranslatedEntity("es", Agency.class, agency).getName());
    assertEquals("Fake Agency French", ts.getTranslatedEntity("fr", Agency.class, agency).getName());
    Stop stop = dao.getStopForId(aid("A"));
    assertEquals("A Spanish", ts.getTranslatedEntity("es", Stop.class, stop).getName());
    assertEquals("A French", ts.getTranslatedEntity("fr", Stop.class, stop).getName());
    Route route = dao.getRouteForId(aid("3"));
    assertEquals("3 Spanish", ts.getTranslatedEntity("es", Route.class, route).getLongName());
    assertEquals("3 French", ts.getTranslatedEntity("fr", Route.class, route).getLongName());
    Trip trip3 = dao.getTripForId(aid("3.1"));
    assertEquals("headsign Spanish", ts.getTranslatedEntity("es", Trip.class, trip3).getTripHeadsign());
    assertEquals("headsign French", ts.getTranslatedEntity("fr", Trip.class, trip3).getTripHeadsign());
    Trip trip4 = dao.getTripForId(aid("4.3"));
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip4);
    StopTime st1 = stopTimes.get(0);
    StopTime st2 = stopTimes.get(1);
    assertEquals("to G Spanish", ts.getTranslatedEntity("es", StopTime.class, st1).getStopHeadsign());
    assertEquals("to H Spanish", ts.getTranslatedEntity("es", StopTime.class, st2).getStopHeadsign());
    assertEquals("to G French", ts.getTranslatedEntity("fr", StopTime.class, st1).getStopHeadsign());
    assertEquals("to H French", ts.getTranslatedEntity("fr", StopTime.class, st2).getStopHeadsign());
    FeedInfo feedInfo = dao.getAllFeedInfos().iterator().next();
    assertEquals("Fake Feed Publisher Spanish", ts.getTranslatedEntity("es", FeedInfo.class, feedInfo).getPublisherName());
    assertEquals("http://fake.example.es", ts.getTranslatedEntity("es", FeedInfo.class, feedInfo).getPublisherUrl());
    assertEquals("Fake Feed Publisher French", ts.getTranslatedEntity("fr", FeedInfo.class, feedInfo).getPublisherName());
    assertEquals("http://fake.example.fr", ts.getTranslatedEntity("fr", FeedInfo.class, feedInfo).getPublisherUrl());
    // Check default translations
    assertEquals("Fake Agency", ts.getTranslatedEntity("en", Agency.class, agency).getName());
    assertEquals("A", ts.getTranslatedEntity("en", Stop.class, stop).getName());
    assertEquals("3", ts.getTranslatedEntity("en", Route.class, route).getLongName());
    assertEquals("headsign", ts.getTranslatedEntity("en", Trip.class, trip3).getTripHeadsign());
    assertEquals("to G", ts.getTranslatedEntity("en", StopTime.class, st1).getStopHeadsign());
    assertEquals("to H", ts.getTranslatedEntity("en", StopTime.class, st2).getStopHeadsign());
    assertEquals("Fake Feed Publisher", ts.getTranslatedEntity("en", FeedInfo.class, feedInfo).getPublisherName());
    assertEquals("http://fake.example.com", ts.getTranslatedEntity("en", FeedInfo.class, feedInfo).getPublisherUrl());
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) Stop(org.onebusaway.gtfs.model.Stop) FeedInfo(org.onebusaway.gtfs.model.FeedInfo) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Aggregations

FeedInfo (org.onebusaway.gtfs.model.FeedInfo)6 Test (org.junit.Test)2 Agency (org.onebusaway.gtfs.model.Agency)2 Stop (org.onebusaway.gtfs.model.Stop)2 File (java.io.File)1 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 ExternalServices (org.onebusaway.cloud.api.ExternalServices)1 ExternalServicesBridgeFactory (org.onebusaway.cloud.api.ExternalServicesBridgeFactory)1 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)1 Pathway (org.onebusaway.gtfs.model.Pathway)1 Route (org.onebusaway.gtfs.model.Route)1 StopTime (org.onebusaway.gtfs.model.StopTime)1 Translation (org.onebusaway.gtfs.model.Translation)1 Trip (org.onebusaway.gtfs.model.Trip)1 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)1 PropertyTranslation (org.onebusaway.gtfs.model.translation.PropertyTranslation)1 TranslationServiceData (org.onebusaway.gtfs.model.translation.TranslationServiceData)1 PathwayUtil (org.onebusaway.gtfs_transformer.util.PathwayUtil)1