use of org.jivesoftware.smackx.geoloc.packet.GeoLocation in project Smack by igniterealtime.
the class GeolocationIntegrationTest method registerListenerAndWait.
/**
* Registers a listener for GeoLocation data. This implicitly publishes a CAPS update to include a notification
* filter for the geolocation node. This method blocks until the server has indicated that this update has been
* received.
*
* @param geoManager The GeoLocationManager instance for the connection that is expected to receive data.
* @param discoManager The ServiceDiscoveryManager instance for the connection that is expected to publish data.
* @param listener A listener instance for GeoLocation data that is to be registered.
*
* @throws Exception if the test fails
*/
public void registerListenerAndWait(GeoLocationManager geoManager, ServiceDiscoveryManager discoManager, PepEventListener<GeoLocation> listener) throws Exception {
final SimpleResultSyncPoint notificationFilterReceived = new SimpleResultSyncPoint();
final EntityCapabilitiesChangedListener notificationFilterReceivedListener = info -> {
if (info.containsFeature(GeoLocationManager.GEOLOCATION_NODE + "+notify")) {
notificationFilterReceived.signal();
}
};
discoManager.addEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
try {
geoManager.addGeoLocationListener(listener);
notificationFilterReceived.waitForResult(timeout);
} finally {
discoManager.removeEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
}
}
use of org.jivesoftware.smackx.geoloc.packet.GeoLocation in project Smack by igniterealtime.
the class GeolocationIntegrationTest method testNotificationAfterFilterChange.
/**
* Verifies that a notification for a previously sent publication is received as soon as notification filtering
* has been adjusted to allow for the notification to be delivered.
*
* @throws Exception if the test fails
*/
@SmackIntegrationTest
public void testNotificationAfterFilterChange() throws Exception {
GeoLocation.Builder builder = GeoLocation.builder();
GeoLocation data = builder.setAccuracy(12d).setAlt(999d).setAltAccuracy(9d).setArea("Amsterdam").setBearing(9d).setBuilding("Test Building").setCountry("Netherlands").setCountryCode("NL").setDescription("My Description").setFloor("middle").setLat(25.098345d).setLocality("brilliant").setLon(77.992034).setPostalcode("110085").setRegion("North").setRoom("small").setSpeed(250.0d).setStreet("Wall Street").setText("Unit Testing GeoLocation 2").setTimestamp(XmppDateTime.parseDate("2007-02-19")).setTzo("+5:30").setUri(new URI("http://xmpp.org")).build();
IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
final SimpleResultSyncPoint geoLocationReceived = new SimpleResultSyncPoint();
final PepEventListener<GeoLocation> geoLocationListener = (jid, geoLocation, id, message) -> {
if (geoLocation.equals(data)) {
geoLocationReceived.signal();
}
};
// TODO Ensure that pre-existing filtering notification excludes geolocation.
try {
// Publish the data
publishAndWait(glm1, ServiceDiscoveryManager.getInstanceFor(conOne), data);
// Adds listener, which implicitly publishes a disco/info filter for geolocation notification.
registerListenerAndWait(glm2, ServiceDiscoveryManager.getInstanceFor(conTwo), geoLocationListener);
// Wait for the data to be received.
try {
Object result = geoLocationReceived.waitForResult(timeout);
// Explicitly assert the success case.
Assertions.assertNotNull(result, "Expected to receive a PEP notification, but did not.");
} catch (TimeoutException e) {
Assertions.fail("Expected to receive a PEP notification, but did not.");
}
} finally {
unregisterListener(glm2, geoLocationListener);
}
}
use of org.jivesoftware.smackx.geoloc.packet.GeoLocation in project Smack by igniterealtime.
the class GeoLocationProviderTest method testGeoLocationWithDatumSet.
@Test
public void testGeoLocationWithDatumSet() throws Exception {
// @formatter:off
final String geoLocationString = "<message from='portia@merchantofvenice.lit'" + " to='bassanio@merchantofvenice.lit'>" + "<geoloc xmlns='http://jabber.org/protocol/geoloc'>" + "<accuracy>23</accuracy>" + "<alt>1000</alt>" + "<altaccuracy>10</altaccuracy>" + "<area>Delhi</area>" + "<bearing>10</bearing>" + "<building>Small Building</building>" + "<country>India</country>" + "<countrycode>IN</countrycode>" + "<datum>Test Datum</datum>" + "<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>";
// @formatter:on
Message messageWithGeoLocation = PacketParserUtils.parseStanza(geoLocationString);
assertNotNull(messageWithGeoLocation);
GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.class);
assertNotNull(geoLocation);
assertEquals((Double) 23d, geoLocation.getAccuracy());
assertEquals((Double) 1000d, geoLocation.getAlt());
assertEquals((Double) 10d, geoLocation.getAltAccuracy());
assertEquals("Delhi", geoLocation.getArea());
assertEquals((Double) 10d, geoLocation.getBearing());
assertEquals("Small Building", geoLocation.getBuilding());
assertEquals("India", geoLocation.getCountry());
assertEquals("IN", geoLocation.getCountryCode());
assertEquals("Test Datum", geoLocation.getDatum());
assertEquals("My Description", geoLocation.getDescription());
@SuppressWarnings("deprecation") Double error = geoLocation.getError();
assertEquals(90, error);
assertEquals("top", geoLocation.getFloor());
assertEquals((Double) 25.098345d, geoLocation.getLat());
assertEquals("awesome", geoLocation.getLocality());
assertEquals((Double) 77.992034d, geoLocation.getLon());
assertEquals("110085", geoLocation.getPostalcode());
assertEquals("North", geoLocation.getRegion());
assertEquals("small", geoLocation.getRoom());
assertEquals((Double) 250d, geoLocation.getSpeed());
assertEquals("Wall Street", geoLocation.getStreet());
assertEquals("Unit Testing GeoLocation", geoLocation.getText());
assertEquals(XmppDateTime.parseDate("2004-02-19"), geoLocation.getTimestamp());
assertEquals("+5:30", geoLocation.getTzo());
assertEquals(new URI("http://xmpp.org"), geoLocation.getUri());
}
use of org.jivesoftware.smackx.geoloc.packet.GeoLocation in project Smack by igniterealtime.
the class GeoLocationProviderTest method testGeoLocationWithoutAccuracySetAndWithErrorSet.
@Test
public void testGeoLocationWithoutAccuracySetAndWithErrorSet() throws Exception {
// @formatter:off
final String geoLocationString = "<message from='portia@merchantofvenice.lit'" + " to='bassanio@merchantofvenice.lit'>" + "<geoloc xmlns='http://jabber.org/protocol/geoloc'>" + "<error>90</error>" + "</geoloc>" + "</message>";
// @formatter:on
Message messageWithGeoLocation = PacketParserUtils.parseStanza(geoLocationString);
GeoLocation geoLocation = messageWithGeoLocation.getExtension(GeoLocation.class);
@SuppressWarnings("deprecation") Double error = geoLocation.getError();
assertEquals((Double) 90d, error);
}
Aggregations