aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-05-18 13:57:29 +0500
committerAbyss777 <abyss@fox5.ru>2017-05-18 13:57:29 +0500
commit660828e48ac0657e9673c1d7647131ffa9d9c963 (patch)
treecf32d32f2c2e40572beeefdbd8f196784970537c /test
parentee66c9239381168b36eaa68cd1e962e4034a81f2 (diff)
downloadtrackermap-server-660828e48ac0657e9673c1d7647131ffa9d9c963.tar.gz
trackermap-server-660828e48ac0657e9673c1d7647131ffa9d9c963.tar.bz2
trackermap-server-660828e48ac0657e9673c1d7647131ffa9d9c963.zip
Unwrap position fields and attributes to computedAttribute context.
Diffstat (limited to 'test')
-rw-r--r--test/org/traccar/processing/ComputedAttributesTest.java37
1 files changed, 32 insertions, 5 deletions
diff --git a/test/org/traccar/processing/ComputedAttributesTest.java b/test/org/traccar/processing/ComputedAttributesTest.java
index 432f1b9ad..ac4331c6d 100644
--- a/test/org/traccar/processing/ComputedAttributesTest.java
+++ b/test/org/traccar/processing/ComputedAttributesTest.java
@@ -1,5 +1,7 @@
package org.traccar.processing;
+import java.util.Date;
+
import org.junit.Assert;
import org.junit.Test;
import org.traccar.model.Attribute;
@@ -11,27 +13,52 @@ public class ComputedAttributesTest {
public void testComputedAttributes() {
Position position = new Position();
ComputedAttributesHandler computedAttributesHandler = new ComputedAttributesHandler();
+ Date date = new Date();
+ position.setTime(date);
+ position.setSpeed(42);
+ position.setValid(false);
position.set("adc1", 128);
position.set("booleanFlag", true);
position.set("adc2", 100);
position.set("bitFlag", 7);
position.set("event", 42);
+ position.set("result", "success");
Attribute attribute = new Attribute();
- attribute.setExpression("position.getInteger(\"adc1\")");
+ attribute.setExpression("adc1");
Assert.assertEquals(128, computedAttributesHandler.computeAttribute(attribute, position));
- attribute.setExpression("!position.getBoolean(\"booleanFlag\")");
+ attribute.setExpression("!booleanFlag");
Assert.assertEquals(false, computedAttributesHandler.computeAttribute(attribute, position));
- attribute.setExpression("position.getInteger(\"adc2\") * 2 + 50");
+ attribute.setExpression("adc2 * 2 + 50");
Assert.assertEquals(250, computedAttributesHandler.computeAttribute(attribute, position));
- attribute.setExpression("(position.getLong(\"bitFlag\") & 4) != 0");
+ attribute.setExpression("(bitFlag & 4) != 0");
Assert.assertEquals(true, computedAttributesHandler.computeAttribute(attribute, position));
- attribute.setExpression("if (position.getLong(\"event\") == 42) \"lowBattery\"");
+ attribute.setExpression("if (event == 42) \"lowBattery\"");
Assert.assertEquals("lowBattery", computedAttributesHandler.computeAttribute(attribute, position));
+
+ attribute.setExpression("speed > 5 && valid");
+ Assert.assertEquals(false, computedAttributesHandler.computeAttribute(attribute, position));
+
+ attribute.setExpression("fixTime");
+ Assert.assertEquals(date, computedAttributesHandler.computeAttribute(attribute, position));
+
+ // modification tests
+ attribute.setExpression("adc1 = 256");
+ computedAttributesHandler.computeAttribute(attribute, position);
+ Assert.assertEquals(128, position.getInteger("adc1"));
+
+ attribute.setExpression("result = \"fail\"");
+ computedAttributesHandler.computeAttribute(attribute, position);
+ Assert.assertEquals("success", position.getString("result"));
+
+ attribute.setExpression("fixTime = \"2017-10-18 10:00:01\"");
+ computedAttributesHandler.computeAttribute(attribute, position);
+ Assert.assertEquals(date, position.getFixTime());
+
}
}