use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucAffiliationTestForReceivingAdmin.
/**
* Asserts that a user who 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 mucAffiliationTestForReceivingAdmin() throws Exception {
EntityBareJid mucAddress = getRandomRoom("smack-inttest");
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();
mucAsSeenByTwo.addUserStatusListener(new UserStatusListener() {
@Override
public void adminGranted() {
resultSyncPoint.signal("done");
}
});
createMuc(mucAsSeenByOne, "one-" + randomString);
try {
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
mucAsSeenByTwo.join(nicknameTwo);
// This implicitly tests "The service MUST add the user to the admin list and then inform the owner of success" in §10.6, since it'll throw on either an error IQ or on no response.
mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid());
resultSyncPoint.waitForResult(timeout);
} finally {
tryDestroy(mucAsSeenByOne);
}
}
use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucTestDefaultRoleForAffiliationInModeratedRoom.
/**
* Asserts that a moderated room assigns the correct default roles for a given affiliation
*
* <p>From XEP-0045 § 5.1.2:</p>
* <blockquote>
* ...the initial default roles that a service SHOULD set based on the user's affiliation...
* </blockquote>
*
* @throws Exception when errors occur
*/
@SmackIntegrationTest
public void mucTestDefaultRoleForAffiliationInModeratedRoom() throws Exception {
EntityBareJid mucAddress = getRandomRoom("smack-inttest-moderatedroles");
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress);
final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);
final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();
mucAsSeenByOne.addParticipantStatusListener(new ParticipantStatusListener() {
@Override
public void adminGranted(EntityFullJid participant) {
resultSyncPoint.signal("done");
}
});
createModeratedMuc(mucAsSeenByOne, nicknameOne);
final MUCRole threeRole;
switch(sinttestConfiguration.compatibilityMode) {
default:
threeRole = MUCRole.visitor;
break;
case ejabberd:
threeRole = MUCRole.participant;
break;
}
try {
mucAsSeenByTwo.join(nicknameTwo);
mucAsSeenByThree.join(nicknameThree);
mucAsSeenByOne.grantAdmin(conTwo.getUser().asBareJid());
resultSyncPoint.waitForResult(timeout);
assertEquals(mucAsSeenByOne.getOccupantsCount(), 3);
assertEquals(MUCRole.moderator, mucAsSeenByOne.getOccupant(JidCreate.entityFullFrom(mucAddress, nicknameOne)).getRole());
assertEquals(MUCRole.moderator, mucAsSeenByOne.getOccupant(JidCreate.entityFullFrom(mucAddress, nicknameTwo)).getRole());
assertEquals(threeRole, mucAsSeenByOne.getOccupant(JidCreate.entityFullFrom(mucAddress, nicknameThree)).getRole());
} finally {
tryDestroy(mucAsSeenByOne);
}
}
use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucAffiliationTestForWitnessingAdminRemoval.
/**
* 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.7:</p>
* <blockquote>
* If the user is in the room, the service MUST then send updated presence from this individual to all occupants,
* indicating the loss of admin status by sending a presence element...
* </blockquote>
*
* @throws Exception when errors occur
*/
@SmackIntegrationTest
public void mucAffiliationTestForWitnessingAdminRemoval() 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 adminRevoked(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());
mucAsSeenByOne.revokeAdmin(conTwo.getUser().asEntityBareJid());
resultSyncPoint.waitForResult(timeout);
} finally {
tryDestroy(mucAsSeenByOne);
}
}
use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucPresenceTestForGettingKicked.
/**
* Asserts that a user who gets kicked receives that change as a presence update
*
* <p>From XEP-0045 § 8.2:</p>
* <blockquote>
* The kick is performed based on the occupant's room nickname and is completed by setting the role of a
* participant or visitor to a value of "none".
*
* The service MUST remove the kicked occupant by sending a presence stanza of type "unavailable" to each kicked
* occupant, including status code 307 in the extended presence information, optionally along with the reason (if
* provided) and the roomnick or bare JID of the user who initiated the kick.
* </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);
try {
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.");
Presence kickPresence = resultSyncPoint.waitForResult(timeout);
MUCUser mucUser = MUCUser.from(kickPresence);
assertNotNull(mucUser);
assertAll(() -> 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"), () -> assertEquals(MUCRole.none, mucUser.getItem().getRole(), "Role other than 'none' in kick presence"));
Jid itemJid = mucUser.getItem().getJid();
if (itemJid != null) {
assertEquals(conTwo.getUser().asEntityFullJidIfPossible(), itemJid, "Incorrect kicked user in kick presence");
}
} finally {
tryDestroy(mucAsSeenByOne);
}
}
use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class IncomingMessageListenerIntegrationTest method test.
@SmackIntegrationTest
public void test() throws Exception {
final String body = StringUtils.randomString(16);
final SimpleResultSyncPoint syncPoint = new SimpleResultSyncPoint();
final IncomingChatMessageListener listener = new IncomingChatMessageListener() {
@Override
public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {
if (body.equals(message.getBody())) {
syncPoint.signal();
}
}
};
try {
chatManagerTwo.addIncomingListener(listener);
Chat chat = chatManagerOne.chatWith(conTwo.getUser().asEntityBareJid());
chat.send(body);
syncPoint.waitForResult(timeout);
} finally {
chatManagerTwo.removeIncomingListener(listener);
}
}
Aggregations