Search in sources :

Example 46 with EntityBareJid

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

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucTestDefaultRoleForAffiliationInMembersOnlyRoom.

/**
 * Asserts that a members-only room assigns the correct default roles for a given affiliation
 *
 * <p>From XEP-0045 § 5.1.2:</p>
 * <blockquote>
 * ...the initial default roles that a service SHOULD set based on the user's affiliation...
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucTestDefaultRoleForAffiliationInMembersOnlyRoom() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest-membersonlyroles");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress);
    final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
    final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
    final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);
    final EntityFullJid jidOne = JidCreate.entityFullFrom(mucAddress, nicknameOne);
    final EntityFullJid jidTwo = JidCreate.entityFullFrom(mucAddress, nicknameTwo);
    final EntityFullJid jidThree = JidCreate.entityFullFrom(mucAddress, nicknameThree);
    createMembersOnlyMuc(mucAsSeenByOne, nicknameOne);
    final ResultSyncPoint<String, Exception> adminResultSyncPoint = new ResultSyncPoint<>();
    mucAsSeenByOne.addParticipantStatusListener(new ParticipantStatusListener() {

        @Override
        public void adminGranted(EntityFullJid participant) {
            adminResultSyncPoint.signal("done");
        }
    });
    try {
        mucAsSeenByOne.grantMembership(conTwo.getUser().asBareJid());
        mucAsSeenByOne.grantMembership(conThree.getUser().asBareJid());
        mucAsSeenByTwo.join(nicknameTwo);
        mucAsSeenByThree.join(nicknameThree);
        mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid());
        adminResultSyncPoint.waitForResult(timeout);
        assertEquals(mucAsSeenByOne.getOccupantsCount(), 3);
        assertEquals(MUCRole.moderator, mucAsSeenByOne.getOccupant(jidOne).getRole());
        assertEquals(MUCRole.moderator, mucAsSeenByOne.getOccupant(jidTwo).getRole());
        assertEquals(MUCRole.participant, mucAsSeenByOne.getOccupant(jidThree).getRole());
    } finally {
        tryDestroy(mucAsSeenByOne);
    }
}
Also used : EntityFullJid(org.jxmpp.jid.EntityFullJid) ResultSyncPoint(org.igniterealtime.smack.inttest.util.ResultSyncPoint) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackException(org.jivesoftware.smack.SmackException) TestNotPossibleException(org.igniterealtime.smack.inttest.TestNotPossibleException) XMPPException(org.jivesoftware.smack.XMPPException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 47 with EntityBareJid

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

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucRoleTestForWitnessingRevokingVoice.

/**
 * Asserts that a user who is present when another user undergoes a role change receives that change as a presence update
 *
 * <p>From XEP-0045 § 5.1.3:</p>
 * <blockquote>
 * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change
 * to all occupants...
 * </blockquote>
 *
 * <p>From XEP-0045 § 8.4:</p>
 * <blockquote>
 * The service MUST then send updated presence from this individual to all occupants, indicating the removal of
 * voice privileges...
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucRoleTestForWitnessingRevokingVoice() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress);
    final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();
    mucAsSeenByThree.addParticipantStatusListener(new ParticipantStatusListener() {

        @Override
        public void voiceRevoked(EntityFullJid participant) {
            resultSyncPoint.signal("done");
        }
    });
    createMuc(mucAsSeenByOne, "one-" + randomString);
    try {
        final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
        final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);
        mucAsSeenByTwo.join(nicknameTwo);
        mucAsSeenByThree.join(nicknameThree);
        mucAsSeenByOne.revokeVoice(nicknameTwo);
        resultSyncPoint.waitForResult(timeout);
    } finally {
        tryDestroy(mucAsSeenByOne);
    }
}
Also used : EntityFullJid(org.jxmpp.jid.EntityFullJid) ResultSyncPoint(org.igniterealtime.smack.inttest.util.ResultSyncPoint) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackException(org.jivesoftware.smack.SmackException) TestNotPossibleException(org.igniterealtime.smack.inttest.TestNotPossibleException) XMPPException(org.jivesoftware.smack.XMPPException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 48 with EntityBareJid

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

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucRoleTestForReceivingModerator.

/**
 * Asserts that a user who undergoes a role change receives that change as a presence update
 *
 * <p>From XEP-0045 § 5.1.3:</p>
 * <blockquote>
 * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change
 * to all occupants...
 * </blockquote>
 *
 * <p>From XEP-0045 § 9.6:</p>
 * <blockquote>
 * The service MUST then send updated presence from this individual to all occupants, indicating the addition of
 * moderator status...
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucRoleTestForReceivingModerator() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
    final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();
    mucAsSeenByTwo.addUserStatusListener(new UserStatusListener() {

        @Override
        public void moderatorGranted() {
            resultSyncPoint.signal("done");
        }
    });
    createMuc(mucAsSeenByOne, "one-" + randomString);
    try {
        final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
        mucAsSeenByTwo.join(nicknameTwo);
        // This implicitly tests "The service MUST add the user to the moderator list and then inform the admin of
        // success" in §9.6, since it'll throw on either an error IQ or on no response.
        mucAsSeenByOne.grantModerator(nicknameTwo);
        resultSyncPoint.waitForResult(timeout);
    } finally {
        tryDestroy(mucAsSeenByOne);
    }
}
Also used : ResultSyncPoint(org.igniterealtime.smack.inttest.util.ResultSyncPoint) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackException(org.jivesoftware.smack.SmackException) TestNotPossibleException(org.igniterealtime.smack.inttest.TestNotPossibleException) XMPPException(org.jivesoftware.smack.XMPPException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 49 with EntityBareJid

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

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucRoleTestForRevokingVoice.

/**
 * Asserts that a user in an unmoderated room who undergoes an afilliation change receives that change as a presence update
 *
 * <p>From XEP-0045 § 5.1.3:</p>
 * <blockquote>
 * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change
 * to all occupants...
 * </blockquote>
 *
 * <p>From XEP-0045 § 8.4:</p>
 * <blockquote>
 * The service MUST then send updated presence from this individual to all occupants, indicating the removal of
 * voice privileges...
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucRoleTestForRevokingVoice() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
    final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();
    mucAsSeenByTwo.addUserStatusListener(new UserStatusListener() {

        @Override
        public void voiceRevoked() {
            resultSyncPoint.signal("done");
        }
    });
    createMuc(mucAsSeenByOne, "one-" + randomString);
    try {
        final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
        mucAsSeenByTwo.join(nicknameTwo);
        mucAsSeenByOne.revokeVoice(nicknameTwo);
        resultSyncPoint.waitForResult(timeout);
    } finally {
        tryDestroy(mucAsSeenByOne);
    }
}
Also used : ResultSyncPoint(org.igniterealtime.smack.inttest.util.ResultSyncPoint) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackException(org.jivesoftware.smack.SmackException) TestNotPossibleException(org.igniterealtime.smack.inttest.TestNotPossibleException) XMPPException(org.jivesoftware.smack.XMPPException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 50 with EntityBareJid

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

the class XmppConnectionManager method disconnectAndCleanup.

void disconnectAndCleanup() throws InterruptedException {
    int successfullyDeletedAccountsCount = 0;
    for (AbstractXMPPConnection connection : connections.keySet()) {
        if (sinttestConfiguration.accountRegistration == AccountRegistration.inBandRegistration) {
            // Note that we use the account manager from the to-be-deleted connection.
            AccountManager accountManager = AccountManager.getInstance(connection);
            try {
                accountManager.deleteAccount();
                successfullyDeletedAccountsCount++;
            } catch (NoResponseException | XMPPErrorException | NotConnectedException e) {
                LOGGER.log(Level.WARNING, "Could not delete dynamically registered account", e);
            }
        }
        connection.disconnect();
        if (sinttestConfiguration.accountRegistration == AccountRegistration.serviceAdministration) {
            String username = connection.getConfiguration().getUsername().toString();
            Localpart usernameAsLocalpart;
            try {
                usernameAsLocalpart = Localpart.from(username);
            } catch (XmppStringprepException e) {
                throw new AssertionError(e);
            }
            EntityBareJid connectionAddress = JidCreate.entityBareFrom(usernameAsLocalpart, sinttestConfiguration.service);
            try {
                adminManager.deleteUser(connectionAddress);
                successfullyDeletedAccountsCount++;
            } catch (NoResponseException | XMPPErrorException | NotConnectedException e) {
                LOGGER.log(Level.WARNING, "Could not delete dynamically registered account", e);
            }
        }
    }
    if (sinttestConfiguration.isAccountRegistrationPossible()) {
        int unsuccessfullyDeletedAccountsCount = connections.size() - successfullyDeletedAccountsCount;
        if (unsuccessfullyDeletedAccountsCount == 0) {
            LOGGER.info("Successfully deleted all created accounts ✔");
        } else {
            LOGGER.warning("Could not delete all created accounts, " + unsuccessfullyDeletedAccountsCount + " remainaing");
        }
    }
    connections.clear();
    if (accountRegistrationConnection != null) {
        accountRegistrationConnection.disconnect();
    }
}
Also used : XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) Localpart(org.jxmpp.jid.parts.Localpart) AccountManager(org.jivesoftware.smackx.iqregister.AccountManager) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) EntityBareJid(org.jxmpp.jid.EntityBareJid) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection)

Aggregations

EntityBareJid (org.jxmpp.jid.EntityBareJid)56 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)30 XMPPException (org.jivesoftware.smack.XMPPException)21 Resourcepart (org.jxmpp.jid.parts.Resourcepart)21 SmackException (org.jivesoftware.smack.SmackException)20 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)16 ResultSyncPoint (org.igniterealtime.smack.inttest.util.ResultSyncPoint)16 EntityFullJid (org.jxmpp.jid.EntityFullJid)15 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)6 Presence (org.jivesoftware.smack.packet.Presence)6 Jid (org.jxmpp.jid.Jid)6 Message (org.jivesoftware.smack.packet.Message)5 ArrayList (java.util.ArrayList)4 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)4 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)4 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)4 UserJid (com.xabber.android.data.entity.UserJid)3 HashMap (java.util.HashMap)3 IOException (java.io.IOException)2 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)2