Skip to main content
summaryrefslogtreecommitdiffstats
blob: 065b2c2e249760320cbe1200d2cbd057ec5f1a5a (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
/****************************************************************************
 * Copyright (c) 2004 Composent, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Composent, Inc. - initial API and implementation
 *****************************************************************************/

package org.eclipse.ecf.tests.presence;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.presence.chatroom.IChatRoomContainer;
import org.eclipse.ecf.presence.chatroom.IChatRoomInfo;
import org.eclipse.ecf.presence.chatroom.IChatRoomInvitationListener;
import org.eclipse.ecf.presence.chatroom.IChatRoomInvitationSender;
import org.eclipse.ecf.presence.chatroom.IChatRoomManager;

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

	IChatRoomManager chat0, chat1 = null;
	public static final int WAITTIME = 20000;
	public static final String CHAT_ROOM_NAME = System.getProperty("chat.room.name");

	List<ID> invitationsReceived = new ArrayList<ID>();

	Object synchObject = new Object();

	IChatRoomInvitationListener invitationListener = new IChatRoomInvitationListener() {
		public void handleInvitationReceived(ID roomID, ID from, String subject, String body) {
			System.out.println("handleInvitationReceived(" + roomID + "," + from + "," + subject + "," + body + ")");
			invitationsReceived.add(roomID);
			synchronized (synchObject) {
				synchObject.notify();
			}
		}
	};

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.tests.presence.AbstractPresenceTestCase#setUp()
	 */
	protected void setUp() throws Exception {
		setClientCount(2);
		clients = createClients();
		chat0 = getPresenceAdapter(0).getChatRoomManager();
		chat1 = getPresenceAdapter(1).getChatRoomManager();
		chat1.addInvitationListener(invitationListener);
		for (int i = 0; i < 2; i++) {
			connectClient(i);
		}
	}

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

	public void testSendInvitation() throws Exception {
		final IChatRoomInvitationSender invitationSender = chat0.getInvitationSender();
		assertNotNull(invitationSender);
		final IChatRoomInfo roomInfo = chat0.getChatRoomInfo(CHAT_ROOM_NAME);
		final IChatRoomContainer chatRoomContainer = roomInfo.createChatRoomContainer();
		chatRoomContainer.connect(roomInfo.getRoomID(), null);
		invitationSender.sendInvitation(roomInfo.getRoomID(), getClient(1).getConnectedID(), null, "this is an invitation");
		try {
			synchronized (synchObject) {
				synchObject.wait(WAITTIME);
			}
		} catch (final Exception e) {
			throw e;
		}
		assertHasEvent(invitationsReceived, ID.class);
	}

}

Back to the top