Search in sources :

Example 1 with GeoLocationManager

use of org.jivesoftware.smackx.geoloc.GeoLocationManager in project Smack by igniterealtime.

the class GeolocationIntegrationTest method publishAndWait.

/**
 * Publish data using PEP, and block until the server has echoed the publication back to the publishing user.
 *
 * @param geoManager The GeoLocationManager instance for the connection that is expected to publish data.
 * @param discoManager The ServiceDiscoveryManager instance for the connection that is expected to publish data.
 * @param data The data to be published.
 *
 * @throws Exception if the test fails
 */
public void publishAndWait(GeoLocationManager geoManager, ServiceDiscoveryManager discoManager, GeoLocation data) throws Exception {
    final SimpleResultSyncPoint publicationEchoReceived = new SimpleResultSyncPoint();
    final PepEventListener<GeoLocation> publicationEchoListener = (jid, geoLocation, id, message) -> {
        if (geoLocation.equals(data)) {
            publicationEchoReceived.signal();
        }
    };
    try {
        registerListenerAndWait(geoManager, discoManager, publicationEchoListener);
        geoManager.addGeoLocationListener(publicationEchoListener);
        geoManager.publishGeoLocation(data);
    } finally {
        geoManager.removeGeoLocationListener(publicationEchoListener);
    }
}
Also used : SmackIntegrationTestEnvironment(org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment) GeoLocation(org.jivesoftware.smackx.geoloc.packet.GeoLocation) AfterClass(org.igniterealtime.smack.inttest.annotations.AfterClass) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) NotLoggedInException(org.jivesoftware.smack.SmackException.NotLoggedInException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) TimeoutException(java.util.concurrent.TimeoutException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) GeoLocationManager(org.jivesoftware.smackx.geoloc.GeoLocationManager) PepEventListener(org.jivesoftware.smackx.pep.PepEventListener) Assertions(org.junit.jupiter.api.Assertions) IntegrationTestRosterUtil(org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil) XmppDateTime(org.jxmpp.util.XmppDateTime) URI(java.net.URI) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) GeoLocation(org.jivesoftware.smackx.geoloc.packet.GeoLocation) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)

Example 2 with GeoLocationManager

use of org.jivesoftware.smackx.geoloc.GeoLocationManager 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);
    }
}
Also used : SmackIntegrationTestEnvironment(org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment) GeoLocation(org.jivesoftware.smackx.geoloc.packet.GeoLocation) AfterClass(org.igniterealtime.smack.inttest.annotations.AfterClass) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) NotLoggedInException(org.jivesoftware.smack.SmackException.NotLoggedInException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) TimeoutException(java.util.concurrent.TimeoutException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) GeoLocationManager(org.jivesoftware.smackx.geoloc.GeoLocationManager) PepEventListener(org.jivesoftware.smackx.pep.PepEventListener) Assertions(org.junit.jupiter.api.Assertions) IntegrationTestRosterUtil(org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil) XmppDateTime(org.jxmpp.util.XmppDateTime) URI(java.net.URI) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)

Aggregations

URI (java.net.URI)2 TimeoutException (java.util.concurrent.TimeoutException)2 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)2 SmackIntegrationTestEnvironment (org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment)2 AfterClass (org.igniterealtime.smack.inttest.annotations.AfterClass)2 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)2 IntegrationTestRosterUtil (org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil)2 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)2 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)2 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)2 NotLoggedInException (org.jivesoftware.smack.SmackException.NotLoggedInException)2 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)2 EntityCapabilitiesChangedListener (org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener)2 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)2 GeoLocationManager (org.jivesoftware.smackx.geoloc.GeoLocationManager)2 GeoLocation (org.jivesoftware.smackx.geoloc.packet.GeoLocation)2 PepEventListener (org.jivesoftware.smackx.pep.PepEventListener)2 Assertions (org.junit.jupiter.api.Assertions)2 XmppDateTime (org.jxmpp.util.XmppDateTime)2