use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class Base64BinaryChunkProviderTest method isNonLatsChunkParsedCorrectly.
@Test
public void isNonLatsChunkParsedCorrectly() throws Exception {
String base64Text = "iVBORw0KGgoAAAANSUhEUgAAASwAAAGQCAYAA";
String string = "<chunk xmlns='urn:xmpp:http' streamId='Stream0001' nr='0'>" + base64Text + "</chunk>";
Base64BinaryChunkProvider provider = new Base64BinaryChunkProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(string);
ExtensionElement extension = provider.parse(parser);
assertTrue(extension instanceof Base64BinaryChunk);
Base64BinaryChunk chunk = (Base64BinaryChunk) extension;
assertEquals("Stream0001", chunk.getStreamId());
assertFalse(chunk.isLast());
assertEquals(base64Text, chunk.getText());
assertEquals(0, chunk.getNr());
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class AbstractHttpOverXmppProviderTest method parseAbstractBody.
// TODO The method name makes no sense after the HOXT re-design, change to parseHttpOverXmppResp()
private static HttpOverXmppResp parseAbstractBody(String string, String tag, SmackTestUtil.XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
XmlPullParser parser = SmackTestUtil.getParserFor(string, tag, parserKind);
IQ iq = provider.parse(parser);
assertTrue(iq instanceof HttpOverXmppResp);
return (HttpOverXmppResp) iq;
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class AbstractHttpOverXmppProviderTest method areRespHeadersParsedCorrectly.
@Test
public void areRespHeadersParsedCorrectly() throws Exception {
String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200' statusMessage='OK'>" + "<headers xmlns='http://jabber.org/protocol/shim'>" + "<header name='Date'>Fri, 03 May 2013 13:52:10 GMT-4</header>" + "<header name='Allow'>OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE</header>" + "<header name='Content-Length'>0</header>" + "</headers>" + "</resp>";
Map<String, String> expectedHeaders = new HashMap<String, String>();
expectedHeaders.put("Date", "Fri, 03 May 2013 13:52:10 GMT-4");
expectedHeaders.put("Allow", "OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE");
expectedHeaders.put("Content-Length", "0");
HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
XmlPullParser parser = PacketParserUtils.getParserFor(string);
IQ iq = provider.parse(parser);
assertTrue(iq instanceof HttpOverXmppResp);
HttpOverXmppResp body = (HttpOverXmppResp) iq;
checkHeaders(body.getHeaders(), expectedHeaders);
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class MamPrefIQProviderTest method checkMamPrefsIQProvider.
@ParameterizedTest
@EnumSource(value = SmackTestUtil.XmlPullParserKind.class)
public void checkMamPrefsIQProvider(XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
XmlPullParser parser1 = SmackTestUtil.getParserFor(exampleMamPrefsIQ1, parserKind);
MamPrefsIQ mamPrefIQ1 = MamPrefsIQProvider.INSTANCE.parse(parser1);
assertEquals(IQ.Type.set, mamPrefIQ1.getType());
assertEquals(mamPrefIQ1.getAlwaysJids().get(0).toString(), "romeo@montague.lit");
assertEquals(mamPrefIQ1.getNeverJids().get(0).toString(), "montague@montague.lit");
XmlPullParser parser2 = SmackTestUtil.getParserFor(exampleMamPrefsIQ2, parserKind);
MamPrefsIQ mamPrefIQ2 = MamPrefsIQProvider.INSTANCE.parse(parser2);
assertEquals(IQ.Type.set, mamPrefIQ2.getType());
assertEquals(mamPrefIQ2.getAlwaysJids().get(0).toString(), "romeo@montague.lit");
assertEquals(mamPrefIQ2.getAlwaysJids().get(1).toString(), "montague@montague.lit");
assertTrue(mamPrefIQ2.getNeverJids().isEmpty());
XmlPullParser parser3 = SmackTestUtil.getParserFor(exampleMamPrefsIQ3, parserKind);
MamPrefsIQ mamPrefIQ3 = MamPrefsIQProvider.INSTANCE.parse(parser3);
assertEquals(IQ.Type.set, mamPrefIQ3.getType());
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class MamResultProviderTest method checkMamResultProvider.
@Test
public void checkMamResultProvider() throws Exception {
XmlPullParser parser = PacketParserUtils.getParserFor(exampleMamResultXml);
MamResultExtension mamResultExtension = new MamResultProvider().parse(parser);
assertEquals(mamResultExtension.getQueryId(), "f27");
assertEquals(mamResultExtension.getId(), "28482-98726-73623");
GregorianCalendar calendar = new GregorianCalendar(2010, 7 - 1, 10, 23, 8, 25);
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = calendar.getTime();
Forwarded<Message> forwarded = mamResultExtension.getForwarded();
assertEquals(forwarded.getDelayInformation().getStamp(), date);
Message message = forwarded.getForwardedStanza();
assertEquals(message.getFrom().toString(), "romeo@montague.lit/orchard");
assertEquals(message.getTo().toString(), "juliet@capulet.lit/balcony");
assertEquals(message.getBody(), "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.");
}
Aggregations