Search in sources :

Example 1 with SpoilerElement

use of org.jivesoftware.smackx.spoiler.element.SpoilerElement in project Smack by igniterealtime.

the class SpoilerTest method emptySpoilerTest.

@Test
public void emptySpoilerTest() throws Exception {
    final String xml = "<spoiler xmlns='urn:xmpp:spoiler:0'/>";
    Message message = StanzaBuilder.buildMessage().build();
    SpoilerElement.addSpoiler(message);
    SpoilerElement empty = (SpoilerElement) message.getExtensionElement(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0);
    assertNull(empty.getHint());
    assertNull(empty.getLanguage());
    assertXmlSimilar(xml, empty.toXML().toString());
    XmlPullParser parser = TestUtils.getParser(xml);
    SpoilerElement parsed = SpoilerProvider.INSTANCE.parse(parser);
    assertXmlSimilar(xml, parsed.toXML().toString());
}
Also used : Message(org.jivesoftware.smack.packet.Message) SpoilerElement(org.jivesoftware.smackx.spoiler.element.SpoilerElement) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Test(org.junit.jupiter.api.Test)

Example 2 with SpoilerElement

use of org.jivesoftware.smackx.spoiler.element.SpoilerElement in project Smack by igniterealtime.

the class SpoilerTest method hintSpoilerTest.

@Test
public void hintSpoilerTest() throws Exception {
    final String xml = "<spoiler xmlns='urn:xmpp:spoiler:0'>Love story end</spoiler>";
    Message message = StanzaBuilder.buildMessage().build();
    SpoilerElement.addSpoiler(message, "Love story end");
    SpoilerElement withHint = (SpoilerElement) message.getExtensionElement(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0);
    assertEquals("Love story end", withHint.getHint());
    assertNull(withHint.getLanguage());
    assertXmlSimilar(xml, withHint.toXML().toString());
    XmlPullParser parser = TestUtils.getParser(xml);
    SpoilerElement parsed = SpoilerProvider.INSTANCE.parse(parser);
    assertXmlSimilar(xml, parsed.toXML().toString());
}
Also used : Message(org.jivesoftware.smack.packet.Message) SpoilerElement(org.jivesoftware.smackx.spoiler.element.SpoilerElement) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Test(org.junit.jupiter.api.Test)

Example 3 with SpoilerElement

use of org.jivesoftware.smackx.spoiler.element.SpoilerElement in project Smack by igniterealtime.

the class SpoilerTest method i18nHintSpoilerTest.

@Test
public void i18nHintSpoilerTest() throws Exception {
    final String xml = "<spoiler xml:lang='de' xmlns='urn:xmpp:spoiler:0'>Der Kuchen ist eine Lüge!</spoiler>";
    Message message = StanzaBuilder.buildMessage().build();
    SpoilerElement.addSpoiler(message, "de", "Der Kuchen ist eine Lüge!");
    SpoilerElement i18nHint = (SpoilerElement) message.getExtensionElement(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0);
    assertEquals("Der Kuchen ist eine Lüge!", i18nHint.getHint());
    assertEquals("de", i18nHint.getLanguage());
    assertXmlSimilar(xml, i18nHint.toXML().toString());
    XmlPullParser parser = TestUtils.getParser(xml);
    SpoilerElement parsed = SpoilerProvider.INSTANCE.parse(parser);
    assertEquals(i18nHint.getLanguage(), parsed.getLanguage());
    assertXmlSimilar(xml, parsed.toXML().toString());
}
Also used : Message(org.jivesoftware.smack.packet.Message) SpoilerElement(org.jivesoftware.smackx.spoiler.element.SpoilerElement) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Test(org.junit.jupiter.api.Test)

Aggregations

Message (org.jivesoftware.smack.packet.Message)3 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)3 SpoilerElement (org.jivesoftware.smackx.spoiler.element.SpoilerElement)3 Test (org.junit.jupiter.api.Test)3