From 22e3f463fac3f64c514f891eb1e5be3536d3d1dd Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sun, 11 Nov 2018 16:32:45 +0100 Subject: [PATCH] Utilize RosterIntegrationTest methods Use RosterIntegrationTest.ensureBothAccountsAreSubscribedToEachOther() to subscribe users to another. --- .../AbstractTwoUsersOmemoIntegrationTest.java | 4 +- .../smackx/omemo/OmemoManagerSetupHelper.java | 53 ------------------- 2 files changed, 2 insertions(+), 55 deletions(-) diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/AbstractTwoUsersOmemoIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/AbstractTwoUsersOmemoIntegrationTest.java index b53b831bb..5f38bded6 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/AbstractTwoUsersOmemoIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/AbstractTwoUsersOmemoIntegrationTest.java @@ -23,6 +23,7 @@ import java.util.logging.Level; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.roster.RosterIntegrationTest; import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment; import org.igniterealtime.smack.inttest.TestNotPossibleException; @@ -53,8 +54,7 @@ public abstract class AbstractTwoUsersOmemoIntegrationTest extends AbstractOmemo assertFalse(alice.getDeviceId().equals(bob.getDeviceId())); // Subscribe presences - OmemoManagerSetupHelper.syncSubscribePresence(alice.getConnection(), bob.getConnection(), "bob", null); - OmemoManagerSetupHelper.syncSubscribePresence(bob.getConnection(), alice.getConnection(), "alice", null); + RosterIntegrationTest.ensureBothAccountsAreSubscribedToEachOther(alice.getConnection(), bob.getConnection(), timeout); OmemoManagerSetupHelper.trustAllIdentitiesWithTests(alice, bob); // Alice trusts Bob's devices OmemoManagerSetupHelper.trustAllIdentitiesWithTests(bob, alice); // Bob trusts Alice' and Mallory's devices diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/OmemoManagerSetupHelper.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/OmemoManagerSetupHelper.java index 8f5556ba6..0c2e7fa34 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/OmemoManagerSetupHelper.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/omemo/OmemoManagerSetupHelper.java @@ -25,8 +25,6 @@ import java.util.HashMap; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; -import org.jivesoftware.smack.packet.Presence; -import org.jivesoftware.smack.roster.PresenceEventListener; import org.jivesoftware.smack.roster.Roster; import org.jivesoftware.smack.roster.RosterEntry; import org.jivesoftware.smackx.omemo.exceptions.CannotEstablishOmemoSessionException; @@ -40,61 +38,10 @@ import org.jivesoftware.smackx.pubsub.PubSubException; import org.jivesoftware.smackx.pubsub.PubSubManager; import com.google.common.collect.Maps; -import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint; -import org.jxmpp.jid.BareJid; -import org.jxmpp.jid.FullJid; -import org.jxmpp.jid.Jid; public class OmemoManagerSetupHelper { - /** - * Synchronously subscribes presence. - * @param subscriber connection of user which subscribes. - * @param target connection of user which gets subscribed. - * @param targetNick nick of the subscribed user. - * @param targetGroups groups of the user. - * @throws Exception - */ - public static void syncSubscribePresence(final XMPPConnection subscriber, - final XMPPConnection target, - String targetNick, - String[] targetGroups) - throws Exception { - final SimpleResultSyncPoint subscribed = new SimpleResultSyncPoint(); - - Roster subscriberRoster = Roster.getInstanceFor(subscriber); - Roster targetRoster = Roster.getInstanceFor(target); - - targetRoster.setSubscriptionMode(Roster.SubscriptionMode.accept_all); - subscriberRoster.addPresenceEventListener(new PresenceEventListener() { - @Override - public void presenceAvailable(FullJid address, Presence availablePresence) { - } - - @Override - public void presenceUnavailable(FullJid address, Presence presence) { - } - - @Override - public void presenceError(Jid address, Presence errorPresence) { - subscribed.signalFailure(); - } - - @Override - public void presenceSubscribed(BareJid address, Presence subscribedPresence) { - subscribed.signal(); - } - - @Override - public void presenceUnsubscribed(BareJid address, Presence unsubscribedPresence) { - } - }); - - subscriberRoster.createEntry(target.getUser().asBareJid(), targetNick, targetGroups); - - subscribed.waitForResult(10 * 1000); - } public static void trustAllIdentities(OmemoManager alice, OmemoManager bob) throws InterruptedException, SmackException.NotConnectedException, SmackException.NotLoggedInException,