Search in sources :

Example 11 with XmlPullParser

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

the class AbstractProviderTest method testWrapsNumberFormatException.

@Test
public void testWrapsNumberFormatException() throws XmlPullParserException, IOException {
    XmlPullParser parser = SmackTestUtil.createDummyParser();
    assertThrows(AbstractProvider.NumberFormatParseException.class, () -> NUMBER_FORMAT_THROWING_PROVIDER.parse(parser));
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Test(org.junit.jupiter.api.Test)

Example 12 with XmlPullParser

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

the class PacketParserUtilsTest method parseElementMultipleNamespace.

// @Test
// public void parseContentDepthTest() throws Exception {
// final String stanza = "<iq type='result' to='foo@bar.com' from='baz.com' id='42'/>";
// XmlPullParser parser = TestUtils.getParser(stanza, "iq");
// CharSequence content = PacketParserUtils.parseContent(parser);
// assertEquals("", content.toString());
// }
@Test
public void parseElementMultipleNamespace() throws ParserConfigurationException, FactoryConfigurationError, XmlPullParserException, IOException, TransformerException, SAXException {
    // @formatter:off
    final String stanza = XMLBuilder.create("outer", "outerNamespace").a("outerAttribute", "outerValue").element("inner", "innerNamespace").a("innerAttribute", "innerValue").element("innermost").t("some text").asString();
    // @formatter:on
    XmlPullParser parser = TestUtils.getParser(stanza, "outer");
    CharSequence result = PacketParserUtils.parseElement(parser, true);
    assertXmlSimilar(stanza, result.toString());
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with XmlPullParser

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

the class PacketParserUtilsTest method testParseElementSimple.

@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void testParseElementSimple(SmackTestUtil.XmlPullParserKind parserKind) throws TransformerException, ParserConfigurationException, FactoryConfigurationError, XmlPullParserException, IOException {
    String unknownElement = XMLBuilder.create("unknown-element").ns("https://example.org/non-existent").e("inner").t("test").asString(outputProperties);
    XmlPullParser xmlPullParser = SmackTestUtil.getParserFor(unknownElement, parserKind);
    CharSequence unknownElementParsed = PacketParserUtils.parseElement(xmlPullParser);
    assertXmlSimilar(unknownElement, unknownElementParsed);
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with XmlPullParser

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

the class TestUtils method getParser.

private static XmlPullParser getParser(Reader reader, String startTag) {
    XmlPullParser parser;
    try {
        parser = SmackXmlParser.newXmlParser(reader);
        if (startTag == null) {
            while (parser.getEventType() != XmlPullParser.Event.START_ELEMENT) {
                parser.next();
            }
            return parser;
        }
        boolean found = false;
        while (!found) {
            if ((parser.next() == XmlPullParser.Event.START_ELEMENT) && parser.getName().equals(startTag))
                found = true;
        }
        if (!found)
            throw new IllegalArgumentException("Can not find start tag '" + startTag + "'");
    } catch (XmlPullParserException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return parser;
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) XmlPullParserException(org.jivesoftware.smack.xml.XmlPullParserException) IOException(java.io.IOException)

Example 15 with XmlPullParser

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

the class SmackTestUtil method getParserFor.

public static XmlPullParser getParserFor(String xml, String startTagLocalpart, XmlPullParserKind parserKind) throws XmlPullParserException, IOException {
    XmlPullParser parser = getParserFor(xml, parserKind);
    forwardParserToStartElement(parser, p -> p.getName().equals(startTagLocalpart));
    return parser;
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser)

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