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);
}
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());
}
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);
}
}
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);
}
}
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);
}
Aggregations