aboutsummaryrefslogtreecommitdiff
path: root/test/org/traccar/events/OverspeedEventHandlerTest.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-02-27 23:02:41 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-02-27 23:02:41 -0800
commit08754125ed5d152efe29926728033da3658c69fc (patch)
tree41a8924575e0e4ad646f3ac44e984e7cb7fccb1d /test/org/traccar/events/OverspeedEventHandlerTest.java
parenta68b4ab19873de65145772b408b4db75da25484a (diff)
downloadtraccar-server-08754125ed5d152efe29926728033da3658c69fc.tar.gz
traccar-server-08754125ed5d152efe29926728033da3658c69fc.tar.bz2
traccar-server-08754125ed5d152efe29926728033da3658c69fc.zip
Move events handler classes
Diffstat (limited to 'test/org/traccar/events/OverspeedEventHandlerTest.java')
-rw-r--r--test/org/traccar/events/OverspeedEventHandlerTest.java118
1 files changed, 0 insertions, 118 deletions
diff --git a/test/org/traccar/events/OverspeedEventHandlerTest.java b/test/org/traccar/events/OverspeedEventHandlerTest.java
deleted file mode 100644
index 98fd0f87a..000000000
--- a/test/org/traccar/events/OverspeedEventHandlerTest.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package org.traccar.events;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Map;
-import java.util.TimeZone;
-
-import org.junit.Test;
-import org.traccar.BaseTest;
-import org.traccar.model.DeviceState;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-
-public class OverspeedEventHandlerTest extends BaseTest {
-
- private Date date(String time) throws ParseException {
- DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- return dateFormat.parse(time);
- }
-
- private void testOverspeedWithPosition(boolean notRepeat, long geofenceId) throws Exception {
- OverspeedEventHandler overspeedEventHandler = new OverspeedEventHandler(15000, notRepeat, false);
-
- Position position = new Position();
- position.setTime(date("2017-01-01 00:00:00"));
- position.setSpeed(50);
- DeviceState deviceState = new DeviceState();
- deviceState.setOverspeedState(false);
-
- Map<Event, Position> events = overspeedEventHandler.updateOverspeedState(deviceState, position, 40, geofenceId);
- assertNull(events);
- assertFalse(deviceState.getOverspeedState());
- assertEquals(position, deviceState.getOverspeedPosition());
- assertEquals(geofenceId, deviceState.getOverspeedGeofenceId());
-
- Position nextPosition = new Position();
- nextPosition.setTime(date("2017-01-01 00:00:10"));
- nextPosition.setSpeed(55);
-
- events = overspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40, geofenceId);
- assertNull(events);
-
- nextPosition.setTime(date("2017-01-01 00:00:20"));
-
- events = overspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40, geofenceId);
- assertNotNull(events);
- Event event = events.keySet().iterator().next();
- assertEquals(Event.TYPE_DEVICE_OVERSPEED, event.getType());
- assertEquals(50, event.getDouble("speed"), 0.1);
- assertEquals(40, event.getDouble(OverspeedEventHandler.ATTRIBUTE_SPEED_LIMIT), 0.1);
- assertEquals(geofenceId, event.getGeofenceId());
-
- assertEquals(notRepeat, deviceState.getOverspeedState());
- assertNull(deviceState.getOverspeedPosition());
- assertEquals(0, deviceState.getOverspeedGeofenceId());
-
- nextPosition.setTime(date("2017-01-01 00:00:30"));
- events = overspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40, geofenceId);
- assertNull(events);
- assertEquals(notRepeat, deviceState.getOverspeedState());
-
- if (notRepeat) {
- assertNull(deviceState.getOverspeedPosition());
- assertEquals(0, deviceState.getOverspeedGeofenceId());
- } else {
- assertNotNull(deviceState.getOverspeedPosition());
- assertEquals(geofenceId, deviceState.getOverspeedGeofenceId());
- }
-
- nextPosition.setTime(date("2017-01-01 00:00:40"));
- nextPosition.setSpeed(30);
-
- events = overspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40, geofenceId);
- assertNull(events);
- assertFalse(deviceState.getOverspeedState());
- assertNull(deviceState.getOverspeedPosition());
- assertEquals(0, deviceState.getOverspeedGeofenceId());
- }
-
- private void testOverspeedWithStatus(boolean notRepeat) throws Exception {
- OverspeedEventHandler overspeedEventHandler = new OverspeedEventHandler(15000, notRepeat, false);
-
- Position position = new Position();
- position.setTime(new Date(System.currentTimeMillis() - 30000));
- position.setSpeed(50);
- DeviceState deviceState = new DeviceState();
- deviceState.setOverspeedState(false);
- deviceState.setOverspeedPosition(position);
-
- Map<Event, Position> events = overspeedEventHandler.updateOverspeedState(deviceState, 40);
-
- assertNotNull(events);
- Event event = events.keySet().iterator().next();
- assertEquals(Event.TYPE_DEVICE_OVERSPEED, event.getType());
- assertEquals(notRepeat, deviceState.getOverspeedState());
- }
-
- @Test
- public void testOverspeedEventHandler() throws Exception {
- testOverspeedWithPosition(false, 0);
- testOverspeedWithPosition(true, 0);
-
- testOverspeedWithPosition(false, 1);
- testOverspeedWithPosition(true, 1);
-
- testOverspeedWithStatus(false);
- testOverspeedWithStatus(true);
- }
-
-}