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