Search in sources :

Example 21 with EntityBareJid

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

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucAffiliationTestForReceivingAdmin.

/**
 * Asserts that a user who undergoes an affiliation change receives that change as a presence update
 *
 * <p>From XEP-0045 § 5.2.2:</p>
 * <blockquote>
 * ...a MUC service implementation MUST change the user's affiliation to reflect the change and communicate that
 * to all occupants...
 * </blockquote>
 *
 * <p>From XEP-0045 § 10.6:</p>
 * <blockquote>
 * If the user is in the room, the service MUST then send updated presence from this individual to all occupants,
 * indicating the granting of admin status...
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucAffiliationTestForReceivingAdmin() 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 adminGranted() {
            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 admin list and then inform the owner of success" in §10.6, since it'll throw on either an error IQ or on no response.
        mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid());
        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 22 with EntityBareJid

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

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucTestDefaultRoleForAffiliationInModeratedRoom.

/**
 * Asserts that a moderated 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 mucTestDefaultRoleForAffiliationInModeratedRoom() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest-moderatedroles");
    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 ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();
    mucAsSeenByOne.addParticipantStatusListener(new ParticipantStatusListener() {

        @Override
        public void adminGranted(EntityFullJid participant) {
            resultSyncPoint.signal("done");
        }
    });
    createModeratedMuc(mucAsSeenByOne, nicknameOne);
    final MUCRole threeRole;
    switch(sinttestConfiguration.compatibilityMode) {
        default:
            threeRole = MUCRole.visitor;
            break;
        case ejabberd:
            threeRole = MUCRole.participant;
            break;
    }
    try {
        mucAsSeenByTwo.join(nicknameTwo);
        mucAsSeenByThree.join(nicknameThree);
        mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid());
        resultSyncPoint.waitForResult(timeout);
        assertEquals(mucAsSeenByOne.getOccupantsCount(), 3);
        assertEquals(MUCRole.moderator, mucAsSeenByOne.getOccupant(JidCreate.entityFullFrom(mucAddress, nicknameOne)).getRole());
        assertEquals(MUCRole.moderator, mucAsSeenByOne.getOccupant(JidCreate.entityFullFrom(mucAddress, nicknameTwo)).getRole());
        assertEquals(threeRole, mucAsSeenByOne.getOccupant(JidCreate.entityFullFrom(mucAddress, nicknameThree)).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 23 with EntityBareJid

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

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucAffiliationTestForWitnessingAdminRemoval.

/**
 * Asserts that a user who is present when another user undergoes an affiliation change receives that change as a presence update
 *
 * <p>From XEP-0045 § 5.2.2:</p>
 * <blockquote>
 * ...a MUC service implementation MUST change the user's affiliation to reflect the change and communicate that to
 * all occupants...
 * </blockquote>
 *
 * <p>From XEP-0045 § 10.7:</p>
 * <blockquote>
 * If the user is in the room, the service MUST then send updated presence from this individual to all occupants,
 * indicating the loss of admin status by sending a presence element...
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucAffiliationTestForWitnessingAdminRemoval() 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 adminRevoked(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.grantAdmin(conTwo.getUser().asBareJid());
        mucAsSeenByOne.revokeAdmin(conTwo.getUser().asEntityBareJid());
        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 24 with EntityBareJid

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

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucPresenceTestForGettingKicked.

/**
 * Asserts that a user who gets kicked receives that change as a presence update
 *
 * <p>From XEP-0045 § 8.2:</p>
 * <blockquote>
 * The kick is performed based on the occupant's room nickname and is completed by setting the role of a
 * participant or visitor to a value of "none".
 *
 * The service MUST remove the kicked occupant by sending a presence stanza of type "unavailable" to each kicked
 * occupant, including status code 307 in the extended presence information, optionally along with the reason (if
 * provided) and the roomnick or bare JID of the user who initiated the kick.
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucPresenceTestForGettingKicked() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
    createMuc(mucAsSeenByOne, "one-" + randomString);
    try {
        final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
        mucAsSeenByTwo.join(nicknameTwo);
        final ResultSyncPoint<Presence, Exception> resultSyncPoint = new ResultSyncPoint<>();
        mucAsSeenByTwo.addParticipantListener(kickPresence -> resultSyncPoint.signal(kickPresence));
        mucAsSeenByOne.kickParticipant(nicknameTwo, "Nothing personal. Just a test.");
        Presence kickPresence = resultSyncPoint.waitForResult(timeout);
        MUCUser mucUser = MUCUser.from(kickPresence);
        assertNotNull(mucUser);
        assertAll(() -> assertTrue(mucUser.getStatus().contains(MUCUser.Status.PRESENCE_TO_SELF_110), "Missing self-presence status code in kick presence"), () -> assertTrue(mucUser.getStatus().contains(MUCUser.Status.KICKED_307), "Missing kick status code in kick presence"), () -> assertEquals(MUCRole.none, mucUser.getItem().getRole(), "Role other than 'none' in kick presence"));
        Jid itemJid = mucUser.getItem().getJid();
        if (itemJid != null) {
            assertEquals(conTwo.getUser().asEntityFullJidIfPossible(), itemJid, "Incorrect kicked user in kick presence");
        }
    } finally {
        tryDestroy(mucAsSeenByOne);
    }
}
Also used : MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) ResultSyncPoint(org.igniterealtime.smack.inttest.util.ResultSyncPoint) Presence(org.jivesoftware.smack.packet.Presence) 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 25 with EntityBareJid

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

the class IncomingMessageListenerIntegrationTest method test.

@SmackIntegrationTest
public void test() throws Exception {
    final String body = StringUtils.randomString(16);
    final SimpleResultSyncPoint syncPoint = new SimpleResultSyncPoint();
    final IncomingChatMessageListener listener = new IncomingChatMessageListener() {

        @Override
        public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {
            if (body.equals(message.getBody())) {
                syncPoint.signal();
            }
        }
    };
    try {
        chatManagerTwo.addIncomingListener(listener);
        Chat chat = chatManagerOne.chatWith(conTwo.getUser().asEntityBareJid());
        chat.send(body);
        syncPoint.waitForResult(timeout);
    } finally {
        chatManagerTwo.removeIncomingListener(listener);
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

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