use of org.onebusaway.api.model.TimeBean in project onebusaway-application-modules by camsys.
the class CurrentTimeActionTest method test.
@Test
public void test() throws ParseException {
CurrentTimeAction action = new CurrentTimeAction();
long t = System.currentTimeMillis();
DefaultHttpHeaders headers = action.index();
assertEquals(200, headers.getStatus());
ResponseBean response = action.getModel();
assertEquals(200, response.getCode());
assertEquals(2, response.getVersion());
@SuppressWarnings("unchecked") EntryWithReferencesBean<TimeBean> entry = (EntryWithReferencesBean<TimeBean>) response.getData();
TimeBean time = entry.getEntry();
assertNotNull(time);
long delta = Math.abs(time.getTime() - t);
assertTrue("check that time delta is within limits: delta=" + delta, delta < 100);
String readableTime = DateLibrary.getTimeAsIso8601String(new Date(time.getTime()));
assertEquals(readableTime, time.getReadableTime());
}
use of org.onebusaway.api.model.TimeBean in project onebusaway-application-modules by camsys.
the class CurrentTimeAction method index.
public DefaultHttpHeaders index() {
Date date = new Date();
date.setTime(SystemTime.currentTimeMillis());
String readableTime = DateLibrary.getTimeAsIso8601String(date);
TimeBean bean = new TimeBean(date, readableTime);
if (isVersion(V1)) {
return setOkResponse(bean);
} else if (isVersion(V2)) {
BeanFactoryV2 factory = getBeanFactoryV2();
EntryWithReferencesBean<TimeBean> response = factory.entry(bean);
return setOkResponse(response);
} else {
return setUnknownVersionResponse();
}
}
Aggregations