Search in sources :

Example 6 with PepEventListener

use of org.jivesoftware.smackx.pep.PepEventListener in project Smack by igniterealtime.

the class UserTuneIntegrationTest 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 {
    URI uri = new URI("http://www.yesworld.com/lyrics/Fragile.html#8");
    UserTuneElement.Builder builder = UserTuneElement.getBuilder();
    UserTuneElement data = builder.setArtist("No").setLength(306).setRating(3).setSource("NoSongs").setTitle("Sunrise of the Heart").setTrack("2").setUri(uri).build();
    IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
    final SimpleResultSyncPoint userTuneReceived = new SimpleResultSyncPoint();
    final PepEventListener<UserTuneElement> userTuneListener = (jid, userTune, id, message) -> {
        if (userTune.equals(data)) {
            userTuneReceived.signal();
        }
    };
    // TODO Ensure that pre-existing filtering notification excludes userTune.
    try {
        // Publish the data
        publishAndWait(utm1, ServiceDiscoveryManager.getInstanceFor(conOne), data);
        // Adds listener, which implicitly publishes a disco/info filter for userTune notification.
        registerListenerAndWait(utm2, ServiceDiscoveryManager.getInstanceFor(conTwo), userTuneListener);
        // Wait for the data to be received.
        try {
            Object result = userTuneReceived.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(utm2, userTuneListener);
    }
}
Also used : SmackException(org.jivesoftware.smack.SmackException) SmackIntegrationTestEnvironment(org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment) AfterClass(org.igniterealtime.smack.inttest.annotations.AfterClass) 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) UserTuneElement(org.jivesoftware.smackx.usertune.element.UserTuneElement) PepEventListener(org.jivesoftware.smackx.pep.PepEventListener) Assertions(org.junit.jupiter.api.Assertions) IntegrationTestRosterUtil(org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil) URI(java.net.URI) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) XMPPException(org.jivesoftware.smack.XMPPException) UserTuneElement(org.jivesoftware.smackx.usertune.element.UserTuneElement) URI(java.net.URI) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) TimeoutException(java.util.concurrent.TimeoutException) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 7 with PepEventListener

use of org.jivesoftware.smackx.pep.PepEventListener in project Smack by igniterealtime.

the class UserTuneIntegrationTest method testNotification.

/**
 * Verifies that a notification is sent when a publication is received, assuming that notification filtering
 * has been adjusted to allow for the notification to be delivered.
 *
 * @throws Exception if the test fails
 */
@SmackIntegrationTest
public void testNotification() throws Exception {
    URI uri = new URI("http://www.yesworld.com/lyrics/Fragile.html#9");
    UserTuneElement.Builder builder = UserTuneElement.getBuilder();
    UserTuneElement data = builder.setArtist("Yes").setLength(686).setRating(8).setSource("Yessongs").setTitle("Heart of the Sunrise").setTrack("3").setUri(uri).build();
    IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
    final SimpleResultSyncPoint userTuneReceived = new SimpleResultSyncPoint();
    final PepEventListener<UserTuneElement> userTuneListener = (jid, userTune, id, message) -> {
        if (userTune.equals(data)) {
            userTuneReceived.signal();
        }
    };
    try {
        // Register ConTwo's interest in receiving user tune notifications, and wait for that interest to have been propagated.
        registerListenerAndWait(utm2, ServiceDiscoveryManager.getInstanceFor(conTwo), userTuneListener);
        // Publish the data.
        // for the purpose of this test, this needs not be blocking/use publishAndWait();
        utm1.publishUserTune(data);
        // Wait for the data to be received.
        Object result = userTuneReceived.waitForResult(timeout);
        // Explicitly assert the success case.
        Assertions.assertNotNull(result, "Expected to receive a PEP notification, but did not.");
    } finally {
        unregisterListener(utm2, userTuneListener);
    }
}
Also used : SmackException(org.jivesoftware.smack.SmackException) SmackIntegrationTestEnvironment(org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment) AfterClass(org.igniterealtime.smack.inttest.annotations.AfterClass) 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) UserTuneElement(org.jivesoftware.smackx.usertune.element.UserTuneElement) PepEventListener(org.jivesoftware.smackx.pep.PepEventListener) Assertions(org.junit.jupiter.api.Assertions) IntegrationTestRosterUtil(org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil) URI(java.net.URI) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) XMPPException(org.jivesoftware.smack.XMPPException) UserTuneElement(org.jivesoftware.smackx.usertune.element.UserTuneElement) URI(java.net.URI) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 8 with PepEventListener

