Search in sources :

Example 81 with XmlPullParser

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

the class MessageMarkupTest method listTest.

@Test
public void listTest() throws Exception {
    String xml = "<markup xmlns='urn:xmpp:markup:0'>" + "<list start='31' end='89'>" + "<li start='31'/>" + "<li start='47'/>" + "<li start='61'/>" + "<li start='69'/>" + "</list>" + "</markup>";
    MarkupElement.Builder m = MarkupElement.getBuilder();
    m = m.beginList().addEntry(31, 47).addEntry(47, 61).addEntry(61, 69).addEntry(69, 89).endList();
    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());
    ListElement list = (ListElement) children.get(0);
    assertEquals(31, list.getStart());
    assertEquals(89, list.getEnd());
    assertEquals(4, list.getEntries().size());
    assertEquals(list.getStart(), list.getEntries().get(0).getStart());
    assertEquals(47, list.getEntries().get(1).getStart());
}
Also used : MarkupElementProvider(org.jivesoftware.smackx.message_markup.provider.MarkupElementProvider) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) ListElement(org.jivesoftware.smackx.message_markup.element.ListElement) MarkupElement(org.jivesoftware.smackx.message_markup.element.MarkupElement) Test(org.junit.jupiter.api.Test)

Example 82 with XmlPullParser

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

the class MessageMarkupTest method emphasisTest.

@Test
public void emphasisTest() throws Exception {
    String xml = "<markup xmlns='urn:xmpp:markup:0'>" + "<span start='9' end='15'>" + "<emphasis/>" + "</span>" + "</markup>";
    MarkupElement.Builder m = MarkupElement.getBuilder();
    m.setEmphasis(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.emphasis, 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 83 with XmlPullParser

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

the class MessageMarkupTest method codeBlockTest.

@Test
public void codeBlockTest() throws Exception {
    String xml = "<markup xmlns='urn:xmpp:markup:0'>" + "<bcode start='23' end='48'/>" + "</markup>";
    MarkupElement.Builder m = MarkupElement.getBuilder();
    m.setCodeBlock(23, 48);
    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());
    CodeBlockElement codeBlock = (CodeBlockElement) children.get(0);
    assertEquals(23, codeBlock.getStart());
    assertEquals(48, codeBlock.getEnd());
}
Also used : MarkupElementProvider(org.jivesoftware.smackx.message_markup.provider.MarkupElementProvider) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) CodeBlockElement(org.jivesoftware.smackx.message_markup.element.CodeBlockElement) MarkupElement(org.jivesoftware.smackx.message_markup.element.MarkupElement) Test(org.junit.jupiter.api.Test)

Example 84 with XmlPullParser

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

the class CarbonTest method carbonSentTest.

@Test
public void carbonSentTest() throws Exception {
    XmlPullParser parser;
    String control;
    CarbonExtension cc;
    Forwarded<Message> fwd;
    control = XMLBuilder.create("sent").e("forwarded").a("xmlns", "urn:xmpp:forwarded:0").e("message").a("from", "romeo@montague.com").asString(outputProperties);
    parser = PacketParserUtils.getParserFor(control);
    cc = new CarbonManagerProvider().parse(parser);
    fwd = cc.getForwarded();
    // meta
    assertEquals(CarbonExtension.Direction.sent, cc.getDirection());
    // no delay in packet
    assertEquals(null, fwd.getDelayInformation());
    // check message
    assertEquals("romeo@montague.com", fwd.getForwardedStanza().getFrom().toString());
    // check end of tag
    assertEquals(XmlPullParser.Event.END_ELEMENT, parser.getEventType());
    assertEquals("sent", parser.getName());
}
Also used : CarbonManagerProvider(org.jivesoftware.smackx.carbons.provider.CarbonManagerProvider) Message(org.jivesoftware.smack.packet.Message) CarbonExtension(org.jivesoftware.smackx.carbons.packet.CarbonExtension) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) ExperimentalInitializerTest(org.jivesoftware.smackx.ExperimentalInitializerTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 85 with XmlPullParser

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

the class ReceivedExtensionTest method checkReceivedProvider.

@Test
public void checkReceivedProvider() throws Exception {
    XmlPullParser parser = PacketParserUtils.getParserFor(receivedExtension);
    ReceivedExtension receivedExtension1 = new ReceivedProvider().parse(parser);
    assertEquals("message-1", receivedExtension1.getId());
    Message message = PacketParserUtils.parseStanza(receivedMessageStanza);
    ReceivedExtension receivedExtension2 = ReceivedExtension.from(message);
    assertEquals("message-1", receivedExtension2.getId());
}
Also used : ReceivedExtension(org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.ReceivedExtension) Message(org.jivesoftware.smack.packet.Message) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) ReceivedProvider(org.jivesoftware.smackx.chat_markers.provider.ReceivedProvider) 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