Search in sources :

Example 51 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest 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 52 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest 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 53 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest 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 54 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest 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 55 with SmackIntegrationTest

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

the class LowLevelRosterIntegrationTest method testPresenceEventListenersOffline.

@SmackIntegrationTest
public void testPresenceEventListenersOffline(final AbstractXMPPConnection conOne, final AbstractXMPPConnection conTwo) throws TimeoutException, Exception {
    IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
    final Roster rosterOne = Roster.getInstanceFor(conOne);
    final Roster rosterTwo = Roster.getInstanceFor(conTwo);
    rosterOne.createItem(conTwo.getUser().asBareJid(), "Con Two", null);
    rosterTwo.createItem(conOne.getUser().asBareJid(), "Con One", null);
    IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
    final SimpleResultSyncPoint offlineTriggered = new SimpleResultSyncPoint();
    rosterOne.addPresenceEventListener(new AbstractPresenceEventListener() {

        @Override
        public void presenceUnavailable(FullJid jid, Presence presence) {
            if (!jid.equals(conTwo.getUser())) {
                return;
            }
            offlineTriggered.signal();
        }
    });
    // Disconnect conTwo, this should cause an 'unavailable' presence to be send from conTwo to
    // conOne.
    conTwo.disconnect();
    Boolean result = offlineTriggered.waitForResult(timeout);
    if (!result) {
        throw new Exception("presenceUnavailable() was not called");
    }
}
Also used : FullJid(org.jxmpp.jid.FullJid) Presence(org.jivesoftware.smack.packet.Presence) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) TimeoutException(java.util.concurrent.TimeoutException) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Aggregations

SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)66 EntityBareJid (org.jxmpp.jid.EntityBareJid)30 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)25 XMPPException (org.jivesoftware.smack.XMPPException)23 SmackException (org.jivesoftware.smack.SmackException)20 Resourcepart (org.jxmpp.jid.parts.Resourcepart)20 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)17 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)17 ResultSyncPoint (org.igniterealtime.smack.inttest.util.ResultSyncPoint)16 EntityFullJid (org.jxmpp.jid.EntityFullJid)12 Message (org.jivesoftware.smack.packet.Message)9 TimeoutException (java.util.concurrent.TimeoutException)8 Presence (org.jivesoftware.smack.packet.Presence)7 SmackIntegrationTestEnvironment (org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment)6 AfterClass (org.igniterealtime.smack.inttest.annotations.AfterClass)6 IntegrationTestRosterUtil (org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil)6 EntityCapabilitiesChangedListener (org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener)6 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)6 PepEventListener (org.jivesoftware.smackx.pep.PepEventListener)6 Assertions (org.junit.jupiter.api.Assertions)6