Search in sources :

Example 11 with MoodElement

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

the class MoodManagerTest method addMessageTest.

@Test
public void addMessageTest() {
    Message message = StanzaBuilder.buildMessage().build();
    MoodManager.addMoodToMessage(message, Mood.sad);
    assertTrue(message.hasExtension(MoodElement.ELEMENT, MoodElement.NAMESPACE));
    assertTrue(MoodElement.hasMoodElement(message));
    MoodElement element = MoodElement.fromMessage(message);
    assertNotNull(element);
    assertEquals(Mood.sad, element.getMood());
    assertFalse(element.hasConcretisation());
    assertFalse(element.hasText());
    message = StanzaBuilder.buildMessage().build();
    MoodManager.addMoodToMessage(message, Mood.happy, new MoodConcretisationTest.EcstaticMoodConcretisation());
    element = MoodElement.fromMessage(message);
    assertTrue(element.hasConcretisation());
}
Also used : Message(org.jivesoftware.smack.packet.Message) MoodElement(org.jivesoftware.smackx.mood.element.MoodElement) Test(org.junit.jupiter.api.Test)

Example 12 with MoodElement

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

the class MoodElementTest method toXmlTest.

@Test
public void toXmlTest() throws Exception {
    String xml = "<mood xmlns='http://jabber.org/protocol/mood'>" + "<happy/>" + "<text>Yay, the mood spec has been approved!</text>" + "</mood>";
    MoodElement moodElement = new MoodElement(new MoodElement.MoodSubjectElement(Mood.happy, null), "Yay, the mood spec has been approved!");
    assertXmlSimilar(xml, moodElement.toXML().toString());
    assertFalse(moodElement.hasConcretisation());
    assertEquals(Mood.happy, moodElement.getMood());
    XmlPullParser parser = TestUtils.getParser(xml);
    MoodElement parsed = MoodProvider.INSTANCE.parse(parser);
    assertEquals(xml, parsed.toXML().toString());
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) MoodElement(org.jivesoftware.smackx.mood.element.MoodElement) Test(org.junit.jupiter.api.Test)

Example 13 with MoodElement

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

the class MoodElementTest method emptyMoodTest.

@Test
public void emptyMoodTest() throws Exception {
    MoodElement empty = new MoodElement(null, null);
    assertNull(empty.getText());
    assertNull(empty.getMood());
    assertNull(empty.getMoodConcretisation());
    assertFalse(empty.hasText());
    assertFalse(empty.hasConcretisation());
    String xml = "<mood xmlns='http://jabber.org/protocol/mood'/>";
    XmlPullParser parser = TestUtils.getParser(xml);
    MoodElement emptyParsed = MoodProvider.INSTANCE.parse(parser);
    assertEquals(empty.toXML().toString(), emptyParsed.toXML().toString());
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) MoodElement(org.jivesoftware.smackx.mood.element.MoodElement) Test(org.junit.jupiter.api.Test)

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