Search in sources :

Example 1 with GoogleAnalyticsResponse

use of com.brsanthu.googleanalytics.GoogleAnalyticsResponse 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>.*"));
}
Also used : SituationRefStructure(uk.org.siri.siri.SituationRefStructure) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Matchers.anyString(org.mockito.Matchers.anyString) LocationStructure(uk.org.siri.siri.LocationStructure) MonitoredVehicleJourney(uk.org.siri.siri.VehicleActivityStructure.MonitoredVehicleJourney) RouteBean(org.onebusaway.transit_data.model.RouteBean) GoogleAnalyticsRequest(com.brsanthu.googleanalytics.GoogleAnalyticsRequest) SiriXmlSerializer(org.onebusaway.transit_data_federation.siri.SiriXmlSerializer) VehicleActivityStructure(uk.org.siri.siri.VehicleActivityStructure) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) GoogleAnalyticsResponse(com.brsanthu.googleanalytics.GoogleAnalyticsResponse) PrintWriter(java.io.PrintWriter) SituationSimpleRefStructure(uk.org.siri.siri.SituationSimpleRefStructure) Test(org.junit.Test)

Aggregations

GoogleAnalyticsRequest (com.brsanthu.googleanalytics.GoogleAnalyticsRequest)1 GoogleAnalyticsResponse (com.brsanthu.googleanalytics.GoogleAnalyticsResponse)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 RouteBean (org.onebusaway.transit_data.model.RouteBean)1 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)1 SiriXmlSerializer (org.onebusaway.transit_data_federation.siri.SiriXmlSerializer)1 LocationStructure (uk.org.siri.siri.LocationStructure)1 SituationRefStructure (uk.org.siri.siri.SituationRefStructure)1 SituationSimpleRefStructure (uk.org.siri.siri.SituationSimpleRefStructure)1 VehicleActivityStructure (uk.org.siri.siri.VehicleActivityStructure)1 MonitoredVehicleJourney (uk.org.siri.siri.VehicleActivityStructure.MonitoredVehicleJourney)1