Search in sources :

Example 31 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.

the class MessageMarkupTest method blockQuoteTest.

@Test
public void blockQuoteTest() throws Exception {
    String xml = "<markup xmlns='urn:xmpp:markup:0'>" + "<bquote start='9' end='32'/>" + "</markup>";
    MarkupElement.Builder m = MarkupElement.getBuilder();
    m.setBlockQuote(9, 32);
    assertXmlSimilar(xml, m.build().toXML().toString());
    XmlPullParser parser = TestUtils.getParser(xml);
    MarkupElement parsed = new MarkupElementProvider().parse(parser);
    List<MarkupElement.MarkupChildElement> children = parsed.getChildElements();
    assertEquals(1, children.size());
    BlockQuoteElement quote = (BlockQuoteElement) children.get(0);
    assertEquals(9, quote.getStart());
    assertEquals(32, quote.getEnd());
}
Also used : MarkupElementProvider(org.jivesoftware.smackx.message_markup.provider.MarkupElementProvider) BlockQuoteElement(org.jivesoftware.smackx.message_markup.element.BlockQuoteElement) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) MarkupElement(org.jivesoftware.smackx.message_markup.element.MarkupElement) Test(org.junit.jupiter.api.Test)

Example 32 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.

the class MessageMarkupTest method deletedTest.

@Test
public void deletedTest() throws Exception {
    String xml = "<markup xmlns='urn:xmpp:markup:0'>" + "<span start='9' end='15'>" + "<deleted/>" + "</span>" + "</markup>";
    MarkupElement.Builder m = MarkupElement.getBuilder();
    m.setDeleted(9, 15);
    assertXmlSimilar(xml, m.build().toXML().toString());
    XmlPullParser parser = TestUtils.getParser(xml);
    MarkupElement parsed = new MarkupElementProvider().parse(parser);
    List<MarkupElement.MarkupChildElement> children = parsed.getChildElements();
    assertEquals(1, children.size());
    SpanElement spanElement = (SpanElement) children.get(0);
    assertEquals(9, spanElement.getStart());
    assertEquals(15, spanElement.getEnd());
    assertEquals(1, spanElement.getStyles().size());
    assertEquals(SpanElement.SpanStyle.deleted, spanElement.getStyles().iterator().next());
}
Also used : SpanElement(org.jivesoftware.smackx.message_markup.element.SpanElement) MarkupElementProvider(org.jivesoftware.smackx.message_markup.provider.MarkupElementProvider) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) MarkupElement(org.jivesoftware.smackx.message_markup.element.MarkupElement) Test(org.junit.jupiter.api.Test)

Example 33 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser 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 34 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser 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 35 with XmlPullParser

use of org.jivesoftware.smack.xml.XmlPullParser 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

XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)139 Test (org.junit.jupiter.api.Test)69 Message (org.jivesoftware.smack.packet.Message)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 Date (java.util.Date)12 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)11 Jid (org.jxmpp.jid.Jid)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 XmlPullParserException (org.jivesoftware.smack.xml.XmlPullParserException)10 EnumSource (org.junit.jupiter.params.provider.EnumSource)9 IQ (org.jivesoftware.smack.packet.IQ)8 Test (org.junit.Test)8 MarkupElement (org.jivesoftware.smackx.message_markup.element.MarkupElement)7 MarkupElementProvider (org.jivesoftware.smackx.message_markup.provider.MarkupElementProvider)7 XmlElement (org.jivesoftware.smack.packet.XmlElement)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 NamedElement (org.jivesoftware.smack.packet.NamedElement)4 HttpOverXmppResp (org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp)4