Added unit tests for MSN ad-hoc multi-user chat.

Added unit tests for Jabber roles in multi-user chat (but not enabled yet).
cusax-fix
Valentin Martinet 16 years ago
parent 93d01f7fbb
commit 24038c7b17

@ -0,0 +1,148 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.slick.protocol.generic;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
/**
* Gather both chat room and chat room members events generated by unit tests.
*
* @author Valentin Martinet
*/
public class AHMUCEventCollector
implements AdHocChatRoomInvitationListener,
AdHocChatRoomInvitationRejectionListener,
AdHocChatRoomMessageListener,
AdHocChatRoomParticipantPresenceListener
{
/**
* Events collector.
*/
public Vector<EventObject> events = new Vector<EventObject>();
/**
* Ad hoc MUC operation set.
*/
public OperationSetAdHocMultiUserChat opSet = null;
/**
* Ad hoc chat room.
*/
public AdHocChatRoom room = null;
/**
* Invite event.
*/
public static final int MESSAGE_EVENT = 1;
/**
* Presence event.
*/
public static final int PRESENCE_EVENT = 2;
/**
* Presence event.
*/
public static final int INVITATION_EVENT = 3;
/**
* Constructor, operation set's side.
*
* @param opSet the operation set which belong to this event collector
* @param evtType event's type
*/
public AHMUCEventCollector(
OperationSetAdHocMultiUserChat pOpSet, int evtType)
{
opSet = pOpSet;
if(evtType == INVITATION_EVENT)
{
opSet.addInvitationListener(this);
opSet.addInvitationRejectionListener(this);
}
}
/**
* Constructor, room's side.
*
* @param pRoom the room which belong to this event collector
* @param evtType event's type
*/
public AHMUCEventCollector(AdHocChatRoom pRoom, int evtType)
{
room = pRoom;
if(evtType == MESSAGE_EVENT)
room.addMessageListener(this);
else if(evtType == PRESENCE_EVENT)
room.addParticipantPresenceListener(this);
}
public void waitForEvent(long howLong)
{
synchronized (this)
{
try
{
wait(howLong);
}
catch (InterruptedException ex)
{
ex.printStackTrace();
}
}
}
public void addEvent(EventObject evt)
{
synchronized (this)
{
events.add(evt);
notifyAll();
}
}
public void invitationReceived(AdHocChatRoomInvitationReceivedEvent evt)
{
addEvent(evt);
}
public void invitationRejected(AdHocChatRoomInvitationRejectedEvent evt)
{
addEvent(evt);
}
public void messageDelivered(AdHocChatRoomMessageDeliveredEvent evt)
{
addEvent(evt);
}
public void messageDeliveryFailed(
AdHocChatRoomMessageDeliveryFailedEvent evt)
{
addEvent(evt);
}
public void messageReceived(AdHocChatRoomMessageReceivedEvent evt)
{
addEvent(evt);
}
public void participantPresenceChanged(
AdHocChatRoomParticipantPresenceChangeEvent evt)
{
addEvent(evt);
}
}

@ -0,0 +1,300 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.slick.protocol.generic;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import net.java.sip.communicator.service.protocol.*;
import org.osgi.framework.*;
import junit.framework.*;
/**
* Generic Slick fixture for ad-hoc multi-user chat.
*
* @author Valentin Martinet
*/
public abstract class AdHocMultiUserChatSlickFixture extends TestCase
{
/**
* To be set by the slick itself upon activation.
*/
public static BundleContext bc = null;
/**
* An osgi service reference for the protocol provider corresponding to our
* first testing account.
*/
public ServiceReference provider1ServiceRef = null;
/**
* The protocol provider corresponding to our first testing account.
*/
public ProtocolProviderService provider1 = null;
/**
* The user ID associated with testing account 1.
*/
public String userID1 = null;
/**
* An osgi service reference for the protocol provider corresponding to our
* second testing account.
*/
public ServiceReference provider2ServiceRef = null;
/**
* The protocol provider corresponding to our second testing account.
*/
public ProtocolProviderService provider2 = null;
/**
* The user ID associated with testing account 2.
*/
public String userID2 = null;
/**
* An osgi service reference for the protocol provider corresponding to our
* third testing account.
*/
public ServiceReference provider3ServiceRef = null;
/**
* The protocol provider corresponding to our third testing account.
*/
public ProtocolProviderService provider3 = null;
/**
* The user ID associated with testing account 3.
*/
public String userID3 = null;
/**
* The tested protocol provider factory.
*/
public ProtocolProviderFactory providerFactory = null;
/**
* Indicates whether the user has requested for onlline tests not to be run.
* (e.g. due to lack of network connectivity or ... time constraints ;)).
*/
public static boolean onlineTestingDisabled = false;
/**
* A Hashtable containing group names mapped against array lists of buddy
* screen names. This is a snapshot of the server stored buddy list for
* the account that is going to be used by the tested implementation.
* It is filled in by the tester agent who'd login with that account
* and initialize the ss contact list before the tested implementation has
* actually done so.
*/
public static Hashtable<String, List<String>> preInstalledBuddyList = null;
/**
* A reference to the bundle containing the tested pp implementation. This
* reference is set during the accoung uninstallation testing and used during
* the account uninstallation persistence testing.
*/
public static Bundle providerBundle = null;
/**
* Constructor
*/
public AdHocMultiUserChatSlickFixture()
{
super();
}
/**
*
*
* @throws IllegalArgumentException
* @throws IllegalStateException
* @throws OperationFailedException
*/
public void clearProvidersLists()
throws IllegalArgumentException,
IllegalStateException,
OperationFailedException
{
Map<String, OperationSet> supportedOperationSets1 =
provider1.getSupportedOperationSets();
if ( supportedOperationSets1 == null
|| supportedOperationSets1.size() < 1)
throw new NullPointerException(
"No OperationSet implementations are supported by "
+"this msn implementation. ");
//get the operation set presence here.
OperationSetPersistentPresence opSetPersPresence1 =
(OperationSetPersistentPresence)supportedOperationSets1.get(
OperationSetPersistentPresence.class.getName());
//if still null then the implementation doesn't offer a presence
//operation set which is unacceptable for msn.
if (opSetPersPresence1 == null)
throw new NullPointerException(
"An implementation of the msn service must provide an "
+ "implementation of at least the one of the Presence "
+ "Operation Sets");
// lets do it once again for the second provider
Map<String, OperationSet> supportedOperationSets2 =
provider2.getSupportedOperationSets();
if (supportedOperationSets2 == null
|| supportedOperationSets2.size() < 1)
throw new NullPointerException(
"No OperationSet implementations are supported by "
+ "this msn implementation. ");
//get the operation set presence here.
OperationSetPersistentPresence opSetPersPresence2 =
(OperationSetPersistentPresence) supportedOperationSets2.get(
OperationSetPersistentPresence.class.getName());
//if still null then the implementation doesn't offer a presence
//operation set which is unacceptable for msn.
if (opSetPersPresence2 == null)
throw new NullPointerException(
"An implementation of the msn service must provide an "
+ "implementation of at least the one of the Presence "
+ "Operation Sets");
// lets do it once again for the third provider
Map<String, OperationSet> supportedOperationSets3 =
provider3.getSupportedOperationSets();
if (supportedOperationSets3 == null
|| supportedOperationSets3.size() < 1)
throw new NullPointerException(
"No OperationSet implementations are supported by "
+ "this msn implementation. ");
//get the operation set presence here.
OperationSetPersistentPresence opSetPersPresence3 =
(OperationSetPersistentPresence) supportedOperationSets3.get(
OperationSetPersistentPresence.class.getName());
//if still null then the implementation doesn't offer a presence
//operation set which is unacceptable for msn.
if (opSetPersPresence3 == null)
throw new NullPointerException(
"An implementation of the msn service must provide an "
+ "implementation of at least the one of the Presence "
+ "Operation Sets");
deleteGroups(opSetPersPresence1);
deleteGroups(opSetPersPresence2);
deleteGroups(opSetPersPresence3);
}
/**
* Returns the bundle that has registered the protocol provider service
* implementation that we're currently testing. The method would go through
* all bundles currently installed in the framework and return the first
* one that exports the same protocol provider instance as the one we test
* in this slick.
* @param provider the provider whose bundle we're looking for.
* @return the Bundle that has registered the protocol provider service
* we're testing in the slick.
*/
public static Bundle findProtocolProviderBundle(
ProtocolProviderService provider)
{
Bundle[] bundles = bc.getBundles();
for (int i = 0; i < bundles.length; i++)
{
ServiceReference[] registeredServices
= bundles[i].getRegisteredServices();
if (registeredServices == null)
continue;
for (int j = 0; j < registeredServices.length; j++)
{
Object service
= bc.getService(registeredServices[j]);
if (service == provider)
return bundles[i];
}
}
return null;
}
/**
* Delete all groups and contacts for the given persistent presence op. set.
*
* @param opSetPersPresence
* @throws IllegalArgumentException
* @throws IllegalStateException
* @throws OperationFailedException
*/
public void deleteGroups(OperationSetPersistentPresence opSetPersPresence)
throws IllegalArgumentException, IllegalStateException,
OperationFailedException
{
ContactGroup rootGroup =
opSetPersPresence.getServerStoredContactListRoot();
// first delete the groups
Vector<ContactGroup> groupsToRemove = new Vector<ContactGroup>();
Iterator<ContactGroup> iter = rootGroup.subgroups();
while (iter.hasNext())
{
groupsToRemove.add(iter.next());
}
iter = groupsToRemove.iterator();
while (iter.hasNext())
{
ContactGroup item = iter.next();
opSetPersPresence.removeServerStoredContactGroup(item);
}
//then delete contacts if any in root list
Vector<Contact> contactsToRemove = new Vector<Contact>();
Iterator<Contact> iter2 = rootGroup.contacts();
while (iter2.hasNext())
{
contactsToRemove.add(iter2.next());
}
iter2 = contactsToRemove.iterator();
while (iter2.hasNext())
{
opSetPersPresence.unsubscribe(iter2.next());
}
}
/**
* JUnit setUp
*/
public void setUp() throws Exception
{
super.setUp();
}
/**
* JUnit tearDown method.
* Unget service references used in here.
*/
public void tearDown() throws Exception
{
bc.ungetService(provider1ServiceRef);
bc.ungetService(provider2ServiceRef);
bc.ungetService(provider3ServiceRef);
}
}

