Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a12da3ecccb43bb9c10d5839e1ddebc33493c459 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/****************************************************************************
 * Copyright (c) 2004 Composent, Inc. and others.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * Contributors:
 *    Composent, Inc. - initial API and implementation
 *
 * SPDX-License-Identifier: EPL-2.0
 *****************************************************************************/

package org.eclipse.ecf.tests.presence;

import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.user.IUser;
import org.eclipse.ecf.presence.IPresence;
import org.eclipse.ecf.presence.chatroom.IChatRoomContainer;
import org.eclipse.ecf.presence.chatroom.IChatRoomInfo;
import org.eclipse.ecf.presence.chatroom.IChatRoomManager;
import org.eclipse.ecf.presence.chatroom.IChatRoomParticipantListener;

/**
 * 
 */
public abstract class AbstractChatRoomParticipantTest extends AbstractPresenceTestCase {

	IChatRoomContainer chatRoomContainer0, chatRoomContainer1 = null;
	public static final int WAITTIME = 20000;
	public static final String CHAT_ROOM_NAME = System.getProperty("chat.room.name");

	protected IChatRoomParticipantListener participantListener0 = new IChatRoomParticipantListener() {
		public void handleArrived(IUser participant) {
			System.out.println("0.handleArrived(" + participant + ")");
		}

		public void handleDeparted(IUser participant) {
			System.out.println("0.handleDeparted(" + participant + ")");
		}

		public void handlePresenceUpdated(ID fromID, IPresence presence) {
			System.out.println("0.handlePresenceUpdated(" + fromID + "," + presence + ")");
		}

		public void handleUpdated(IUser updatedParticipant) {
			System.out.println("0.handleUpdated(" + updatedParticipant + ")");
		}
	};

	protected IChatRoomParticipantListener participantListener1 = new IChatRoomParticipantListener() {
		public void handleArrived(IUser participant) {
			System.out.println("1.handleArrived(" + participant + ")");
		}

		public void handleDeparted(IUser participant) {
			System.out.println("1.handleDeparted(" + participant + ")");
		}

		public void handlePresenceUpdated(ID fromID, IPresence presence) {
			System.out.println("0.handlePresenceUpdated(" + fromID + "," + presence + ")");
		}

		public void handleUpdated(IUser updatedParticipant) {
			System.out.println("1.handleUpdated(" + updatedParticipant + ")");
		}
	};

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.tests.presence.AbstractPresenceTestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
		setClientCount(2);
		clients = createClients();
		IChatRoomManager chat0, chat1;
		chat0 = getPresenceAdapter(0).getChatRoomManager();
		chat1 = getPresenceAdapter(1).getChatRoomManager();
		for (int i = 0; i < getClientCount(); i++) {
			connectClient(i);
		}
		final IChatRoomInfo roomInfo0 = chat0.getChatRoomInfo(CHAT_ROOM_NAME);
		if (roomInfo0 == null) return;
		chatRoomContainer0 = roomInfo0.createChatRoomContainer();
		chatRoomContainer0.addChatRoomParticipantListener(participantListener0);
		chatRoomContainer0.connect(roomInfo0.getRoomID(), null);
		final IChatRoomInfo roomInfo1 = chat1.getChatRoomInfo(CHAT_ROOM_NAME);
		chatRoomContainer1 = roomInfo1.createChatRoomContainer();
		chatRoomContainer1.addChatRoomParticipantListener(participantListener1);
		chatRoomContainer1.connect(roomInfo1.getRoomID(), null);
		Thread.sleep(2000);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		disconnectClients();
	}

	public void testGetChatRoomParticipants0() throws Exception {
		if (chatRoomContainer0 == null) return;
		final ID[] participants = chatRoomContainer0.getChatRoomParticipants();
		assertNotNull(participants);
		assertTrue(participants.length == getClientCount());
	}

	public void testGetChatRoomParticipants1() throws Exception {
		if (chatRoomContainer1 == null) return;
		final ID[] participants = chatRoomContainer1.getChatRoomParticipants();
		assertNotNull(participants);
		assertTrue(participants.length == getClientCount());
	}

	public void testGetChatRoomParticipants2() throws Exception {
		if (chatRoomContainer0 == null) return;
		chatRoomContainer0.disconnect();
		Thread.sleep(2000);
		final ID[] participants = chatRoomContainer1.getChatRoomParticipants();
		assertNotNull(participants);
		assertTrue(participants.length == (getClientCount() - 1));
	}

	public void testGetChatRoomParticipants3() throws Exception {
		if (chatRoomContainer1 == null) return;
		chatRoomContainer1.disconnect();
		final ID[] participants = chatRoomContainer1.getChatRoomParticipants();
		assertNotNull(participants);
		assertTrue(participants.length == 0);
	}

	public void testGetChatRoomParticipants4() throws Exception {
		if (chatRoomContainer1 == null) return;
		chatRoomContainer1.disconnect();
		Thread.sleep(2000);
		final ID[] participants = chatRoomContainer0.getChatRoomParticipants();
		assertNotNull(participants);
		assertTrue(participants.length == (getClientCount() - 1));
	}

	public void testGetChatRoomParticipants5() throws Exception {
		if (chatRoomContainer0 == null) return;
		chatRoomContainer0.disconnect();
		final ID[] participants = chatRoomContainer0.getChatRoomParticipants();
		assertNotNull(participants);
		assertTrue(participants.length == 0);
	}

}

Back to the top