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);
}
}
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);
}
}
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));
}
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());
}
Aggregations