@ -0,0 +1,848 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.slick.protocol.generic;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import junit.framework.*;
/**
* Generic tests suite for the ad-hoc multi-user chat functionality.
*
* @author Valentin Martinet
*/
public abstract class TestOperationSetAdHocMultiUserChat extends TestCase
{
/**
* The name for the AdHocChatRoom we will use in this test case.
*/
protected static String adHocChatRoomName = "AdHocMUC-test";
/**
* A reason to be sent with an invitation for an ad-hoc chatroom.
*/
protected static String invitationReason = "Free 4 a chat?";
/**
* A reason for the rejection of an invitation.
*/
protected static String invitationRejectReason = "Sorry, no time 4 U.";
/**
* Fixture.
*/
protected AdHocMultiUserChatSlickFixture fixture = null;
public OperationSetPresence opSetPresence1 = null;
public OperationSetPresence opSetPresence2 = null;
public OperationSetPresence opSetPresence3 = null;
public OperationSetAdHocMultiUserChat opSetAHMUC1 = null;
public OperationSetAdHocMultiUserChat opSetAHMUC2 = null;
public OperationSetAdHocMultiUserChat opSetAHMUC3 = null;
/**
* Constructor: creates the test with the specified method name.
*
* @param name the name of the method to execute.
*/
public TestOperationSetAdHocMultiUserChat(String name)
{
super(name);
}
/**
* JUnit setUp method.
*/
public void setUp() throws Exception
{
start();
}
/**
* JUnit tearDown method.
*/
public void tearDown() throws Exception
{
fixture.tearDown();
}
public void start() throws Exception {}
public void stop() {}
/**
* Creates an ad-hoc chat room and check if it's registered on the server.
*
* @throws OperationFailedException
* @throws OperationNotSupportedException
*/
public void testCreateRoom()
throws OperationFailedException, OperationNotSupportedException
{
AdHocChatRoom adHocChatRoom = opSetAHMUC1.createAdHocChatRoom(
adHocChatRoomName, new Hashtable<String,Object>());
assertNotNull("The created ad-hoc room is null.", adHocChatRoom);
// We wait some time to let the MsnSwitchboard attached to this room
// started...
try { Thread.sleep(10000); }
catch (InterruptedException e) { e.printStackTrace(); }
// Check that we retrieved the only one room that should be available:
assertEquals("The room can't be retrieved",
1, opSetAHMUC1.getAdHocChatRooms().size());
}
/**
* Creates an ad-hoc chat room in including participants, then check if it's
* registered on the server.
*
* -Users will be part of the participants to invite when creating the room.
* -Thez will accept the invitation so we'll check that thez'll be actually
* in the room.
* -Then they will leave the room. They will be invited again in another
* test.
*
* NOTE that this test will be especially used by Yahoo! protocol because of
* the fact that creating a conference chat with this protocol fails if any
* participants are given to the dedicated constructor of the library.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testCreateRoomWithParticipants()
throws OperationFailedException, OperationNotSupportedException
{
List<String> contacts = new ArrayList<String>();
contacts.add(fixture.userID2);
contacts.add(fixture.userID3);
// Collectors allows to gather the events which are generated:
AHMUCEventCollector collectorUser1 = null;
AHMUCEventCollector collectorUser2 = new AHMUCEventCollector(
opSetAHMUC2, AHMUCEventCollector.INVITATION_EVENT);
AHMUCEventCollector collectorUser3 = new AHMUCEventCollector(
opSetAHMUC3, AHMUCEventCollector.INVITATION_EVENT);
// We create the room with the given contacts:
// (NOTE that in Yahoo! adHocChatRoomName won't be considered!)
AdHocChatRoom room = opSetAHMUC1.createAdHocChatRoom(
adHocChatRoomName, contacts, invitationReason);
assertNotNull("Returned room is null", room);
// A room should have been created on user1's side:
assertEquals("The room can't be retrieved",
1, opSetAHMUC1.getAdHocChatRooms().size());
assertNotNull("The newly created room is null",
opSetAHMUC1.getAdHocChatRooms().get(0));
collectorUser2.waitForEvent(40000);
// Check that an event has been generated on the other side
assertEquals("User2 didn't receive an invitation. Wrong number of " +
"collected events", 1, collectorUser2.events.size());
assertTrue("Unexpected event type", collectorUser2.events.get(0)
instanceof AdHocChatRoomInvitationReceivedEvent);
collectorUser3.waitForEvent(40000);
assertEquals("User3 didn't receive an invitation. Wrong number of " +
"collected events", 1, collectorUser3.events.size());
assertTrue("Unexpected event type", collectorUser3.events.get(0)
instanceof AdHocChatRoomInvitationReceivedEvent);
// Check event's properties for user2:
AdHocChatRoomInvitationReceivedEvent event2 =
(AdHocChatRoomInvitationReceivedEvent) collectorUser2.events.get(0);
assertEquals("Received invitation does NOT concern the right chatroom",
opSetAHMUC1.getAdHocChatRooms().get(0).getName(),
event2.getInvitation().getTargetAdHocChatRoom().getName());
assertEquals("Received invitation does NOT come from expected user",
fixture.userID1, event2.getInvitation().getInviter());
assertEquals("Invitation's reason does NOT match",
invitationReason, event2.getInvitation().getReason());
// Check event's properties for user3:
AdHocChatRoomInvitationReceivedEvent event3 =
(AdHocChatRoomInvitationReceivedEvent) collectorUser3.events.get(0);
assertEquals("Received invitation does NOT concern the right chatroom",
opSetAHMUC1.getAdHocChatRooms().get(0).getName(),
event3.getInvitation().getTargetAdHocChatRoom().getName());
assertEquals("Received invitation does NOT come from expected user",
fixture.userID1, event3.getInvitation().getInviter());
assertEquals("Invitation's reason does NOT match",
invitationReason, event3.getInvitation().getReason());
collectorUser1 = new AHMUCEventCollector(
opSetAHMUC1.getAdHocChatRooms().get(0),
AHMUCEventCollector.PRESENCE_EVENT);
//
// Our guest accepts our invitation
//
assertEquals(1, opSetAHMUC2.getAdHocChatRooms().size());
assertNotNull(opSetAHMUC2.getAdHocChatRooms().get(0));
event2.getInvitation().getTargetAdHocChatRoom().join();
collectorUser1.waitForEvent(40000);
assertEquals("Wrong count of generated events",
1, collectorUser1.events.size());
assertTrue("Wrong event instance", collectorUser1.events.get(0)
instanceof AdHocChatRoomParticipantPresenceChangeEvent);
// First peer
AdHocChatRoomParticipantPresenceChangeEvent presenceEvent2 =
(AdHocChatRoomParticipantPresenceChangeEvent)
collectorUser1.events.get(0);
assertEquals("Presence event does NOT concern expected chatroom",
opSetAHMUC1.getAdHocChatRooms().get(0).getName(),
presenceEvent2.getAdHocChatRoom().getName());
assertEquals("Wrong event type",
AdHocChatRoomParticipantPresenceChangeEvent.CONTACT_JOINED,
presenceEvent2.getEventType());
assertEquals("Presence event does NOT come from the expected user",
fixture.userID2, presenceEvent2.getParticipant().getAddress());
assertEquals("Unexpected participants count", 1,
opSetAHMUC1.getAdHocChatRooms().get(0).getParticipantsCount());
assertEquals("Unexpected room participant",
fixture.userID2,
opSetAHMUC1.getAdHocChatRooms().get(0).getParticipants().get(0)
.getAddress());
// Second peer
assertEquals(1, opSetAHMUC3.getAdHocChatRooms().size());
assertNotNull(opSetAHMUC3.getAdHocChatRooms().get(0));
event3.getInvitation().getTargetAdHocChatRoom().join();
collectorUser1.waitForEvent(20000);
assertEquals("Wrong count of generated events",
2, collectorUser1.events.size());
assertTrue("Wrong event instance", collectorUser1.events.get(1)
instanceof AdHocChatRoomParticipantPresenceChangeEvent);
AdHocChatRoomParticipantPresenceChangeEvent presenceEvent3 =
(AdHocChatRoomParticipantPresenceChangeEvent)
collectorUser1.events.get(1);
assertEquals("Presence event does NOT concern expected chatroom",
opSetAHMUC1.getAdHocChatRooms().get(0).getName(),
presenceEvent3.getAdHocChatRoom().getName());
assertEquals("Wrong event type",
AdHocChatRoomParticipantPresenceChangeEvent.CONTACT_JOINED,
presenceEvent3.getEventType());
assertEquals("Presence event does NOT come from the expected user",
fixture.userID3, presenceEvent3.getParticipant().getAddress());
assertEquals("Unexpected participants count", 2,
opSetAHMUC1.getAdHocChatRooms().get(0).getParticipantsCount());
assertEquals("Unexpected room participant",
fixture.userID3,
opSetAHMUC1.getAdHocChatRooms().get(0).getParticipants().get(1)
.getAddress());
//
// Ok, our guests are actually in the room, now they leave:
//
opSetAHMUC2.getAdHocChatRooms().get(0).leave();
collectorUser1.waitForEvent(40000);
// Check the generated events and what information they give:
presenceEvent2 = (AdHocChatRoomParticipantPresenceChangeEvent)
collectorUser1.events.get(2);
assertEquals("Wrong type of event", presenceEvent2.getEventType(),
AdHocChatRoomParticipantPresenceChangeEvent.CONTACT_LEFT);
assertEquals("The event belongs to an unexpected room",
opSetAHMUC1.getAdHocChatRooms().get(0).getName(),
presenceEvent2.getAdHocChatRoom().getName());
assertEquals("The event belongs to an unexpected user", fixture.userID2,
presenceEvent2.getParticipant().getAddress());
// Check the current state of the room:
assertEquals("Wrong count of participants", 1,
opSetAHMUC1.getAdHocChatRooms().get(0).getParticipantsCount());
opSetAHMUC3.getAdHocChatRooms().get(0).leave();
collectorUser1.waitForEvent(10000);
// Check the generated events and what information they give:
presenceEvent3 = (AdHocChatRoomParticipantPresenceChangeEvent)
collectorUser1.events.get(3);
assertEquals("Wrong type of event", presenceEvent3.getEventType(),
AdHocChatRoomParticipantPresenceChangeEvent.CONTACT_LEFT);
assertEquals("The event belongs to an unexpected room",
opSetAHMUC1.getAdHocChatRooms().get(0).getName(),
presenceEvent3.getAdHocChatRoom().getName());
assertEquals("The event belongs to an unexpected user", fixture.userID3,
presenceEvent3.getParticipant().getAddress());
// Check the current state of the room:
assertEquals("The room was supposed to be empty, but it still contains"+
" participants", 0,
opSetAHMUC1.getAdHocChatRooms().get(0).getParticipantsCount());
}
/**
* Invite both second and third users and check that they correctly have
* joined the room. MSN does not support invitations (with rejection), so we
* just have to check if the users are present in the room.
*
* @throws OperationFailedException
*/
public void testPeerJoined() throws OperationFailedException
{
// First make sure the cache contains rooms:
// (If no, the test will fails and not generate an index error)
assertEquals("There are any rooms to retrieve on user 1 side's", 1,
opSetAHMUC1.getAdHocChatRooms().size());
// Then make sure the room is still here:
AdHocChatRoom adHocChatRoom = opSetAHMUC1.getAdHocChatRooms().get(0);
assertNotNull("The room can NOT been retrieved.", adHocChatRoom);
// Collectors allows to gather the events which are generated:
AHMUCEventCollector collector = new AHMUCEventCollector(
adHocChatRoom, AHMUCEventCollector.PRESENCE_EVENT);
// We invite and wait for the other side:
// (Here with MSN and the ad-hoc group chat, we have to invite at least
// two users if we want a (ad-hoc) chatroom to be created on the other
// side: it means you are NOT able to start an ad-hoc MULTI user chat
// with just one peer, else it will be considered as a simple one-to-one
// chat).
adHocChatRoom.invite(fixture.userID2, "");
adHocChatRoom.invite(fixture.userID3, "");
collector.waitForEvent(10000);
collector.waitForEvent(10000);
// We first check if presence events have been generated:
// (one event for user2, and another one for user3)
assertEquals("Wrong number of collected events",
2, collector.events.size());
// Check generated event's properties:
AdHocChatRoomParticipantPresenceChangeEvent presenceEvent1 =
(AdHocChatRoomParticipantPresenceChangeEvent)
collector.events.get(0);
assertEquals("Wrong event type",
AdHocChatRoomParticipantPresenceChangeEvent.CONTACT_JOINED,
presenceEvent1.getEventType());
assertEquals("Unexpected chatroom",
adHocChatRoom.getName(),
presenceEvent1.getAdHocChatRoom().getName());
AdHocChatRoomParticipantPresenceChangeEvent presenceEvent2 =
(AdHocChatRoomParticipantPresenceChangeEvent)
collector.events.get(1);
assertEquals("Wrong event type",
AdHocChatRoomParticipantPresenceChangeEvent.CONTACT_JOINED,
presenceEvent2.getEventType());
assertEquals("Unexpected chatroom",
adHocChatRoom.getName(),
presenceEvent2.getAdHocChatRoom().getName());
// Two users are supposed to be in the room now:
assertEquals("Wrong number of participants",
2, adHocChatRoom.getParticipantsCount());
// Gather room participants address...
List<String> participantsAdress = new ArrayList<String>();
for(Contact c : adHocChatRoom.getParticipants())
{
participantsAdress.add(c.getAddress());
}
// ... and finally check that both of our guests are here by searching
// for their identity:
assertTrue("A participant is missing",
participantsAdress.contains(fixture.userID2));
assertTrue("A participant is missing",
participantsAdress.contains(fixture.userID3));
// We force the creation of an ad-hoc chatroom on each side:
// (In some cases, the chat room is created when an instant message has
// been received).
AHMUCEventCollector collector2 = new AHMUCEventCollector(
adHocChatRoom, AHMUCEventCollector.MESSAGE_EVENT);
Message message = adHocChatRoom.createMessage("Don't ask your country" +
"what it can do for you, ask you what you can do for it.");
adHocChatRoom.sendMessage(message);
collector2.waitForEvent(10000);
// Check event's properties:
AdHocChatRoomMessageDeliveredEvent deliveredMessage =
(AdHocChatRoomMessageDeliveredEvent) collector2.events.get(0);
assertEquals("Message delivered to an unexpected room",
adHocChatRoom.getName(),
deliveredMessage.getSourceAdHocChatRoom().getName());
assertEquals("Wrong message type",
AdHocChatRoomMessageDeliveredEvent.CONVERSATION_MESSAGE_DELIVERED,
deliveredMessage.getEventType());
assertEquals("Message's content does NOT match", message.getContent(),
deliveredMessage.getMessage().getContent());
}
/**
* Make sure that invitations have been received on both side (user2 and
* user3). Note that it only make sense to use this method with protocol
* who support invitations (Yahoo! and ICQ).
*
* We will first test that after having accept an invitation the concerned
* user joins the room and be a part of participants.
*
* We will then test that after having reject an invitation we receive the
* rejection message and the concerned user is not a part of the room
* participants.
*
* Note that before the end of this test we will invite again the user who
* rejected our invitation and he will accept our invitation because we will
* need his presence for the remaining tests.
*
* @throws OperationFailedException if something wrong happens when joining
* the room
*/
public void testInvitations() throws OperationFailedException
{
// First make sure the cache contains rooms:
// (If no, the test will fails and not generate an index error)
assertEquals("There are no rooms to retrieve on user 1 side's", 1,
opSetAHMUC1.getAdHocChatRooms().size());
// Then make sure the room is still here:
AdHocChatRoom adHocChatRoom = opSetAHMUC1.getAdHocChatRooms().get(0);
assertNotNull("The room can NOT been retrieved.", adHocChatRoom);
// Collectors allows to gather the events which are generated:
AHMUCEventCollector collectorUser1 = new AHMUCEventCollector(
opSetAHMUC1, AHMUCEventCollector.PRESENCE_EVENT);
AHMUCEventCollector collectorUser2 = new AHMUCEventCollector(
opSetAHMUC2, AHMUCEventCollector.INVITATION_EVENT);
AHMUCEventCollector collectorUser3 = new AHMUCEventCollector(
opSetAHMUC3, AHMUCEventCollector.INVITATION_EVENT);
// We invite and wait for the other side:
adHocChatRoom.invite(fixture.userID2, invitationReason);
adHocChatRoom.invite(fixture.userID3, invitationReason);
collectorUser2.waitForEvent(10000);
collectorUser3.waitForEvent(10000);
// We check if invitations have been well delivered:
// (one event for user2, and another one for user3)
assertEquals("Wrong number of collected events",
1, collectorUser2.events.size());
assertEquals("Wrong number of collected events",
1, collectorUser3.events.size());
assertTrue("Unexpected event type", collectorUser2.events.get(0)
instanceof AdHocChatRoomInvitationReceivedEvent);
assertTrue("Unexpected event type", collectorUser3.events.get(0)
instanceof AdHocChatRoomInvitationReceivedEvent);
// Check event's properties for user2:
AdHocChatRoomInvitationReceivedEvent event2 =
(AdHocChatRoomInvitationReceivedEvent) collectorUser2.events.get(0);
assertEquals("Received invitation does NOT concern the right chatroom",
adHocChatRoom.getName(),
event2.getInvitation().getTargetAdHocChatRoom().getName());
assertEquals("Received invitation does NOT come from expected user",
fixture.userID1, event2.getInvitation().getInviter());
assertEquals("Invitation's reason does NOT match",
invitationReason, event2.getInvitation().getReason());
// Check event's properties for user3:
AdHocChatRoomInvitationReceivedEvent event3 =
(AdHocChatRoomInvitationReceivedEvent) collectorUser3.events.get(0);
assertEquals("Received invitation does NOT concern the right chatroom",
adHocChatRoom.getName(),
event3.getInvitation().getTargetAdHocChatRoom().getName());
assertEquals("Received invitation does NOT come from expected user",
fixture.userID1, event3.getInvitation().getInviter());
assertEquals("Invitation's reason does NOT match",
invitationReason, event3.getInvitation().getReason());
//
// User2 accepts our invitation
//
event2.getInvitation().getTargetAdHocChatRoom().join();
try { Thread.sleep(10000); }
catch (InterruptedException e) { e.printStackTrace(); }
assertEquals("Wrong count of generated events",
1, collectorUser1.events.size());
assertTrue("Wrong event instance", collectorUser1.events.get(0)
instanceof AdHocChatRoomParticipantPresenceChangeEvent);
AdHocChatRoomParticipantPresenceChangeEvent presenceEvent2 =
(AdHocChatRoomParticipantPresenceChangeEvent)
collectorUser1.events.get(0);
assertEquals("Presence event does NOT concern expected chatroom",
adHocChatRoom.getName(),
presenceEvent2.getAdHocChatRoom().getName());
assertEquals("Wrong event type",
AdHocChatRoomParticipantPresenceChangeEvent.CONTACT_JOINED,
presenceEvent2.getEventType());
assertEquals("Presence event does NOT come from the expected user",
fixture.userID2, presenceEvent2.getParticipant().getAddress());
assertEquals("Unexpected participants count",
1, adHocChatRoom.getParticipantsCount());
assertEquals("Unexpected room participant",
fixture.userID2,
adHocChatRoom.getParticipants().get(0).getAddress());
//
// User3 rejects our invitation (we invite him again then, and he joins)
//
opSetAHMUC3.rejectInvitation(
event3.getInvitation(), invitationRejectReason);
try { Thread.sleep(10000); }
catch (InterruptedException e) { e.printStackTrace(); }
assertEquals("Wrong count of generated events",
2, collectorUser1.events.size());
assertTrue("Wrong event instance", collectorUser1.events.get(1)
instanceof AdHocChatRoomInvitationRejectedEvent);
AdHocChatRoomInvitationRejectedEvent rejectEvent =
(AdHocChatRoomInvitationRejectedEvent)
collectorUser1.events.get(1);
assertEquals("Reject event does NOT concern expected room",
adHocChatRoom.getName(), rejectEvent.getChatRoom().getName());
assertEquals("Reject event does NOT come from expected user",
fixture.userID3, rejectEvent.getInvitee());
assertEquals("Reject event's reason does NOT match with expected one",
invitationRejectReason,
rejectEvent.getReason());
// Makes sure that previous user is still the only one participant
assertEquals("Unexpected participants count",
1, adHocChatRoom.getParticipantsCount());
assertEquals("Unexpected room participant",
fixture.userID2,
adHocChatRoom.getParticipants().get(0).getAddress());
// Now invite again user3:
adHocChatRoom.invite(fixture.userID3, "");
try { Thread.sleep(10000); }
catch (InterruptedException e) { e.printStackTrace(); }
assertEquals("Wrong number of collected events",
2, collectorUser3.events.size());
assertTrue("Unexpected event type", collectorUser3.events.get(1)
instanceof AdHocChatRoomInvitationReceivedEvent);
// Check event's properties for user3:
event3 =
(AdHocChatRoomInvitationReceivedEvent) collectorUser3.events.get(1);
assertEquals("Received invitation does NOT concern the right chatroom",
adHocChatRoom.getName(),
event3.getInvitation().getTargetAdHocChatRoom().getName());
assertEquals("Received invitation does NOT come from expected user",
fixture.userID1, event3.getInvitation().getInviter());
assertEquals("Invitation's reason does NOT match",
invitationReason, event3.getInvitation().getReason());
event3.getInvitation().getTargetAdHocChatRoom().join();
try { Thread.sleep(10000); }
catch (InterruptedException e) { e.printStackTrace(); }
assertEquals("Wrong count of generated events",
3, collectorUser1.events.size() == 1);
assertTrue("Wrong event instance", collectorUser1.events.get(0)
instanceof AdHocChatRoomParticipantPresenceChangeEvent);
AdHocChatRoomParticipantPresenceChangeEvent presenceEvent3 =
(AdHocChatRoomParticipantPresenceChangeEvent)
collectorUser1.events.get(2);
assertEquals("Presence event does NOT concern expected chatroom",
adHocChatRoom.getName(),
presenceEvent3.getAdHocChatRoom().getName());
assertEquals("Wrong event type",
AdHocChatRoomParticipantPresenceChangeEvent.CONTACT_JOINED,
presenceEvent3.getEventType());
assertEquals("Presence event does NOT come from the expected user",
fixture.userID3, presenceEvent3.getParticipant().getAddress());
assertEquals("Unexpected participants count",
2, adHocChatRoom.getParticipantsCount());
assertEquals("Unexpected room participant",
fixture.userID3,
adHocChatRoom.getParticipants().get(1).getAddress());
}
/**
* Send an instant message to the room and check that second user in the
* room receives it.
*
* @throws OperationFailedException if an error occurs while sending a
* message
* @throws OperationNotSupportedException
*/
public void testSendIM()
throws OperationFailedException, OperationNotSupportedException
{
// First make sure the cache contains the expected rooms:
// (If no, the test will fails and not generate an index error)
assertEquals("There are any rooms to retrieve on user 1 side's", 1,
opSetAHMUC1.getAdHocChatRooms().size());
assertEquals("There are any rooms to retrieve on user 2 side's", 1,
opSetAHMUC2.getAdHocChatRooms().size());
assertEquals("There are any rooms to retrieve on user 3 side's", 1,
opSetAHMUC3.getAdHocChatRooms().size());
// Then make sure the room is still here:
AdHocChatRoom roomUser1 = opSetAHMUC1.getAdHocChatRooms().get(0);
AdHocChatRoom roomUser2 = opSetAHMUC2.getAdHocChatRooms().get(0);
AdHocChatRoom roomUser3 = opSetAHMUC3.getAdHocChatRooms().get(0);
assertNotNull("The room can NOT been retrieved on user's 1 side.",
roomUser1);
assertNotNull("The room can NOT been retrieved on user's 2 side.",
roomUser2);
assertNotNull("The room can NOT been retrieved on user's 3 side.",
roomUser3);
// Collectors allows to gather the events which are generated:
AHMUCEventCollector collectorUser1 = new AHMUCEventCollector(
roomUser1, AHMUCEventCollector.MESSAGE_EVENT);
AHMUCEventCollector collectorUser2 = new AHMUCEventCollector(
roomUser2, AHMUCEventCollector.MESSAGE_EVENT);
AHMUCEventCollector collectorUser3 = new AHMUCEventCollector(
roomUser3, AHMUCEventCollector.MESSAGE_EVENT);
// We create a new message to be sent through the room:
Message message =
roomUser1.createMessage("Quick brown fox jumps over the lazy dog");
roomUser1.sendMessage(message);
try { Thread.sleep(10000); }
catch (InterruptedException e) { e.printStackTrace(); }
// Check that events are dispatched on each side:
assertEquals("User 1 did NOT receive a message delivered event. Wrong" +
" event collected number", 1, collectorUser1.events.size());
assertEquals("User 2 did NOT receive a message received event. Wrong " +
"event collected number", 1, collectorUser2.events.size());
assertEquals("User 3 did NOT receive a message received event. Wrong " +
"event collected number", 1, collectorUser3.events.size());
// Check event's pertinency on user's 1 side:
AdHocChatRoomMessageDeliveredEvent deliveredMessage =
(AdHocChatRoomMessageDeliveredEvent) collectorUser1.events.get(0);
assertEquals("Message delivered to an unexpected room",
roomUser1.getName(),
deliveredMessage.getSourceAdHocChatRoom().getName());
assertEquals("Wrong message type",
AdHocChatRoomMessageDeliveredEvent.CONVERSATION_MESSAGE_DELIVERED,
deliveredMessage.getEventType());
assertEquals("Message's content does NOT match", message.getContent(),
deliveredMessage.getMessage().getContent());
// Check event's pertinency on user's 2 side:
AdHocChatRoomMessageReceivedEvent receivedMessage =
(AdHocChatRoomMessageReceivedEvent) collectorUser2.events.get(0);
assertEquals("Message does NOT belong to this room",
roomUser2.getName(),
receivedMessage.getSourceChatRoom().getName());
assertEquals("Wrong message type",
AdHocChatRoomMessageReceivedEvent.CONVERSATION_MESSAGE_RECEIVED,
receivedMessage.getEventType());
assertEquals("Message's content does NOT match", message.getContent(),
receivedMessage.getMessage().getContent());
// Check event's pertinency on user's 3 side:
receivedMessage =
(AdHocChatRoomMessageReceivedEvent) collectorUser3.events.get(0);
assertEquals("Message does NOT belong to this room",
roomUser3.getName(),
receivedMessage.getSourceChatRoom().getName());
assertEquals("Wrong message type",
AdHocChatRoomMessageReceivedEvent.CONVERSATION_MESSAGE_RECEIVED,
receivedMessage.getEventType());
assertEquals("Message's content does NOT match", message.getContent(),
receivedMessage.getMessage().getContent());
}
/**
* Our peer leave the room: we check that there is no more participants in
* the room.
*/
public void testPeerLeaved()
{
// First make sure the cache contains rooms:
// (If no, the test will fails and not generate an index error)
assertEquals("There are any rooms to retrieve on user 1 side's", 1,
opSetAHMUC1.getAdHocChatRooms().size());
assertEquals("There are any rooms to retrieve on user 2 side's", 1,
opSetAHMUC2.getAdHocChatRooms().size());
assertEquals("There are any rooms to retrieve on user 3 side's", 1,
opSetAHMUC3.getAdHocChatRooms().size());
AdHocChatRoom room = opSetAHMUC1.getAdHocChatRooms().get(0);
AHMUCEventCollector collector = new AHMUCEventCollector(
room, AHMUCEventCollector.PRESENCE_EVENT);
//
// Our first peer leaves the room:
//
opSetAHMUC2.getAdHocChatRooms().get(0).leave();
collector.waitForEvent(10000);
// Check the generated events and what information they give:
assertEquals("Wrong events count when first peer leaved the room",
1, collector.events.size());
AdHocChatRoomParticipantPresenceChangeEvent presenceEvent =
(AdHocChatRoomParticipantPresenceChangeEvent)
collector.events.get(0);
assertEquals("Wrong type of event", presenceEvent.getEventType(),
AdHocChatRoomParticipantPresenceChangeEvent.CONTACT_LEFT);
assertEquals("The event belongs to an unexpected room", room.getName(),
presenceEvent.getAdHocChatRoom().getName());
assertEquals("The event belongs to an unexpected user", fixture.userID2,
presenceEvent.getParticipant().getAddress());
// Check the current state of the room:
assertEquals("No event was generated when second peer leaved the room",
1, room.getParticipantsCount());
assertEquals("The room was not supposed to contain this user anymore",
fixture.userID3, room.getParticipants().get(0).getAddress());
//
// Our second peer leaves the room:
//
opSetAHMUC3.getAdHocChatRooms().get(0).leave();
collector.waitForEvent(10000);
// Check the generated events and what information they give:
presenceEvent = (AdHocChatRoomParticipantPresenceChangeEvent)
collector.events.get(1);
assertEquals("Wrong type of event", presenceEvent.getEventType(),
AdHocChatRoomParticipantPresenceChangeEvent.CONTACT_LEFT);
assertEquals("The event belongs to an unexpected room", room.getName(),
presenceEvent.getAdHocChatRoom().getName());
assertEquals("The event belongs to an unexpected user", fixture.userID3,
presenceEvent.getParticipant().getAddress());
// Check the current state of the room:
assertEquals("The room was supposed to be empty, but it still contains"+
" participants", 0, room.getParticipantsCount());
}
/**
* Make sure each user is on the contact list of others.
*
* @throws Exception
*/
public void prepareContactList() throws Exception
{
fixture.clearProvidersLists();
try
{
opSetPresence1.subscribe(fixture.userID2);
}
catch (OperationFailedException e)
{
// means that the contacts already exits.
}
try
{
opSetPresence1.subscribe(fixture.userID3);
}
catch (OperationFailedException e)
{
// means that the contacts already exits.
}
try
{
opSetPresence2.subscribe(fixture.userID1);
}
catch (OperationFailedException e)
{
// means that the contacts already exits.
}
try
{
opSetPresence2.subscribe(fixture.userID3);
}
catch (OperationFailedException e)
{
// means that the contacts already exits.
}
try
{
opSetPresence3.subscribe(fixture.userID1);
}
catch (OperationFailedException e)
{
// means that the contacts already exits.
}
try
{
opSetPresence3.subscribe(fixture.userID2);
}
catch (OperationFailedException e)
{
// means that the contacts already exits.
}
}
}

