test/net/java/sip/communicator/slick/protocol/jabber/TestOperationSetMultiUserChat2.java
/**
     * In <tt>testJoinLeave</tt>, we join a room then leave it and see if the
     * reported <tt>ChatRoom</tt> members are reflecting our actions.
     */
In testJoinLeave, we join a room then leave it and see if the
reported ChatRoom members are reflecting our actions.
In testJoinLeave we join a room then leave it and see if the reported ChatRoom members are reflecting our actions .
public void testLeave()
        throws OperationFailedException,
               OperationNotSupportedException
    {
        String testRoomName = testRoomBaseName + roomID++;
        ChatRoom opSet1Room =
            opSetMUC1.createChatRoom(testRoomName, null);
        opSet1Room.join();
        ChatRoom opSet2Room = opSetMUC2.findRoom(testRoomName);
        if (opSet2Room.isJoined())
            opSet2Room.leave();
        assertFalse("user is in a room he left or didnt joined"
            , opSet2Room.isJoined());
        MUCEventCollector opSet1RoomCollector =
            new MUCEventCollector(opSet1Room, MUCEventCollector.EVENT_PRESENCE);
        MUCEventCollector opSet2RoomCollector =
            new MUCEventCollector(opSet2Room, MUCEventCollector.EVENT_PRESENCE);
        opSet2Room.join();
        opSet2RoomCollector.waitForEvent(10000);
        opSet1RoomCollector.waitForEvent(10000);
        assertEquals("a room member has not been notified that someone else " +
            "joined the room"
            , 1, opSet1RoomCollector.collectedEvents.size());
        assertTrue("user failed to join a room", opSet2Room.isJoined());
        assertTrue("user nickname not found in the room after join "
            , nameIsOnMemberList(
            opSet2Room.getUserNickname(), opSet2Room.getMembers()));
        assertTrue("user nickname not found in the room after join, " +
            "from peer side"
            , nameIsOnMemberList(
            opSet2Room.getUserNickname(), opSet1Room.getMembers()));
        opSet1RoomCollector.collectedEvents.clear();
        opSet2Room.leave();
        opSet1RoomCollector.waitForEvent(10000);
        assertFalse("an user is reported present in a room he left"
            , opSet2Room.isJoined());
        assertFalse("user nickname is still on the room list after he left"
            , nameIsOnMemberList(opSet2Room.getUserNickname()
            , opSet2Room.getMembers()));
        assertEquals("an user joined and left and a room member missed events "
            , 1, opSet1RoomCollector.collectedEvents.size());
        ChatRoomMemberPresenceChangeEvent memberEvent =
            (ChatRoomMemberPresenceChangeEvent)
            opSet1RoomCollector.collectedEvents.get(0);
        assertEquals("user received an event of the wrong type "
            , ChatRoomMemberPresenceChangeEvent.MEMBER_LEFT
            , memberEvent.getEventType());
        assertEquals("the user who left is not the expected one"
            , fixture.userID2
            , memberEvent.getChatRoomMember().getContactAddress());
        assertFalse("user nickname is still on the room list after he left, " +
            "from the peer side"
            , nameIsOnMemberList(opSet2Room.getUserNickname()
            , opSet1Room.getMembers()));
    }
public void testLeave ( ) throws OperationFailedException , OperationNotSupportedException { String testRoomName = testRoomBaseName + roomID ++ ; ChatRoom opSet1Room = opSetMUC1 . createChatRoom ( testRoomName , null ) ; opSet1Room . join ( ) ; ChatRoom opSet2Room = opSetMUC2 . findRoom ( testRoomName ) ; if ( opSet2Room . isJoined ( ) ) opSet2Room . leave ( ) ; assertFalse ( "user is in a room he left or didnt joined" , opSet2Room . isJoined ( ) ) ; MUCEventCollector opSet1RoomCollector = new MUCEventCollector ( opSet1Room , MUCEventCollector . EVENT_PRESENCE ) ; MUCEventCollector opSet2RoomCollector = new MUCEventCollector ( opSet2Room , MUCEventCollector . EVENT_PRESENCE ) ; opSet2Room . join ( ) ; opSet2RoomCollector . waitForEvent ( 10000 ) ; opSet1RoomCollector . waitForEvent ( 10000 ) ; assertEquals ( "a room member has not been notified that someone else " + "joined the room" , 1 , opSet1RoomCollector . collectedEvents . size ( ) ) ; assertTrue ( "user failed to join a room" , opSet2Room . isJoined ( ) ) ; assertTrue ( "user nickname not found in the room after join " , nameIsOnMemberList ( opSet2Room . getUserNickname ( ) , opSet2Room . getMembers ( ) ) ) ; assertTrue ( "user nickname not found in the room after join, " + "from peer side" , nameIsOnMemberList ( opSet2Room . getUserNickname ( ) , opSet1Room . getMembers ( ) ) ) ; opSet1RoomCollector . collectedEvents . clear ( ) ; opSet2Room . leave ( ) ; opSet1RoomCollector . waitForEvent ( 10000 ) ; assertFalse ( "an user is reported present in a room he left" , opSet2Room . isJoined ( ) ) ; assertFalse ( "user nickname is still on the room list after he left" , nameIsOnMemberList ( opSet2Room . getUserNickname ( ) , opSet2Room . getMembers ( ) ) ) ; assertEquals ( "an user joined and left and a room member missed events " , 1 , opSet1RoomCollector . collectedEvents . size ( ) ) ; ChatRoomMemberPresenceChangeEvent memberEvent = ( ChatRoomMemberPresenceChangeEvent ) opSet1RoomCollector . collectedEvents . get ( 0 ) ; assertEquals ( "user received an event of the wrong type " , ChatRoomMemberPresenceChangeEvent . MEMBER_LEFT , memberEvent . getEventType ( ) ) ; assertEquals ( "the user who left is not the expected one" , fixture . userID2 , memberEvent . getChatRoomMember ( ) . getContactAddress ( ) ) ; assertFalse ( "user nickname is still on the room list after he left, " + "from the peer side" , nameIsOnMemberList ( opSet2Room . getUserNickname ( ) , opSet1Room . getMembers ( ) ) ) ; }
In <tt>testJoinLeave</tt>, we join a room then leave it and see if the
 reported <tt>ChatRoom</tt> members are reflecting our actions.
In <tt > testJoinLeave< / tt > we join a room then leave it and see if the reported <tt > ChatRoom< / tt > members are reflecting our actions .
// we create the test room // first be sure to be outside the room // does users received events since a member joined // checking if the user is listed with the right nickname //and we check on the other side // leaving // the nickname shouldnt be listed anymore // and the other side // does user1 received notifcation since user2 left