diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/org/traccar/FilterHandlerTest.java | 84 | ||||
-rw-r--r-- | test/org/traccar/processing/FilterHandlerTest.java | 88 |
2 files changed, 88 insertions, 84 deletions
diff --git a/test/org/traccar/FilterHandlerTest.java b/test/org/traccar/FilterHandlerTest.java deleted file mode 100644 index 818583eb7..000000000 --- a/test/org/traccar/FilterHandlerTest.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.traccar; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.traccar.model.Position; - -import java.util.Date; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -public class FilterHandlerTest extends BaseTest { - - private FilterHandler filtingHandler; - private FilterHandler passingHandler; - - @Before - public void setUp() { - passingHandler = new FilterHandler(); - filtingHandler = new FilterHandler(); - filtingHandler.setFilterInvalid(true); - filtingHandler.setFilterZero(true); - filtingHandler.setFilterDuplicate(true); - filtingHandler.setFilterFuture(5 * 60); - filtingHandler.setFilterApproximate(true); - filtingHandler.setFilterStatic(true); - filtingHandler.setFilterDistance(10); - filtingHandler.setFilterMaxSpeed(500); - filtingHandler.setSkipLimit(10); - } - - @After - public void tearDown() { - filtingHandler = null; - passingHandler = null; - } - - private Position createPosition( - long deviceId, - Date time, - boolean valid, - double latitude, - double longitude, - double altitude, - double speed, - double course) { - - Position p = new Position(); - p.setDeviceId(deviceId); - p.setTime(time); - p.setValid(valid); - p.setLatitude(latitude); - p.setLongitude(longitude); - p.setAltitude(altitude); - p.setSpeed(speed); - p.setCourse(course); - return p; - } - - @Test - public void testFilterInvalid() throws Exception { - - Position position = createPosition(0, new Date(), true, 10, 10, 10, 10, 10); - - assertNotNull(filtingHandler.handlePosition(position)); - assertNotNull(passingHandler.handlePosition(position)); - - position = createPosition(0, new Date(Long.MAX_VALUE), true, 10, 10, 10, 10, 10); - - assertNull(filtingHandler.handlePosition(position)); - assertNotNull(passingHandler.handlePosition(position)); - - position = createPosition(0, new Date(), false, 10, 10, 10, 10, 10); - - assertNull(filtingHandler.handlePosition(position)); - assertNotNull(passingHandler.handlePosition(position)); - - position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); - filtingHandler.setSkipAttributes(true); - assertNotNull(filtingHandler.handlePosition(position)); - } - -} diff --git a/test/org/traccar/processing/FilterHandlerTest.java b/test/org/traccar/processing/FilterHandlerTest.java new file mode 100644 index 000000000..e0e9a9912 --- /dev/null +++ b/test/org/traccar/processing/FilterHandlerTest.java @@ -0,0 +1,88 @@ +package org.traccar.processing; + +import org.junit.Before; +import org.junit.Test; +import org.traccar.BaseTest; +import org.traccar.config.Config; +import org.traccar.config.Keys; +import org.traccar.model.Position; + +import java.util.Date; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +public class FilterHandlerTest extends BaseTest { + + private FilterHandler passingHandler = new FilterHandler(new Config()); + private FilterHandler filteringHandler; + + @Before + public void before() { + Config config = new Config(); + config.setString(Keys.FILTER_INVALID, String.valueOf(true)); + config.setString(Keys.FILTER_ZERO, String.valueOf(true)); + config.setString(Keys.FILTER_DUPLICATE, String.valueOf(true)); + config.setString(Keys.FILTER_FUTURE, String.valueOf(5 * 60)); + config.setString(Keys.FILTER_APPROXIMATE, String.valueOf(true)); + config.setString(Keys.FILTER_STATIC, String.valueOf(true)); + config.setString(Keys.FILTER_DISTANCE, String.valueOf(10)); + config.setString(Keys.FILTER_MAX_SPEED, String.valueOf(500)); + config.setString(Keys.FILTER_SKIP_LIMIT, String.valueOf(10)); + config.setString(Keys.FILTER_SKIP_ATTRIBUTES_ENABLE, String.valueOf(true)); + filteringHandler = new FilterHandler(config); + } + + private Position createPosition( + long deviceId, + Date time, + boolean valid, + double latitude, + double longitude, + double altitude, + double speed, + double course) { + + Position position = new Position(); + position.setDeviceId(deviceId); + position.setTime(time); + position.setValid(valid); + position.setLatitude(latitude); + position.setLongitude(longitude); + position.setAltitude(altitude); + position.setSpeed(speed); + position.setCourse(course); + return position; + } + + @Test + public void testFilter() { + + Position position = createPosition(0, new Date(), true, 10, 10, 10, 10, 10); + + assertNotNull(filteringHandler.handlePosition(position)); + assertNotNull(passingHandler.handlePosition(position)); + + position = createPosition(0, new Date(Long.MAX_VALUE), true, 10, 10, 10, 10, 10); + + assertNull(filteringHandler.handlePosition(position)); + assertNotNull(passingHandler.handlePosition(position)); + + position = createPosition(0, new Date(), false, 10, 10, 10, 10, 10); + + assertNull(filteringHandler.handlePosition(position)); + assertNotNull(passingHandler.handlePosition(position)); + + } + + @Test + public void testSkipAttributes() { + + Position position = createPosition(0, new Date(), false, 10, 10, 10, 10, 10); + position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); + + assertNotNull(filteringHandler.handlePosition(position)); + + } + +} |