Search in sources :

Example 1 with IQ

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

the class LastActivityTest method checkProvider.

@Test
public void checkProvider() throws Exception {
    XMLBuilder xml = XMLBuilder.create("iq");
    xml.a("from", "romeo@montague.net/orchard").a("id", "last2").a("to", "juliet@capulet.com/balcony").a("type", "get").e("query").namespace(LastActivity.NAMESPACE);
    DummyConnection c = new DummyConnection();
    c.connect();
    IQ lastRequest = (IQ) PacketParserUtils.parseStanza(xml.asString());
    assertTrue(lastRequest instanceof LastActivity);
    c.processStanza(lastRequest);
    Stanza reply = c.getSentPacket();
    assertTrue(reply instanceof LastActivity);
    LastActivity l = (LastActivity) reply;
    assertEquals("last2", l.getStanzaId());
    assertEquals(IQ.Type.result, l.getType());
}
Also used : DummyConnection(org.jivesoftware.smack.DummyConnection) Stanza(org.jivesoftware.smack.packet.Stanza) IQ(org.jivesoftware.smack.packet.IQ) XMLBuilder(com.jamesmurty.utils.XMLBuilder) LastActivity(org.jivesoftware.smackx.iqlast.packet.LastActivity) Test(org.junit.Test)

Example 2 with IQ

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

the class VersionTest method checkProvider.

@Test
public void checkProvider() throws Exception {
    // @formatter:off
    String control = "<iq from='capulet.lit' to='juliet@capulet.lit/balcony' id='s2c1' type='get'>" + "<query xmlns='jabber:iq:version'/>" + "</iq>";
    // @formatter:on
    DummyConnection con = new DummyConnection();
    con.connect();
    // Enable version replys for this connection
    VersionManager.setAutoAppendSmackVersion(false);
    VersionManager.getInstanceFor(con).setVersion("Test", "0.23", "DummyOS");
    IQ versionRequest = (IQ) PacketParserUtils.parseStanza(control);
    assertTrue(versionRequest instanceof Version);
    con.processStanza(versionRequest);
    Stanza replyPacket = con.getSentPacket();
    assertTrue(replyPacket instanceof Version);
    Version reply = (Version) replyPacket;
    //getFrom check is pending for SMACK-547
    //assertEquals("juliet@capulet.lit/balcony", reply.getFrom());
    assertThat("capulet.lit", equalsCharSequence(reply.getTo()));
    assertEquals("s2c1", reply.getStanzaId());
    assertEquals(IQ.Type.result, reply.getType());
    assertEquals("Test", reply.getName());
    assertEquals("0.23", reply.getVersion());
    assertEquals("DummyOS", reply.getOs());
}
Also used : Version(org.jivesoftware.smackx.iqversion.packet.Version) DummyConnection(org.jivesoftware.smack.DummyConnection) Stanza(org.jivesoftware.smack.packet.Stanza) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Example 3 with IQ

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

the class PingTest method checkProvider.

@Test
public void checkProvider() throws Exception {
    // @formatter:off
    String control = "<iq from='capulet.lit' to='juliet@capulet.lit/balcony' id='s2c1' type='get'>" + "<ping xmlns='urn:xmpp:ping'/>" + "</iq>";
    // @formatter:on
    DummyConnection con = new DummyConnection();
    con.connect();
    // Enable ping for this connection
    PingManager.getInstanceFor(con);
    IQ pingRequest = (IQ) PacketParserUtils.parseStanza(control);
    assertTrue(pingRequest instanceof Ping);
    con.processStanza(pingRequest);
    Stanza pongPacket = con.getSentPacket();
    assertTrue(pongPacket instanceof IQ);
    IQ pong = (IQ) pongPacket;
    assertThat("capulet.lit", equalsCharSequence(pong.getTo()));
    assertEquals("s2c1", pong.getStanzaId());
    assertEquals(IQ.Type.result, pong.getType());
}
Also used : DummyConnection(org.jivesoftware.smack.DummyConnection) ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection) Ping(org.jivesoftware.smackx.ping.packet.Ping) Stanza(org.jivesoftware.smack.packet.Stanza) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Example 4 with IQ

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

the class PingTest method checkSuccessfulDiscoRequest.

@Test
public void checkSuccessfulDiscoRequest() throws Exception {
    ThreadedDummyConnection con = getAuthentiactedDummyConnection();
    DiscoverInfo info = new DiscoverInfo();
    info.addFeature(Ping.NAMESPACE);
    //@formatter:off
    String reply = "<iq type='result' id='qrzSp-16' to='test@myserver.com'>" + "<query xmlns='http://jabber.org/protocol/disco#info'><identity category='client' type='pc' name='Pidgin'/>" + "<feature var='urn:xmpp:ping'/>" + "</query></iq>";
    //@formatter:on
    IQ discoReply = (IQ) PacketParserUtils.parseStanza(reply);
    con.addIQReply(discoReply);
    PingManager pinger = PingManager.getInstanceFor(con);
    boolean pingSupported = pinger.isPingSupported(DUMMY_AT_EXAMPLE_ORG);
    assertTrue(pingSupported);
}
Also used : ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Example 5 with IQ

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

the class RosterVersioningTest method answerWithEmptyRosterResult.

private void answerWithEmptyRosterResult() {
    // We expect that the roster request is the only packet sent. This is not part of the specification,
    // but a shortcut in the test implementation.
    Stanza sentPacket = connection.getSentPacket();
    if (sentPacket instanceof RosterPacket) {
        final IQ emptyIQ = IQ.createResultIQ((RosterPacket) sentPacket);
        connection.processStanza(emptyIQ);
    } else {
        assertTrue("Expected to get a RosterPacket ", false);
    }
}
Also used : RosterPacket(org.jivesoftware.smack.roster.packet.RosterPacket) Stanza(org.jivesoftware.smack.packet.Stanza) IQ(org.jivesoftware.smack.packet.IQ)

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