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;
}
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);
}
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());
}
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());
}
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());
}
Aggregations