// Check that user2 doesn't have a reserved nickname yet
String reservedNickname = muc2.getReservedNickname();
assertNull("Reserved nickname is not null", reservedNickname);
// User2 registers with the room and reserves a nickname
Form registrationForm = muc2.getRegistrationForm();
Form answerForm = registrationForm.createAnswerForm();
answerForm.setAnswer("muc#register_first", "MyFirstName");
answerForm.setAnswer("muc#register_last", "MyLastName");
answerForm.setAnswer("muc#register_roomnick", "MyNick");
muc2.sendRegistrationForm(answerForm);
// Check that user2 has a reserved nickname
reservedNickname = muc2.getReservedNickname();
assertEquals("Reserved nickname is wrong", "MyNick", reservedNickname);
// Check that user2 can join the room using his reserved nickname
muc2.join("MyNick");
muc2.leave();
// Check that other users cannot join the room with user2's reserved nickname
MultiUserChat muc3 = new MultiUserChat(getConnection(2), room);
try {
muc3.join("MyNick");
fail("Other user was able to join with other user's reserved nickname");
}
catch (XMPPException e) {
XMPPError xmppError = e.getXMPPError();
assertNotNull(
"No XMPPError was received when joining with other user's reserved nickname",
xmppError);
assertEquals(
"Different error code was received while joining with other user's reserved nickname",
409,
xmppError.getCode());
}
// Check that user3 can join the room using his own nickname (not reserved)
muc3.join("MyNotReservedNick");
muc3.leave();
// Check that another user cannot reserve an already reserved nickname
registrationForm = muc3.getRegistrationForm();
answerForm = registrationForm.createAnswerForm();
answerForm.setAnswer("muc#register_first", "MyFirstName 2");
answerForm.setAnswer("muc#register_last", "MyLastName 2");
answerForm.setAnswer("muc#register_roomnick", "MyNick");
try {
muc3.sendRegistrationForm(answerForm);
}
catch (XMPPException e) {
XMPPError xmppError = e.getXMPPError();
assertNotNull(
"No XMPPError was received when reserving an already reserved nickname",
xmppError);
assertEquals(
"Different error code was received while reserving an already reserved nickname",
409,
xmppError.getCode());
}
// Check that another user can reserve a new nickname
registrationForm = muc3.getRegistrationForm();
answerForm = registrationForm.createAnswerForm();
answerForm.setAnswer("muc#register_first", "MyFirstName 2");
answerForm.setAnswer("muc#register_last", "MyLastName 2");
answerForm.setAnswer("muc#register_roomnick", "MyNick 2");
muc3.sendRegistrationForm(answerForm);
}
catch (XMPPException e) {
e.printStackTrace();