@ -16,6 +16,7 @@
* The test suite registers two accounts for
*
* @author Damian Minkov
* @author Valentin Martinet
*/
public class JabberProtocolProviderServiceLick
extends TestSuite
@ -34,6 +35,13 @@ public class JabberProtocolProviderServiceLick
*/
public static final String ACCOUNT_2_PREFIX
= "accounts.jabber.account2.";
/**
* The prefix used for property names containing settings for our third
* testing account.
*/
public static final String ACCOUNT_3_PREFIX
= "accounts.jabber.account3.";
/**
* The name of the property that indicates whether the user would like to

@ -18,6 +18,7 @@
* Contains fields and methods used by most or all tests in the Jabber slick.
*
* @author Damian Minkov
* @author Valentin Martinet
*/
public class JabberSlickFixture
extends TestCase
@ -36,7 +37,7 @@ public class JabberSlickFixture
/**
* The protocol provider corresponding to our first testing account.
*/
public ProtocolProviderService provider1 = null;
public ProtocolProviderService provider1 = null;
/**
* The user ID associated with testing account 1.
@ -52,12 +53,28 @@ public class JabberSlickFixture
/**
* The protocol provider corresponding to our first testing account.
*/
public ProtocolProviderService provider2 = null;
public ProtocolProviderService provider2 = null;
/**
* The user ID associated with testing account 2.
*/
public String userID2 = null;
/**
* An osgi service reference for the protocol provider corresponding to our
* third testing account.
*/
public ServiceReference provider3ServiceRef = null;
/**
* The protocol provider corresponding to our third testing account.
*/
public ProtocolProviderService provider3 = null;
/**
* The user ID associated with testing account 3.
*/
public String userID3 = null;
/**
* The name of the chat room that we are using for testing of multi user
@ -65,8 +82,6 @@ public class JabberSlickFixture
*/
public String chatRoomName = null;
/**
* The tested protocol provider factory.
*/
@ -135,27 +150,31 @@ public void setUp()
= System.getProperty(
JabberProtocolProviderServiceLick.ACCOUNT_2_PREFIX
+ ProtocolProviderFactory.USER_ID);
userID3
= System.getProperty(
JabberProtocolProviderServiceLick.ACCOUNT_3_PREFIX
+ ProtocolProviderFactory.USER_ID);
chatRoomName
= System.getProperty(
JabberProtocolProviderServiceLick.CHAT_ROOM_NAME);
//find the protocol providers exported for the two accounts
//find the protocol providers exported for the three accounts
ServiceReference[] jabberProvider1Refs
= bc.getServiceReferences(
ProtocolProviderService.class.getName(),
"(&"
+"("+ProtocolProviderFactory.PROTOCOL+"="+ProtocolNames.JABBER+")"
+"("+ProtocolProviderFactory.USER_ID+"="
+ userID1 +")"
+")");
= bc.getServiceReferences(
ProtocolProviderService.class.getName(),
"(&"
+"("+ProtocolProviderFactory.PROTOCOL+"="+ProtocolNames.JABBER+")"
+"("+ProtocolProviderFactory.USER_ID+"="
+ userID1 +")"
+")");
//make sure we found a service
assertNotNull("No Protocol Provider was found for Jabber account1:"
+ userID1
, jabberProvider1Refs);
assertTrue("No Protocol Provider was found for Jabber account1:"+ userID1,
jabberProvider1Refs.length > 0);
+ userID1, jabberProvider1Refs);
assertTrue("No Protocol Provider was found for Jabber account1:"+
userID1, jabberProvider1Refs.length > 0);
ServiceReference[] jabberProvider2Refs
= bc.getServiceReferences(
@ -168,16 +187,34 @@ public void setUp()
//again make sure we found a service.
assertNotNull("No Protocol Provider was found for Jabber account2:"
+ userID2
, jabberProvider2Refs);
assertTrue("No Protocol Provider was found for Jabber account2:"+ userID2,
jabberProvider2Refs.length > 0);
+ userID2, jabberProvider2Refs);
assertTrue("No Protocol Provider was found for Jabber account2:"+
userID2, jabberProvider2Refs.length > 0);
ServiceReference[] jabberProvider3Refs
= bc.getServiceReferences(
ProtocolProviderService.class.getName(),
"(&"
+"("+ProtocolProviderFactory.PROTOCOL+"="+ProtocolNames.JABBER+")"
+"("+ProtocolProviderFactory.USER_ID+"="
+ userID3 +")"
+")");
//again make sure we found a service.
assertNotNull("No Protocol Provider was found for Jabber account3:"
+ userID3, jabberProvider3Refs);
assertTrue("No Protocol Provider was found for Jabber account3:"+
userID3, jabberProvider3Refs.length > 0);
//save the service for other tests to use.
provider1ServiceRef = jabberProvider1Refs[0];
provider1 = (ProtocolProviderService)bc.getService(provider1ServiceRef);
provider2ServiceRef = jabberProvider2Refs[0];
provider2 = (ProtocolProviderService)bc.getService(provider2ServiceRef);
provider3ServiceRef = jabberProvider3Refs[0];
provider3 = (ProtocolProviderService)bc.getService(provider3ServiceRef);
}
/**
@ -187,6 +224,7 @@ public void tearDown()
{
bc.ungetService(provider1ServiceRef);
bc.ungetService(provider2ServiceRef);
bc.ungetService(provider3ServiceRef);
}
/**
@ -199,7 +237,7 @@ public void tearDown()
* @return the Bundle that has registered the protocol provider service
* we're testing in the slick.
*/
public static Bundle findProtocolProviderBundle(
public Bundle findProtocolProviderBundle(
ProtocolProviderService provider)
{
Bundle[] bundles = bc.getBundles();
@ -224,59 +262,79 @@ public static Bundle findProtocolProviderBundle(
return null;
}
/**
* Clears all the providers of this fixture.
*
* @throws Exception
*/
public void clearProvidersLists()
throws Exception
{
Map<String, OperationSet> supportedOperationSets1 =
provider1.getSupportedOperationSets();
clearProvider(provider1);
clearProvider(provider2);
clearProvider(provider3);
}
/**
* Clears the given <tt>provider</tt>. It means delete existing contacts,
* existing groups.
*
* @param provider
* @throws IllegalArgumentException
* @throws IllegalStateException
* @throws OperationFailedException
*/
public void clearProvider(ProtocolProviderService provider)
throws IllegalArgumentException,
IllegalStateException,
OperationFailedException
{
Map<String, OperationSet> supportedOperationSets =
provider.getSupportedOperationSets();
if ( supportedOperationSets1 == null
|| supportedOperationSets1.size() < 1)
if ( supportedOperationSets == null
|| supportedOperationSets.size() < 1)
throw new NullPointerException(
"No OperationSet implementations are supported by "
+"this Jabber implementation. ");
//get the operation set presence here.
OperationSetPersistentPresence opSetPersPresence1 =
(OperationSetPersistentPresence)supportedOperationSets1.get(
OperationSetPersistentPresence.class.getName());
//if still null then the implementation doesn't offer a presence
//operation set which is unacceptable for jabber.
if (opSetPersPresence1 == null)
throw new NullPointerException(
"An implementation of the Jabber service must provide an "
+ "implementation of at least the one of the Presence "
+ "Operation Sets");
// lets do it once again for the second provider
Map<String, OperationSet> supportedOperationSets2 =
provider2.getSupportedOperationSets();
if (supportedOperationSets2 == null
|| supportedOperationSets2.size() < 1)
throw new NullPointerException(
"No OperationSet implementations are supported by "
+ "this Jabber implementation. ");
//get the operation set presence here.
OperationSetPersistentPresence opSetPersPresence2 =
(OperationSetPersistentPresence) supportedOperationSets2.get(
OperationSetPersistentPresence opSetPersPresence =
(OperationSetPersistentPresence) supportedOperationSets.get(
OperationSetPersistentPresence.class.getName());
//if still null then the implementation doesn't offer a presence
//operation set which is unacceptable for jabber.
if (opSetPersPresence2 == null)
if (opSetPersPresence == null)
throw new NullPointerException(
"An implementation of the Jabber service must provide an "
+ "implementation of at least the one of the Presence "
+ "Operation Sets");
ContactGroup rootGroup1 = opSetPersPresence1.getServerStoredContactListRoot();
deleteGroups(opSetPersPresence);
}
/**
* Delete all groups and contacts for the given persistent presence op. set.
*
* @param opSetPersPresence
* @throws IllegalArgumentException
* @throws IllegalStateException
* @throws OperationFailedException
*/
public void deleteGroups(OperationSetPersistentPresence opSetPersPresence)
throws IllegalArgumentException,
IllegalStateException,
OperationFailedException
{
ContactGroup rootGroup =
opSetPersPresence.getServerStoredContactListRoot();
// first delete the groups
Vector<ContactGroup> groupsToRemove = new Vector<ContactGroup>();
Iterator<ContactGroup> iter = rootGroup1.subgroups();
Iterator<ContactGroup> iter = rootGroup.subgroups();
while (iter.hasNext())
{
groupsToRemove.add(iter.next());
@ -286,42 +344,12 @@ public void clearProvidersLists()
while (iter.hasNext())
{
ContactGroup item = iter.next();
opSetPersPresence1.removeServerStoredContactGroup(item);
opSetPersPresence.removeServerStoredContactGroup(item);
}
//then delete contacts if any in root list
Vector<Contact> contactsToRemove = new Vector<Contact>();
Iterator<Contact> iter2 = rootGroup1.contacts();
while (iter2.hasNext())
{
contactsToRemove.add(iter2.next());
}
iter2 = contactsToRemove.iterator();
while (iter2.hasNext())
{
opSetPersPresence1.unsubscribe(iter2.next());
}
ContactGroup rootGroup2 = opSetPersPresence2.getServerStoredContactListRoot();
// delete groups
groupsToRemove = new Vector<ContactGroup>();
iter = rootGroup2.subgroups();
while (iter.hasNext())
{
groupsToRemove.add(iter.next());
}
iter = groupsToRemove.iterator();
while (iter.hasNext())
{
ContactGroup item = iter.next();
opSetPersPresence2.removeServerStoredContactGroup(item);
}
//then delete contacts if any in root list
contactsToRemove = new Vector<Contact>();
iter2 = rootGroup2.contacts();
Iterator<Contact> iter2 = rootGroup.contacts();
while (iter2.hasNext())
{
contactsToRemove.add(iter2.next());
@ -329,7 +357,7 @@ public void clearProvidersLists()
iter2 = contactsToRemove.iterator();
while (iter2.hasNext())
{
opSetPersPresence2.unsubscribe(iter2.next());
opSetPersPresence.unsubscribe(iter2.next());
}
}
}

@ -82,6 +82,8 @@ public void testInstallAccount()
JabberProtocolProviderServiceLick.ACCOUNT_1_PREFIX);
Hashtable<String, String> jabberAccount2Properties = getAccountProperties(
JabberProtocolProviderServiceLick.ACCOUNT_2_PREFIX);
Hashtable<String, String> jabberAccount3Properties = getAccountProperties(
JabberProtocolProviderServiceLick.ACCOUNT_3_PREFIX);
//try to install an account with a null account id
try{
@ -101,6 +103,9 @@ public void testInstallAccount()
jabberProviderFactory.installAccount(
jabberAccount2Properties.get(ProtocolProviderFactory.USER_ID)
, jabberAccount2Properties);
jabberProviderFactory.installAccount(
jabberAccount3Properties.get(ProtocolProviderFactory.USER_ID)
, jabberAccount3Properties);
//try to install one of the accounts one more time and verify that an
@ -122,7 +127,7 @@ public void testInstallAccount()
assertTrue(
"The newly installed account was not in the acc man's "
+"registered accounts!",
jabberProviderFactory.getRegisteredAccounts().size() == 2);
jabberProviderFactory.getRegisteredAccounts().size() == 3);
//Verify protocol providers corresponding to the new account have
//been properly registered with the osgi framework.

@ -228,9 +228,14 @@ public void testUninstallAccount()
fixture.provider1.getAccountID()));
assertTrue(
"Failed to remove a provider corresponding to URI "
+ fixture.userID1
+ fixture.userID2
,fixture.providerFactory.uninstallAccount(
fixture.provider2.getAccountID()));
assertTrue(
"Failed to remove a provider corresponding to URI "
+ fixture.userID3
,fixture.providerFactory.uninstallAccount(
fixture.provider3.getAccountID()));
//make sure no providers have remained installed.
ServiceReference[] jabberProviderRefs = null;

@ -17,7 +17,7 @@
import net.java.sip.communicator.util.*;
/**
* Tests multi user chat functionalities
* Tests multi user chat functionalities.
*
* @author Symphorien Wanko
* @author Valentin Martinet
@ -32,7 +32,9 @@ public class TestOperationSetMultiUserChat2
private static final Logger logger =
Logger.getLogger(TestOperationSetMultiUserChat2.class);
//room name for each test will be testRoomBaseName + roomID
/**
* Room name for each test will be testRoomBaseName + roomID
*/
private static String testRoomBaseName = "lmuctestroom";
private static int roomID = 0;
@ -43,12 +45,12 @@ public class TestOperationSetMultiUserChat2
private final JabberSlickFixture fixture = new JabberSlickFixture();
private OperationSetMultiUserChat opSetMUC1;
private OperationSetMultiUserChat opSetMUC2;
private OperationSetMultiUserChat opSetMUC3;
private OperationSetPresence opSetPresence1;
private OperationSetPresence opSetPresence2;
private OperationSetPresence opSetPresence3;
/**
* Initializes the test with the specified <tt>name</tt>.
@ -135,6 +137,38 @@ protected void setUp() throws Exception
"An implementation of the service must provide an " +
"implementation of at least one of the PresenceOperationSets");
}
Map<String, OperationSet> supportedOperationSets3 =
fixture.provider3.getSupportedOperationSets();
if (supportedOperationSets3 == null
|| (supportedOperationSets3.size() < 1))
{
throw new NullPointerException(
"No OperationSet implementations are supported by " +
"this implementation. ");
}
opSetMUC3 = (OperationSetMultiUserChat)
supportedOperationSets3.get(
OperationSetMultiUserChat.class.getName());
if (opSetMUC3 == null)
{
throw new NullPointerException(
"No implementation for MUC was found");
}
opSetPresence3 = (OperationSetPresence)
supportedOperationSets3.get(OperationSetPresence.class.getName());
//if the op set is null show that we're not happy.
if (opSetPresence3 == null)
{
throw new NullPointerException(
"An implementation of the service must provide an " +
"implementation of at least one of the PresenceOperationSets");
}
}
/**
@ -173,6 +207,15 @@ public void prepareContactList()
// the contact already exist its OK
}
try
{
opSetPresence1.subscribe(fixture.userID3);
}
catch (OperationFailedException ex)
{
// the contact already exist its OK
}
try
{
opSetPresence2.subscribe(fixture.userID1);
@ -181,7 +224,34 @@ public void prepareContactList()
{
// the contact already exist its OK
}
try
{
opSetPresence2.subscribe(fixture.userID3);
}
catch (OperationFailedException ex1)
{
// the contact already exist its OK
}
try
{
opSetPresence3.subscribe(fixture.userID1);
}
catch (OperationFailedException ex1)
{
// the contact already exist its OK
}
try
{
opSetPresence3.subscribe(fixture.userID2);
}
catch (OperationFailedException ex1)
{
// the contact already exist its OK
}
logger.info("will wait till the list prepare is completed");
synchronized (o)
{
@ -257,7 +327,74 @@ public static Test suite()
suite.addTest(
new TestOperationSetMultiUserChat2("testMemberKick"));
/*
* Unit tests who belong to users role functionalities are orderly added
* below. They are added in a specific order which match a predefined
* scenario. It's not recommended to change this order, some tests may
* then fail.
*
* Please note:
* - when the room is created, participants are considered (by default)
* as members (not guests).
* - in this test suite, the room will use three participants.
*
* Scenario:
* - testInitialParticipantsRoles: verify participants role in the newly
* created room.
* - testRevokeMembership: administrator/owner of the room revokes
* membership to a participant of the room.
* - testGrantMembership: administrator/owner of the room grants
* membership to the participant of the room who just loses it in the
* previous test.
* - testGrantModerator: administrator/owner of the room grants
* moderator rights to a participant of the room.
* - testRevokeVoice: the new moderator of the room (previous test) will
* revoke voice right to the remaining guest, who will become a silent
* member (the room currently includes the administrator/owner, the
* moderator from the previous test, and it remains a participant).
* - testGrantVoice: moderator will grant voice the user he previously
* revokes voice right.
* - testRevokeModerator: moderator of the room will have his rights
* revoked by the owner/admin of the room.
* - testGrantAdmin: owner/admin of the room grants administrator rights
* to the revoked-moderator (previous test).
* - testGrantOwnership: owner/admin of the room grants the new admin as
* co-owner of the room.
* - testRevokeOwnership: owner/admin of the room revokes ownership to
* his co-owner (granted in previous test).
* - testRevokeAdmin: after having been ownership-revoked, the
* considered member is supposed to be an administrator: here his
* administrative rights are revoked by owner/admin of the room.
*
*/
// suite.addTest(
// new TestOperationSetMultiUserChat2("testInitialParticipantsRoles"));
//
// suite.addTest(
// new TestOperationSetMultiUserChat2("testRevokeMembership"));
//
// suite.addTest(
// new TestOperationSetMultiUserChat2("testGrantMembership"));
//
// suite.addTest(new TestOperationSetMultiUserChat2("testGrantModerator"));
//
// suite.addTest(new TestOperationSetMultiUserChat2("testRevokeVoice"));
//
// suite.addTest(new TestOperationSetMultiUserChat2("testGrantVoice"));
//
// suite.addTest(
// new TestOperationSetMultiUserChat2("testRevokeModerator"));
//
// suite.addTest(new TestOperationSetMultiUserChat2("testGrantAdmin"));
//
// suite.addTest(new TestOperationSetMultiUserChat2("testGrantOwnership"));
//
// suite.addTest(
// new TestOperationSetMultiUserChat2("testRevokeOwnership"));
//
// suite.addTest(new TestOperationSetMultiUserChat2("testRevokeAdmin"));
return suite;
}
@ -318,7 +455,7 @@ public void testJoinRoom()
opSet1Collector.waitForEvent(10000);
assertEquals("user1 didn't ge an event since he joinde"
assertEquals("user1 didn't get an event since he joined"
, 1, opSet1Collector.collectedEvents.size());
LocalUserChatRoomPresenceChangeEvent changeEvent =
@ -484,8 +621,9 @@ public void testInviteReject()
}
/**
* <tt>testInviteFindJoin</tt> reproduces the following scenario : user1
* invite user2. user2 retrieves the room where he is invited then, he joins it.
* <tt>testInviteJoin</tt> reproduces the following scenario : user1
* invite user2. user2 retrieves the room where he is invited then,
* he joins it.
*/
public void testInviteJoin()
throws OperationFailedException,
@ -1103,6 +1241,647 @@ public void testMemberKick()
, nameIsOnMemberList(fixture.userID2, opSet1Room.getMembers()));
}
/**
* Tests participant roles when the room just has been created.
* The member who has created the room should have OWNER role.
* Others participants who are invited to the room should be MEMBER.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testInitialParticipantsRoles()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID++;
// We create the test room
ChatRoom roomUser1 = opSetMUC1.createChatRoom(roomName, null);
roomUser1.join();
MUCEventCollector roomUser1Collector =
new MUCEventCollector(roomUser1, MUCEventCollector.EVENT_PRESENCE);
// User1 who just created the room is supposed to be the owner:
assertEquals("Unexpected role for user1",
roomUser1.getUserRole(), ChatRoomMemberRole.OWNER);
// Both of our peers join the room:
ChatRoom roomUser2 = opSetMUC2.findRoom(roomName);
assertNotNull("Room can't be retrieved on user2's side", roomUser2);
roomUser2.join();
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("Room can't be retrieved on user3's side", roomUser2);
roomUser3.join();
// Wait for our peers:
roomUser1Collector.waitForEvent(10000);
roomUser1Collector.waitForEvent(10000);
assertTrue("User2 not on member list after having join the room"
, nameIsOnMemberList(fixture.userID2, roomUser1.getMembers()));
assertTrue("User3 not on member list after having join the room"
, nameIsOnMemberList(fixture.userID3, roomUser1.getMembers()));
List<ChatRoomMember> members = roomUser1.getMembers();
// Two members are supposed to be in the room:
assertTrue("Unexpected members count", members.size() == 2);
// We are sure these members are our peers (checked before the last
// test), now we make sure they are both members:
assertEquals("The current implementation requires that room's new " +
"comers must have MEMBER role",
ChatRoomMemberRole.MEMBER, members.get(0).getRole());
assertEquals("The current implementation requires that room's new " +
"comers must have the MEMBER role",
ChatRoomMemberRole.MEMBER, members.get(1).getRole());
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will grant membership's role to one
* of our peers (user2).
* Membership means a long-life affiliation to the room, rather than being a
* guest.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testGrantMembership()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room grants user2 member rights:
roomUser1.grantMembership(fixture.userID2);
roomUser1Col.waitForEvent(10000);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, roleEventUser1.getSourceChatRoom().getName());
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
roleEventUser1.getPreviousRole(), ChatRoomMemberRole.GUEST);
assertEquals("Unexpected new role",
roleEventUser1.getNewRole(), ChatRoomMemberRole.MEMBER);
// We finally check that event is the same on each side:
assertEquals(roleEventUser1, roleEventUser3);
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will grant moderator role to one
* of our peers (user2).
* A moderator is allowed to kick users, grant and revoke voice,
* invite other users, modify room's subject plus all the participants
* privileges.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testGrantModerator()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room grants user2 moderator rights:
roomUser1.grantModerator(fixture.userID2);
roomUser1Col.waitForEvent(10000);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, roleEventUser1.getSourceChatRoom().getName());
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
roleEventUser1.getPreviousRole(), ChatRoomMemberRole.GUEST);
assertEquals("Unexpected new role",
roleEventUser1.getNewRole(), ChatRoomMemberRole.MODERATOR);
// We finally check that event is the same on each side:
assertEquals(roleEventUser1, roleEventUser3);
}
/**
* User2 which is currently moderator in the room for our scenario will
* revoke voice to user3, thanks to his moderator privileges.
*
* We will first check that user3 has become a silent member before making
* sure that he can't send messages through the room.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testRevokeVoice()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser2 = opSetMUC2.findRoom(roomName);
assertNotNull("The room can't be retrieved on user2's side", roomUser2);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser2Col = new MUCEventCollector(
roomUser2, MUCEventCollector.EVENT_ROLE);
// User2 (moderator role) revokes voice right to user2 (guest):
roomUser2.revokeVoice(fixture.userID3);
roomUser1Col.waitForEvent(10000);
roomUser2Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user2's side",
1, roomUser2Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser2 =
(ChatRoomMemberRoleChangeEvent) roomUser2Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, roleEventUser1.getSourceChatRoom().getName());
assertEquals("Collected event does not belong to the expected user",
fixture.userID3,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
roleEventUser1.getPreviousRole(), ChatRoomMemberRole.GUEST);
assertEquals("Unexpected new role",
roleEventUser1.getNewRole(), ChatRoomMemberRole.SILENT_MEMBER);
// We check that event is the same on each side:
assertEquals(roleEventUser1, roleEventUser2);
// Now user3 (silent member) will send a message to the room. This
// action has to fail because user3 has no more voice right.
Message messageUser3 = roomUser3.createMessage("Mute?");
try
{
roomUser3.sendMessage(messageUser3);
}
catch (OperationFailedException ofe)
{
// that's what was supposed to happen.
return; // We exit here, otherwise the test fails.
}
fail("User3 may have succeeded to send a message through the room");
}
/**
* User2 which is currently moderator in the room for our scenario will
* grant voice to user3 (thanks to his moderator privileges) after having
* revoked him it in the previous test of the suite.
*
* We will first check that user3 has become a guest before making
* sure that he can again send messages through the room.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testGrantVoice()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser2 = opSetMUC2.findRoom(roomName);
assertNotNull("The room can't be retrieved on user2's side", roomUser2);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser2Col = new MUCEventCollector(
roomUser2, MUCEventCollector.EVENT_ROLE);
// User2 of the room grants voice right to user2:
roomUser2.grantVoice(fixture.userID3);
roomUser1Col.waitForEvent(10000);
roomUser2Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser2Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser2 =
(ChatRoomMemberRoleChangeEvent) roomUser2Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, roleEventUser1.getSourceChatRoom().getName());
assertEquals("Collected event does not belong to the expected user",
fixture.userID3,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
roleEventUser1.getPreviousRole(), ChatRoomMemberRole.SILENT_MEMBER);
assertEquals("Unexpected new role",
roleEventUser1.getNewRole(), ChatRoomMemberRole.GUEST);
// We finally check that event is the same on each side:
assertEquals(roleEventUser1, roleEventUser2);
// Now user3 (silent member) will send a message to the room. This
// action has to fail because user3 has no more voice right.
Message messageUser3 = roomUser3.createMessage("Mute?");
try
{
roomUser3.sendMessage(messageUser3);
}
catch (OperationFailedException ofe)
{
// this was not supposed to happen.
fail("User3 didn't succeed to send a message through the room");
}
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will grant administrator role to one
* of our peers (user2).
* An administrator is allowed to perform administrative functions such as
* banning users and edit moderator list.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testGrantAdmin()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser2 = opSetMUC2.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser2);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room grants administrator rights to user2:
roomUser1.grantAdmin(fixture.userID2);
roomUser1Col.waitForEvent(10000);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, roleEventUser1.getSourceChatRoom().getName());
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
roleEventUser1.getPreviousRole(), ChatRoomMemberRole.MEMBER);
assertEquals("Unexpected new role",
roleEventUser1.getNewRole(), ChatRoomMemberRole.ADMINISTRATOR);
// We check that event is the same on each side:
assertEquals(roleEventUser1, roleEventUser3);
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will grant ownership privileges to
* one of our peers (user2).
* An owner is allowed to change defining room features as well as perform
* all administrative functions.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testGrantOwnership()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room grants ownership privileges to user2:
roomUser1.grantOwnership(fixture.userID2);
roomUser1Col.waitForEvent(10000);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, roleEventUser1.getSourceChatRoom().getName());
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
roleEventUser1.getPreviousRole(), ChatRoomMemberRole.ADMINISTRATOR);
assertEquals("Unexpected new role",
roleEventUser1.getNewRole(), ChatRoomMemberRole.OWNER);
// We check that event is the same on each side:
assertEquals(roleEventUser1, roleEventUser3);
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will revoke membership's role to one
* of our peers (user2).
* The considered participant is then supposed to be a guest.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testRevokeMembership()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room revokes user2 member rights:
roomUser1.revokeMembership(fixture.userID2);
roomUser1Col.waitForEvent(10000);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, roleEventUser1.getSourceChatRoom().getName());
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
roleEventUser1.getPreviousRole(), ChatRoomMemberRole.MEMBER);
assertEquals("Unexpected new role",
roleEventUser1.getNewRole(), ChatRoomMemberRole.GUEST);
// We finally check that event is the same on each side:
assertEquals(roleEventUser1, roleEventUser3);
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will revoke moderator role to user2.
* The considered participant is then supposed to be a member.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testRevokeModerator()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room revokes user2 member rights:
roomUser1.revokeModerator(fixture.userID2);
roomUser1Col.waitForEvent(10000);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, roleEventUser1.getSourceChatRoom().getName());
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
roleEventUser1.getPreviousRole(), ChatRoomMemberRole.MEMBER);
assertEquals("Unexpected new role",
roleEventUser1.getNewRole(), ChatRoomMemberRole.GUEST);
// We finally check that event is the same on each side:
assertEquals(roleEventUser1, roleEventUser3);
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will revoke administrator role to
* user2.
* The considered participant is then supposed to be a moderator.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testRevokeAdmin()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room revokes user2 member rights:
roomUser1.revokeAdmin(fixture.userID2);
roomUser1Col.waitForEvent(10000);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, roleEventUser1.getSourceChatRoom().getName());
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
roleEventUser1.getPreviousRole(), ChatRoomMemberRole.ADMINISTRATOR);
assertEquals("Unexpected new role",
roleEventUser1.getNewRole(), ChatRoomMemberRole.MODERATOR);
// We finally check that event is the same on each side:
assertEquals(roleEventUser1, roleEventUser3);
}
/**
* The owner of the room (the user who created it, and which is an
* administrator too, typically user1) will revoke ownership rights to
* user2.
* The considered participant is then supposed to be an admin.
*
* @throws OperationNotSupportedException
* @throws OperationFailedException
*/
public void testRevokeOwnership()
throws OperationFailedException, OperationNotSupportedException
{
String roomName = testRoomBaseName + roomID;
ChatRoom roomUser1 = opSetMUC1.findRoom(roomName);
assertNotNull("The room can't be retrieved on user1's side", roomUser1);
ChatRoom roomUser3 = opSetMUC3.findRoom(roomName);
assertNotNull("The room can't be retrieved on user3's side", roomUser3);
MUCEventCollector roomUser1Col = new MUCEventCollector(
roomUser1, MUCEventCollector.EVENT_ROLE);
MUCEventCollector roomUser3Col = new MUCEventCollector(
roomUser3, MUCEventCollector.EVENT_ROLE);
// Owner of the room revokes user2 member rights:
roomUser1.revokeOwnership(fixture.userID2);
roomUser1Col.waitForEvent(10000);
roomUser3Col.waitForEvent(10000);
assertEquals("Wrong count of collected events on user1's side",
1, roomUser1Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser1 =
(ChatRoomMemberRoleChangeEvent) roomUser1Col.collectedEvents.get(0);
assertEquals("Wrong count of collected events on user3's side",
1, roomUser3Col.collectedEvents.size());
ChatRoomMemberRoleChangeEvent roleEventUser3 =
(ChatRoomMemberRoleChangeEvent) roomUser3Col.collectedEvents.get(0);
assertEquals("Collected event does not belong to the right chatroom",
roomName, roleEventUser1.getSourceChatRoom().getName());
assertEquals("Collected event does not belong to the expected user",
fixture.userID2,
roleEventUser1.getSourceMember().getContactAddress());
assertEquals("User2's previous role does not match",
roleEventUser1.getPreviousRole(), ChatRoomMemberRole.OWNER);
assertEquals("Unexpected new role",
roleEventUser1.getNewRole(), ChatRoomMemberRole.ADMINISTRATOR);
// We finally check that event is the same on each side:
assertEquals(roleEventUser1, roleEventUser3);
}
/**
* Utility class used to collect events received during tests.
*/
@ -1117,12 +1896,15 @@ class MUCEventCollector
ChatRoomMemberRoleListener,
ChatRoomLocalUserRoleListener
{
private final ArrayList<EventObject> collectedEvents = new ArrayList<EventObject>();
private final ArrayList<EventObject> collectedEvents
= new ArrayList<EventObject>();
private int waitCount = 0;
@SuppressWarnings("unused")
private final OperationSetMultiUserChat opSet;
@SuppressWarnings("unused")
private final ChatRoom room;
private static final int EVENT_INVITE = 1;

@ -16,7 +16,9 @@
/**
* Performs testing on protocol provider methods.
* @todo add more detailed docs once the tests are written.
*
* @author Emil Ivov
* @author Valentin Martinet
*/
public class TestProtocolProviderServiceJabberImpl
extends TestCase
@ -37,6 +39,12 @@ public class TestProtocolProviderServiceJabberImpl
*/
public RegistrationEventCollector regEvtCollector2
= new RegistrationEventCollector();
/**
* An event adapter that would collec registation state change events
*/
public RegistrationEventCollector regEvtCollector3
= new RegistrationEventCollector();
/**
* Creates a test encapsulator for the method with the specified name.
@ -87,13 +95,20 @@ public void testRegister()
//they were properly dispatched.
fixture.provider1.addRegistrationStateChangeListener(regEvtCollector1);
fixture.provider2.addRegistrationStateChangeListener(regEvtCollector2);
//register both our providers
fixture.provider3.addRegistrationStateChangeListener(regEvtCollector3);
//register our three providers
fixture.provider1.register(new SecurityAuthorityImpl(
System.getProperty(JabberProtocolProviderServiceLick.ACCOUNT_1_PREFIX
System.getProperty(
JabberProtocolProviderServiceLick.ACCOUNT_1_PREFIX
+ ProtocolProviderFactory.PASSWORD).toCharArray()));
fixture.provider2.register(new SecurityAuthorityImpl(
System.getProperty(JabberProtocolProviderServiceLick.ACCOUNT_2_PREFIX
System.getProperty(
JabberProtocolProviderServiceLick.ACCOUNT_2_PREFIX
+ ProtocolProviderFactory.PASSWORD).toCharArray()));
fixture.provider3.register(new SecurityAuthorityImpl(
System.getProperty(
JabberProtocolProviderServiceLick.ACCOUNT_3_PREFIX
+ ProtocolProviderFactory.PASSWORD).toCharArray()));
//give it enough time to register. We won't really have to wait all this
@ -103,6 +118,7 @@ public void testRegister()
regEvtCollector1.waitForEvent(15000);
regEvtCollector2.waitForEvent(40000);
regEvtCollector3.waitForEvent(60000);
//make sure that the registration process trigerred the corresponding
//events.
@ -127,12 +143,26 @@ public void testRegister()
+"All events were: " + regEvtCollector2.collectedNewStates
,regEvtCollector2.collectedNewStates
.contains(RegistrationState.REGISTERED));
//now the same for provider 3
assertTrue(
"No events were dispatched during the registration process "
+"of provider3."
,regEvtCollector3.collectedNewStates.size() > 0);
assertTrue(
"No registration event notifying of registration was dispatched. "
+"All events were: " + regEvtCollector3.collectedNewStates
,regEvtCollector3.collectedNewStates
.contains(RegistrationState.REGISTERED));
fixture.provider1
.removeRegistrationStateChangeListener(regEvtCollector1);
fixture.provider2
.removeRegistrationStateChangeListener(regEvtCollector2);
fixture.provider3
.removeRegistrationStateChangeListener(regEvtCollector3);
}

@ -13,9 +13,10 @@
/**
* Msn specific testing for a Msn Protocol Provider Service implementation.
* The test suite registers two accounts for
* The test suite registers three accounts for
*
* @author Damian Minkov
* @author Valentin Martinet
*/
public class MsnProtocolProviderServiceLick
extends TestSuite
@ -34,6 +35,13 @@ public class MsnProtocolProviderServiceLick
*/
public static final String ACCOUNT_2_PREFIX
= "accounts.msn.account2.";
/**
* The prefix used for property names containing settings for our third
* testing account.
*/
public static final String ACCOUNT_3_PREFIX
= "accounts.msn.account3.";
/**
* The name of the property that indicates whether the user would like to
@ -89,6 +97,8 @@ public void start(BundleContext context)
addTest(TestOperationSetTypingNotifications.suite());
addTestSuite(TestOperationSetFileTransferImpl.class);
addTest(TestOperationSetAdHocMultiUserChatMsnImpl.suite());
}
addTest(TestAccountUninstallation.suite());

@ -7,95 +7,36 @@
package net.java.sip.communicator.slick.protocol.msn;
import org.osgi.framework.*;
import junit.framework.*;
import net.java.sip.communicator.service.protocol.*;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.slick.protocol.generic.*;
/**
* Contains fields and methods used by most or all tests in the msn slick.
*
* @author Damian Minkov
* @author Valentin Martinet
*/
public class MsnSlickFixture
extends TestCase
extends AdHocMultiUserChatSlickFixture
{
/**
* To be set by the slick itself upon activation.
*/
public static BundleContext bc = null;
/**
* An osgi service reference for the protocol provider corresponding to our
* first testing account.
*/
public ServiceReference provider1ServiceRef = null;
/**
* The protocol provider corresponding to our first testing account.
*/
public ProtocolProviderService provider1 = null;
/**
* The user ID associated with testing account 1.
*/
public String userID1 = null;
/**
* An osgi service reference for the protocol provider corresponding to our
* second testing account.
*/
public ServiceReference provider2ServiceRef = null;
/**
* The protocol provider corresponding to our first testing account.
*/
public ProtocolProviderService provider2 = null;
/**
* The user ID associated with testing account 2.
*/
public String userID2 = null;
/**
* The tested protocol provider factory.
* Constructor
*/
public ProtocolProviderFactory providerFactory = null;
/**
* A reference to the bundle containing the tested pp implementation. This
* reference is set during the accoung uninstallation testing and used during
* the account uninstallation persistence testing.
*/
public static Bundle providerBundle = null;
/**
* Indicates whether the user has requested for onlline tests not to be run.
* (e.g. due to lack of network connectivity or ... time constraints ;)).
*/
public static boolean onlineTestingDisabled = false;
/**
* A Hashtable containing group names mapped against array lists of buddy
* screen names. This is a snapshot of the server stored buddy list for
* the account that is going to be used by the tested implementation.
* It is filled in by the tester agent who'd login with that account
* and initialize the ss contact list before the tested implementation has
* actually done so.
*/
public static Hashtable<String, List<String>> preInstalledBuddyList = null;
public MsnSlickFixture()
{
super();
}
/**
* Initializes protocol provider references and whatever else there is to
* initialize.
*
* @throws java.lang.Exception in case we meet problems while retrieving
*
* @throws InvalidSyntaxException in case we meet problems while retrieving
* protocol providers through OSGI
*/
public void setUp()
throws Exception
public void setUp() throws InvalidSyntaxException
{
// first obtain a reference to the provider factory
ServiceReference[] serRefs = null;
@ -126,6 +67,11 @@ public void setUp()
System.getProperty(
MsnProtocolProviderServiceLick.ACCOUNT_2_PREFIX
+ ProtocolProviderFactory.USER_ID);
userID3 =
System.getProperty(
MsnProtocolProviderServiceLick.ACCOUNT_3_PREFIX
+ ProtocolProviderFactory.USER_ID);
//find the protocol providers exported for the two accounts
ServiceReference[] msnProvider1Refs
@ -159,164 +105,29 @@ public void setUp()
, msnProvider2Refs);
assertTrue("No Protocol Provider was found for msn account2:"+ userID2,
msnProvider2Refs.length > 0);
ServiceReference[] msnProvider3Refs
= bc.getServiceReferences(
ProtocolProviderService.class.getName(),
"(&"
+"("+ProtocolProviderFactory.PROTOCOL+"="+ProtocolNames.MSN+")"
+"("+ProtocolProviderFactory.USER_ID+"="
+ userID3 +")"
+")");
//again make sure we found a service.
assertNotNull("No Protocol Provider was found for msn account3:"
+ userID3
, msnProvider3Refs);
assertTrue("No Protocol Provider was found for msn account3:"+ userID3,
msnProvider3Refs.length > 0);
//save the service for other tests to use.
provider1ServiceRef = msnProvider1Refs[0];
provider1 = (ProtocolProviderService)bc.getService(provider1ServiceRef);
provider2ServiceRef = msnProvider2Refs[0];
provider2 = (ProtocolProviderService)bc.getService(provider2ServiceRef);
}
/**
* Un get service references used in here.
*/
public void tearDown()
{
bc.ungetService(provider1ServiceRef);
bc.ungetService(provider2ServiceRef);
}
/**
* Returns the bundle that has registered the protocol provider service
* implementation that we're currently testing. The method would go through
* all bundles currently installed in the framework and return the first
* one that exports the same protocol provider instance as the one we test
* in this slick.
* @param provider the provider whose bundle we're looking for.
* @return the Bundle that has registered the protocol provider service
* we're testing in the slick.
*/
public static Bundle findProtocolProviderBundle(
ProtocolProviderService provider)
{
Bundle[] bundles = bc.getBundles();
for (int i = 0; i < bundles.length; i++)
{
ServiceReference[] registeredServices
= bundles[i].getRegisteredServices();
if (registeredServices == null)
continue;
for (int j = 0; j < registeredServices.length; j++)
{
Object service
= bc.getService(registeredServices[j]);
if (service == provider)
return bundles[i];
}
}
return null;
}
public void clearProvidersLists()
throws Exception
{
Map<String, OperationSet> supportedOperationSets1 =
provider1.getSupportedOperationSets();
if ( supportedOperationSets1 == null
|| supportedOperationSets1.size() < 1)
throw new NullPointerException(
"No OperationSet implementations are supported by "
+"this msn implementation. ");
//get the operation set presence here.
OperationSetPersistentPresence opSetPersPresence1 =
(OperationSetPersistentPresence)supportedOperationSets1.get(
OperationSetPersistentPresence.class.getName());
//if still null then the implementation doesn't offer a presence
//operation set which is unacceptable for msn.
if (opSetPersPresence1 == null)
throw new NullPointerException(
"An implementation of the msn service must provide an "
+ "implementation of at least the one of the Presence "
+ "Operation Sets");
// lets do it once again for the second provider
Map<String, OperationSet> supportedOperationSets2 =
provider2.getSupportedOperationSets();
if (supportedOperationSets2 == null
|| supportedOperationSets2.size() < 1)
throw new NullPointerException(
"No OperationSet implementations are supported by "
+ "this msn implementation. ");
//get the operation set presence here.
OperationSetPersistentPresence opSetPersPresence2 =
(OperationSetPersistentPresence) supportedOperationSets2.get(
OperationSetPersistentPresence.class.getName());
//if still null then the implementation doesn't offer a presence
//operation set which is unacceptable for msn.
if (opSetPersPresence2 == null)
throw new NullPointerException(
"An implementation of the msn service must provide an "
+ "implementation of at least the one of the Presence "
+ "Operation Sets");
ContactGroup rootGroup1 = opSetPersPresence1.getServerStoredContactListRoot();
// first delete the groups
Vector<ContactGroup> groupsToRemove = new Vector<ContactGroup>();
Iterator<ContactGroup> iter = rootGroup1.subgroups();
while (iter.hasNext())
{
groupsToRemove.add(iter.next());
}
iter = groupsToRemove.iterator();
while (iter.hasNext())
{
ContactGroup item = iter.next();
opSetPersPresence1.removeServerStoredContactGroup(item);
}
//then delete contacts if any in root list
Vector<Contact> contactsToRemove = new Vector<Contact>();
Iterator<Contact> iter2 = rootGroup1.contacts();
while (iter2.hasNext())
{
contactsToRemove.add(iter2.next());
}
iter2 = contactsToRemove.iterator();
while (iter2.hasNext())
{
opSetPersPresence1.unsubscribe(iter2.next());
}
ContactGroup rootGroup2 = opSetPersPresence2.getServerStoredContactListRoot();
// delete groups
groupsToRemove = new Vector<ContactGroup>();
iter = rootGroup2.subgroups();
while (iter.hasNext())
{
groupsToRemove.add(iter.next());
}
iter = groupsToRemove.iterator();
while (iter.hasNext())
{
ContactGroup item = iter.next();
opSetPersPresence2.removeServerStoredContactGroup(item);
}
//then delete contacts if any in root list
contactsToRemove = new Vector<Contact>();
iter2 = rootGroup2.contacts();
while (iter2.hasNext())
{
contactsToRemove.add(iter2.next());
}
iter2 = contactsToRemove.iterator();
while (iter2.hasNext())
{
opSetPersPresence2.unsubscribe(iter2.next());
}
provider3ServiceRef = msnProvider3Refs[0];
provider3 = (ProtocolProviderService)bc.getService(provider3ServiceRef);
}
}

@ -82,6 +82,8 @@ public void testInstallAccount()
MsnProtocolProviderServiceLick.ACCOUNT_1_PREFIX);
Hashtable<String, String> msnAccount2Properties = getAccountProperties(
MsnProtocolProviderServiceLick.ACCOUNT_2_PREFIX);
Hashtable<String, String> msnAccount3Properties = getAccountProperties(
MsnProtocolProviderServiceLick.ACCOUNT_3_PREFIX);
//try to install an account with a null account id
try{
@ -101,10 +103,13 @@ public void testInstallAccount()
msnProviderFactory.installAccount(
msnAccount2Properties.get(ProtocolProviderFactory.USER_ID)
, msnAccount2Properties);
msnProviderFactory.installAccount(
msnAccount3Properties.get(ProtocolProviderFactory.USER_ID)
, msnAccount3Properties);
//try to install one of the accounts one more time and verify that an
//excepion is thrown.
//exception is thrown.
try{
msnProviderFactory.installAccount(
msnAccount1Properties.get(ProtocolProviderFactory.USER_ID)
@ -122,7 +127,7 @@ public void testInstallAccount()
assertTrue(
"The newly installed account was not in the acc man's "
+"registered accounts!",
msnProviderFactory.getRegisteredAccounts().size() == 2);
msnProviderFactory.getRegisteredAccounts().size() == 3);
//Verify protocol providers corresponding to the new account have
//been properly registered with the osgi framework.

@ -228,9 +228,14 @@ public void testUninstallAccount()
fixture.provider1.getAccountID()));
assertTrue(
"Failed to remove a provider corresponding to URI "
+ fixture.userID1
+ fixture.userID2
,fixture.providerFactory.uninstallAccount(
fixture.provider2.getAccountID()));
assertTrue(
"Failed to remove a provider corresponding to URI "
+ fixture.userID3
,fixture.providerFactory.uninstallAccount(
fixture.provider3.getAccountID()));
//make sure no providers have remained installed.
ServiceReference[] msnProviderRefs = null;

