aboutsummaryrefslogtreecommitdiff
path: root/test/org/traccar/events
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-08-10 16:30:37 +1200
committerGitHub <noreply@github.com>2017-08-10 16:30:37 +1200
commitb82be4f9f3b4d1d6c345bc41d5c26aca03e369cb (patch)
treed0765e885e4d3af1cc5b58011df5574c6ad82ea6 /test/org/traccar/events
parentea1b94b524c880927f85fd0c94a26bd3ec17c898 (diff)
parent34faf7e1d024596b388d1dd3a062f19adde0027c (diff)
downloadtrackermap-server-b82be4f9f3b4d1d6c345bc41d5c26aca03e369cb.tar.gz
trackermap-server-b82be4f9f3b4d1d6c345bc41d5c26aca03e369cb.tar.bz2
trackermap-server-b82be4f9f3b4d1d6c345bc41d5c26aca03e369cb.zip
Merge pull request #3426 from Abyss777/delayed_motion_events
Implement motion detection similar to trips detection
Diffstat (limited to 'test/org/traccar/events')
-rw-r--r--test/org/traccar/events/MotionEventHandlerTest.java56
1 files changed, 47 insertions, 9 deletions
diff --git a/test/org/traccar/events/MotionEventHandlerTest.java b/test/org/traccar/events/MotionEventHandlerTest.java
index f05ef54d5..c44f3f4eb 100644
--- a/test/org/traccar/events/MotionEventHandlerTest.java
+++ b/test/org/traccar/events/MotionEventHandlerTest.java
@@ -2,28 +2,66 @@ package org.traccar.events;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
-import java.util.Collection;
+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;
+import org.traccar.reports.model.TripsConfig;
public class MotionEventHandlerTest 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);
+ }
+
@Test
public void testMotionEventHandler() throws Exception {
-
- MotionEventHandler motionEventHandler = new MotionEventHandler();
-
+ TripsConfig tripsConfig = new TripsConfig(500, 300 * 1000, 300 * 1000, false, 0);
+
Position position = new Position();
+ position.setTime(date("2017-01-01 00:00:00"));
position.set(Position.KEY_MOTION, true);
- position.setValid(true);
- Collection<Event> events = motionEventHandler.analyzePosition(position);
- assertNotNull(events);
- Event event = (Event) events.toArray()[0];
+ 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);
+
+ Event event = MotionEventHandler.updateMotionState(deviceState, nextPosition, tripsConfig);
+ assertNull(event);
+
+ nextPosition.set(Position.KEY_TOTAL_DISTANCE, 600);
+ event = MotionEventHandler.updateMotionState(deviceState, nextPosition, tripsConfig);
+ assertNotNull(event);
+ 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);
+ event = MotionEventHandler.updateMotionState(deviceState, nextPosition, tripsConfig);
+ assertNotNull(event);
assertEquals(Event.TYPE_DEVICE_MOVING, event.getType());
+ assertTrue(deviceState.getMotionState());
+ assertNull(deviceState.getMotionPosition());
}
}