diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2014-12-31 12:04:28 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2014-12-31 12:04:28 +1300 |
commit | aba7cfe71c1ed3290d3b331169c5d56010763b15 (patch) | |
tree | b7b7a78c3c873e7f967af2b478dcd2e3a5c0a3a6 | |
parent | c241127ab32eab9a63cc04fdbd99c08fa0e7b25f (diff) | |
download | traccar-server-aba7cfe71c1ed3290d3b331169c5d56010763b15.tar.gz traccar-server-aba7cfe71c1ed3290d3b331169c5d56010763b15.tar.bz2 traccar-server-aba7cfe71c1ed3290d3b331169c5d56010763b15.zip |
Add filter unit tests
-rw-r--r-- | src/org/traccar/BasePipelineFactory.java | 2 | ||||
-rw-r--r-- | src/org/traccar/FilterHandler.java | 17 | ||||
-rw-r--r-- | src/org/traccar/model/Position.java | 24 | ||||
-rw-r--r-- | test/org/traccar/FilterHandlerTest.java | 49 |
4 files changed, 89 insertions, 3 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index aba568de6..585f3e273 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -99,7 +99,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { String enableFilter = serverManager.getProperties().getProperty("filter.enable"); if (enableFilter != null && Boolean.valueOf(enableFilter)) { - filterHandler = new FilterHandler(serverManager); + filterHandler = new FilterHandler(serverManager.getProperties()); } if (reverseGeocoder != null) { diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index 5298f1d7f..5e1910210 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -36,9 +36,22 @@ public class FilterHandler extends OneToOneDecoder { private long filterLimit; private final Map<Long, Position> lastPositions = new HashMap<Long, Position>(); + + public FilterHandler( + boolean filterInvalid, + boolean filterZero, + boolean filterDuplicate, + int filterDistance, + long filterLimit) { + + this.filterInvalid = filterInvalid; + this.filterZero = filterZero; + this.filterDuplicate = filterDuplicate; + this.filterDistance = filterDistance; + this.filterLimit = filterLimit; + } - public FilterHandler(ServerManager serverManager) { - Properties properties = serverManager.getProperties(); + public FilterHandler(Properties properties) { String value = properties.getProperty("filter.invalid"); if (value != null) filterInvalid = Boolean.valueOf(value); diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 0ee79b744..898b0d144 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -22,6 +22,30 @@ import java.util.Date; */ public class Position extends Data { + public Position() { + } + + public Position( + long deviceId, + Date time, + boolean valid, + double latitude, + double longitude, + double altitude, + double speed, + double course) { + + setDeviceId(deviceId); + setTime(time); + setValid(valid); + setLatitude(latitude); + setLongitude(longitude); + setAltitude(altitude); + setSpeed(speed); + setCourse(course); + } + + /** * Time (UTC) */ diff --git a/test/org/traccar/FilterHandlerTest.java b/test/org/traccar/FilterHandlerTest.java new file mode 100644 index 000000000..1dacab692 --- /dev/null +++ b/test/org/traccar/FilterHandlerTest.java @@ -0,0 +1,49 @@ +package org.traccar; + +import org.jboss.netty.buffer.ChannelBuffers; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.traccar.helper.ChannelBufferTools; +import org.traccar.helper.TestDataManager; +import org.traccar.model.Position; +import org.traccar.protocol.AtrackProtocolDecoder; + +import java.util.Date; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.traccar.helper.DecoderVerifier.verify; + +public class FilterHandlerTest { + + private FilterHandler filtingHandler; + private FilterHandler passingHandler; + + @Before + public void setUp() { + filtingHandler = new FilterHandler(true, true, true, 10, 10); + passingHandler = new FilterHandler(false, false, false, 0, 0); + } + + @After + public void tearDown() { + filtingHandler = null; + passingHandler = null; + } + + @Test + public void testFilterInvalid() throws Exception { + + Position position = new Position(0, new Date(), true, 10, 10, 10, 10, 10); + + assertNotNull(filtingHandler.decode(null, null, position)); + assertNotNull(passingHandler.decode(null, null, position)); + + position = new Position(0, new Date(), false, 10, 10, 10, 10, 10); + + assertNull(filtingHandler.decode(null, null, position)); + assertNotNull(passingHandler.decode(null, null, position)); + } + +} |