Search in sources :

Example 86 with IQ

use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.

the class MamFinProviderTest method checkQueryLimitedResults.

@Test
public void checkQueryLimitedResults() throws Exception {
    // @formatter:off
    final String IQ_LIMITED_RESULTS_EXAMPLE = "<iq type='result' id='u29303'>" + "<fin xmlns='urn:xmpp:mam:1' complete='true'>" + "<set xmlns='http://jabber.org/protocol/rsm'>" + "<first index='0'>23452-4534-1</first>" + "<last>390-2342-22</last>" + "<count>16</count>" + "</set>" + "</fin>" + "</iq>";
    // @formatter:on
    IQ iq = (IQ) PacketParserUtils.parseStanza(IQ_LIMITED_RESULTS_EXAMPLE);
    MamFinIQ mamFinIQ = (MamFinIQ) iq;
    Assert.assertEquals(mamFinIQ.getType(), Type.result);
    Assert.assertTrue(mamFinIQ.isComplete());
    Assert.assertEquals(mamFinIQ.getRSMSet().getCount(), 16);
    Assert.assertEquals(mamFinIQ.getRSMSet().getFirst(), "23452-4534-1");
    Assert.assertEquals(mamFinIQ.getRSMSet().getFirstIndex(), 0);
    Assert.assertEquals(mamFinIQ.getRSMSet().getLast(), "390-2342-22");
}
Also used : MamFinIQ(org.jivesoftware.smackx.mam.element.MamFinIQ) IQ(org.jivesoftware.smack.packet.IQ) MamFinIQ(org.jivesoftware.smackx.mam.element.MamFinIQ) Test(org.junit.Test)

Example 87 with IQ

use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.

the class MamQueryIQProviderTest method checkMamQueryIQProvider.

@Test
public void checkMamQueryIQProvider() throws Exception {
    // example 1
    IQ iq1 = (IQ) PacketParserUtils.parseStanza(exampleMamQueryIQ1);
    MamQueryIQ mamQueryIQ1 = (MamQueryIQ) iq1;
    Assert.assertEquals(mamQueryIQ1.getType(), Type.set);
    Assert.assertEquals(mamQueryIQ1.getQueryId(), "test");
    DataForm dataForm1 = (DataForm) mamQueryIQ1.getExtension(DataForm.NAMESPACE);
    Assert.assertEquals(dataForm1.getType(), DataForm.Type.submit);
    List<FormField> fields1 = dataForm1.getFields();
    Assert.assertEquals(fields1.get(0).getType(), FormField.Type.hidden);
    Assert.assertEquals(fields1.get(1).getType(), FormField.Type.text_single);
    Assert.assertEquals(fields1.get(1).getValues().get(0), "Where arth thou, my Juliet?");
    Assert.assertEquals(fields1.get(2).getValues().get(0), "{http://jabber.org/protocol/mood}mood/lonely");
    // example2
    IQ iq2 = (IQ) PacketParserUtils.parseStanza(exampleMamQueryIQ2);
    MamQueryIQ mamQueryIQ2 = (MamQueryIQ) iq2;
    Assert.assertEquals(mamQueryIQ2.getType(), Type.result);
    Assert.assertNull(mamQueryIQ2.getQueryId());
    DataForm dataForm2 = (DataForm) mamQueryIQ2.getExtension(DataForm.NAMESPACE);
    Assert.assertEquals(dataForm2.getType(), DataForm.Type.form);
    List<FormField> fields2 = dataForm2.getFields();
    Assert.assertEquals(fields2.get(0).getValues().get(0), "urn:xmpp:mam:1");
    Assert.assertTrue(fields2.get(0).getValues().size() == 1);
    Assert.assertEquals(fields2.get(1).getType(), FormField.Type.jid_single);
    Assert.assertEquals(fields2.get(2).getType(), FormField.Type.text_single);
    Assert.assertEquals(fields2.get(2).getValues(), new ArrayList<>());
    Assert.assertEquals(fields2.get(4).getVariable(), "urn:example:xmpp:free-text-search");
}
Also used : MamQueryIQ(org.jivesoftware.smackx.mam.element.MamQueryIQ) IQ(org.jivesoftware.smack.packet.IQ) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField) MamQueryIQ(org.jivesoftware.smackx.mam.element.MamQueryIQ) Test(org.junit.Test)

