Search in sources :

Example 1 with Id

use of org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Id in project onebusaway-application-modules by camsys.

the class GtfsRealtimeEntitySourceTest method testGetTripId.

@Test
public void testGetTripId() {
    TripEntryImpl trip = new TripEntryImpl();
    trip.setId(new AgencyAndId("2", "T10"));
    Mockito.when(_dao.getTripEntryForId(trip.getId())).thenReturn(trip);
    Id tripId = _source.getTripId("T10");
    assertEquals("2", tripId.getAgencyId());
    assertEquals("T10", tripId.getId());
    tripId = _source.getTripId("T11");
    assertEquals("1", tripId.getAgencyId());
    assertEquals("T11", tripId.getId());
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Id(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Id) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) Test(org.junit.Test)

Example 2 with Id

use of org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Id in project onebusaway-application-modules by camsys.

the class GtfsRealtimeAlertLibraryTest method testGetAlertAsServiceAlert.

@Test
public void testGetAlertAsServiceAlert() {
    AgencyAndId alertId = new AgencyAndId("1", "A1");
    Alert.Builder alert = Alert.newBuilder();
    GtfsRealtime.TimeRange.Builder timeRange = GtfsRealtime.TimeRange.newBuilder();
    timeRange.setStart(1L);
    timeRange.setStart(2L);
    alert.addActivePeriod(timeRange);
    EntitySelector.Builder entitySelector = EntitySelector.newBuilder();
    entitySelector.setAgencyId("agencyId");
    entitySelector.setRouteId("routeId");
    entitySelector.setStopId("stopId");
    TripDescriptor.Builder tripDescriptor = TripDescriptor.newBuilder();
    tripDescriptor.setTripId("tripId");
    entitySelector.setTrip(tripDescriptor);
    alert.addInformedEntity(entitySelector);
    alert.setCause(Alert.Cause.ACCIDENT);
    alert.setEffect(Alert.Effect.DETOUR);
    TranslatedString.Builder headerTexts = TranslatedString.newBuilder();
    Translation.Builder headerText = Translation.newBuilder();
    headerText.setLanguage("en");
    headerText.setText("Summary");
    headerTexts.addTranslation(headerText);
    alert.setHeaderText(headerTexts);
    TranslatedString.Builder descriptionTexts = TranslatedString.newBuilder();
    Translation.Builder descriptionText = Translation.newBuilder();
    descriptionText.setLanguage("fr");
    descriptionText.setText("Description");
    descriptionTexts.addTranslation(descriptionText);
    alert.setDescriptionText(descriptionTexts);
    TranslatedString.Builder urls = TranslatedString.newBuilder();
    Translation.Builder url = Translation.newBuilder();
    url.setLanguage("es");
    url.setText("http://something/");
    urls.addTranslation(url);
    alert.setUrl(urls);
    Mockito.when(_entitySource.getRouteId("routeId")).thenReturn(ServiceAlertLibrary.id("1", "routeId"));
    Mockito.when(_entitySource.getStopId("stopId")).thenReturn(ServiceAlertLibrary.id("2", "stopId"));
    Mockito.when(_entitySource.getTripId("tripId")).thenReturn(ServiceAlertLibrary.id("3", "tripId"));
    ServiceAlert.Builder serviceAlert = _library.getAlertAsServiceAlert(alertId, alert.build());
    Id id = serviceAlert.getId();
    assertEquals("1", id.getAgencyId());
    assertEquals("A1", id.getId());
    assertEquals(1, serviceAlert.getAffectsCount());
    Affects affects = serviceAlert.getAffects(0);
    assertEquals("agencyId", affects.getAgencyId());
    assertEquals("1", affects.getRouteId().getAgencyId());
    assertEquals("routeId", affects.getRouteId().getId());
    assertEquals("2", affects.getStopId().getAgencyId());
    assertEquals("stopId", affects.getStopId().getId());
    assertEquals("3", affects.getTripId().getAgencyId());
    assertEquals("tripId", affects.getTripId().getId());
    assertEquals(ServiceAlert.Cause.ACCIDENT, serviceAlert.getCause());
    assertEquals(1, serviceAlert.getConsequenceCount());
    Consequence consequence = serviceAlert.getConsequence(0);
    assertEquals(Effect.DETOUR, consequence.getEffect());
    ServiceAlerts.TranslatedString summaries = serviceAlert.getSummary();
    assertEquals(1, summaries.getTranslationCount());
    ServiceAlerts.TranslatedString.Translation summary = summaries.getTranslation(0);
    assertEquals("en", summary.getLanguage());
    assertEquals("Summary", summary.getText());
    ServiceAlerts.TranslatedString descriptions = serviceAlert.getDescription();
    assertEquals(1, descriptions.getTranslationCount());
    ServiceAlerts.TranslatedString.Translation description = descriptions.getTranslation(0);
    assertEquals("fr", description.getLanguage());
    assertEquals("Description", description.getText());
    ServiceAlerts.TranslatedString alertUrls = serviceAlert.getUrl();
    assertEquals(1, alertUrls.getTranslationCount());
    ServiceAlerts.TranslatedString.Translation alertUrl = alertUrls.getTranslation(0);
    assertEquals("es", alertUrl.getLanguage());
    assertEquals("http://something/", alertUrl.getText());
}
Also used : TranslatedString(com.google.transit.realtime.GtfsRealtime.TranslatedString) EntitySelector(com.google.transit.realtime.GtfsRealtime.EntitySelector) Translation(com.google.transit.realtime.GtfsRealtime.TranslatedString.Translation) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceAlerts(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts) Consequence(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Consequence) Affects(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Affects) ServiceAlert(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.ServiceAlert) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) ServiceAlert(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.ServiceAlert) Alert(com.google.transit.realtime.GtfsRealtime.Alert) Id(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Id) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Example 3 with Id

