use of org.traccar.model.Position in project traccar by traccar.
the class FilterHandlerTest method createPosition.
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;
}
use of org.traccar.model.Position in project traccar by traccar.
the class ProtocolTest method verifyDecodedPosition.
private void verifyDecodedPosition(Object decodedObject, boolean checkLocation, boolean checkAttributes, Position expected) {
assertNotNull("position is null", decodedObject);
assertTrue("not a position", decodedObject instanceof Position);
Position position = (Position) decodedObject;
if (checkLocation) {
if (expected != null) {
if (expected.getFixTime() != null) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
assertEquals("time", dateFormat.format(expected.getFixTime()), dateFormat.format(position.getFixTime()));
}
assertEquals("valid", expected.getValid(), position.getValid());
assertEquals("latitude", expected.getLatitude(), position.getLatitude(), 0.00001);
assertEquals("longitude", expected.getLongitude(), position.getLongitude(), 0.00001);
} else {
assertNotNull(position.getFixTime());
assertTrue("year > 1999", position.getFixTime().after(new Date(915148800000L)));
assertTrue("time < +25 hours", position.getFixTime().getTime() < System.currentTimeMillis() + 25 * 3600000);
assertTrue("latitude >= -90", position.getLatitude() >= -90);
assertTrue("latitude <= 90", position.getLatitude() <= 90);
assertTrue("longitude >= -180", position.getLongitude() >= -180);
assertTrue("longitude <= 180", position.getLongitude() <= 180);
}
assertTrue("altitude >= -12262", position.getAltitude() >= -12262);
assertTrue("altitude <= 18000", position.getAltitude() <= 18000);
assertTrue("speed >= 0", position.getSpeed() >= 0);
assertTrue("speed <= 869", position.getSpeed() <= 869);
assertTrue("course >= 0", position.getCourse() >= 0);
assertTrue("course <= 360", position.getCourse() <= 360);
assertNotNull("protocol is null", position.getProtocol());
}
Map<String, Object> attributes = position.getAttributes();
if (checkAttributes) {
assertFalse("no attributes", attributes.isEmpty());
}
if (attributes.containsKey(Position.KEY_INDEX)) {
assertTrue(attributes.get(Position.KEY_INDEX) instanceof Number);
}
if (attributes.containsKey(Position.KEY_HDOP)) {
assertTrue(attributes.get(Position.KEY_HDOP) instanceof Number);
}
if (attributes.containsKey(Position.KEY_VDOP)) {
assertTrue(attributes.get(Position.KEY_VDOP) instanceof Number);
}
if (attributes.containsKey(Position.KEY_PDOP)) {
assertTrue(attributes.get(Position.KEY_PDOP) instanceof Number);
}
if (attributes.containsKey(Position.KEY_SATELLITES)) {
assertTrue(attributes.get(Position.KEY_SATELLITES) instanceof Number);
}
if (attributes.containsKey(Position.KEY_SATELLITES_VISIBLE)) {
assertTrue(attributes.get(Position.KEY_SATELLITES_VISIBLE) instanceof Number);
}
if (attributes.containsKey(Position.KEY_RSSI)) {
assertTrue(attributes.get(Position.KEY_RSSI) instanceof Number);
}
if (attributes.containsKey(Position.KEY_ODOMETER)) {
assertTrue(attributes.get(Position.KEY_ODOMETER) instanceof Number);
}
if (attributes.containsKey(Position.KEY_RPM)) {
assertTrue(attributes.get(Position.KEY_RPM) instanceof Number);
}
if (attributes.containsKey(Position.KEY_FUEL_LEVEL)) {
assertTrue(attributes.get(Position.KEY_FUEL_LEVEL) instanceof Number);
}
if (attributes.containsKey(Position.KEY_POWER)) {
assertTrue(attributes.get(Position.KEY_POWER) instanceof Number);
}
if (attributes.containsKey(Position.KEY_BATTERY)) {
assertTrue(attributes.get(Position.KEY_BATTERY) instanceof Number);
}
if (attributes.containsKey(Position.KEY_BATTERY_LEVEL)) {
int batteryLevel = ((Number) attributes.get(Position.KEY_BATTERY_LEVEL)).intValue();
assertTrue(batteryLevel <= 100 && batteryLevel >= 0);
}
if (attributes.containsKey(Position.KEY_CHARGE)) {
assertTrue(attributes.get(Position.KEY_CHARGE) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_IGNITION)) {
assertTrue(attributes.get(Position.KEY_IGNITION) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_MOTION)) {
assertTrue(attributes.get(Position.KEY_MOTION) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_ARCHIVE)) {
assertTrue(attributes.get(Position.KEY_ARCHIVE) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_DRIVER_UNIQUE_ID)) {
assertTrue(attributes.get(Position.KEY_DRIVER_UNIQUE_ID) instanceof String);
}
if (attributes.containsKey(Position.KEY_STEPS)) {
assertTrue(attributes.get(Position.KEY_STEPS) instanceof Number);
}
if (attributes.containsKey(Position.KEY_ROAMING)) {
assertTrue(attributes.get(Position.KEY_ROAMING) instanceof Boolean);
}
if (position.getNetwork() != null && position.getNetwork().getCellTowers() != 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);
}
}
}
use of org.traccar.model.Position in project traccar by traccar.
the class ProtocolTest method position.
protected Position position(String time, boolean valid, double lat, double lon) throws ParseException {
Position position = new Position();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
position.setTime(dateFormat.parse(time));
position.setValid(valid);
position.setLatitude(lat);
position.setLongitude(lon);
return position;
}
use of org.traccar.model.Position in project traccar by traccar.
the class WebDataHandlerTest method testPrepareJsonPayload.
@Test
public void testPrepareJsonPayload() throws ParseException {
Position p = position("2016-01-01 01:02:03.000", true, 20, 30);
WebDataHandler handler = new WebDataHandler("http://localhost/", true);
assertEquals("{\"position\":{\"id\":0,\"attributes\":{},\"deviceId\":0,\"type\":null,\"protocol\":null,\"serverTime\":null,\"deviceTime\":1451610123000,\"fixTime\":1451610123000,\"outdated\":false,\"valid\":true,\"latitude\":20.0,\"longitude\":30.0,\"altitude\":0.0,\"speed\":0.0,\"course\":0.0,\"address\":null,\"accuracy\":0.0,\"network\":null},\"device\":{\"id\":1,\"attributes\":{},\"groupId\":0,\"name\":\"test\",\"uniqueId\":\"123456789012345\",\"status\":\"offline\",\"lastUpdate\":null,\"positionId\":0,\"geofenceIds\":null,\"phone\":null,\"model\":null,\"contact\":null,\"category\":null,\"disabled\":false}}", handler.prepareJsonPayload(p));
}
use of org.traccar.model.Position in project traccar by traccar.
the class AlertEventHandlerTest method testAlertEventHandler.
@Test
public void testAlertEventHandler() throws Exception {
AlertEventHandler alertEventHandler = new AlertEventHandler();
Position position = new Position();
position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
Map<Event, Position> events = alertEventHandler.analyzePosition(position);
assertNotNull(events);
Event event = events.keySet().iterator().next();
assertEquals(Event.TYPE_ALARM, event.getType());
}
Aggregations