use of org.jivesoftware.smackx.pep.PepEventListener in project Smack by igniterealtime.

the class MoodIntegrationTest method registerListenerAndWait.

/**
 * Registers a listener for User Tune data. This implicitly publishes a CAPS update to include a notification
 * filter for the mood node. This method blocks until the server has indicated that this update has been
 * received.
 *
 * @param moodManager The MoodManager 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 Mood data that is to be registered.
 *
 * @throws Exception if the test fails
 */
public void registerListenerAndWait(MoodManager moodManager, ServiceDiscoveryManager discoManager, PepEventListener<MoodElement> listener) throws Exception {
    final SimpleResultSyncPoint notificationFilterReceived = new SimpleResultSyncPoint();
    final EntityCapabilitiesChangedListener notificationFilterReceivedListener = info -> {
        if (info.containsFeature(MoodManager.MOOD_NODE + "+notify")) {
            notificationFilterReceived.signal();
        }
    };
    discoManager.addEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
    try {
        moodManager.addMoodListener(listener);
        notificationFilterReceived.waitForResult(timeout);
    } finally {
        discoManager.removeEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
    }
}
Also used : SmackException(org.jivesoftware.smack.SmackException) SmackIntegrationTestEnvironment(org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment) AfterClass(org.igniterealtime.smack.inttest.annotations.AfterClass) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) TimeoutException(java.util.concurrent.TimeoutException) MoodElement(org.jivesoftware.smackx.mood.element.MoodElement) PepEventListener(org.jivesoftware.smackx.pep.PepEventListener) Assertions(org.junit.jupiter.api.Assertions) IntegrationTestRosterUtil(org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) XMPPException(org.jivesoftware.smack.XMPPException) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)

Example 9 with PepEventListener

use of org.jivesoftware.smackx.pep.PepEventListener in project Smack by igniterealtime.

the class MoodIntegrationTest 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 {
    Mood data = Mood.cautious;
    IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
    final SimpleResultSyncPoint moodReceived = new SimpleResultSyncPoint();
    final PepEventListener<MoodElement> moodListener = (jid, moodElement, id, message) -> {
        if (moodElement.getMood().equals(data)) {
            moodReceived.signal();
        }
    };
    // TODO Ensure that pre-existing filtering notification excludes mood.
    try {
        // Publish the data
        publishAndWait(mm1, ServiceDiscoveryManager.getInstanceFor(conOne), data);
        // Adds listener, which implicitly publishes a disco/info filter for mood notification.
        registerListenerAndWait(mm2, ServiceDiscoveryManager.getInstanceFor(conTwo), moodListener);
        // Wait for the data to be received.
        try {
            Object result = moodReceived.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(mm2, moodListener);
    }
}
Also used : SmackException(org.jivesoftware.smack.SmackException) SmackIntegrationTestEnvironment(org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment) AfterClass(org.igniterealtime.smack.inttest.annotations.AfterClass) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) TimeoutException(java.util.concurrent.TimeoutException) MoodElement(org.jivesoftware.smackx.mood.element.MoodElement) PepEventListener(org.jivesoftware.smackx.pep.PepEventListener) Assertions(org.junit.jupiter.api.Assertions) IntegrationTestRosterUtil(org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) XMPPException(org.jivesoftware.smack.XMPPException) MoodElement(org.jivesoftware.smackx.mood.element.MoodElement) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) TimeoutException(java.util.concurrent.TimeoutException) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 10 with PepEventListener

use of org.jivesoftware.smackx.pep.PepEventListener 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)

Aggregations

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