Search in sources :

Example 1 with MoodElement

use of org.jivesoftware.smackx.mood.element.MoodElement in project Smack by igniterealtime.

the class MoodManager method setMood.

public void setMood(Mood mood, MoodConcretisation concretisation, String text) throws InterruptedException, SmackException.NotLoggedInException, SmackException.NoResponseException, SmackException.NotConnectedException, XMPPException.XMPPErrorException, PubSubException.NotALeafNodeException {
    MoodElement element = buildMood(mood, concretisation, text);
    publishMood(element);
}
Also used : MoodElement(org.jivesoftware.smackx.mood.element.MoodElement)

Example 2 with MoodElement

use of org.jivesoftware.smackx.mood.element.MoodElement in project Smack by igniterealtime.

the class MoodConcretisationTest method unknownConcretisationTest.

@Test
public void unknownConcretisationTest() throws Exception {
    String xml = "<mood xmlns='http://jabber.org/protocol/mood'>" + "<sad>" + "<owl xmlns='https://reddit.com/r/superbowl/'/>" + "</sad>" + "<text>Hoot hoot!</text>" + "</mood>";
    XmlPullParser parser = TestUtils.getParser(xml);
    MoodElement element = MoodProvider.INSTANCE.parse(parser);
    // We should not have a provider for sad owls, so the concretisation should not be there.
    assertFalse(element.hasConcretisation());
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) MoodElement(org.jivesoftware.smackx.mood.element.MoodElement) Test(org.junit.jupiter.api.Test)

Example 3 with MoodElement

use of org.jivesoftware.smackx.mood.element.MoodElement in project Smack by igniterealtime.

the class MoodIntegrationTest method publishAndWait.

/**
 * Publish data using PEP, and block until the server has echoed the publication back to the publishing user.
 *
 * @param moodManager The MoodManager 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(MoodManager moodManager, ServiceDiscoveryManager discoManager, Mood data) throws Exception {
    final SimpleResultSyncPoint publicationEchoReceived = new SimpleResultSyncPoint();
    final PepEventListener<MoodElement> publicationEchoListener = (jid, moodElement, id, message) -> {
        if (moodElement.getMood().equals(data)) {
            publicationEchoReceived.signal();
        }
    };
    try {
        registerListenerAndWait(moodManager, discoManager, publicationEchoListener);
        moodManager.addMoodListener(publicationEchoListener);
        moodManager.setMood(data);
    } finally {
        moodManager.removeMoodListener(publicationEchoListener);
    }
}
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)

Example 4 with MoodElement

use of org.jivesoftware.smackx.mood.element.MoodElement in project Smack by igniterealtime.

the class MoodIntegrationTest 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 {
    Mood data = Mood.satisfied;
    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();
        }
    };
    try {
        // Register ConTwo's interest in receiving mood notifications, and wait for that interest to have been propagated.
        registerListenerAndWait(mm2, ServiceDiscoveryManager.getInstanceFor(conTwo), moodListener);
        // Publish the data.
        // for the purpose of this test, this needs not be blocking/use publishAndWait();
        mm1.setMood(data);
        // Wait for the data to be received.
        try {
            moodReceived.waitForResult(timeout);
        } 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 5 with MoodElement

use of org.jivesoftware.smackx.mood.element.MoodElement in project Smack by igniterealtime.

the class MoodManager method addMoodToMessage.

public static void addMoodToMessage(Message message, Mood mood, MoodConcretisation concretisation) {
    MoodElement element = buildMood(mood, concretisation, null);
    message.addExtension(element);
}
Also used : MoodElement(org.jivesoftware.smackx.mood.element.MoodElement)

Aggregations

MoodElement (org.jivesoftware.smackx.mood.element.MoodElement)13 Test (org.junit.jupiter.api.Test)5 TimeoutException (java.util.concurrent.TimeoutException)4 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)4 SmackIntegrationTestEnvironment (org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment)4 AfterClass (org.igniterealtime.smack.inttest.annotations.AfterClass)4 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)4 IntegrationTestRosterUtil (org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil)4 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)4 SmackException (org.jivesoftware.smack.SmackException)4 XMPPException (org.jivesoftware.smack.XMPPException)4 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)4 EntityCapabilitiesChangedListener (org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener)4 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)4 PepEventListener (org.jivesoftware.smackx.pep.PepEventListener)4 Assertions (org.junit.jupiter.api.Assertions)4 Message (org.jivesoftware.smack.packet.Message)1 XmlPullParserException (org.jivesoftware.smack.xml.XmlPullParserException)1 Mood (org.jivesoftware.smackx.mood.Mood)1 MoodConcretisation (org.jivesoftware.smackx.mood.element.MoodConcretisation)1