Skip to content

Commit

Permalink
Merge pull request #586 from guusdk/sint_muc-defaultaffilition-order
Browse files Browse the repository at this point in the history
[sinttest] Refactoring XEP-0045 test for default roles
  • Loading branch information
Flowdalic authored Apr 10, 2024
2 parents 6b300ec + 900b252 commit 355cc4e
Showing 1 changed file with 45 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.Set;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;

import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
Expand Down Expand Up @@ -687,22 +689,30 @@ public void mucTestDefaultRoleForAffiliationInUnmoderatedRoom() throws Exception
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);

final EntityFullJid jidOne = JidCreate.entityFullFrom(mucAddress, nicknameOne);
final EntityFullJid jidTwo = JidCreate.entityFullFrom(mucAddress, nicknameTwo);
final EntityFullJid jidThree = JidCreate.entityFullFrom(mucAddress, nicknameThree);

createMuc(mucAsSeenByOne, nicknameOne);
try {
mucAsSeenByTwo.join(nicknameTwo);
mucAsSeenByThree.join(nicknameThree);

final SimpleResultSyncPoint resultSyncPoint = new SimpleResultSyncPoint();
mucAsSeenByOne.addParticipantStatusListener(new ParticipantStatusListener() {
@Override
public void adminGranted(EntityFullJid participant) {
resultSyncPoint.signal();
final SimpleResultSyncPoint allOccupantsDetectedSyncPoint = new SimpleResultSyncPoint();
final Set<EntityFullJid> expectedOccupants = Set.of(jidOne, jidTwo, jidThree);
mucAsSeenByOne.addParticipantStatusListener(new ParticipantStatusListener() {
@Override
public void joined(EntityFullJid participant) {
if (mucAsSeenByOne.getOccupants().containsAll(expectedOccupants)) {
allOccupantsDetectedSyncPoint.signal();
}
});
}
});

try {
mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid());
resultSyncPoint.waitForResult(timeout);

assertEquals(3, mucAsSeenByOne.getOccupantsCount(), "Unexpected occupant count in room " + mucAddress);
mucAsSeenByTwo.join(nicknameTwo);
mucAsSeenByThree.join(nicknameThree);

assertResult(allOccupantsDetectedSyncPoint, "Expected " + conOne.getUser() + " to observe all of these occupants in room " + mucAddress + ", but not all of them appear to be in: " + expectedOccupants.stream().map(Object::toString).collect(Collectors.joining(", ")));
assertEquals(MUCRole.moderator, mucAsSeenByOne.getOccupant(JidCreate.entityFullFrom(mucAddress, nicknameOne)).getRole(),
"Unexpected role for occupant " + nicknameOne + " of " + mucAddress);
assertEquals(MUCRole.moderator, mucAsSeenByOne.getOccupant(JidCreate.entityFullFrom(mucAddress, nicknameTwo)).getRole(),
Expand Down Expand Up @@ -732,16 +742,23 @@ public void mucTestDefaultRoleForAffiliationInModeratedRoom() throws Exception {
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);

final SimpleResultSyncPoint resultSyncPoint = new SimpleResultSyncPoint();
final EntityFullJid jidOne = JidCreate.entityFullFrom(mucAddress, nicknameOne);
final EntityFullJid jidTwo = JidCreate.entityFullFrom(mucAddress, nicknameTwo);
final EntityFullJid jidThree = JidCreate.entityFullFrom(mucAddress, nicknameThree);

createModeratedMuc(mucAsSeenByOne, nicknameOne);

final SimpleResultSyncPoint allOccupantsDetectedSyncPoint = new SimpleResultSyncPoint();
final Set<EntityFullJid> expectedOccupants = Set.of(jidOne, jidTwo, jidThree);
mucAsSeenByOne.addParticipantStatusListener(new ParticipantStatusListener() {
@Override
public void adminGranted(EntityFullJid participant) {
resultSyncPoint.signal();
public void joined(EntityFullJid participant) {
if (mucAsSeenByOne.getOccupants().containsAll(expectedOccupants)) {
allOccupantsDetectedSyncPoint.signal();
}
}
});

createModeratedMuc(mucAsSeenByOne, nicknameOne);

final MUCRole threeRole;
switch (sinttestConfiguration.compatibilityMode) {
default:
Expand All @@ -753,12 +770,12 @@ public void adminGranted(EntityFullJid participant) {
}

try {
mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid());

mucAsSeenByTwo.join(nicknameTwo);
mucAsSeenByThree.join(nicknameThree);
mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid());
resultSyncPoint.waitForResult(timeout);

assertEquals(3, mucAsSeenByOne.getOccupantsCount(), "Unexpected occupant count in room " + mucAddress);
assertResult(allOccupantsDetectedSyncPoint, "Expected " + conOne.getUser() + " to observe all of these occupants in room " + mucAddress + ", but not all of them appear to be in: " + expectedOccupants.stream().map(Object::toString).collect(Collectors.joining(", ")));
assertEquals(MUCRole.moderator, mucAsSeenByOne.getOccupant(JidCreate.entityFullFrom(mucAddress, nicknameOne)).getRole(),
"Unexpected role for occupant " + nicknameOne + " of " + mucAddress);
assertEquals(MUCRole.moderator, mucAsSeenByOne.getOccupant(JidCreate.entityFullFrom(mucAddress, nicknameTwo)).getRole(),
Expand Down Expand Up @@ -794,23 +811,26 @@ public void mucTestDefaultRoleForAffiliationInMembersOnlyRoom() throws Exception

createMembersOnlyMuc(mucAsSeenByOne, nicknameOne);

final SimpleResultSyncPoint adminResultSyncPoint = new SimpleResultSyncPoint();
final SimpleResultSyncPoint allOccupantsDetectedSyncPoint = new SimpleResultSyncPoint();
final Set<EntityFullJid> expectedOccupants = Set.of(jidOne, jidTwo, jidThree);
mucAsSeenByOne.addParticipantStatusListener(new ParticipantStatusListener() {
@Override
public void adminGranted(EntityFullJid participant) {
adminResultSyncPoint.signal();
public void joined(EntityFullJid participant) {
if (mucAsSeenByOne.getOccupants().containsAll(expectedOccupants)) {
allOccupantsDetectedSyncPoint.signal();
}
}
});

try {
mucAsSeenByOne.grantMembership(conTwo.getUser().asBareJid());
mucAsSeenByOne.grantMembership(conThree.getUser().asBareJid());
mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid());

mucAsSeenByTwo.join(nicknameTwo);
mucAsSeenByThree.join(nicknameThree);
mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid());
adminResultSyncPoint.waitForResult(timeout);
assertEquals(3, mucAsSeenByOne.getOccupantsCount(), "Unexpected occupant count in room " + mucAddress);

assertResult(allOccupantsDetectedSyncPoint, "Expected " + conOne.getUser() + " to observe all of these occupants in room " + mucAddress + ", but not all of them appear to be in: " + expectedOccupants.stream().map(Object::toString).collect(Collectors.joining(", ")));
assertEquals(MUCRole.moderator, mucAsSeenByOne.getOccupant(jidOne).getRole(), "Unexpected role for occupant " + jidOne + " in room " + mucAddress);
assertEquals(MUCRole.moderator, mucAsSeenByOne.getOccupant(jidTwo).getRole(), "Unexpected role for occupant " + jidTwo + " in room " + mucAddress);
assertEquals(MUCRole.participant, mucAsSeenByOne.getOccupant(jidThree).getRole(), "Unexpected role for occupant " + jidThree + " in room " + mucAddress);
Expand Down

0 comments on commit 355cc4e

Please sign in to comment.