Skip to content

Commit

Permalink
WIP: Kick presence tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fishbowler committed Apr 17, 2021
1 parent 35c645e commit 0e69633
Showing 1 changed file with 88 additions and 5 deletions.
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -646,6 +645,90 @@ public void adminRevoked(EntityFullJid participant) {
}
}

/**
* Asserts that a user who gets kicked receives that change as a presence update
*
* <p>From XEP-0045 § ???:</p>
* <blockquote>
* ???
* </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);
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.");
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
*
* <p>From XEP-0045 § ???:</p>
* <blockquote>
* ???
* </blockquote>
*
* @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<Presence, Exception> 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 {

Expand Down

0 comments on commit 0e69633

Please sign in to comment.