test/net/java/sip/communicator/slick/protocol/jabber/TestOperationSetMultiUserChat2.java
/**
     * <tt>testInviteJoin</tt> reproduces the following scenario : user1
     * invite user2. user2 retrieves the room where he is invited then,
     * he joins it.
     */
testInviteJoin reproduces the following scenario : user1
invite user2. user2 retrieves the room where he is invited then,
he joins it.
testInviteJoin reproduces the following scenario : user1 invite user2 . user2 retrieves the room where he is invited then he joins it .
public void testInviteJoin()
        throws OperationFailedException,
               OperationNotSupportedException, XmppStringprepException
    {
        String testRoomName = testRoomBaseName + roomID++;
        ChatRoom opSet1Room =
            opSetMUC1.createChatRoom(testRoomName, null);
        opSet1Room.join();
        MUCEventCollector opSet1RoomCollector =
            new MUCEventCollector(
            opSet1Room, MUCEventCollector.EVENT_PRESENCE);
        MUCEventCollector opSet2Collector =
            new MUCEventCollector(opSetMUC2, MUCEventCollector.EVENT_INVITE);
        opSet1Room.invite(fixture.userID2, "testInviteAccept");
        opSet2Collector.waitForEvent(10000);
        assertEquals("the invitation has not been received"
            , 1, opSet2Collector.collectedEvents.size());
        ChatRoomInvitationReceivedEvent invitationReceivedEvent =
            (ChatRoomInvitationReceivedEvent)
            opSet2Collector.collectedEvents.get(0);
        ChatRoomInvitation invitation = invitationReceivedEvent.getInvitation();
        assertEquals("The inviter is not the expected user",
            JidCreate.bareFrom(fixture.userID1),
            JidCreate.bareFrom(invitation.getInviter()));
        assertEquals("The invitation reason received differs from the one sent"
            , "testInviteAccept", invitation.getReason());
        ChatRoom opSet2Room = invitation.getTargetChatRoom();
        MUCEventCollector opSet2RoomCollector =
            new MUCEventCollector(opSet2Room, MUCEventCollector.EVENT_PRESENCE);
        opSet2Collector =
            new MUCEventCollector(opSetMUC2, MUCEventCollector.EVENT_PRESENCE);
        opSet2Room.join();
        opSet2Collector.waitForEvent(10000);      
        opSet2RoomCollector.waitForEvent(10000);  
        opSet1RoomCollector.waitForEvent(10000);  
        assertEquals("a room member has not been notified that someone " +
            "joined the room"
            , 1, opSet1RoomCollector.collectedEvents.size());
        assertEquals("a room member has not been notified that someone " +
            "joined the room"
            , 1, opSet2RoomCollector.collectedEvents.size());
        ChatRoomMemberPresenceChangeEvent memberEvent =
            (ChatRoomMemberPresenceChangeEvent)
            opSet1RoomCollector.collectedEvents.get(0);
        assertEquals("user received an event of the wrong type "
            , ChatRoomMemberPresenceChangeEvent.MEMBER_JOINED
            , memberEvent.getEventType());
        assertEquals("the user who joined is not the one who was invited"
            , fixture.userID2
            , memberEvent.getChatRoomMember().getContactAddress());
        assertEquals("there is not exactly two members in the room"
            , 2, opSet1Room.getMembersCount());
        assertEquals("user hasn't been notified of its own join"
            , 1, opSet2Collector.collectedEvents.size());
        LocalUserChatRoomPresenceChangeEvent localEvent =
            (LocalUserChatRoomPresenceChangeEvent)
            opSet2Collector.collectedEvents.get(0);
        assertEquals("the event user2 received is not LOCAL_USER_JOINED"
            , LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_JOINED
            , localEvent.getEventType());
        assertEquals("the same room reports different members count " +
            "from one side to other"
            , opSet1Room.getMembers().size()
            , opSet2Room.getMembers().size());
        assertTrue("user is not listed in the room with his nickname",
            nameIsOnMemberList(
            opSet2Room.getUserNickname(), opSet2Room.getMembers()));
        assertTrue("user is not listed in the room with his nickname ,from " +
            "peer side",
            nameIsOnMemberList(
            opSet2Room.getUserNickname(), opSet1Room.getMembers()));
    }
