aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/org/traccar/ProtocolTest.java18
-rw-r--r--test/org/traccar/location/CellInfoTest.java36
-rw-r--r--test/org/traccar/location/LocationProviderTest.java27
3 files changed, 24 insertions, 57 deletions
diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java
index 93f3150c7..43be1a59e 100644
--- a/test/org/traccar/ProtocolTest.java
+++ b/test/org/traccar/ProtocolTest.java
@@ -7,6 +7,7 @@ import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpVersion;
import org.junit.Assert;
import org.traccar.database.IdentityManager;
+import org.traccar.model.CellTower;
import org.traccar.model.Command;
import org.traccar.model.Device;
import org.traccar.model.Position;
@@ -174,16 +175,13 @@ public class ProtocolTest extends BaseTest {
Assert.assertFalse("no attributes", attributes.isEmpty());
}
- if (attributes.containsKey(Position.KEY_LAC) || attributes.containsKey(Position.KEY_CID)) {
- checkInteger(attributes.get(Position.KEY_LAC), 1, 65535);
- checkInteger(attributes.get(Position.KEY_CID), 0, 268435455);
- }
-
- if (attributes.containsKey(Position.KEY_MCC) || attributes.containsKey(Position.KEY_MNC)) {
- checkInteger(attributes.get(Position.KEY_MCC), 100, 999);
- checkInteger(attributes.get(Position.KEY_MNC), 0, 999);
- Assert.assertTrue("value missing", attributes.containsKey(Position.KEY_LAC));
- Assert.assertTrue("value missing", attributes.containsKey(Position.KEY_CID));
+ if (position.getNetwork() != null) {
+ for (CellTower cellTower : position.getNetwork().getCellTowers()) {
+ checkInteger(cellTower.getMobileCountryCode(), 0, 999);
+ checkInteger(cellTower.getMobileNetworkCode(), 0, 999);
+ checkInteger(cellTower.getLocationAreaCode(), 1, 65535);
+ checkInteger(cellTower.getCellId(), 0, 268435455);
+ }
}
}
diff --git a/test/org/traccar/location/CellInfoTest.java b/test/org/traccar/location/CellInfoTest.java
deleted file mode 100644
index e78ce51fb..000000000
--- a/test/org/traccar/location/CellInfoTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.traccar.location;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class CellInfoTest {
-
- @Test
- public void testToString() {
-
- CellInfo info = new CellInfo();
- info.addCell(0, 0, 1000, 2000);
- info.addCell(400, 1, 3000, 4000);
-
- Assert.assertEquals("[{\"lac\":1000,\"cid\":2000},{\"mcc\":400,\"mnc\":1,\"lac\":3000,\"cid\":4000}]", info.toString());
-
- }
-
- @Test
- public void testFromString() {
-
- CellInfo info = CellInfo.fromString("[{\"lac\":1000,\"cid\":2000}]");
-
- Assert.assertEquals(1, info.getCells().size());
-
- CellInfo.Cell cell = info.getCells().get(0);
-
- Assert.assertEquals(0, cell.getMcc());
- Assert.assertEquals(0, cell.getMnc());
- Assert.assertEquals(1000, cell.getLac());
- Assert.assertEquals(2000, cell.getCid());
- Assert.assertEquals(0, cell.getSignal());
-
- }
-
-}
diff --git a/test/org/traccar/location/LocationProviderTest.java b/test/org/traccar/location/LocationProviderTest.java
index 910f9e9ea..9c6000121 100644
--- a/test/org/traccar/location/LocationProviderTest.java
+++ b/test/org/traccar/location/LocationProviderTest.java
@@ -2,34 +2,33 @@ package org.traccar.location;
import org.junit.Assert;
import org.junit.Test;
+import org.traccar.BaseTest;
+import org.traccar.model.CellTower;
+import org.traccar.model.Network;
import org.traccar.model.Position;
import java.util.HashMap;
import java.util.Map;
-public class LocationProviderTest {
+public class LocationProviderTest extends BaseTest {
private boolean enable = false;
@Test
public void test() {
if (enable) {
- testOpenCellId();
+ testMozilla();
}
}
- public void testOpenCellId() {
- OpenCellIdLocationProvider locationProvider = new OpenCellIdLocationProvider("fake");
+ public void testMozilla() {
+ MozillaLocationProvider locationProvider = new MozillaLocationProvider();
- Map<String, Object> attributes = new HashMap<>();
- attributes.put(Position.KEY_MCC, 260);
- attributes.put(Position.KEY_MNC, 2);
- attributes.put(Position.KEY_LAC, 10250);
- attributes.put(Position.KEY_CID, 26511);
+ Network network = new Network(CellTower.from(260, 2, 10250, 26511));
- locationProvider.getLocation(attributes, new LocationProvider.LocationProviderCallback() {
+ locationProvider.getLocation(network, new LocationProvider.LocationProviderCallback() {
@Override
- public void onSuccess(double latitude, double longitude) {
+ public void onSuccess(double latitude, double longitude, double accuracy) {
Assert.assertEquals(60.07254, latitude, 0.00001);
Assert.assertEquals(30.30996, longitude, 0.00001);
}
@@ -39,6 +38,12 @@ public class LocationProviderTest {
Assert.fail();
}
});
+
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
}