use of org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Id in project onebusaway-application-modules by camsys.

the class GtfsRealtimeEntitySourceTest method testGetStopId.

@Test
public void testGetStopId() {
    StopEntryImpl stop = new StopEntryImpl(new AgencyAndId("2", "S10"), 0, 0);
    Mockito.when(_dao.getStopEntryForId(stop.getId())).thenReturn(stop);
    Id stopId = _source.getStopId("S10");
    assertEquals("2", stopId.getAgencyId());
    assertEquals("S10", stopId.getId());
    stopId = _source.getStopId("S11");
    assertEquals("1", stopId.getAgencyId());
    assertEquals("S11", stopId.getId());
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Id(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Id) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 4 with Id

use of org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Id in project onebusaway-application-modules by camsys.

the class GtfsRealtimeEntitySourceTest method testGetRouteId.

@Test
public void testGetRouteId() {
    RouteCollectionEntryImpl routeCollection = new RouteCollectionEntryImpl();
    routeCollection.setId(new AgencyAndId("2", "R10C"));
    RouteEntryImpl route = new RouteEntryImpl();
    route.setId(new AgencyAndId("2", "R10"));
    route.setParent(routeCollection);
    Mockito.when(_dao.getRouteForId(route.getId())).thenReturn(route);
    Id routeId = _source.getRouteId("R10");
    assertEquals("2", routeId.getAgencyId());
    assertEquals("R10C", routeId.getId());
    routeId = _source.getRouteId("R11");
    assertEquals("1", routeId.getAgencyId());
    assertEquals("R11", routeId.getId());
}
Also used : RouteCollectionEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) Id(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Id) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Test(org.junit.Test)

Example 5 with Id

use of org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Id in project onebusaway-application-modules by camsys.

the class GtfsRealtimeAlertLibrary method getEntitySelectorAsAffects.

private Affects.Builder getEntitySelectorAsAffects(EntitySelector selector, Map agencyIdMap) {
    Affects.Builder affects = Affects.newBuilder();
    if (selector.hasAgencyId()) {
        String agencyId = selector.getAgencyId();
        if (agencyIdMap != null && agencyIdMap.get(agencyId) != null) {
            agencyId = (String) agencyIdMap.get(agencyId);
        }
        affects.setAgencyId(agencyId);
    }
    if (selector.hasRouteId()) {
        Id routeId = _entitySource.getRouteId(selector.getRouteId());
        affects.setRouteId(routeId);
    }
    if (selector.hasStopId()) {
        Id stopId = _entitySource.getStopId(selector.getStopId());
        affects.setStopId(stopId);
    }
    if (selector.hasTrip()) {
        TripDescriptor trip = selector.getTrip();
        if (trip.hasTripId())
            affects.setTripId(_entitySource.getTripId(trip.getTripId()));
        else if (trip.hasRouteId())
            affects.setRouteId(_entitySource.getRouteId(trip.getRouteId()));
    }
    return affects;
}
Also used : TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) Id(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Id) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Affects(org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Affects)

Aggregations

AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 Id (org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Id)5 Test (org.junit.Test)4 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)2 Affects (org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Affects)2 Alert (com.google.transit.realtime.GtfsRealtime.Alert)1 EntitySelector (com.google.transit.realtime.GtfsRealtime.EntitySelector)1 TranslatedString (com.google.transit.realtime.GtfsRealtime.TranslatedString)1 Translation (com.google.transit.realtime.GtfsRealtime.TranslatedString.Translation)1 RouteCollectionEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteCollectionEntryImpl)1 RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)1 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)1 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)1 ServiceAlerts (org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts)1 Consequence (org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.Consequence)1 ServiceAlert (org.onebusaway.transit_data_federation.services.service_alerts.ServiceAlerts.ServiceAlert)1