Search in sources :

Example 6 with ThreadedDummyConnection

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

the class PingTest method getAuthentiactedDummyConnection.

private static ThreadedDummyConnection getAuthentiactedDummyConnection() throws SmackException, IOException, XMPPException, InterruptedException {
    ThreadedDummyConnection connection = new ThreadedDummyConnection();
    connection.connect();
    connection.login();
    return connection;
}
Also used : ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection)

Example 7 with ThreadedDummyConnection

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

the class ConfigureFormTest method getConfigFormWithTimeout.

@Test(expected = SmackException.class)
public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException {
    ThreadedDummyConnection con = new ThreadedDummyConnection();
    PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
    DiscoverInfo info = new DiscoverInfo();
    Identity ident = new Identity("pubsub", null, "leaf");
    info.addIdentity(ident);
    con.addIQReply(info);
    Node node = mgr.getNode("princely_musings");
    SmackConfiguration.setDefaultReplyTimeout(100);
    con.setTimeout();
    node.getNodeConfiguration();
}
Also used : ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) Identity(org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity) Test(org.junit.Test)

Example 8 with ThreadedDummyConnection

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

the class ConfigureFormTest method getConfigFormWithInsufficientPriviliges.

@Test
public void getConfigFormWithInsufficientPriviliges() throws XMPPException, SmackException, IOException, InterruptedException {
    ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
    PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
    DiscoverInfo info = new DiscoverInfo();
    Identity ident = new Identity("pubsub", null, "leaf");
    info.addIdentity(ident);
    con.addIQReply(info);
    Node node = mgr.getNode("princely_musings");
    PubSub errorIq = new PubSub();
    XMPPError.Builder error = XMPPError.getBuilder(Condition.forbidden);
    errorIq.setError(error);
    con.addIQReply(errorIq);
    try {
        node.getNodeConfiguration();
    } catch (XMPPErrorException e) {
        Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().getType());
    }
}
Also used : ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) XMPPError(org.jivesoftware.smack.packet.XMPPError) Identity(org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity) Test(org.junit.Test)

Example 9 with ThreadedDummyConnection

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

the class PingTest method checkFailedPingToEntityError.

/**
     * Server returns an exception for entity.
     * @throws Exception
     */
@Test
public void checkFailedPingToEntityError() throws Exception {
    ThreadedDummyConnection threadedCon = getAuthentiactedDummyConnection();
    //@formatter:off
    String reply = "<iq type='error' id='qrzSp-16' to='test@myserver.com'>" + "<ping xmlns='urn:xmpp:ping'/>" + "<error type='cancel'>" + "<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "</error>" + "</iq>";
    //@formatter:on
    IQ serviceUnavailable = (IQ) PacketParserUtils.parseStanza(reply);
    threadedCon.addIQReply(serviceUnavailable);
    PingManager pinger = PingManager.getInstanceFor(threadedCon);
    boolean pingSuccess = pinger.ping(DUMMY_AT_EXAMPLE_ORG);
    assertFalse(pingSuccess);
}
Also used : ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Example 10 with ThreadedDummyConnection

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

the class PingTest method checkPingToServerError.

/**
     * Server returns an exception.
     * @throws Exception
     */
@Test
public void checkPingToServerError() throws Exception {
    ThreadedDummyConnection con = getAuthentiactedDummyConnection();
    //@formatter:off
    String reply = "<iq type='error' id='qrzSp-16' to='test@myserver.com' from='" + con.getXMPPServiceDomain() + "'>" + "<ping xmlns='urn:xmpp:ping'/>" + "<error type='cancel'>" + "<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "</error>" + "</iq>";
    //@formatter:on
    IQ serviceUnavailable = (IQ) PacketParserUtils.parseStanza(reply);
    con.addIQReply(serviceUnavailable);
    PingManager pinger = PingManager.getInstanceFor(con);
    boolean pingSuccess = pinger.pingMyServer();
    assertTrue(pingSuccess);
}
Also used : ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.Test)

Aggregations

ThreadedDummyConnection (org.jivesoftware.smack.ThreadedDummyConnection)11 Test (org.junit.Test)9 IQ (org.jivesoftware.smack.packet.IQ)4 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)4 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)2 PubSub (org.jivesoftware.smackx.pubsub.packet.PubSub)2 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)1 XMPPError (org.jivesoftware.smack.packet.XMPPError)1 Before (org.junit.Before)1