aboutsummaryrefslogtreecommitdiff
path: root/test/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-05-11 14:22:21 -0700
committerGitHub <noreply@github.com>2018-05-11 14:22:21 -0700
commit662b774234298c38a38c172d1dcb4668996045ac (patch)
tree7f46a605aabd630d3f07b7ec6f7d8713ed3be2ce /test/org
parenta97c12829e99b63f1951bffc658c37ec180e5379 (diff)
parent3639bc6d289fa137d5dc7aaa47b67cd6a6bcc47d (diff)
downloadtraccar-server-662b774234298c38a38c172d1dcb4668996045ac.tar.gz
traccar-server-662b774234298c38a38c172d1dcb4668996045ac.tar.bz2
traccar-server-662b774234298c38a38c172d1dcb4668996045ac.zip
Merge pull request #3870 from Abyss777/geo_overspeed
Add basic support of overspeeding inside geofences.
Diffstat (limited to 'test/org')
-rw-r--r--test/org/traccar/events/OverspeedEventHandlerTest.java29
1 files changed, 19 insertions, 10 deletions
diff --git a/test/org/traccar/events/OverspeedEventHandlerTest.java b/test/org/traccar/events/OverspeedEventHandlerTest.java
index d38367cd9..98fd0f87a 100644
--- a/test/org/traccar/events/OverspeedEventHandlerTest.java
+++ b/test/org/traccar/events/OverspeedEventHandlerTest.java
@@ -26,8 +26,8 @@ public class OverspeedEventHandlerTest extends BaseTest {
return dateFormat.parse(time);
}
- private void testOverspeedWithPosition(boolean notRepeat) throws Exception {
- OverspeedEventHandler overspeedEventHandler = new OverspeedEventHandler(15000, notRepeat);
+ 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"));
@@ -35,52 +35,58 @@ public class OverspeedEventHandlerTest extends BaseTest {
DeviceState deviceState = new DeviceState();
deviceState.setOverspeedState(false);
- Map<Event, Position> events = overspeedEventHandler.updateOverspeedState(deviceState, position, 40);
+ 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);
+ events = overspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40, geofenceId);
assertNull(events);
nextPosition.setTime(date("2017-01-01 00:00:20"));
- events = overspeedEventHandler.updateOverspeedState(deviceState, nextPosition, 40);
+ 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);
+ 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);
+ 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);
+ OverspeedEventHandler overspeedEventHandler = new OverspeedEventHandler(15000, notRepeat, false);
Position position = new Position();
position.setTime(new Date(System.currentTimeMillis() - 30000));
@@ -99,8 +105,11 @@ public class OverspeedEventHandlerTest extends BaseTest {
@Test
public void testOverspeedEventHandler() throws Exception {
- testOverspeedWithPosition(false);
- testOverspeedWithPosition(true);
+ testOverspeedWithPosition(false, 0);
+ testOverspeedWithPosition(true, 0);
+
+ testOverspeedWithPosition(false, 1);
+ testOverspeedWithPosition(true, 1);
testOverspeedWithStatus(false);
testOverspeedWithStatus(true);