Search in sources :

Example 16 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.SmackIntegrationTest in project Smack by igniterealtime.

the class ChatTest method chatManagerTest.

@SuppressWarnings("deprecation")
@SmackIntegrationTest
public void chatManagerTest() {
    ChatManagerListener listener = new ChatManagerListener() {

        @Override
        public void chatCreated(org.jivesoftware.smack.chat.Chat chat, boolean createdLocally) {
            invoked = true;
        }
    };
    try {
        chatManagerOne.addChatListener(listener);
        chatManagerOne.createChat(conTwo.getUser());
        assertTrue("TestChatManagerListener wasn't invoked", invoked);
    } finally {
        chatManagerOne.removeChatListener(listener);
    }
}
Also used : ChatManagerListener(org.jivesoftware.smack.chat.ChatManagerListener) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 17 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.SmackIntegrationTest in project Smack by igniterealtime.

the class RosterIntegrationTest method subscribeRequestListenerTest.

@SmackIntegrationTest
public void subscribeRequestListenerTest() throws TimeoutException, Exception {
    ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
    final SubscribeListener subscribeListener = new SubscribeListener() {

        @Override
        public SubscribeAnswer processSubscribe(Jid from, Presence subscribeRequest) {
            if (from.equals(conOne.getUser().asBareJid())) {
                return SubscribeAnswer.Approve;
            }
            return SubscribeAnswer.Deny;
        }
    };
    rosterTwo.addSubscribeListener(subscribeListener);
    final String conTwosRosterName = "ConTwo " + testRunId;
    final SimpleResultSyncPoint addedAndSubscribed = new SimpleResultSyncPoint();
    rosterOne.addRosterListener(new AbstractRosterListener() {

        @Override
        public void entriesAdded(Collection<Jid> addresses) {
            checkIfAddedAndSubscribed(addresses);
        }

        @Override
        public void entriesUpdated(Collection<Jid> addresses) {
            checkIfAddedAndSubscribed(addresses);
        }

        private void checkIfAddedAndSubscribed(Collection<Jid> addresses) {
            for (Jid jid : addresses) {
                if (!jid.equals(conTwo.getUser().asBareJid())) {
                    continue;
                }
                BareJid bareJid = conTwo.getUser().asBareJid();
                RosterEntry rosterEntry = rosterOne.getEntry(bareJid);
                if (rosterEntry == null) {
                    addedAndSubscribed.signalFailure("No roster entry for " + bareJid);
                    return;
                }
                String name = rosterEntry.getName();
                if (StringUtils.isNullOrEmpty(name)) {
                    addedAndSubscribed.signalFailure("Roster entry without name");
                    return;
                }
                if (!rosterEntry.getName().equals(conTwosRosterName)) {
                    addedAndSubscribed.signalFailure("Roster name does not match");
                    return;
                }
                if (!rosterEntry.getType().equals(ItemType.to)) {
                    return;
                }
                addedAndSubscribed.signal();
            }
        }
    });
    try {
        rosterOne.createEntry(conTwo.getUser().asBareJid(), conTwosRosterName, null);
        assertTrue(addedAndSubscribed.waitForResult(2 * connection.getReplyTimeout()));
    } finally {
        rosterTwo.removeSubscribeListener(subscribeListener);
    }
}
Also used : Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) BareJid(org.jxmpp.jid.BareJid) Presence(org.jivesoftware.smack.packet.Presence) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 18 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.SmackIntegrationTest in project Smack by igniterealtime.

the class EntityCapsTest method testLocalEntityCaps.

@SmackIntegrationTest
public void testLocalEntityCaps() throws InterruptedException, NoResponseException, XMPPErrorException, NotConnectedException {
    final String dummyFeature = getNewDummyFeature();
    DiscoverInfo info = EntityCapsManager.getDiscoveryInfoByNodeVer(ecmTwo.getLocalNodeVer());
    assertFalse(info.containsFeature(dummyFeature));
    dropWholeEntityCapsCache();
    performActionAndWaitUntilStanzaReceived(new Runnable() {

        @Override
        public void run() {
            // This should cause a new presence stanza from con1 with and updated
            // 'ver' String
            sdmTwo.addFeature(dummyFeature);
        }
    }, conOne, new AndFilter(PresenceTypeFilter.AVAILABLE, FromMatchesFilter.create(conTwo.getUser())));
    // The presence stanza should get received by con0 and the data should
    // be recorded in the map
    // Note that while both connections use the same static Entity Caps
    // cache,
    // it's assured that *not* con1 added the data to the Entity Caps cache.
    // Every time the entities features
    // and identities change only a new caps 'ver' is calculated and send
    // with the presence stanza
    // The other connection has to receive this stanza and record the
    // information in order for this test to succeed.
    info = EntityCapsManager.getDiscoveryInfoByNodeVer(ecmTwo.getLocalNodeVer());
    assertNotNull(info);
    assertTrue(info.containsFeature(dummyFeature));
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) AndFilter(org.jivesoftware.smack.filter.AndFilter) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)

Example 19 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.SmackIntegrationTest in project Smack by igniterealtime.

the class EntityCapsTest method testEntityCaps.

@SmackIntegrationTest
public void testEntityCaps() throws XMPPException, InterruptedException, NoResponseException, NotConnectedException, TimeoutException {
    final String dummyFeature = getNewDummyFeature();
    dropWholeEntityCapsCache();
    performActionAndWaitUntilStanzaReceived(new Runnable() {

        @Override
        public void run() {
            sdmTwo.addFeature(dummyFeature);
        }
    }, connection, new AndFilter(PresenceTypeFilter.AVAILABLE, FromMatchesFilter.create(conTwo.getUser())));
    waitUntilTrue(new Condition() {

        @Override
        public boolean evaluate() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
            DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser());
            return info.containsFeature(dummyFeature);
        }
    });
    DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser());
    String u1ver = EntityCapsManager.getNodeVersionByJid(conTwo.getUser());
    assertNotNull(u1ver);
    DiscoverInfo entityInfo = EntityCapsManager.CAPS_CACHE.lookup(u1ver);
    assertNotNull(entityInfo);
    assertEquals(info.toXML(), entityInfo.toXML());
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)

Aggregations

SmackIntegrationTest (org.igniterealtime.smack.inttest.SmackIntegrationTest)19 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)14 AndFilter (org.jivesoftware.smack.filter.AndFilter)4 Message (org.jivesoftware.smack.packet.Message)4 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)3 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)3 TimeoutException (java.util.concurrent.TimeoutException)2 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)2 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)2 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)2 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)2 ThreadFilter (org.jivesoftware.smack.filter.ThreadFilter)2 Presence (org.jivesoftware.smack.packet.Presence)2 MucCreateConfigFormHandle (org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle)2 EntityBareJid (org.jxmpp.jid.EntityBareJid)2 Jid (org.jxmpp.jid.Jid)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1