@ -0,0 +1,147 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.slick.protocol.msn;
import java.util.*;
import junit.framework.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.slick.protocol.generic.*;
/**
* Tests for the MSN ad-hoc multi-user chat operation set.
*
* @author Valentin Martinet
*/
public class TestOperationSetAdHocMultiUserChatMsnImpl
extends TestOperationSetAdHocMultiUserChat
{
/**
* Creates the test with the specified method name.
*
* @param name the name of the method to execute.
*/
public TestOperationSetAdHocMultiUserChatMsnImpl(String name)
{
super(name);
}
/**
* Creates a test suite containing tests of this class in a specific order.
*
* @return Test a tests suite containing all tests to execute.
*/
public static TestSuite suite()
{
TestSuite suite = new TestSuite();
suite.addTest(new TestOperationSetAdHocMultiUserChatMsnImpl(
"prepareContactList"));
suite.addTest(new TestOperationSetAdHocMultiUserChatMsnImpl(
"testCreateRoom"));
suite.addTest(new TestOperationSetAdHocMultiUserChatMsnImpl(
"testPeerJoined"));
suite.addTest(new TestOperationSetAdHocMultiUserChatMsnImpl(
"testSendIM"));
suite.addTest(new TestOperationSetAdHocMultiUserChatMsnImpl(
"testPeerLeaved"));
return suite;
}
public void start() throws Exception
{
fixture = new MsnSlickFixture();
fixture.setUp();
// Supported operation sets by each protocol provider.
Map<String, OperationSet>
supportedOpSets1, supportedOpSets2, supportedOpSets3;
supportedOpSets1 = fixture.provider1.getSupportedOperationSets();
supportedOpSets2 = fixture.provider2.getSupportedOperationSets();
supportedOpSets3 = fixture.provider3.getSupportedOperationSets();
//
// Initialization of operation sets for the first testing account:
//
if (supportedOpSets1 == null || supportedOpSets1.size() < 1)
throw new NullPointerException(
"No OperationSet implementations are supported by " +
"this implementation. ");
opSetAHMUC1 = (OperationSetAdHocMultiUserChat) supportedOpSets1.get(
OperationSetAdHocMultiUserChat.class.getName());
if (opSetAHMUC1 == null)
throw new NullPointerException(
"No implementation for multi user chat was found");
opSetPresence1 = (OperationSetPresence) supportedOpSets1.get(
OperationSetPresence.class.getName());
if (opSetPresence1 == null)
throw new NullPointerException(
"An implementation of the service must provide an " +
"implementation of at least one of the PresenceOperationSets");
//
// Initialization of operation sets for the second testing account:
//
if (supportedOpSets2 == null || supportedOpSets2.size() < 1)
throw new NullPointerException(
"No OperationSet implementations are supported by " +
"this implementation. ");
opSetAHMUC2 = (OperationSetAdHocMultiUserChat) supportedOpSets2.get(
OperationSetAdHocMultiUserChat.class.getName());
if (opSetAHMUC2 == null)
throw new NullPointerException(
"No implementation for ad hoc multi user chat was found");
opSetPresence2 = (OperationSetPresence) supportedOpSets2.get(
OperationSetPresence.class.getName());
if (opSetPresence2 == null)
throw new NullPointerException(
"An implementation of the service must provide an " +
"implementation of at least one of the PresenceOperationSets");
//
// Initialization of operation sets for the third testing account:
//
if (supportedOpSets3 == null || supportedOpSets3.size() < 1)
throw new NullPointerException(
"No OperationSet implementations are supported by " +
"this implementation. ");
opSetAHMUC3 = (OperationSetAdHocMultiUserChat) supportedOpSets3.get(
OperationSetAdHocMultiUserChat.class.getName());
if (opSetAHMUC3 == null)
throw new NullPointerException(
"No implementation for ad hoc multi user chat was found");
opSetPresence3 = (OperationSetPresence) supportedOpSets3.get(
OperationSetPresence.class.getName());
if (opSetPresence3 == null)
throw new NullPointerException(
"An implementation of the service must provide an " +
"implementation of at least one of the PresenceOperationSets");
}
}

