use of org.traccar.reports.model.TripsConfig in project traccar by tananaev.
the class MotionEventHandlerTest method testMotionWithPosition.
@Test
public void testMotionWithPosition() throws Exception {
MotionEventHandler motionEventHandler = new MotionEventHandler(new TripsConfig(500, 300 * 1000, 300 * 1000, 0, false, false, 0.01));
Position position = new Position();
position.setTime(date("2017-01-01 00:00:00"));
position.set(Position.KEY_MOTION, true);
position.set(Position.KEY_TOTAL_DISTANCE, 0);
DeviceState deviceState = new DeviceState();
deviceState.setMotionState(false);
deviceState.setMotionPosition(position);
Position nextPosition = new Position();
nextPosition.setTime(date("2017-01-01 00:02:00"));
nextPosition.set(Position.KEY_MOTION, true);
nextPosition.set(Position.KEY_TOTAL_DISTANCE, 200);
Map<Event, Position> events = motionEventHandler.updateMotionState(deviceState, nextPosition);
assertNull(events);
nextPosition.set(Position.KEY_TOTAL_DISTANCE, 600);
events = motionEventHandler.updateMotionState(deviceState, nextPosition);
assertNotNull(events);
Event event = events.keySet().iterator().next();
assertEquals(Event.TYPE_DEVICE_MOVING, event.getType());
assertTrue(deviceState.getMotionState());
assertNull(deviceState.getMotionPosition());
deviceState.setMotionState(false);
deviceState.setMotionPosition(position);
nextPosition.setTime(date("2017-01-01 00:06:00"));
nextPosition.set(Position.KEY_TOTAL_DISTANCE, 200);
events = motionEventHandler.updateMotionState(deviceState, nextPosition);
assertNotNull(event);
event = events.keySet().iterator().next();
assertEquals(Event.TYPE_DEVICE_MOVING, event.getType());
assertTrue(deviceState.getMotionState());
assertNull(deviceState.getMotionPosition());
}
use of org.traccar.reports.model.TripsConfig in project traccar by tananaev.
the class MotionEventHandlerTest method testMotionWithStatus.
@Test
public void testMotionWithStatus() throws Exception {
MotionEventHandler motionEventHandler = new MotionEventHandler(new TripsConfig(500, 300 * 1000, 300 * 1000, 0, false, false, 0.01));
Position position = new Position();
position.setTime(new Date(System.currentTimeMillis() - 360000));
position.set(Position.KEY_MOTION, true);
DeviceState deviceState = new DeviceState();
deviceState.setMotionState(false);
deviceState.setMotionPosition(position);
Map<Event, Position> events = motionEventHandler.updateMotionState(deviceState);
assertNotNull(events);
Event event = events.keySet().iterator().next();
assertEquals(Event.TYPE_DEVICE_MOVING, event.getType());
assertTrue(deviceState.getMotionState());
assertNull(deviceState.getMotionPosition());
}
Aggregations