Search in sources :

Example 1 with DummyConnection

use of org.jivesoftware.smack.DummyConnection 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 DummyConnection

use of org.jivesoftware.smack.DummyConnection 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 DummyConnection

use of org.jivesoftware.smack.DummyConnection in project Smack by igniterealtime.

the class PingTest method checkFailedPingOnTimeout.

/**
     * DummyConnection will not reply so it will timeout.
     * @throws SmackException 
     * @throws XMPPException 
     * @throws IOException 
     * @throws InterruptedException 
     */
@Test
public void checkFailedPingOnTimeout() throws SmackException, IOException, XMPPException, InterruptedException {
    DummyConnection dummyCon = getAuthenticatedDummyConnectionWithoutIqReplies();
    PingManager pinger = PingManager.getInstanceFor(dummyCon);
    try {
        pinger.ping(DUMMY_AT_EXAMPLE_ORG);
    } catch (NoResponseException e) {
        return;
    }
    fail();
}
Also used : DummyConnection(org.jivesoftware.smack.DummyConnection) ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) Test(org.junit.Test)

Example 4 with DummyConnection

use of org.jivesoftware.smack.DummyConnection 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 5 with DummyConnection

use of org.jivesoftware.smack.DummyConnection in project Smack by igniterealtime.

the class ChatConnectionTest method validateDefaultSetNormalIncludedTrue.

@Test
public void validateDefaultSetNormalIncludedTrue() {
    ChatManager.setDefaultIsNormalIncluded(true);
    assertTrue(ChatManager.getInstanceFor(new DummyConnection()).isNormalIncluded());
}
Also used : DummyConnection(org.jivesoftware.smack.DummyConnection) Test(org.junit.Test)

Aggregations

DummyConnection (org.jivesoftware.smack.DummyConnection)20 Test (org.junit.Test)13 Before (org.junit.Before)6 ThreadedDummyConnection (org.jivesoftware.smack.ThreadedDummyConnection)5 Stanza (org.jivesoftware.smack.packet.Stanza)5 IQ (org.jivesoftware.smack.packet.IQ)3 Message (org.jivesoftware.smack.packet.Message)2 TestRosterListener (org.jivesoftware.smack.roster.RosterTest.TestRosterListener)2 Ping (org.jivesoftware.smackx.ping.packet.Ping)2 XMLBuilder (com.jamesmurty.utils.XMLBuilder)1 SmackException (org.jivesoftware.smack.SmackException)1 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)1 DirectoryRosterStore (org.jivesoftware.smack.roster.rosterstore.DirectoryRosterStore)1 AuthMechanism (org.jivesoftware.smack.sasl.packet.SaslStreamElements.AuthMechanism)1 Response (org.jivesoftware.smack.sasl.packet.SaslStreamElements.Response)1 LastActivity (org.jivesoftware.smackx.iqlast.packet.LastActivity)1 Version (org.jivesoftware.smackx.iqversion.packet.Version)1