@ -18,6 +18,7 @@
* Performs testing on protocol provider methods.
* @todo add more detailed docs once the tests are written.
* @author Damian Minkov
* @author Valentin Martinet
*/
public class TestProtocolProviderServiceMsnImpl
extends TestCase
@ -38,6 +39,12 @@ public class TestProtocolProviderServiceMsnImpl
*/
public RegistrationEventCollector regEvtCollector2
= new RegistrationEventCollector();
/**
* An event adapter that would collec registation state change events
*/
public RegistrationEventCollector regEvtCollector3
= new RegistrationEventCollector();
/**
* Creates a test encapsulator for the method with the specified name.
@ -88,14 +95,18 @@ public void testRegister()
//they were properly dispatched.
fixture.provider1.addRegistrationStateChangeListener(regEvtCollector1);
fixture.provider2.addRegistrationStateChangeListener(regEvtCollector2);
fixture.provider3.addRegistrationStateChangeListener(regEvtCollector3);
//register both our providers
//register all of our providers
fixture.provider1.register(new SecurityAuthorityImpl(
System.getProperty(MsnProtocolProviderServiceLick.ACCOUNT_1_PREFIX
+ ProtocolProviderFactory.PASSWORD).toCharArray()));
fixture.provider2.register(new SecurityAuthorityImpl(
System.getProperty(MsnProtocolProviderServiceLick.ACCOUNT_2_PREFIX
+ ProtocolProviderFactory.PASSWORD).toCharArray()));
fixture.provider3.register(new SecurityAuthorityImpl(
System.getProperty(MsnProtocolProviderServiceLick.ACCOUNT_3_PREFIX
+ ProtocolProviderFactory.PASSWORD).toCharArray()));
//give it enough time to register. We won't really have to wait all this
//time since the registration event collector would notify us the moment
@ -104,6 +115,7 @@ public void testRegister()
regEvtCollector1.waitForEvent(15000);
regEvtCollector2.waitForEvent(40000);
regEvtCollector3.waitForEvent(60000);
//make sure that the registration process trigerred the corresponding
//events.
@ -128,12 +140,26 @@ public void testRegister()
+"All events were: " + regEvtCollector2.collectedNewStates
,regEvtCollector2.collectedNewStates
.contains(RegistrationState.REGISTERED));
//now the same for provider 3
assertTrue(
"No events were dispatched during the registration process "
+"of provider3."
,regEvtCollector3.collectedNewStates.size() > 0);
assertTrue(
"No registration event notifying of registration was dispatched. "
+"All events were: " + regEvtCollector3.collectedNewStates
,regEvtCollector3.collectedNewStates
.contains(RegistrationState.REGISTERED));
fixture.provider1
.removeRegistrationStateChangeListener(regEvtCollector1);
fixture.provider2
.removeRegistrationStateChangeListener(regEvtCollector2);
fixture.provider3
.removeRegistrationStateChangeListener(regEvtCollector3);
}

Loading…
Cancel
Save