Search in sources :

Example 1 with FullJid

use of org.jxmpp.jid.FullJid in project Smack by igniterealtime.

the class LowLevelRosterIntegrationTest method testPresenceEventListenersOffline.

@SmackIntegrationTest
public void testPresenceEventListenersOffline(final XMPPTCPConnection conOne, final XMPPTCPConnection conTwo) throws TimeoutException, Exception {
    RosterIntegrationTest.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
    final Roster rosterOne = Roster.getInstanceFor(conOne);
    final Roster rosterTwo = Roster.getInstanceFor(conTwo);
    // TODO create Roster.createEntry() with boolean flag for subscribe or not.
    rosterOne.createEntry(conTwo.getUser().asBareJid(), "Con Two", null);
    rosterTwo.createEntry(conOne.getUser().asBareJid(), "Con One", null);
    // TODO Change timeout form '5000' to something configurable.
    final long timeout = 5000;
    RosterIntegrationTest.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
    final SimpleResultSyncPoint offlineTriggered = new SimpleResultSyncPoint();
    rosterOne.addPresenceEventListener(new AbstractPresenceEventListener() {

        @Override
        public void presenceUnavailable(FullJid jid, Presence presence) {
            if (!jid.equals(conTwo.getUser())) {
                return;
            }
            offlineTriggered.signal();
        }
    });
    // Disconnect conTwo, this should cause an 'unavilable' presence to be send from conTwo to
    // conOne.
    conTwo.disconnect();
    Boolean result = offlineTriggered.waitForResult(timeout);
    if (!result) {
        throw new Exception("presenceUnavailable() was not called");
    }
}
Also used : FullJid(org.jxmpp.jid.FullJid) Presence(org.jivesoftware.smack.packet.Presence) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) TimeoutException(java.util.concurrent.TimeoutException) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Aggregations

TimeoutException (java.util.concurrent.TimeoutException)1 SmackIntegrationTest (org.igniterealtime.smack.inttest.SmackIntegrationTest)1 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)1 Presence (org.jivesoftware.smack.packet.Presence)1 FullJid (org.jxmpp.jid.FullJid)1