From 0e6963330804580a43f82b61f667fc40163189da Mon Sep 17 00:00:00 2001 From: Dan Caseley Date: Sat, 17 Apr 2021 20:32:10 +0100 Subject: [PATCH] WIP: Kick presence tests --- .../muc/MultiUserChatIntegrationTest.java | 93 ++++++++++++++++++- 1 file changed, 88 insertions(+), 5 deletions(-) diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatIntegrationTest.java index 28a9f26b3a..40ab0e6aba 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatIntegrationTest.java @@ -16,16 +16,12 @@ */ package org.jivesoftware.smackx.muc; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - import java.util.List; import java.util.concurrent.TimeoutException; import java.util.logging.Level; import org.jivesoftware.smack.MessageListener; +import org.jivesoftware.smack.PresenceListener; import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPException.XMPPErrorException; @@ -45,11 +41,14 @@ import org.jxmpp.jid.DomainBareJid; import org.jxmpp.jid.EntityBareJid; import org.jxmpp.jid.EntityFullJid; +import org.jxmpp.jid.Jid; import org.jxmpp.jid.impl.JidCreate; import org.jxmpp.jid.parts.Localpart; import org.jxmpp.jid.parts.Resourcepart; import org.jxmpp.stringprep.XmppStringprepException; +import static org.junit.jupiter.api.Assertions.*; + public class MultiUserChatIntegrationTest extends AbstractSmackIntegrationTest { private final String randomString = StringUtils.insecureRandomString(6); @@ -646,6 +645,90 @@ public void adminRevoked(EntityFullJid participant) { } } + /** + * Asserts that a user who gets kicked receives that change as a presence update + * + *

From XEP-0045 § ???:

+ *
+ * ??? + *
+ * + * @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); + final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); + mucAsSeenByTwo.join(nicknameTwo); + + final ResultSyncPoint resultSyncPoint = new ResultSyncPoint<>(); + mucAsSeenByTwo.addParticipantListener(kickPresence -> resultSyncPoint.signal(kickPresence)); + + mucAsSeenByOne.kickParticipant(nicknameTwo, "Nothing personal. Just a test."); + try { + Presence kickPresence = resultSyncPoint.waitForResult(timeout); + MUCUser mucUser = MUCUser.from(kickPresence); + assertAll( + () -> assertNotNull(mucUser), + () -> 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"), + () -> assertTrue(mucUser.getItem().getJid().isEntityFullJid(), "No kicked user in kick presence"), + () -> assertEquals(mucUser.getItem().getJid().toString(), conTwo.getUser().asEntityFullJidIfPossible().toString(), "Incorrect kicked user in kick presence") + ); + } finally { + tryDestroy(mucAsSeenByOne); + } + } + + /** + * Asserts that a user who is present when another user gets kicked receives that change as a presence update + * + *

From XEP-0045 § ???:

+ *
+ * ??? + *
+ * + * @throws Exception when errors occur + */ + @SmackIntegrationTest + public void mucPresenceTestForWitnessingKick() throws Exception { + EntityBareJid mucAddress = getRandomRoom("smack-inttest"); + + MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress); + MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress); + + createMUC(mucAsSeenByOne, "one-" + randomString); + final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString); + final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString); + mucAsSeenByTwo.join(nicknameTwo); + mucAsSeenByThree.join(nicknameThree); + + final ResultSyncPoint resultSyncPoint = new ResultSyncPoint<>(); + mucAsSeenByThree.addParticipantListener(kickPresence -> resultSyncPoint.signal(kickPresence)); + + mucAsSeenByOne.kickParticipant(nicknameTwo, "Nothing personal. Just a test."); + try { + Presence kickPresence = resultSyncPoint.waitForResult(timeout); + MUCUser mucUser = MUCUser.from(kickPresence); + assertAll( + () -> assertNotNull(mucUser), + () -> assertFalse(mucUser.getStatus().contains(MUCUser.Status.PRESENCE_TO_SELF_110), "Incorrect self-presence status code in kick presence"), + () -> assertTrue(mucUser.getStatus().contains(MUCUser.Status.KICKED_307), "Missing kick status code in kick presence"), + () -> assertTrue(mucUser.getItem().getJid().isEntityFullJid(), "No kicked user in kick presence"), + () -> assertEquals(mucUser.getItem().getJid().toString(), conTwo.getUser().asEntityFullJidIfPossible().toString(), "Incorrect kicked user in kick presence") + ); + } finally { + tryDestroy(mucAsSeenByOne); + } + + } + @SmackIntegrationTest public void mucDestroyTest() throws TimeoutException, Exception {