Search in sources :

Example 41 with EntityBareJid

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

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucRoleTestForWitnessingModeratorRemoval.

/**
 * 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 § 9.7:</p>
 * <blockquote>
 * The service MUST then send updated presence from this individual to all occupants, indicating the removal of
 * moderator status...
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucRoleTestForWitnessingModeratorRemoval() 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 moderatorRevoked(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.grantModerator(nicknameTwo);
        mucAsSeenByOne.revokeModerator(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 42 with EntityBareJid

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

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucAffiliationTestForWitnessingAdmin.

/**
 * 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.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 mucAffiliationTestForWitnessingAdmin() 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 adminGranted(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());
        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 43 with EntityBareJid

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

the class MamIntegrationTest method mamTest.

@SmackIntegrationTest
public void mamTest() throws TimeoutException, Exception {
    EntityBareJid userOne = conOne.getUser().asEntityBareJid();
    EntityBareJid userTwo = conTwo.getUser().asEntityBareJid();
    final String messageBody = "Test MAM message (" + testRunId + ')';
    Message message = conTwo.getStanzaFactory().buildMessageStanza().to(userTwo).setBody(messageBody).build();
    final String messageId = message.getStanzaId();
    final SimpleResultSyncPoint messageReceived = new SimpleResultSyncPoint();
    final StanzaListener stanzaListener = new StanzaListener() {

        @Override
        public void processStanza(Stanza stanza) {
            Message message = (Message) stanza;
            if (message.getBody().equals(messageBody)) {
                messageReceived.signal();
            }
        }
    };
    conTwo.addAsyncStanzaListener(stanzaListener, MessageWithBodiesFilter.INSTANCE);
    try {
        conOne.sendStanza(message);
        messageReceived.waitForResult(timeout);
    } finally {
        conTwo.removeAsyncStanzaListener(stanzaListener);
    }
    MamQueryArgs mamQueryArgs = MamQueryArgs.builder().setResultPageSizeTo(1).limitResultsToJid(userOne).queryLastPage().build();
    MamQuery mamQuery = mamManagerConTwo.queryArchive(mamQueryArgs);
    assertEquals(1, mamQuery.getMessages().size());
    Message mamMessage = mamQuery.getMessages().get(0);
    assertEquals(messageId, mamMessage.getStanzaId());
    assertEquals(messageBody, mamMessage.getBody());
    assertEquals(conOne.getUser(), mamMessage.getFrom());
    assertEquals(userTwo, mamMessage.getTo());
}
Also used : Message(org.jivesoftware.smack.packet.Message) Stanza(org.jivesoftware.smack.packet.Stanza) StanzaListener(org.jivesoftware.smack.StanzaListener) MamQuery(org.jivesoftware.smackx.mam.MamManager.MamQuery) EntityBareJid(org.jxmpp.jid.EntityBareJid) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) MamQueryArgs(org.jivesoftware.smackx.mam.MamManager.MamQueryArgs) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)

Example 44 with EntityBareJid

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

the class MultiUserChatIntegrationTest method mucLeaveTest.

/**
 * Asserts that when a user leaves a room, they are themselves included on the list of users notified (self-presence).
 *
 * <p>From XEP-0045 § 7.14:</p>
 * <blockquote>
 * The service MUST then send a presence stanzas of type "unavailable" from the departing user's occupant JID to
 * the departing occupant's full JIDs, including a status code of "110" to indicate that this notification is
 * "self-presence"
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucLeaveTest() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest-leave");
    MultiUserChat muc = mucManagerOne.getMultiUserChat(mucAddress);
    try {
        muc.join(Resourcepart.from("nick-one"));
        Presence reflectedLeavePresence = muc.leave();
        MUCUser mucUser = MUCUser.from(reflectedLeavePresence);
        assertNotNull(mucUser);
        assertTrue(mucUser.getStatus().contains(MUCUser.Status.PRESENCE_TO_SELF_110));
        assertEquals(mucAddress + "/nick-one", reflectedLeavePresence.getFrom().toString());
        assertEquals(conOne.getUser().asEntityFullJidIfPossible().toString(), reflectedLeavePresence.getTo().toString());
    } finally {
        // We need to be in the room to destroy the room
        muc.join(Resourcepart.from("nick-one"));
        tryDestroy(muc);
    }
}
Also used : MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Presence(org.jivesoftware.smack.packet.Presence) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 45 with EntityBareJid

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

the class MultiUserChatIntegrationTest method mucDestroyTest.

/**
 * Asserts that a user is notified when a room is destroyed
 *
 * <p>From XEP-0045 § 10.9:</p>
 * <blockquote>
 * A room owner MUST be able to destroy a room, especially if the room is persistent... The room removes all users from the room... and destroys the room
 * </blockquote>
 *
 * @throws TimeoutException when roomDestroyed event doesn't get fired
 * @throws Exception when other errors occur
 */
@SmackIntegrationTest
public void mucDestroyTest() throws TimeoutException, Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest-destroy");
    MultiUserChat muc = mucManagerOne.getMultiUserChat(mucAddress);
    muc.join(Resourcepart.from("nick-one"));
    final SimpleResultSyncPoint mucDestroyed = new SimpleResultSyncPoint();
    @SuppressWarnings("deprecation") DefaultUserStatusListener userStatusListener = new DefaultUserStatusListener() {

        @Override
        public void roomDestroyed(MultiUserChat alternateMUC, String reason) {
            mucDestroyed.signal();
        }
    };
    muc.addUserStatusListener(userStatusListener);
    assertEquals(1, mucManagerOne.getJoinedRooms().size());
    assertEquals(1, muc.getOccupantsCount());
    assertNotNull(muc.getNickname());
    try {
        muc.destroy("Dummy reason", null);
        mucDestroyed.waitForResult(timeout);
    } finally {
        muc.removeUserStatusListener(userStatusListener);
    }
    assertEquals(0, mucManagerOne.getJoinedRooms().size());
    assertEquals(0, muc.getOccupantsCount());
    assertNull(muc.getNickname());
}
Also used : EntityBareJid(org.jxmpp.jid.EntityBareJid) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) 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