use of com.google.transit.realtime.GtfsRealtime.TranslatedString 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.TranslatedString in project onebusaway-application-modules by camsys.
the class FeedServiceImplTest method createAlert.
private FeedEntity createAlert(String alertId, String header, String desc, Alert.Cause cause, Alert.Effect effect, String url, long startTime, long endTime, String agency, String route, String stop) {
Alert.Builder alertBldr = Alert.newBuilder();
// Header
Translation translation = Translation.newBuilder().setLanguage("en").setText(header).build();
TranslatedString trnStr = TranslatedString.newBuilder().addTranslation(translation).build();
alertBldr.setHeaderText(trnStr);
// Description
translation = Translation.newBuilder().setLanguage("en").setText(desc).build();
trnStr = TranslatedString.newBuilder().addTranslation(translation).build();
alertBldr.setDescriptionText(trnStr);
// Cause
alertBldr.setCause(cause);
// Effect
alertBldr.setEffect(effect);
// URL
translation = Translation.newBuilder().setLanguage("en").setText(url).build();
trnStr = TranslatedString.newBuilder().addTranslation(translation).build();
alertBldr.setUrl(trnStr);
// Build TimeRangeEntity
TimeRange timeRange = createTimeRange(startTime, endTime);
alertBldr.addActivePeriod(timeRange);
// Build EntitySelectorEntity
EntitySelector entitySelector = createEntitySelector(agency, route, stop);
alertBldr.addInformedEntity(entitySelector);
FeedEntity.Builder alertEntity = FeedEntity.newBuilder();
alertEntity.setId(alertId);
alertEntity.setAlert(alertBldr.build());
return alertEntity.build();
}
Aggregations