use of com.google.transit.realtime.GtfsRealtime.FeedEntity in project onebusaway-application-modules by camsys.
the class VehiclePositionsForAgencyActionTest method test.
@Test
public void test() {
long now = System.currentTimeMillis();
List<VehicleStatusBean> vehicles = new ArrayList<VehicleStatusBean>();
RouteBean.Builder routeBuilder = RouteBean.builder();
routeBuilder.setId("1_r1");
RouteBean route = routeBuilder.create();
{
VehicleStatusBean vehicle = new VehicleStatusBean();
vehicles.add(vehicle);
vehicle.setLastUpdateTime(1234 * 1000);
vehicle.setVehicleId("1_v1");
TripStatusBean tripStatus = new TripStatusBean();
vehicle.setTripStatus(tripStatus);
TripBean trip = new TripBean();
trip.setId("1_t0");
trip.setRoute(route);
tripStatus.setActiveTrip(trip);
vehicle.setLocation(new CoordinatePoint(47.0, -122.0));
}
{
VehicleStatusBean vehicle = new VehicleStatusBean();
vehicles.add(vehicle);
vehicle.setLastUpdateTime(5678 * 1000);
vehicle.setVehicleId("1_v2");
TripStatusBean tripStatus = new TripStatusBean();
vehicle.setTripStatus(tripStatus);
TripBean trip = new TripBean();
trip.setId("1_t1");
trip.setRoute(route);
tripStatus.setActiveTrip(trip);
vehicle.setLocation(new CoordinatePoint(47.1, -122.1));
}
ListBean<VehicleStatusBean> bean = new ListBean<VehicleStatusBean>();
bean.setList(vehicles);
Mockito.when(_service.getAllVehiclesForAgency("1", now)).thenReturn(bean);
_action.setId("1");
_action.setTime(new Date(now));
_action.show();
ResponseBean model = _action.getModel();
FeedMessage feed = (FeedMessage) model.getData();
assertEquals(now / 1000, feed.getHeader().getTimestamp());
assertEquals(2, feed.getEntityCount());
{
FeedEntity entity = feed.getEntity(0);
assertEquals("1", entity.getId());
VehiclePosition vehiclePosition = entity.getVehicle();
assertEquals("t0", vehiclePosition.getTrip().getTripId());
assertEquals("r1", vehiclePosition.getTrip().getRouteId());
assertEquals("v1", vehiclePosition.getVehicle().getId());
assertEquals(1234, vehiclePosition.getTimestamp());
assertEquals(47.0, vehiclePosition.getPosition().getLatitude(), 0.01);
assertEquals(-122.0, vehiclePosition.getPosition().getLongitude(), 0.01);
}
{
FeedEntity entity = feed.getEntity(1);
assertEquals("2", entity.getId());
VehiclePosition vehiclePosition = entity.getVehicle();
assertEquals("t1", vehiclePosition.getTrip().getTripId());
assertEquals("r1", vehiclePosition.getTrip().getRouteId());
assertEquals("v2", vehiclePosition.getVehicle().getId());
assertEquals(5678, vehiclePosition.getTimestamp());
assertEquals(47.1, vehiclePosition.getPosition().getLatitude(), 0.01);
assertEquals(-122.1, vehiclePosition.getPosition().getLongitude(), 0.01);
}
}
use of com.google.transit.realtime.GtfsRealtime.FeedEntity in project onebusaway-application-modules by camsys.
the class AlertsForAgencyActionTest method test.
@Test
public void test() {
long now = System.currentTimeMillis();
List<ServiceAlertBean> alerts = new ArrayList<ServiceAlertBean>();
{
ServiceAlertBean alert = new ServiceAlertBean();
alerts.add(alert);
TimeRangeBean range = new TimeRangeBean(1234 * 1000, 5678 * 1000);
alert.setActiveWindows(Arrays.asList(range));
SituationAffectsBean affects = new SituationAffectsBean();
affects.setAgencyId("1");
affects.setRouteId("1_r0");
affects.setStopId("1_s0");
affects.setTripId("1_t0");
SituationAffectsBean alsoAffects = new SituationAffectsBean();
alsoAffects.setAgencyId("2");
alert.setAllAffects(Arrays.asList(affects, alsoAffects));
alert.setSummaries(Arrays.asList(new NaturalLanguageStringBean("Name", "en"), new NaturalLanguageStringBean("Nombre", "es")));
alert.setDescriptions(Arrays.asList(new NaturalLanguageStringBean("Description", "en"), new NaturalLanguageStringBean("DescripciĆ³n", "es")));
}
{
ServiceAlertBean alert = new ServiceAlertBean();
alerts.add(alert);
TimeRangeBean range = new TimeRangeBean(5678 * 1000, 1234 * 1000);
alert.setActiveWindows(Arrays.asList(range));
SituationAffectsBean affects = new SituationAffectsBean();
affects.setAgencyId("2");
affects.setRouteId("1_r1");
affects.setStopId("1_s1");
affects.setTripId("1_t1");
alert.setAllAffects(Arrays.asList(affects));
alert.setSummaries(Arrays.asList(new NaturalLanguageStringBean("Name", "en")));
alert.setDescriptions(Arrays.asList(new NaturalLanguageStringBean("Description", "en")));
}
ListBean<ServiceAlertBean> bean = new ListBean<ServiceAlertBean>();
bean.setList(alerts);
Mockito.when(_service.getAllServiceAlertsForAgencyId("1")).thenReturn(bean);
_action.setId("1");
_action.setTime(new Date(now));
_action.show();
ResponseBean model = _action.getModel();
FeedMessage feed = (FeedMessage) model.getData();
assertEquals(now / 1000, feed.getHeader().getTimestamp());
assertEquals(2, feed.getEntityCount());
{
FeedEntity entity = feed.getEntity(0);
assertEquals("1", entity.getId());
Alert alert = entity.getAlert();
assertEquals(1, alert.getActivePeriodCount());
TimeRange range = alert.getActivePeriod(0);
assertEquals(1234, range.getStart());
assertEquals(5678, range.getEnd());
assertEquals(2, alert.getInformedEntityCount());
{
EntitySelector affects = alert.getInformedEntity(0);
assertEquals("1", affects.getAgencyId());
assertEquals("r0", affects.getRouteId());
assertEquals("t0", affects.getTrip().getTripId());
assertEquals("s0", affects.getStopId());
}
{
EntitySelector affects = alert.getInformedEntity(1);
assertEquals("2", affects.getAgencyId());
}
TranslatedString header = alert.getHeaderText();
assertEquals(2, header.getTranslationCount());
{
Translation translation = header.getTranslation(0);
assertEquals("Name", translation.getText());
assertEquals("en", translation.getLanguage());
}
{
Translation translation = header.getTranslation(1);
assertEquals("Nombre", translation.getText());
assertEquals("es", translation.getLanguage());
}
TranslatedString description = alert.getDescriptionText();
assertEquals(2, description.getTranslationCount());
{
Translation translation = description.getTranslation(0);
assertEquals("Description", translation.getText());
assertEquals("en", translation.getLanguage());
}
{
Translation translation = description.getTranslation(1);
assertEquals("DescripciĆ³n", translation.getText());
assertEquals("es", translation.getLanguage());
}
}
{
FeedEntity entity = feed.getEntity(1);
assertEquals("2", entity.getId());
Alert alert = entity.getAlert();
assertEquals(1, alert.getActivePeriodCount());
TimeRange range = alert.getActivePeriod(0);
assertEquals(5678, range.getStart());
assertEquals(1234, range.getEnd());
assertEquals(1, alert.getInformedEntityCount());
{
EntitySelector affects = alert.getInformedEntity(0);
assertEquals("2", affects.getAgencyId());
assertEquals("r1", affects.getRouteId());
assertEquals("t1", affects.getTrip().getTripId());
assertEquals("s1", affects.getStopId());
}
}
}
use of com.google.transit.realtime.GtfsRealtime.FeedEntity in project onebusaway-application-modules by camsys.
the class TripUpdatesForAgencyActionTest method test.
@Test
public void test() {
long now = System.currentTimeMillis();
List<VehicleStatusBean> vehicles = new ArrayList<VehicleStatusBean>();
RouteBean.Builder routeBuilder = RouteBean.builder();
routeBuilder.setId("1_r1");
RouteBean route = routeBuilder.create();
{
VehicleStatusBean vehicle = new VehicleStatusBean();
vehicles.add(vehicle);
vehicle.setLastUpdateTime(1234 * 1000);
vehicle.setVehicleId("1_v1");
TripStatusBean tripStatus = new TripStatusBean();
vehicle.setTripStatus(tripStatus);
tripStatus.setScheduleDeviation(2 * 60);
TripBean trip = new TripBean();
trip.setId("1_t0");
trip.setRoute(route);
tripStatus.setActiveTrip(trip);
StopBean stop = new StopBean();
stop.setId("1_s2");
tripStatus.setNextStop(stop);
tripStatus.setNextStopTimeOffset(5 * 60);
}
{
VehicleStatusBean vehicle = new VehicleStatusBean();
vehicles.add(vehicle);
vehicle.setLastUpdateTime(5678 * 1000);
vehicle.setVehicleId("1_v2");
TripStatusBean tripStatus = new TripStatusBean();
vehicle.setTripStatus(tripStatus);
tripStatus.setScheduleDeviation(3 * 60);
TripBean trip = new TripBean();
trip.setId("1_t1");
trip.setRoute(route);
tripStatus.setActiveTrip(trip);
StopBean stop = new StopBean();
stop.setId("1_s3");
tripStatus.setNextStop(stop);
tripStatus.setNextStopTimeOffset(10 * 60);
}
ListBean<VehicleStatusBean> bean = new ListBean<VehicleStatusBean>();
bean.setList(vehicles);
Mockito.when(_service.getAllVehiclesForAgency("1", now)).thenReturn(bean);
_action.setId("1");
_action.setTime(new Date(now));
_action.show();
ResponseBean model = _action.getModel();
FeedMessage feed = (FeedMessage) model.getData();
assertEquals(now / 1000, feed.getHeader().getTimestamp());
assertEquals(2, feed.getEntityCount());
{
FeedEntity entity = feed.getEntity(0);
assertEquals("1", entity.getId());
TripUpdate tripUpdate = entity.getTripUpdate();
assertEquals("t0", tripUpdate.getTrip().getTripId());
assertEquals("r1", tripUpdate.getTrip().getRouteId());
assertEquals("v1", tripUpdate.getVehicle().getId());
assertEquals(1234, tripUpdate.getTimestamp());
assertEquals(120, tripUpdate.getDelay());
assertEquals(1, tripUpdate.getStopTimeUpdateCount());
StopTimeUpdate stopTimeUpdate = tripUpdate.getStopTimeUpdate(0);
assertEquals("s2", stopTimeUpdate.getStopId());
assertEquals(now / 1000 + 5 * 60, stopTimeUpdate.getDeparture().getTime());
}
{
FeedEntity entity = feed.getEntity(1);
assertEquals("2", entity.getId());
TripUpdate tripUpdate = entity.getTripUpdate();
assertEquals("t1", tripUpdate.getTrip().getTripId());
assertEquals("r1", tripUpdate.getTrip().getRouteId());
assertEquals("v2", tripUpdate.getVehicle().getId());
assertEquals(5678, tripUpdate.getTimestamp());
assertEquals(180, tripUpdate.getDelay());
assertEquals(1, tripUpdate.getStopTimeUpdateCount());
StopTimeUpdate stopTimeUpdate = tripUpdate.getStopTimeUpdate(0);
assertEquals("s3", stopTimeUpdate.getStopId());
assertEquals(now / 1000 + 10 * 60, stopTimeUpdate.getDeparture().getTime());
}
}
use of com.google.transit.realtime.GtfsRealtime.FeedEntity in project onebusaway-application-modules by camsys.
the class GtfsRealtimeTripLibraryTest method test.
@Test
public void test() {
FeedEntity tripUpdateEntityA = createTripUpdate("tripA", "stopA", 60, true);
FeedEntity tripUpdateEntityB = createTripUpdate("tripB", "stopB", 120, true);
FeedEntity tripUpdateEntityC = createTripUpdate("tripC", "stopA", 30, true);
FeedEntity tripUpdateEntityD = createTripUpdate("tripD", "stopB", 90, true);
FeedMessage.Builder tripUpdates = createFeed();
tripUpdates.addEntity(tripUpdateEntityA);
tripUpdates.addEntity(tripUpdateEntityB);
tripUpdates.addEntity(tripUpdateEntityC);
tripUpdates.addEntity(tripUpdateEntityD);
TripEntryImpl tripA = trip("tripA");
TripEntryImpl tripB = trip("tripB");
TripEntryImpl tripC = trip("tripC");
TripEntryImpl tripD = trip("tripD");
StopEntryImpl stopA = stop("stopA", 0, 0);
StopEntryImpl stopB = stop("stopB", 0, 0);
stopTime(0, stopA, tripA, time(7, 30), 0.0);
stopTime(1, stopB, tripB, time(8, 30), 0.0);
stopTime(2, stopA, tripC, time(8, 30), 0.0);
stopTime(3, stopB, tripD, time(9, 30), 0.0);
Mockito.when(_entitySource.getTrip("tripA")).thenReturn(tripA);
Mockito.when(_entitySource.getTrip("tripB")).thenReturn(tripB);
Mockito.when(_entitySource.getTrip("tripC")).thenReturn(tripC);
Mockito.when(_entitySource.getTrip("tripD")).thenReturn(tripD);
BlockEntryImpl blockA = block("blockA");
BlockEntryImpl blockB = block("blockB");
BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds("s1"), tripA, tripB);
BlockConfigurationEntry blockConfigB = blockConfiguration(blockB, serviceIds("s1"), tripC, tripD);
BlockInstance blockInstanceA = new BlockInstance(blockConfigA, 0L);
BlockInstance blockInstanceB = new BlockInstance(blockConfigB, 0L);
Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn(Arrays.asList(blockInstanceA));
Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockB.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn(Arrays.asList(blockInstanceB));
FeedMessage.Builder vehiclePositions = createFeed();
// FeedEntity.Builder vehiclePositionEntity = FeedEntity.newBuilder();
// vehiclePositions.addEntity(vehiclePositionEntity);
List<CombinedTripUpdatesAndVehiclePosition> groups = _library.groupTripUpdatesAndVehiclePositions(tripUpdates.build(), vehiclePositions.build());
assertEquals(2, groups.size());
Collections.sort(groups);
CombinedTripUpdatesAndVehiclePosition group = groups.get(0);
assertSame(blockA, group.block.getBlockInstance().getBlock().getBlock());
assertEquals(2, group.tripUpdates.size());
TripUpdate tripUpdate = group.tripUpdates.get(0);
assertEquals("tripA", tripUpdate.getTrip().getTripId());
tripUpdate = group.tripUpdates.get(1);
assertEquals("tripB", tripUpdate.getTrip().getTripId());
group = groups.get(1);
assertSame(blockB, group.block.getBlockInstance().getBlock().getBlock());
assertEquals(2, group.tripUpdates.size());
tripUpdate = group.tripUpdates.get(0);
assertEquals("tripC", tripUpdate.getTrip().getTripId());
tripUpdate = group.tripUpdates.get(1);
assertEquals("tripD", tripUpdate.getTrip().getTripId());
VehicleLocationRecord record = _library.createVehicleLocationRecordForUpdate(groups.get(0));
assertEquals(blockA.getId(), record.getBlockId());
assertEquals(120, record.getScheduleDeviation(), 0.0);
assertEquals(0L, record.getServiceDate());
assertEquals(blockA.getId(), record.getVehicleId());
record = _library.createVehicleLocationRecordForUpdate(groups.get(1));
assertEquals(blockB.getId(), record.getBlockId());
assertEquals(30, record.getScheduleDeviation(), 0.0);
assertEquals(0L, record.getServiceDate());
assertEquals(blockB.getId(), record.getVehicleId());
}
use of com.google.transit.realtime.GtfsRealtime.FeedEntity in project OpenTripPlanner by opentripplanner.
the class GtfsTest method setUp.
protected void setUp() {
File gtfs = new File("src/test/resources/" + getFeedName());
File gtfsRealTime = new File("src/test/resources/" + getFeedName() + ".pb");
GtfsBundle gtfsBundle = new GtfsBundle(gtfs);
feedId = new GtfsFeedId.Builder().id("FEED").build();
gtfsBundle.setFeedId(feedId);
List<GtfsBundle> gtfsBundleList = Collections.singletonList(gtfsBundle);
GtfsModule gtfsGraphBuilderImpl = new GtfsModule(gtfsBundleList);
alertsUpdateHandler = new AlertsUpdateHandler();
graph = new Graph();
router = new Router("TEST", graph);
gtfsBundle.setTransfersTxtDefinesStationPaths(true);
gtfsGraphBuilderImpl.buildGraph(graph, null);
// Set the agency ID to be used for tests to the first one in the feed.
agencyId = graph.getAgencies(feedId.getId()).iterator().next().getId();
System.out.printf("Set the agency ID for this test to %s\n", agencyId);
graph.index(new DefaultStreetVertexIndexFactory());
timetableSnapshotSource = new TimetableSnapshotSource(graph);
timetableSnapshotSource.purgeExpiredData = (false);
graph.timetableSnapshotSource = (timetableSnapshotSource);
alertPatchServiceImpl = new AlertPatchServiceImpl(graph);
alertsUpdateHandler.setAlertPatchService(alertPatchServiceImpl);
alertsUpdateHandler.setFeedId(feedId.getId());
try {
final boolean fullDataset = false;
InputStream inputStream = new FileInputStream(gtfsRealTime);
FeedMessage feedMessage = FeedMessage.PARSER.parseFrom(inputStream);
List<FeedEntity> feedEntityList = feedMessage.getEntityList();
List<TripUpdate> updates = new ArrayList<TripUpdate>(feedEntityList.size());
for (FeedEntity feedEntity : feedEntityList) {
updates.add(feedEntity.getTripUpdate());
}
timetableSnapshotSource.applyTripUpdates(graph, fullDataset, updates, feedId.getId());
alertsUpdateHandler.update(feedMessage);
} catch (Exception exception) {
}
}
Aggregations