public void testInviteJoin ( ) throws OperationFailedException , OperationNotSupportedException , XmppStringprepException { String testRoomName = testRoomBaseName + roomID ++ ; ChatRoom opSet1Room = opSetMUC1 . createChatRoom ( testRoomName , null ) ; opSet1Room . join ( ) ; MUCEventCollector opSet1RoomCollector = new MUCEventCollector ( opSet1Room , MUCEventCollector . EVENT_PRESENCE ) ; MUCEventCollector opSet2Collector = new MUCEventCollector ( opSetMUC2 , MUCEventCollector . EVENT_INVITE ) ; opSet1Room . invite ( fixture . userID2 , "testInviteAccept" ) ; opSet2Collector . waitForEvent ( 10000 ) ; assertEquals ( "the invitation has not been received" , 1 , opSet2Collector . collectedEvents . size ( ) ) ; ChatRoomInvitationReceivedEvent invitationReceivedEvent = ( ChatRoomInvitationReceivedEvent ) opSet2Collector . collectedEvents . get ( 0 ) ; ChatRoomInvitation invitation = invitationReceivedEvent . getInvitation ( ) ; assertEquals ( "The inviter is not the expected user" , JidCreate . bareFrom ( fixture . userID1 ) , JidCreate . bareFrom ( invitation . getInviter ( ) ) ) ; assertEquals ( "The invitation reason received differs from the one sent" , "testInviteAccept" , invitation . getReason ( ) ) ; ChatRoom opSet2Room = invitation . getTargetChatRoom ( ) ; MUCEventCollector opSet2RoomCollector = new MUCEventCollector ( opSet2Room , MUCEventCollector . EVENT_PRESENCE ) ; opSet2Collector = new MUCEventCollector ( opSetMUC2 , MUCEventCollector . EVENT_PRESENCE ) ; opSet2Room . join ( ) ; opSet2Collector . waitForEvent ( 10000 ) ; opSet2RoomCollector . waitForEvent ( 10000 ) ; opSet1RoomCollector . waitForEvent ( 10000 ) ; assertEquals ( "a room member has not been notified that someone " + "joined the room" , 1 , opSet1RoomCollector . collectedEvents . size ( ) ) ; assertEquals ( "a room member has not been notified that someone " + "joined the room" , 1 , opSet2RoomCollector . collectedEvents . size ( ) ) ; ChatRoomMemberPresenceChangeEvent memberEvent = ( ChatRoomMemberPresenceChangeEvent ) opSet1RoomCollector . collectedEvents . get ( 0 ) ; assertEquals ( "user received an event of the wrong type " , ChatRoomMemberPresenceChangeEvent . MEMBER_JOINED , memberEvent . getEventType ( ) ) ; assertEquals ( "the user who joined is not the one who was invited" , fixture . userID2 , memberEvent . getChatRoomMember ( ) . getContactAddress ( ) ) ; assertEquals ( "there is not exactly two members in the room" , 2 , opSet1Room . getMembersCount ( ) ) ; assertEquals ( "user hasn't been notified of its own join" , 1 , opSet2Collector . collectedEvents . size ( ) ) ; LocalUserChatRoomPresenceChangeEvent localEvent = ( LocalUserChatRoomPresenceChangeEvent ) opSet2Collector . collectedEvents . get ( 0 ) ; assertEquals ( "the event user2 received is not LOCAL_USER_JOINED" , LocalUserChatRoomPresenceChangeEvent . LOCAL_USER_JOINED , localEvent . getEventType ( ) ) ; assertEquals ( "the same room reports different members count " + "from one side to other" , opSet1Room . getMembers ( ) . size ( ) , opSet2Room . getMembers ( ) . size ( ) ) ; assertTrue ( "user is not listed in the room with his nickname" , nameIsOnMemberList ( opSet2Room . getUserNickname ( ) , opSet2Room . getMembers ( ) ) ) ; assertTrue ( "user is not listed in the room with his nickname ,from " + "peer side" , nameIsOnMemberList ( opSet2Room . getUserNickname ( ) , opSet1Room . getMembers ( ) ) ) ; }
<tt>testInviteJoin</tt> reproduces the following scenario : user1
 invite user2.
<tt > testInviteJoin< / tt > reproduces the following scenario : user1 invite user2 .
// we create the test room //make sure the invitation has been received // does the invitation comes from user1 with the correct reason //user accept the invitation // listening for user2 own join // listening for user1 join // listening for user2 join // we know check if both member received events // is user2 notified of its own join // both sides should report the same members number. // here we use opSet2Room.getMembers().size() rather than // opSet2Room.getMembersCount() because the last method will not // be always accurate for a newly joined jabber room (stated in // the smack lib) //user2 must be on room members list now //and he must be listed on both sides