2015-03-18 09:52:33 +01:00
|
|
|
/**
|
|
|
|
*
|
2020-04-04 13:03:31 +02:00
|
|
|
* Copyright 2015-2020 Florian Schmaus
|
2015-03-18 09:52:33 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smackx.muc;
|
|
|
|
|
2020-10-03 16:34:18 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
2020-04-12 21:54:18 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
2020-10-03 16:34:18 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
2020-04-12 21:54:18 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
2018-12-26 21:39:25 +01:00
|
|
|
|
2020-05-14 12:59:20 +02:00
|
|
|
import java.util.concurrent.TimeoutException;
|
2015-03-18 09:52:33 +01:00
|
|
|
|
|
|
|
import org.jivesoftware.smack.MessageListener;
|
2021-06-15 14:03:03 +02:00
|
|
|
import org.jivesoftware.smack.SmackException;
|
|
|
|
import org.jivesoftware.smack.XMPPException;
|
2015-03-18 09:52:33 +01:00
|
|
|
import org.jivesoftware.smack.packet.Message;
|
2018-12-26 21:39:25 +01:00
|
|
|
import org.jivesoftware.smack.packet.Presence;
|
2019-10-24 15:45:08 +02:00
|
|
|
|
2018-12-26 21:39:25 +01:00
|
|
|
import org.jivesoftware.smackx.muc.packet.MUCUser;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
|
|
|
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
|
|
|
import org.igniterealtime.smack.inttest.TestNotPossibleException;
|
2020-04-12 21:54:18 +02:00
|
|
|
import org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest;
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.igniterealtime.smack.inttest.util.ResultSyncPoint;
|
2020-05-14 12:59:20 +02:00
|
|
|
import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint;
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.jxmpp.jid.EntityBareJid;
|
2015-03-18 09:52:33 +01:00
|
|
|
import org.jxmpp.jid.parts.Resourcepart;
|
|
|
|
|
2021-06-15 14:03:03 +02:00
|
|
|
public class MultiUserChatIntegrationTest extends AbstractMultiUserChatIntegrationTest {
|
2015-03-18 09:52:33 +01:00
|
|
|
|
2020-04-04 13:03:31 +02:00
|
|
|
public MultiUserChatIntegrationTest(SmackIntegrationTestEnvironment environment)
|
2021-06-15 14:03:03 +02:00
|
|
|
throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException,
|
|
|
|
InterruptedException, TestNotPossibleException {
|
2015-03-18 09:52:33 +01:00
|
|
|
super(environment);
|
|
|
|
}
|
|
|
|
|
2021-04-07 11:32:58 +02:00
|
|
|
/**
|
|
|
|
* Asserts that when a user joins a room, they are themselves included on the list of users notified (self-presence).
|
|
|
|
*
|
|
|
|
* <p>From XEP-0045 § 7.2.2:</p>
|
|
|
|
* <blockquote>
|
|
|
|
* ...the service MUST also send presence from the new participant's occupant JID to the full JIDs of all the
|
|
|
|
* occupants (including the new occupant)
|
|
|
|
* </blockquote>
|
|
|
|
*
|
|
|
|
* @throws Exception when errors occur
|
|
|
|
*/
|
2018-12-26 21:39:25 +01:00
|
|
|
@SmackIntegrationTest
|
2021-04-07 11:32:58 +02:00
|
|
|
public void mucJoinTest() throws Exception {
|
2021-06-15 14:03:03 +02:00
|
|
|
EntityBareJid mucAddress = getRandomRoom("smack-inttest-join");
|
2018-12-26 21:39:25 +01:00
|
|
|
|
|
|
|
MultiUserChat muc = mucManagerOne.getMultiUserChat(mucAddress);
|
2021-04-07 11:32:58 +02:00
|
|
|
try {
|
|
|
|
Presence reflectedJoinPresence = muc.join(Resourcepart.from("nick-one"));
|
2018-12-26 21:39:25 +01:00
|
|
|
|
2021-04-07 11:32:58 +02:00
|
|
|
MUCUser mucUser = MUCUser.from(reflectedJoinPresence);
|
2018-12-26 21:39:25 +01:00
|
|
|
|
2021-04-07 11:32:58 +02:00
|
|
|
assertNotNull(mucUser);
|
|
|
|
assertTrue(mucUser.getStatus().contains(MUCUser.Status.PRESENCE_TO_SELF_110));
|
|
|
|
assertEquals(mucAddress + "/nick-one", reflectedJoinPresence.getFrom().toString());
|
2021-04-23 17:50:33 +02:00
|
|
|
assertEquals(conOne.getUser().asEntityFullJidIfPossible().toString(), reflectedJoinPresence.getTo().toString());
|
2021-04-07 11:32:58 +02:00
|
|
|
} finally {
|
|
|
|
tryDestroy(muc);
|
|
|
|
}
|
|
|
|
}
|
2018-12-26 21:39:25 +01:00
|
|
|
|
2021-04-07 11:32:58 +02:00
|
|
|
/**
|
|
|
|
* 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 {
|
2021-06-15 14:03:03 +02:00
|
|
|
EntityBareJid mucAddress = getRandomRoom("smack-inttest-leave");
|
2018-12-26 21:39:25 +01:00
|
|
|
|
2021-04-07 11:32:58 +02:00
|
|
|
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());
|
2021-04-23 17:50:33 +02:00
|
|
|
assertEquals(conOne.getUser().asEntityFullJidIfPossible().toString(), reflectedLeavePresence.getTo().toString());
|
2021-04-07 11:32:58 +02:00
|
|
|
} finally {
|
2021-06-15 14:03:03 +02:00
|
|
|
muc.join(Resourcepart.from("nick-one")); // We need to be in the room to destroy the room
|
2021-04-07 11:32:58 +02:00
|
|
|
tryDestroy(muc);
|
|
|
|
}
|
2018-12-26 21:39:25 +01:00
|
|
|
}
|
|
|
|
|
2015-03-18 09:52:33 +01:00
|
|
|
@SmackIntegrationTest
|
2017-12-13 23:10:11 +01:00
|
|
|
public void mucTest() throws Exception {
|
2021-06-15 14:03:03 +02:00
|
|
|
EntityBareJid mucAddress = getRandomRoom("smack-inttest-message");
|
2015-03-18 09:52:33 +01:00
|
|
|
|
|
|
|
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
|
|
|
|
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
|
|
|
|
|
|
|
|
final String mucMessage = "Smack Integration Test MUC Test Message " + randomString;
|
|
|
|
final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();
|
|
|
|
|
|
|
|
mucAsSeenByTwo.addMessageListener(new MessageListener() {
|
|
|
|
@Override
|
|
|
|
public void processMessage(Message message) {
|
|
|
|
String body = message.getBody();
|
|
|
|
if (mucMessage.equals(body)) {
|
|
|
|
resultSyncPoint.signal(body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-06-21 14:52:18 +02:00
|
|
|
createMuc(mucAsSeenByOne, "one-" + randomString);
|
2015-03-18 09:52:33 +01:00
|
|
|
mucAsSeenByTwo.join(Resourcepart.from("two-" + randomString));
|
|
|
|
mucAsSeenByOne.sendMessage(mucMessage);
|
2021-04-07 11:32:58 +02:00
|
|
|
try {
|
|
|
|
resultSyncPoint.waitForResult(timeout);
|
|
|
|
} catch (TimeoutException e) {
|
|
|
|
throw new AssertionError("Failed to receive presence", e);
|
|
|
|
} finally {
|
|
|
|
tryDestroy(mucAsSeenByOne);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-17 21:32:10 +02:00
|
|
|
|
2021-04-23 16:14:51 +02:00
|
|
|
/**
|
2021-06-15 14:03:03 +02:00
|
|
|
* Asserts that a user is notified when a room is destroyed
|
2021-04-23 16:14:51 +02:00
|
|
|
*
|
|
|
|
* <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
|
2020-05-14 12:59:20 +02:00
|
|
|
public void mucDestroyTest() throws TimeoutException, Exception {
|
|
|
|
|
2021-06-15 14:03:03 +02:00
|
|
|
EntityBareJid mucAddress = getRandomRoom("smack-inttest-destroy");
|
2020-05-14 12:59:20 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-10-03 16:34:18 +02:00
|
|
|
assertEquals(1, mucManagerOne.getJoinedRooms().size());
|
|
|
|
assertEquals(1, muc.getOccupantsCount());
|
|
|
|
assertNotNull(muc.getNickname());
|
2020-05-14 12:59:20 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
muc.destroy("Dummy reason", null);
|
|
|
|
mucDestroyed.waitForResult(timeout);
|
|
|
|
} finally {
|
|
|
|
muc.removeUserStatusListener(userStatusListener);
|
|
|
|
}
|
|
|
|
|
2020-10-03 16:34:18 +02:00
|
|
|
assertEquals(0, mucManagerOne.getJoinedRooms().size());
|
|
|
|
assertEquals(0, muc.getOccupantsCount());
|
|
|
|
assertNull(muc.getNickname());
|
2020-05-14 12:59:20 +02:00
|
|
|
}
|
2021-04-07 11:32:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-18 09:52:33 +01:00
|
|
|
}
|