Search in sources :

Example 6 with XmlPullParser

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

the class PacketParserUtils method getParserFor.

public static XmlPullParser getParserFor(Reader reader) throws XmlPullParserException, IOException {
    XmlPullParser parser = SmackXmlParser.newXmlParser(reader);
    ParserUtils.forwardToStartElement(parser);
    return parser;
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser)

Example 7 with XmlPullParser

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

the class StreamErrorTest method testParsingOfStreamErrorWithTextAndOptionalElement.

@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void testParsingOfStreamErrorWithTextAndOptionalElement(SmackTestUtil.XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
    final String xml = // We omit those, since they are not relevant for testing
    "<stream:stream from='im.example.com' id='++TR84Sm6A3hnt3Q065SnAbbk3Y=' xmlns:stream='http://etherx.jabber.org/streams'>" + "<stream:error>" + "<conflict xmlns='urn:ietf:params:xml:ns:xmpp-streams' />" + "<text xml:lang='' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>" + "Replaced by new connection" + "</text>" + "<appSpecificElement xmlns='myns'>" + "Text contents of application-specific condition element: Foo Bar" + "</appSpecificElement>" + "</stream:error>" + "</stream:stream>";
    XmlPullParser parser = SmackTestUtil.getParserFor(xml, "error", parserKind);
    StreamError error = PacketParserUtils.parseStreamError(parser);
    assertNotNull(error);
    assertEquals(Condition.conflict, error.getCondition());
    assertEquals("Replaced by new connection", error.getDescriptiveText());
    XmlElement appSpecificElement = error.getExtension("appSpecificElement", "myns");
    assertNotNull(appSpecificElement);
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with XmlPullParser

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

the class StreamErrorTest method testStreamErrorXmlNotWellFormed.

@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void testStreamErrorXmlNotWellFormed(SmackTestUtil.XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
    final String xml = // We omit those, since they are not relevant for testing
    "<stream:stream from='im.example.com' id='++TR84Sm6A3hnt3Q065SnAbbk3Y=' xmlns:stream='http://etherx.jabber.org/streams'>" + "<stream:error><xml-not-well-formed xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error>" + "</stream:stream>";
    XmlPullParser parser = SmackTestUtil.getParserFor(xml, "error", parserKind);
    StreamError error = PacketParserUtils.parseStreamError(parser);
    assertNotNull(error);
    assertEquals(Condition.not_well_formed, error.getCondition());
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with XmlPullParser

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

the class StreamErrorTest method testParsingOfSimpleStreamError.

@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void testParsingOfSimpleStreamError(SmackTestUtil.XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
    final String xml = // We omit those, since they are not relevant for testing
    "<stream:stream from='im.example.com' id='++TR84Sm6A3hnt3Q065SnAbbk3Y=' xmlns:stream='http://etherx.jabber.org/streams'>" + "<stream:error>" + "<conflict xmlns='urn:ietf:params:xml:ns:xmpp-streams' /> +" + "</stream:error>" + "</stream:stream>";
    XmlPullParser parser = SmackTestUtil.getParserFor(xml, "error", parserKind);
    StreamError error = PacketParserUtils.parseStreamError(parser);
    assertNotNull(error);
    assertEquals(Condition.conflict, error.getCondition());
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with XmlPullParser

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

the class AbstractProviderTest method testWrapsParseException.

@Test
public void testWrapsParseException() throws XmlPullParserException, IOException {
    XmlPullParser parser = SmackTestUtil.createDummyParser();
    AbstractProvider.TextParseException testParseException = assertThrows(AbstractProvider.TextParseException.class, () -> PARSE_EXCEPTION_THROWING_PROVIDER.parse(parser));
    ParseException parseException = testParseException.getParseException();
    assertEquals(MESSAGE, parseException.getMessage());
    assertEquals(VALUE, parseException.getErrorOffset());
}
Also used : XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) ParseException(java.text.ParseException) 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