mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 09:09:38 +02:00
Re-activate EntityCaps integration test
This commit is contained in:
parent
1f7770b831
commit
7655ac17f2
16 changed files with 358 additions and 181 deletions
|
@ -1099,6 +1099,25 @@ public final class Roster extends Manager {
|
|||
return entry.canSeeMyPresence();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the XMPP entity this roster belongs to is subscribed to the presence of the given JID.
|
||||
*
|
||||
* @param jid the jid to check.
|
||||
* @return <code>true</code> if we are subscribed to the presence of the given jid.
|
||||
* @since 4.2
|
||||
*/
|
||||
public boolean iAmSubscribedTo(Jid jid) {
|
||||
if (jid == null) {
|
||||
return false;
|
||||
}
|
||||
BareJid bareJid = jid.asBareJid();
|
||||
RosterEntry entry = getEntry(bareJid);
|
||||
if (entry == null) {
|
||||
return false;
|
||||
}
|
||||
return entry.canSeeHisPresence();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the roster will be loaded from the server when logging in for newly created instances
|
||||
* of {@link Roster}.
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.SmackException.NotLoggedInException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
|
@ -111,4 +112,46 @@ public class RosterUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static void ensureSubscribed(XMPPConnection connectionOne, XMPPConnection connectionTwo, long timeout)
|
||||
throws NotLoggedInException, NotConnectedException, InterruptedException, TimeoutException {
|
||||
ensureSubscribedTo(connectionOne, connectionTwo, timeout);
|
||||
ensureSubscribedTo(connectionTwo, connectionOne, timeout);
|
||||
}
|
||||
|
||||
public static void ensureSubscribedTo(XMPPConnection connectionOne, XMPPConnection connectionTwo, long timeout)
|
||||
throws NotLoggedInException, NotConnectedException, InterruptedException, TimeoutException {
|
||||
Date deadline = new Date(System.currentTimeMillis() + timeout);
|
||||
ensureSubscribedTo(connectionOne, connectionTwo, deadline);
|
||||
}
|
||||
|
||||
public static void ensureSubscribedTo(final XMPPConnection connectionOne, final XMPPConnection connectionTwo,
|
||||
final Date deadline)
|
||||
throws NotLoggedInException, NotConnectedException, InterruptedException, TimeoutException {
|
||||
final Roster rosterOne = Roster.getInstanceFor(connectionOne);
|
||||
final BareJid jidTwo = connectionTwo.getUser().asBareJid();
|
||||
|
||||
if (rosterOne.iAmSubscribedTo(jidTwo))
|
||||
return;
|
||||
|
||||
final BareJid jidOne = connectionOne.getUser().asBareJid();
|
||||
final SubscribeListener subscribeListener = new SubscribeListener() {
|
||||
@Override
|
||||
public SubscribeAnswer processSubscribe(Jid from, Presence subscribeRequest) {
|
||||
if (from.equals(jidOne)) {
|
||||
return SubscribeAnswer.Approve;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
final Roster rosterTwo = Roster.getInstanceFor(connectionTwo);
|
||||
|
||||
rosterTwo.addSubscribeListener(subscribeListener);
|
||||
try {
|
||||
rosterOne.sendSubscriptionRequest(jidTwo);
|
||||
waitUntilOtherEntityIsSubscribed(rosterTwo, jidOne, deadline);
|
||||
}
|
||||
finally {
|
||||
rosterTwo.removeSubscribeListener(subscribeListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue