Search in sources :

Example 26 with XmlPullParser

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());
}
Also used : Base64BinaryChunk(org.jivesoftware.smackx.hoxt.packet.Base64BinaryChunk) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) Test(org.junit.jupiter.api.Test)

Example 27 with XmlPullParser

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;
}
Also used : HttpOverXmppResp(org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) IQ(org.jivesoftware.smack.packet.IQ)

Example 28 with XmlPullParser

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);
}
Also used : HttpOverXmppResp(org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp) HashMap(java.util.HashMap) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with XmlPullParser

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());
}
Also used : MamPrefsIQ(org.jivesoftware.smackx.mam.element.MamPrefsIQ) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with XmlPullParser

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.");
}
Also used : MamResultProvider(org.jivesoftware.smackx.mam.provider.MamResultProvider) Message(org.jivesoftware.smack.packet.Message) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) GregorianCalendar(java.util.GregorianCalendar) MamResultExtension(org.jivesoftware.smackx.mam.element.MamElements.MamResultExtension) Date(java.util.Date) 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