Example 88 with IQ

use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.

the class HttpOverXmppRespProviderTest method areRespAttributesWothoutMessageCorrectlyParsed.

@Test
public void areRespAttributesWothoutMessageCorrectlyParsed() throws Exception {
    String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200'/>";
    HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
    XmlPullParser parser = PacketParserUtils.getParserFor(string);
    IQ iq = provider.parse(parser);
    assertTrue(iq instanceof HttpOverXmppResp);
    HttpOverXmppResp resp = (HttpOverXmppResp) iq;
    assertEquals(resp.getVersion(), "1.1");
    assertEquals(resp.getStatusCode(), 200);
    assertNull(resp.getStatusMessage());
}
Also used : HttpOverXmppResp(org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp) XmlPullParser(org.xmlpull.v1.XmlPullParser) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Example 89 with IQ

use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.

the class HttpOverXmppRespProviderTest method areAllRespAttributesCorrectlyParsed.

@Test
public void areAllRespAttributesCorrectlyParsed() throws Exception {
    String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200' statusMessage='OK'/>";
    HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
    XmlPullParser parser = PacketParserUtils.getParserFor(string);
    IQ iq = provider.parse(parser);
    assertTrue(iq instanceof HttpOverXmppResp);
    HttpOverXmppResp resp = (HttpOverXmppResp) iq;
    assertEquals(resp.getVersion(), "1.1");
    assertEquals(resp.getStatusCode(), 200);
    assertEquals(resp.getStatusMessage(), "OK");
}
Also used : HttpOverXmppResp(org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp) XmlPullParser(org.xmlpull.v1.XmlPullParser) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Example 90 with IQ

use of org.jivesoftware.smack.packet.IQ in project Smack by igniterealtime.

the class FileTooLargeErrorProviderTest method checkSlotErrorFileToLarge.

@Test
public void checkSlotErrorFileToLarge() throws Exception {
    IQ fileTooLargeErrorIQ = PacketParserUtils.parseStanza(slotErrorFileToLarge);
    Assert.assertEquals(IQ.Type.error, fileTooLargeErrorIQ.getType());
    FileTooLargeError fileTooLargeError = FileTooLargeError.from(fileTooLargeErrorIQ);
    Assert.assertEquals(20000, fileTooLargeError.getMaxFileSize());
}
Also used : FileTooLargeError(org.jivesoftware.smackx.httpfileupload.element.FileTooLargeError) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Aggregations

IQ (org.jivesoftware.smack.packet.IQ)138 Test (org.junit.Test)57 ErrorIQ (org.jivesoftware.smack.packet.ErrorIQ)12 Stanza (org.jivesoftware.smack.packet.Stanza)12 InputStream (java.io.InputStream)11 StanzaListener (org.jivesoftware.smack.StanzaListener)10 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)10 Data (org.jivesoftware.smackx.bytestreams.ibb.packet.Data)10 DataPacketExtension (org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension)10 OutputStream (java.io.OutputStream)9 ArrayList (java.util.ArrayList)9 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)8 XMPPError (org.jivesoftware.smack.packet.XMPPError)7 Jid (org.jxmpp.jid.Jid)7 NetworkException (com.xabber.android.data.NetworkException)6 OnResponseListener (com.xabber.android.data.connection.OnResponseListener)6 IOException (java.io.IOException)6 XMPPConnection (org.jivesoftware.smack.XMPPConnection)6 EmptyResultIQ (org.jivesoftware.smack.packet.EmptyResultIQ)6 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)6