2015-03-13 07:08:21 +01:00
|
|
|
/**
|
|
|
|
*
|
2018-04-04 15:02:23 +02:00
|
|
|
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez
|
2015-03-13 07:08:21 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smackx.geoloc.packet;
|
|
|
|
|
2020-04-06 13:25:07 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
2015-03-13 07:08:21 +01:00
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.TimeZone;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.packet.Message;
|
2020-04-12 09:34:08 +02:00
|
|
|
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
2015-03-13 07:08:21 +01:00
|
|
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2015-03-13 07:08:21 +01:00
|
|
|
import org.jivesoftware.smackx.time.packet.Time;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2020-04-06 13:25:07 +02:00
|
|
|
import org.junit.jupiter.api.Test;
|
2015-03-13 07:08:21 +01:00
|
|
|
import org.jxmpp.util.XmppDateTime;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for GeoLocation.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2015-03-13 07:08:21 +01:00
|
|
|
* @author Ishan Khanna
|
|
|
|
*/
|
2020-04-12 09:34:08 +02:00
|
|
|
public class GeoLocationTest extends SmackTestSuite {
|
2015-03-13 07:08:21 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void negativeTimezoneTest() {
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
calendar.setTimeZone(TimeZone.getTimeZone("GMT-830"));
|
|
|
|
|
|
|
|
Time time = new Time(calendar);
|
|
|
|
|
|
|
|
GeoLocation geoLocation = new GeoLocation.Builder().setTzo(time.getTzo()).build();
|
|
|
|
|
|
|
|
assertEquals("-8:30", geoLocation.getTzo());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void positiveTimezonTest() {
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
calendar.setTimeZone(TimeZone.getTimeZone("GMT+530"));
|
|
|
|
|
|
|
|
Time time = new Time(calendar);
|
|
|
|
|
|
|
|
GeoLocation geoLocation = new GeoLocation.Builder().setTzo(time.getTzo()).build();
|
|
|
|
|
|
|
|
assertEquals("+5:30", geoLocation.getTzo());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void accuracyTest() {
|
|
|
|
|
|
|
|
GeoLocation geoLocation = new GeoLocation.Builder().setAccuracy(1.34d).build();
|
|
|
|
|
|
|
|
assertEquals((Double) 1.34, geoLocation.getAccuracy());
|
|
|
|
}
|
|
|
|
|
2018-04-04 15:02:23 +02:00
|
|
|
@Test
|
|
|
|
public void altAccuracyTest() {
|
|
|
|
|
|
|
|
GeoLocation geoLocation = new GeoLocation.Builder().setAltAccuracy(1.52d).build();
|
|
|
|
|
|
|
|
assertEquals((Double) 1.52, geoLocation.getAltAccuracy());
|
|
|
|
}
|
|
|
|
|
2015-03-13 07:08:21 +01:00
|
|
|
@Test
|
|
|
|
public void toXMLMethodTest() throws Exception {
|
|
|
|
|
|
|
|
// @formatter:off
|
2018-05-09 23:06:12 +02:00
|
|
|
final String geoLocationMessageString = "<message from='portia@merchantofvenice.lit'"
|
2017-05-23 16:45:04 +02:00
|
|
|
+ " to='bassanio@merchantofvenice.lit'>"
|
|
|
|
+ "<geoloc xmlns='http://jabber.org/protocol/geoloc'>"
|
|
|
|
+ "<accuracy>23</accuracy>"
|
|
|
|
+ "<alt>1000</alt>"
|
2018-04-04 15:02:23 +02:00
|
|
|
+ "<altaccuracy>10</altaccuracy>"
|
2017-05-23 16:45:04 +02:00
|
|
|
+ "<area>Delhi</area>"
|
|
|
|
+ "<bearing>10</bearing>"
|
|
|
|
+ "<building>Small Building</building>"
|
|
|
|
+ "<country>India</country>"
|
|
|
|
+ "<countrycode>IN</countrycode>"
|
|
|
|
+ "<description>My Description</description>"
|
|
|
|
+ "<error>90</error>"
|
|
|
|
+ "<floor>top</floor>"
|
|
|
|
+ "<lat>25.098345</lat>"
|
|
|
|
+ "<locality>awesome</locality>"
|
|
|
|
+ "<lon>77.992034</lon>"
|
|
|
|
+ "<postalcode>110085</postalcode>"
|
|
|
|
+ "<region>North</region>"
|
|
|
|
+ "<room>small</room>"
|
|
|
|
+ "<speed>250.0</speed>"
|
|
|
|
+ "<street>Wall Street</street>"
|
|
|
|
+ "<text>Unit Testing GeoLocation</text>"
|
|
|
|
+ "<timestamp>2004-02-19</timestamp>"
|
|
|
|
+ "<tzo>+5:30</tzo>"
|
|
|
|
+ "<uri>http://xmpp.org</uri>"
|
|
|
|
+ "</geoloc>"
|
|
|
|
+ "</message>";
|
2015-03-13 07:08:21 +01:00
|
|
|
// @formatter:on
|
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
Message messageWithGeoLocation = PacketParserUtils.parseStanza(geoLocationMessageString);
|
2015-03-13 07:08:21 +01:00
|
|
|
assertNotNull(messageWithGeoLocation);
|
|
|
|
|
2020-04-05 22:10:05 +02:00
|
|
|
GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.class);
|
2015-03-13 07:08:21 +01:00
|
|
|
assertNotNull(geoLocation);
|
2019-02-04 13:27:41 +01:00
|
|
|
assertNotNull(geoLocation.toXML());
|
2015-03-13 07:08:21 +01:00
|
|
|
|
2018-04-04 15:02:23 +02:00
|
|
|
GeoLocation constructedGeoLocation = GeoLocation.builder().setAccuracy(23d).setAlt(1000d).setAltAccuracy(10d).setArea("Delhi").setBearing(
|
2015-03-13 07:08:21 +01:00
|
|
|
10d).setBuilding("Small Building").setCountry("India").setCountryCode("IN").setDescription(
|
|
|
|
"My Description").setError(90d).setFloor("top").setLat(25.098345d).setLocality("awesome").setLon(
|
|
|
|
77.992034).setPostalcode("110085").setRegion("North").setRoom("small").setSpeed(250.0d).setStreet(
|
|
|
|
"Wall Street").setText("Unit Testing GeoLocation").setTimestamp(
|
|
|
|
XmppDateTime.parseDate("2004-02-19")).setTzo("+5:30").setUri(new URI("http://xmpp.org")).build();
|
|
|
|
|
2019-02-04 13:27:41 +01:00
|
|
|
assertEquals(constructedGeoLocation.toXML().toString(), geoLocation.toXML().toString());
|
2015-03-13 07:08:21 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|