Search in sources :

Example 96 with XmlPullParser

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

the class AbstractDelayInformationProvider method parse.

@Override
public final DelayInformation parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, ParseException {
    String stampString = parser.getAttributeValue("", "stamp");
    String from = parser.getAttributeValue("", "from");
    final String reason;
    XmlPullParser.Event event = parser.next();
    switch(event) {
        case TEXT_CHARACTERS:
            reason = parser.getText();
            parser.next();
            break;
        case END_ELEMENT:
            reason = null;
            break;
        default:
            // TODO: Should be SmackParseException.
            throw new IOException("Unexpected event: " + event);
    }
    Date stamp = parseDate(stampString);
    return new DelayInformation(stamp, from, reason);
}
Also used : DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) IOException(java.io.IOException) Date(java.util.Date)

Example 97 with XmlPullParser

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

the class OpenIQProviderTest method shouldCorrectlyParseIQStanzaAttribute.

@Test
public void shouldCorrectlyParseIQStanzaAttribute() throws Exception {
    String control = XMLBuilder.create("open").a("xmlns", "http://jabber.org/protocol/ibb").a("block-size", "4096").a("sid", "i781hf64").a("stanza", "iq").asString(outputProperties);
    OpenIQProvider oip = new OpenIQProvider();
    XmlPullParser parser = PacketParserUtils.getParserFor(control);
    Open open = oip.parse(parser);
    assertEquals(StanzaType.IQ, open.getStanza());
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Open(org.jivesoftware.smackx.bytestreams.ibb.packet.Open) Test(org.junit.jupiter.api.Test)

Example 98 with XmlPullParser

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

the class OpenIQProviderTest method shouldCorrectlyParseMessageStanzaAttribute.

@Test
public void shouldCorrectlyParseMessageStanzaAttribute() throws Exception {
    String control = XMLBuilder.create("open").a("xmlns", "http://jabber.org/protocol/ibb").a("block-size", "4096").a("sid", "i781hf64").a("stanza", "message").asString(outputProperties);
    OpenIQProvider oip = new OpenIQProvider();
    XmlPullParser parser = PacketParserUtils.getParserFor(control);
    Open open = oip.parse(parser);
    assertEquals(StanzaType.MESSAGE, open.getStanza());
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Open(org.jivesoftware.smackx.bytestreams.ibb.packet.Open) Test(org.junit.jupiter.api.Test)

Example 99 with XmlPullParser

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

the class MoodConcretisationTest method concretisationTest.

@Test
public void concretisationTest() throws Exception {
    ProviderManager.addExtensionProvider(EcstaticMoodConcretisation.ELEMENT, EcstaticMoodConcretisation.NAMESPACE, EcstaticMoodConcretisationProvider.INSTANCE);
    String xml = "<mood xmlns='http://jabber.org/protocol/mood'>" + "<happy>" + "<ecstatic xmlns='https://example.org/'/>" + "</happy>" + "<text>Yay, the mood spec has been approved!</text>" + "</mood>";
    MoodElement element = new MoodElement(new MoodElement.MoodSubjectElement(Mood.happy, new EcstaticMoodConcretisation()), "Yay, the mood spec has been approved!");
    assertXmlSimilar(xml, element.toXML().toString());
    XmlPullParser parser = TestUtils.getParser(xml);
    MoodElement parsed = MoodProvider.INSTANCE.parse(parser);
    assertXmlSimilar(xml, parsed.toXML().toString());
    assertTrue(parsed.hasConcretisation());
    assertTrue(parsed.hasText());
    assertEquals(EcstaticMoodConcretisation.ELEMENT, parsed.getMoodConcretisation().getMood());
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) MoodElement(org.jivesoftware.smackx.mood.element.MoodElement) Test(org.junit.jupiter.api.Test)

Example 100 with XmlPullParser

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

the class DelayInformationTest method delayInformationTest.

@Test
public void delayInformationTest() throws Exception {
    DelayInformationProvider p = new DelayInformationProvider();
    DelayInformation delayInfo;
    XmlPullParser parser;
    String control;
    GregorianCalendar calendar = new GregorianCalendar(2002, 9 - 1, 10, 23, 8, 25);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = calendar.getTime();
    control = XMLBuilder.create("x").a("xmlns", "jabber:x:delay").a("from", "capulet.com").a("stamp", "2002-09-10T23:08:25Z").t("Offline Storage").asString(outputProperties);
    parser = PacketParserUtils.getParserFor(control);
    delayInfo = p.parse(parser);
    assertEquals("capulet.com", delayInfo.getFrom());
    assertEquals(date, delayInfo.getStamp());
    assertEquals("Offline Storage", delayInfo.getReason());
    assertEquals(XmlPullParser.Event.END_ELEMENT, parser.getEventType());
    assertEquals("x", parser.getName());
    control = XMLBuilder.create("x").a("xmlns", "jabber:x:delay").a("from", "capulet.com").a("stamp", "2002-09-10T23:08:25Z").asString(outputProperties);
    parser = PacketParserUtils.getParserFor(control);
    delayInfo = p.parse(parser);
    assertEquals("capulet.com", delayInfo.getFrom());
    assertEquals(date, delayInfo.getStamp());
    assertNull(delayInfo.getReason());
    assertEquals(XmlPullParser.Event.END_ELEMENT, parser.getEventType());
    assertEquals("x", parser.getName());
}
Also used : DelayInformation(org.jivesoftware.smackx.delay.packet.DelayInformation) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) 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