aboutsummaryrefslogtreecommitdiff
path: root/test/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-05-13 11:01:48 +1200
committerGitHub <noreply@github.com>2017-05-13 11:01:48 +1200
commit713d6c55a007aa80850810f447308976516bfa63 (patch)
tree057e9147e724a56b6e2f3820fcf3d9ab67561fdf /test/org
parent51920cae6438f8888090f177761a82afff33067f (diff)
parent6c17f85d04b224ff2a09265918765c9f4fc8cf94 (diff)
downloadtraccar-server-713d6c55a007aa80850810f447308976516bfa63.tar.gz
traccar-server-713d6c55a007aa80850810f447308976516bfa63.tar.bz2
traccar-server-713d6c55a007aa80850810f447308976516bfa63.zip
Merge pull request #3156 from Abyss777/computed_attributes
Implement computed attributes
Diffstat (limited to 'test/org')
-rw-r--r--test/org/traccar/processing/ComputedAttributesTest.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/org/traccar/processing/ComputedAttributesTest.java b/test/org/traccar/processing/ComputedAttributesTest.java
new file mode 100644
index 000000000..432f1b9ad
--- /dev/null
+++ b/test/org/traccar/processing/ComputedAttributesTest.java
@@ -0,0 +1,37 @@
+package org.traccar.processing;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.traccar.model.Attribute;
+import org.traccar.model.Position;
+
+public class ComputedAttributesTest {
+
+ @Test
+ public void testComputedAttributes() {
+ Position position = new Position();
+ ComputedAttributesHandler computedAttributesHandler = new ComputedAttributesHandler();
+ position.set("adc1", 128);
+ position.set("booleanFlag", true);
+ position.set("adc2", 100);
+ position.set("bitFlag", 7);
+ position.set("event", 42);
+ Attribute attribute = new Attribute();
+
+ attribute.setExpression("position.getInteger(\"adc1\")");
+ Assert.assertEquals(128, computedAttributesHandler.computeAttribute(attribute, position));
+
+ attribute.setExpression("!position.getBoolean(\"booleanFlag\")");
+ Assert.assertEquals(false, computedAttributesHandler.computeAttribute(attribute, position));
+
+ attribute.setExpression("position.getInteger(\"adc2\") * 2 + 50");
+ Assert.assertEquals(250, computedAttributesHandler.computeAttribute(attribute, position));
+
+ attribute.setExpression("(position.getLong(\"bitFlag\") & 4) != 0");
+ Assert.assertEquals(true, computedAttributesHandler.computeAttribute(attribute, position));
+
+ attribute.setExpression("if (position.getLong(\"event\") == 42) \"lowBattery\"");
+ Assert.assertEquals("lowBattery", computedAttributesHandler.computeAttribute(attribute, position));
+ }
+
+}