use of org.onebusaway.transit_data_federation.siri.SiriXmlSerializer in project onebusaway-application-modules by camsys.
the class VehicleMonitoringActionTest method testExecuteByRoute.
@Test
public void testExecuteByRoute() throws Exception {
when(request.getParameter(eq("LineRef"))).thenReturn("40_100479");
when(request.getParameter(eq("OperatorRef"))).thenReturn("1");
PrintWriter nothingPrintWriter = new PrintWriter(new OutputStream() {
@Override
public void write(int b) throws IOException {
// Do nothing
}
});
when(servletResponse.getWriter()).thenReturn(nothingPrintWriter);
List<VehicleActivityStructure> vehicleActivities = new ArrayList<VehicleActivityStructure>();
when(realtimeService.getVehicleActivityForRoute(eq("40_100479"), anyString(), eq(0), anyLong(), eq(false))).thenReturn(vehicleActivities);
VehicleActivityStructure vehicleActivity = new VehicleActivityStructure();
vehicleActivities.add(vehicleActivity);
MonitoredVehicleJourney mvJourney = new MonitoredVehicleJourney();
vehicleActivity.setMonitoredVehicleJourney(mvJourney);
LocationStructure locationStructure = new LocationStructure();
mvJourney.setVehicleLocation(locationStructure);
locationStructure.setLatitude(BigDecimal.valueOf(88.0));
locationStructure.setLongitude(BigDecimal.valueOf(89.0));
ServiceAlertBean serviceAlertBean = ServiceAlertsTestSupport.createServiceAlertBean("1_1");
when(transitDataService.getServiceAlertForId(anyString())).thenReturn(serviceAlertBean);
RouteBean routeBean = RouteBean.builder().create();
when(transitDataService.getRouteForId(anyString())).thenReturn(routeBean);
when(configurationService.getConfigurationValueAsString(eq("display.googleAnalyticsSiteId"), anyString())).thenReturn("foo");
List<SituationRefStructure> sitRef = mvJourney.getSituationRef();
SituationRefStructure sitRefStructure = new SituationRefStructure();
sitRef.add(sitRefStructure);
SituationSimpleRefStructure sitSimpleRef = new SituationSimpleRefStructure();
sitRefStructure.setSituationSimpleRef(sitSimpleRef);
sitSimpleRef.setValue("situation ref");
SiriXmlSerializer serializer = new SiriXmlSerializer();
when(realtimeService.getSiriXmlSerializer()).thenReturn(serializer);
// doNothing().when(gaService).post(new PageViewHit());
when(gaService.post(new GoogleAnalyticsRequest())).thenReturn(new GoogleAnalyticsResponse());
action.setServletRequest(request);
action.setServletResponse(servletResponse);
action.index();
String monitoring = action.getVehicleMonitoring();
assertTrue("Result XML does not match expected", monitoring.matches("(?s).*<ServiceDelivery><ResponseTimestamp>.+</ResponseTimestamp><VehicleMonitoringDelivery><ResponseTimestamp>.+</ResponseTimestamp><ValidUntil>.+</ValidUntil><VehicleActivity><MonitoredVehicleJourney><SituationRef><SituationSimpleRef>situation ref</SituationSimpleRef></SituationRef><VehicleLocation><Longitude>89.0</Longitude><Latitude>88.0</Latitude></VehicleLocation></MonitoredVehicleJourney></VehicleActivity></VehicleMonitoringDelivery><SituationExchangeDelivery><Situations><PtSituationElement><SituationNumber>1_1</SituationNumber><Summary xml:lang=\"EN\">summary</Summary><Description xml:lang=\"EN\">description</Description><Affects><VehicleJourneys><AffectedVehicleJourney><LineRef>1_100277</LineRef><DirectionRef>0</DirectionRef></AffectedVehicleJourney><AffectedVehicleJourney><LineRef>1_100277</LineRef><DirectionRef>1</DirectionRef></AffectedVehicleJourney><AffectedVehicleJourney><LineRef>1_100194</LineRef><DirectionRef>0</DirectionRef></AffectedVehicleJourney><AffectedVehicleJourney><LineRef>1_100194</LineRef><DirectionRef>1</DirectionRef></AffectedVehicleJourney></VehicleJourneys></Affects></PtSituationElement></Situations></SituationExchangeDelivery></ServiceDelivery></Siri>.*"));
}
use of org.onebusaway.transit_data_federation.siri.SiriXmlSerializer in project onebusaway-application-modules by camsys.
the class VehicleMonitoringActionTest method testExecuteByRouteNoActivity.
@Test
public void testExecuteByRouteNoActivity() throws Exception {
when(request.getParameter(eq("LineRef"))).thenReturn("40_100479");
when(request.getParameter(eq("OperatorRef"))).thenReturn("1");
PrintWriter nothingPrintWriter = new PrintWriter(new OutputStream() {
@Override
public void write(int b) throws IOException {
// Do nothing
}
});
when(servletResponse.getWriter()).thenReturn(nothingPrintWriter);
List<VehicleActivityStructure> vehicleActivities = new ArrayList<VehicleActivityStructure>();
when(realtimeService.getVehicleActivityForRoute(eq("40_100479"), anyString(), eq(0), anyLong(), eq(false))).thenReturn(vehicleActivities);
ServiceAlertBean serviceAlertBean = ServiceAlertsTestSupport.createServiceAlertBean("1_1");
when(transitDataService.getServiceAlertForId(anyString())).thenReturn(serviceAlertBean);
RouteBean routeBean = RouteBean.builder().create();
when(transitDataService.getRouteForId(anyString())).thenReturn(routeBean);
ListBean<ServiceAlertBean> serviceAlertListBean = new ListBean<ServiceAlertBean>();
List<ServiceAlertBean> list = new ArrayList<ServiceAlertBean>();
list.add(serviceAlertBean);
serviceAlertListBean.setList(list);
when(transitDataService.getServiceAlerts(any(SituationQueryBean.class))).thenReturn(serviceAlertListBean);
SiriXmlSerializer serializer = new SiriXmlSerializer();
when(realtimeService.getSiriXmlSerializer()).thenReturn(serializer);
action.setServletRequest(request);
action.setServletResponse(servletResponse);
action.index();
String monitoring = action.getVehicleMonitoring();
assertTrue("Result XML does not match expected", monitoring.matches("(?s).*<SituationExchangeDelivery><Situations><PtSituationElement><SituationNumber>1_1</SituationNumber><Summary xml:lang=\"EN\">summary</Summary><Description xml:lang=\"EN\">description</Description><Affects><VehicleJourneys><AffectedVehicleJourney><LineRef>1_100277</LineRef><DirectionRef>0</DirectionRef></AffectedVehicleJourney><AffectedVehicleJourney><LineRef>1_100277</LineRef><DirectionRef>1</DirectionRef></AffectedVehicleJourney><AffectedVehicleJourney><LineRef>1_100194</LineRef><DirectionRef>0</DirectionRef></AffectedVehicleJourney><AffectedVehicleJourney><LineRef>1_100194</LineRef><DirectionRef>1</DirectionRef></AffectedVehicleJourney></VehicleJourneys></Affects></PtSituationElement></Situations></SituationExchangeDelivery></ServiceDelivery></Siri>.*"));
}
Aggregations