Package org.onebusaway.transit_data.model.service_alerts

Examples of org.onebusaway.transit_data.model.service_alerts.TimeRangeBean


  private List<TimeRangeBean> getRangesAsBeans(List<TimeRange> ranges) {
    if (ranges == null || ranges.isEmpty())
      return null;
    List<TimeRangeBean> beans = new ArrayList<TimeRangeBean>();
    for (TimeRange range : ranges) {
      TimeRangeBean bean = new TimeRangeBean();
      if (range.hasStart())
        bean.setFrom(range.getStart());
      if (range.hasEnd())
        bean.setTo(range.getEnd());
      beans.add(bean);
    }
    return beans;
  }
View Full Code Here


    /**
     * Construct the bean we'll use in the call to the service
     */
    ServiceAlertBean bean = new ServiceAlertBean();
    bean.setActiveWindows(Arrays.asList(new TimeRangeBean(30, 40)));
    SituationAffectsBean affectsBean = new SituationAffectsBean();
    affectsBean.setAgencyId("1");
    affectsBean.setApplicationId("key");
    affectsBean.setDirectionId("0");
    affectsBean.setRouteId("1_route");
    affectsBean.setTripId("1_trip");
    affectsBean.setStopId("1_stop");
    bean.setAllAffects(Arrays.asList(affectsBean));
    SituationConsequenceBean consequenceBean = new SituationConsequenceBean();
    consequenceBean.setEffect(EEffect.DETOUR);
    consequenceBean.setDetourPath("path");
    consequenceBean.setDetourStopIds(Arrays.asList("1_stop"));
    bean.setConsequences(Arrays.asList(consequenceBean));
    bean.setCreationTime(5);
    bean.setDescriptions(Arrays.asList(new NaturalLanguageStringBean(
        "description", "en")));
    bean.setId("1_ignore_this");
    bean.setPublicationWindows(Arrays.asList(new TimeRangeBean(20, 40)));
    bean.setReason("ACCIDENT");
    bean.setSeverity(ESeverity.VERY_SEVERE);
    bean.setSummaries(Arrays.asList(new NaturalLanguageStringBean("summary",
        "en")));
    bean.setUrls(Arrays.asList(new NaturalLanguageStringBean(
        "http://somewhere", "en")));

    /**
     * Construct the ServiceAlert.Builder that we'll return from the
     * ServiceAlertService mock when called by the bean service
     */
    ServiceAlert.Builder builder = ServiceAlert.newBuilder();
    TimeRange.Builder trBuilder = TimeRange.newBuilder();
    trBuilder.setStart(30);
    trBuilder.setEnd(40);
    builder.addActiveWindow(trBuilder);
    Affects.Builder affectsBuilder = Affects.newBuilder();
    affectsBuilder.setAgencyId("B");
    affectsBuilder.setApplicationId("keyB");
    affectsBuilder.setDirectionId("1");
    affectsBuilder.setRouteId(ServiceAlertLibrary.id("1", "routeB"));
    affectsBuilder.setTripId(ServiceAlertLibrary.id("1", "tripB"));
    affectsBuilder.setStopId(ServiceAlertLibrary.id("1", "stopB"));
    builder.addAffects(affectsBuilder);
    Consequence.Builder consequenceBuilder = Consequence.newBuilder();
    consequenceBuilder.setEffect(Effect.MODIFIED_SERVICE);
    consequenceBuilder.setDetourPath("pathB");
    consequenceBuilder.addDetourStopIds(ServiceAlertLibrary.id("1", "stopB"));
    builder.addConsequence(consequenceBuilder);
    builder.setCreationTime(1000);
    builder.setCause(Cause.CONSTRUCTION);
    TranslatedString.Builder tsBuilder = TranslatedString.newBuilder();
    Translation.Builder tBuilder = Translation.newBuilder();
    tBuilder.setLanguage("fr");
    tBuilder.setText("descriptionB");
    tsBuilder.addTranslation(tBuilder);
    builder.setDescription(tsBuilder);
    builder.setId(ServiceAlertLibrary.id("1", "updated_id"));
    builder.setModifiedTime(System.currentTimeMillis());
    trBuilder = TimeRange.newBuilder();
    trBuilder.setStart(20);
    trBuilder.setEnd(40);
    builder.addPublicationWindow(trBuilder);
    builder.setSeverity(Severity.NO_IMPACT);
    tsBuilder = TranslatedString.newBuilder();
    tBuilder = Translation.newBuilder();
    tBuilder.setLanguage("fr");
    tBuilder.setText("summaryB");
    tsBuilder.addTranslation(tBuilder);
    builder.setSummary(tsBuilder);
    tsBuilder = TranslatedString.newBuilder();
    tBuilder = Translation.newBuilder();
    tBuilder.setLanguage("fr");
    tBuilder.setText("http://somewhere/else/");
    tsBuilder.addTranslation(tBuilder);
    builder.setUrl(tsBuilder);

    ArgumentCaptor<ServiceAlert.Builder> captor = ArgumentCaptor.forClass(ServiceAlert.Builder.class);
    Mockito.when(
        _serviceAlertService.createOrUpdateServiceAlert(captor.capture(),
            Mockito.eq("1"))).thenReturn(builder.build());

    ServiceAlertBean updated = _service.createServiceAlert("1", bean);

    Mockito.verify(_serviceAlertService).createOrUpdateServiceAlert(
        Mockito.any(ServiceAlert.Builder.class), Mockito.eq("1"));

    assertNotSame(updated, bean);

    /**
     * Verify that the conversion of the ServiceAlertBean into a
     * ServiceAlert.Builder looks right
     */
    builder = captor.getValue();
    assertEquals(1, builder.getActiveWindowCount());
    TimeRange range = builder.getActiveWindow(0);
    assertEquals(30L, range.getStart());
    assertEquals(40L, range.getEnd());
    assertEquals(1, builder.getAffectsCount());
    Affects affects = builder.getAffects(0);
    assertEquals("1", affects.getAgencyId());
    assertEquals("key", affects.getApplicationId());
    assertEquals("0", affects.getDirectionId());
    assertEquals("route", affects.getRouteId().getId());
    assertEquals("trip", affects.getTripId().getId());
    assertEquals("stop", affects.getStopId().getId());
    assertEquals(Cause.ACCIDENT, builder.getCause());
    assertEquals(1, builder.getConsequenceCount());
    Consequence consequence = builder.getConsequence(0);
    assertEquals(Effect.DETOUR, consequence.getEffect());
    assertEquals("path", consequence.getDetourPath());
    assertEquals(1, consequence.getDetourStopIdsCount());
    assertEquals("stop", consequence.getDetourStopIds(0).getId());
    assertEquals(5, builder.getCreationTime());
    assertTrue(builder.hasDescription());
    TranslatedString descs = builder.getDescription();
    assertEquals(1, descs.getTranslationCount());
    Translation desc = descs.getTranslation(0);
    assertEquals("en", desc.getLanguage());
    assertEquals("description", desc.getText());
    assertEquals("ignore_this", builder.getId().getId());
    assertEquals(1, builder.getPublicationWindowCount());
    range = builder.getPublicationWindow(0);
    assertEquals(20L, range.getStart());
    assertEquals(40L, range.getEnd());
    assertEquals(Severity.VERY_SEVERE, builder.getSeverity());
    TranslatedString summaries = builder.getSummary();
    assertEquals(1, summaries.getTranslationCount());
    Translation summary = summaries.getTranslation(0);
    assertEquals("en", summary.getLanguage());
    assertEquals("summary", summary.getText());
    TranslatedString urls = builder.getUrl();
    assertEquals(1, urls.getTranslationCount());
    Translation url = urls.getTranslation(0);
    assertEquals("en", url.getLanguage());
    assertEquals("http://somewhere", url.getText());

    /**
     * Verify that the conversion from the ServiceAlert to ServiceAlertBean
     * looks good
     */
    List<TimeRangeBean> windows = updated.getActiveWindows();
    assertEquals(1, windows.size());
    TimeRangeBean window = windows.get(0);
    assertEquals(30L, window.getFrom());
    assertEquals(40L, window.getTo());
    assertEquals(1, updated.getAllAffects().size());
    affectsBean = updated.getAllAffects().get(0);
    assertEquals("B", affectsBean.getAgencyId());
    assertEquals("keyB", affectsBean.getApplicationId());
    assertEquals("1", affectsBean.getDirectionId());
    assertEquals("1_routeB", affectsBean.getRouteId());
    assertEquals("1_stopB", affectsBean.getStopId());
    assertEquals("1_tripB", affectsBean.getTripId());
    assertEquals(1, updated.getConsequences().size());
    consequenceBean = updated.getConsequences().get(0);
    assertEquals(EEffect.MODIFIED_SERVICE, consequenceBean.getEffect());
    assertEquals("pathB", consequenceBean.getDetourPath());
    assertEquals(1, consequenceBean.getDetourStopIds().size());
    assertEquals("1_stopB", consequenceBean.getDetourStopIds().get(0));
    assertEquals(1000, updated.getCreationTime());
    assertEquals(1, updated.getDescriptions().size());
    NaturalLanguageStringBean nls = updated.getDescriptions().get(0);
    assertEquals("fr", nls.getLang());
    assertEquals("descriptionB", nls.getValue());
    assertEquals("1_updated_id", updated.getId());
    assertEquals(1, updated.getPublicationWindows().size());
    window = updated.getPublicationWindows().get(0);
    assertEquals(20L, window.getFrom());
    assertEquals(40L, window.getTo());
    assertEquals("CONSTRUCTION", updated.getReason());
    assertEquals(ESeverity.NO_IMPACT, updated.getSeverity());
    assertEquals(1, updated.getSummaries().size());
    nls = updated.getSummaries().get(0);
    assertEquals("fr", nls.getLang());
View Full Code Here

    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());
View Full Code Here

TOP

Related Classes of org.onebusaway.transit_data.model.service_alerts.TimeRangeBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.