aboutsummaryrefslogtreecommitdiff
path: root/test/org/traccar/events
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-08-10 13:31:18 +0500
committerAbyss777 <abyss@fox5.ru>2017-08-10 13:31:18 +0500
commit532e0a98d469573a575dc595554792cbbd4cd953 (patch)
treef05220655a2df11cbdbe57f8da7e1d86ef27f491 /test/org/traccar/events
parentb82be4f9f3b4d1d6c345bc41d5c26aca03e369cb (diff)
downloadtrackermap-server-532e0a98d469573a575dc595554792cbbd4cd953.tar.gz
trackermap-server-532e0a98d469573a575dc595554792cbbd4cd953.tar.bz2
trackermap-server-532e0a98d469573a575dc595554792cbbd4cd953.zip
Implement delayed overspeed events
Diffstat (limited to 'test/org/traccar/events')
-rw-r--r--test/org/traccar/events/OverspeedEventHandlerTest.java85
1 files changed, 85 insertions, 0 deletions
diff --git a/test/org/traccar/events/OverspeedEventHandlerTest.java b/test/org/traccar/events/OverspeedEventHandlerTest.java
new file mode 100644
index 000000000..25bbb4319
--- /dev/null
+++ b/test/org/traccar/events/OverspeedEventHandlerTest.java
@@ -0,0 +1,85 @@
+package org.traccar.events;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+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.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 testOverspeed(boolean notRepeat) throws Exception {
+ Position position = new Position();
+ position.setTime(date("2017-01-01 00:00:00"));
+ position.setSpeed(50);
+ DeviceState deviceState = new DeviceState();
+ deviceState.setOverspeedState(false);
+
+ Event event = OverspeedEventHandler.updateOverspeedState(deviceState, position, 40, 15000, notRepeat);
+ assertNull(event);
+ assertFalse(deviceState.getOverspeedState());
+ assertEquals(position, deviceState.getOverspeedPosition());
+
+ Position nextPosition = new Position();
+ nextPosition.setTime(date("2017-01-01 00:00:10"));
+ nextPosition.setSpeed(55);
+
+ event = OverspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40, 15000, notRepeat);
+ assertNull(event);
+
+ nextPosition.setTime(date("2017-01-01 00:00:20"));
+
+ event = OverspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40, 15000, notRepeat);
+ assertNotNull(event);
+ 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(notRepeat, deviceState.getOverspeedState());
+ assertNull(deviceState.getOverspeedPosition());
+
+ nextPosition.setTime(date("2017-01-01 00:00:30"));
+ event = OverspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40, 15000, notRepeat);
+ assertNull(event);
+ assertEquals(notRepeat, deviceState.getOverspeedState());
+
+ if (notRepeat) {
+ assertNull(deviceState.getOverspeedPosition());
+ } else {
+ assertNotNull(deviceState.getOverspeedPosition());
+ }
+
+ nextPosition.setTime(date("2017-01-01 00:00:40"));
+ nextPosition.setSpeed(30);
+
+ event = OverspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40, 15000, notRepeat);
+ assertNull(event);
+ assertFalse(deviceState.getOverspeedState());
+ assertNull(deviceState.getOverspeedPosition());
+ }
+
+ @Test
+ public void testOverspeedEventHandler() throws Exception {
+ testOverspeed(false);
+ testOverspeed(true);
+ }
+
+}