Added support for contact list modifications to the meta contact list.

cusax-fix
Emil Ivov 20 years ago
parent dbbcabe285
commit 319358105d

@ -87,12 +87,17 @@ public int countSubgroups()
/**
* Returns a <tt>java.util.Iterator</tt> over the <tt>MetaContact</tt>s
* contained in this <tt>MetaContactGroup</tt>.
* <p>
* In order to prevent problems with concurrency, the <tt>Iterator</tt>
* returned by this method is not over the actual list of groups but over a
* copy of that list.
* <p>
*
* @return a <tt>java.util.Iterator</tt> over an empty contacts list.
*/
public Iterator getChildContacts()
{
return childContacts.iterator();
return new LinkedList(childContacts).iterator();
}
/**
@ -116,6 +121,32 @@ public MetaContact getMetaContact(String metaContactID)
return null;
}
/**
* Returns the meta contact encapsulating a contact belonging to the
* specified <tt>provider</tt> with the specified identifier.
*
* @param provider the ProtocolProviderService that the specified
* <tt>contactID</tt> is pertaining to.
* @param contactID a String identifier of the protocol specific contact
* whose container meta contact we're looking for.
* @return the <tt>MetaContact</tt> with the specified idnetifier.
*/
public MetaContact getMetaContact(ProtocolProviderService provider,
String contactID)
{
Iterator contactsIter = getChildContacts();
while(contactsIter.hasNext())
{
MetaContact contact = (MetaContact)contactsIter.next();
if (contact.getContact(contactID, provider) != null)
return contact;
}
return null;
}
/**
* Returns a meta contact, a child of this group or its subgroups, that
* has the specified metaUID. If no such meta contact exists, the method
@ -157,12 +188,17 @@ public MetaContactImpl findMetaContactByMetaUID(String metaUID)
/**
* Returns an iterator over all the protocol specific groups that this
* contact group represents.
* <p>
* In order to prevent problems with concurrency, the <tt>Iterator</tt>
* returned by this method is not over the actual list of groups but over a
* copy of that list.
* <p>
* @return an Iterator over the protocol specific groups that this group
* represents.
*/
public Iterator getContactGroups()
{
return this.protoGroups.iterator();
return new LinkedList( this.protoGroups ).iterator();
}
/**
@ -371,15 +407,46 @@ public MetaContactGroup getMetaContactSubgroup(String groupName)
return null;
}
/**
* Returns true if and only if <tt>contact</tt> is a direct child of this
* group.
* @param contact the <tt>MetaContact</tt> whose relation to this group
* we'd like to determine.
* @return <tt>true</tt> if <tt>contact</tt> is a direct child of this group
* and <tt>false</tt> otherwise.
*/
public boolean contains(MetaContact contact)
{
return this.childContacts.contains(contact);
}
/**
* Returns true if and only if <tt>group</tt> is a direct subgroup of this
* <tt>MetaContactGroup</tt>.
* @param group the <tt>MetaContactGroup</tt> whose relation to this group
* we'd like to determine.
* @return <tt>true</tt> if <tt>group</tt> is a direct child of this
* <tt>MetaContactGroup</tt> and <tt>false</tt> otherwise.
*/
public boolean contains(MetaContactGroup group)
{
return this.subgroups.contains(group);
}
/**
* Returns an <tt>java.util.Iterator</tt> over the sub groups that this
* <tt>MetaContactGroup</tt> contains.
* <p>
* In order to prevent problems with concurrency, the <tt>Iterator</tt>
* returned by this method is not over the actual list of groups but over a
* copy of that list.
* <p>
* @return a <tt>java.util.Iterator</tt> containing all subgroups.
*/
public Iterator getSubgroups()
{
return subgroups.iterator();
return new LinkedList( subgroups ).iterator();
}
/**
@ -391,6 +458,16 @@ public String getGroupName()
return groupName;
}
/**
* Sets the name of this group.
* @param newGroupName a String containing the new name of this group.
*/
void setGroupName(String newGroupName)
{
this.groupName = newGroupName;
}
/**
* Returns a String representation of this group and the contacts it
* contains (may turn out to be a relatively long string).

@ -57,6 +57,10 @@ public int getContactCount()
/**
* Returns a Contact, encapsulated by this MetaContact and coming from
* the specified ProtocolProviderService.
* <p>
* In order to prevent problems with concurrency, the <tt>Iterator</tt>
* returned by this method is not be over the actual list of contacts but
* over a copy of that list.
*
* @param provider a reference to the <tt>ProtocolProviderService</tt>
* that we'd like to get a <tt>Contact</tt> for.
@ -82,6 +86,7 @@ public Iterator getContactsForProvider(ProtocolProviderService provider)
/**
* Returns a contact encapsulated by this meta contact, having the specified
* contactAddress and coming from the indicated ownerProvider.
* <p>
* @param contactAddress the address of the contact who we're looking for.
* @param ownerProvider a reference to the ProtocolProviderService that
* the contact we're looking for belongs to.
@ -110,14 +115,19 @@ public Contact getContact(String contactAddress,
/**
* Returns a <tt>java.util.Iterator</tt> over all protocol specific
* <tt>Contacts</tt> encapsulated by this <tt>MetaContact</tt>.
*
* <p>
* In order to prevent problems with concurrency, the <tt>Iterator</tt>
* returned by this method is not over the actual list of contacts but over
* a copy of that list.
* <p>
* @return a <tt>java.util.Ierator</tt> over all protocol specific
* <tt>Contact</tt>s that were registered as subcontacts for this
* <tt>MetaContact</tt>
*/
public Iterator getContacts()
{
return protoContacts.iterator();
List contactsCopy = new LinkedList(protoContacts);
return contactsCopy.iterator();
}
/**
@ -189,6 +199,10 @@ void setDisplayName(String displayName)
void addProtoContact(Contact contact)
{
this.protoContacts.add(contact);
//if this is our firt contact - set the display name too.
if(this.protoContacts.size() == 1)
setDisplayName(contact.getDisplayName());
}
/**
@ -209,7 +223,7 @@ boolean removeProtoContact(Contact contact)
/**
* Removes all proto contacts that belong to the specified provider.
*
* @param contact the contact to remove
* @param provider the provider whose contacts we want removed.
*
* @return true if this <tt>MetaContact</tt> was modified and false
* otherwise.

@ -233,7 +233,7 @@ public void addSubsciptionListener(SubscriptionListener listener)
* Removes the specified subscription listener.
* @param listener the listener to remove.
*/
public void removeSubsciptionListener(SubscriptionListener listener)
public void removeSubscriptionListener(SubscriptionListener listener)
{
synchronized(subscriptionListeners){
subscriptionListeners.remove(listener);

@ -32,6 +32,11 @@ public interface MetaContact
/**
* Returns a <tt>java.util.Iterator</tt> with all protocol specific
* <tt>Contacts</tt> encapsulated by this <tt>MetaContact</tt>.
* <p>
* Note to implementors: In order to prevent problems with concurrency, the
* <tt>Iterator</tt> returned by this method should not be over the actual
* list of contacts but rather over a copy of that list.
* <p>
* @return a <tt>java.util.Iterator</tt> containing all protocol specific
* <tt>Contact</tt>s that were registered as subcontacts for this
* <tt>MetaContact</tt>
@ -65,6 +70,10 @@ public Contact getContact( String contactAddress,
* contacts encapsulated by this MetaContact is originating from the
* specified provider then an empty iterator is returned.
* <p>
* Note to implementors: In order to prevent problems with concurrency, the
* <tt>Iterator</tt> returned by this method should not be over the actual
* list of contacts but rather over a copy of that list.
* <p>
* @param provider a reference to the <tt>ProtocolProviderService</tt>
* whose contacts we'd like to get.
* @return an <tt>Iterator</tt> over all contacts encapsulated in this

@ -25,6 +25,11 @@ public interface MetaContactGroup
/**
* Returns an iterator over all the protocol specific groups that this
* contact group represents.
* <p>
* Note to implementors: In order to prevent problems with concurrency, the
* <tt>Iterator</tt> returned by this method should not be over the actual
* list of groups but rather over a copy of that list.
* <p>
* @return an Iterator over the protocol specific groups that this group
* represents.
*/
@ -36,6 +41,10 @@ public interface MetaContactGroup
* If none of the contacts encapsulated by this MetaContact is originating
* from the specified provider then an empty iterator is returned.
* <p>
* Note to implementors: In order to prevent problems with concurrency, the
* <tt>Iterator</tt> returned by this method should not be over the actual
* list of groups but rather over a copy of that list.
* <p>
* @param provider a reference to the <tt>ProtocolProviderService</tt>
* whose ContactGroups we'd like to get.
* @return an <tt>Iterator</tt> over all contacts encapsulated in this
@ -43,6 +52,26 @@ public interface MetaContactGroup
*/
public Iterator getContactGroupsForProvider(ProtocolProviderService provider);
/**
* Returns true if and only if <tt>contact</tt> is a direct child of this
* group.
* @param contact the <tt>MetaContact</tt> whose relation to this group
* we'd like to determine.
* @return <tt>true</tt> if <tt>contact</tt> is a direct child of this group
* and <tt>false</tt> otherwise.
*/
public boolean contains(MetaContact contact);
/**
* Returns true if and only if <tt>group</tt> is a direct subgroup of this
* <tt>MetaContactGroup</tt>.
* @param group the <tt>MetaContactGroup</tt> whose relation to this group
* we'd like to determine.
* @return <tt>true</tt> if <tt>group</tt> is a direct child of this
* <tt>MetaContactGroup</tt> and <tt>false</tt> otherwise.
*/
public boolean contains(MetaContactGroup group);
/**
* Returns a contact group encapsulated by this meta contact group, having
* the specified groupName and coming from the indicated ownerProvider.
@ -61,6 +90,11 @@ public ContactGroup getContactGroup(String groupName,
/**
* Returns a <tt>java.util.Iterator</tt> over the <tt>MetaContact</tt>s
* contained in this <tt>MetaContactGroup</tt>.
* <p>
* Note to implementors: In order to prevent problems with concurrency, the
* <tt>Iterator</tt> returned by this method should not be over the actual
* list of contacts but rather over a copy of that list.
* <p>
* @return a <tt>java.util.Iterator</tt> over the <tt>MetaContacts</tt> in
* this group.
*/
@ -82,6 +116,11 @@ public ContactGroup getContactGroup(String groupName,
* The <tt>canContainSubgroups()</tt> method allows us to verify whether
* this is the case with the group at hand.
* <p>
* <p>
* Note to implementors: In order to prevent problems with concurrency, the
* <tt>Iterator</tt> returned by this method should not be over the actual
* list of groups but rather over a copy of that list.
* <p>
* @return a <tt>java.util.Iterator</tt> containing all subgroups.
*/
public Iterator getSubgroups();
@ -103,6 +142,19 @@ public ContactGroup getContactGroup(String groupName,
*/
public boolean canContainSubgroups();
/**
* Returns the meta contact encapsulating a contact belonging to the
* specified <tt>provider</tt> with the specified identifier.
*
* @param provider the ProtocolProviderService that the specified
* <tt>contactID</tt> is pertaining to.
* @param contactID a String identifier of the protocol specific contact
* whose container meta contact we're looking for.
* @return the <tt>MetaContact</tt> with the specified idnetifier.
*/
public MetaContact getMetaContact(ProtocolProviderService provider,
String contactID);
/**
* Returns the contact with the specified identifier
* @param metaUID a String identifier obtained through the

@ -73,6 +73,29 @@ public interface MetaContactListService
*/
public MetaContactGroup getRoot();
/**
* Returns the meta contact group that is a direct parent of the specified
* <tt>child</tt>.
* @param child the <tt>MetaContactGroup</tt> whose paret group we're
* looking for. If no parent is found <tt>null</tt> is returned.
*
* @return the <tt>MetaContactGroup</tt> that contains <tt>child</tt> or
* null if no parent couldn't be found.
*/
public MetaContactGroup findParentMetaContactGroup(MetaContactGroup child);
/**
* Returns the meta contact group that is a direct parent of the specified
* <tt>child</tt>. If no parent is found <tt>null</tt> is returned.
* @param child the <tt>MetaContact</tt> whose paret group we're looking
* for.
*
* @return the <tt>MetaContactGroup</tt> that contains <tt>child</tt> or
* null if no such group could be found.
*/
public MetaContactGroup findParentMetaContactGroup(MetaContact child);
/**
* Returns the MetaContact containing the specified contact or null if no
* such MetaContact was found. The method can be used when for example
@ -232,14 +255,32 @@ public void removeMetaContact(MetaContact metaContact)
* specific contacts are added to the group if the protocol lying behind
* them supports that.
* <p>
* @param parentGroup the <tt>MetaContactGroup</tt> that should be the
* parent of the newly created group.
* @param groupName the name of the <tt>MetaContactGroup</tt> to create.
*
* @throws MetaContactListException with an appropriate code if the
* operation fails for some reason.
*/
public void createMetaContactGroup(String groupName)
public void createMetaContactGroup(MetaContactGroup parent,
String groupName)
throws MetaContactListException;
/**
* Renames the specified <tt>MetaContactGroup</tt> as indicated by the
* <tt>newName</tt> param.
* The operation would only affect the local meta group and would not
* "touch" any encapsulated protocol specific group.
* <p>
* @param newGroupName the new name of the <tt>MetaContactGroup</tt> to
* rename.
*/
public void renameMetaContactGroup(MetaContactGroup group,
String newGroupName)
throws MetaContactListException;
/**
* Removes the specified meta contact group, all its corresponding protocol
* specific groups and all their children. If some of the children belong to

@ -41,10 +41,17 @@ public class MetaContactEvent
/**
* Indicates that the MetaContactEvent instance was triggered by the
* addition of a protocol specific contact to an existing MetaContact.
* a protocol specific contact to a new MetaContact parent.
*/
public static final int PROTO_CONTACT_ADDED = 4;
/**
* Indicates that the MetaContactEvent instance was triggered by moving
* addition of a protocol specific contact to an existing MetaContact.
*/
public static final int PROTO_CONTACT_MOVED = 5;
private ProtocolProviderService sourceProvider = null;

@ -220,7 +220,7 @@ public void removeContactPresenceStatusListener(
* Removes the specified subscription listener.
* @param listener the listener to remove.
*/
public void removeSubsciptionListener(SubscriptionListener listener);
public void removeSubscriptionListener(SubscriptionListener listener);
/**
* Returns the status message that was confirmed by the serfver

@ -34,11 +34,19 @@ public class MetaContactListServiceLick
*/
private ServiceRegistration mockProviderRegistration = null;
static final String THE_NAME_OF_A_GROUP = "SomePeople";
//Convenience referenes to some groups and contacts.
static final String THE_NAME_OF_A_CONTACT = "Spencer";
static final String topLevelGroupName = "SomePeople";
static MockContact THE_CONTACT = null;
static MockContactGroup topLevelMockGroup = null;
static final String subLevelContactName = "Spencer";
static MockContact subLevelContact = null;
static MockContactGroup subLevelGroup = null;
static MockContact subsubContact = null;
/**
* Start, init and register the SLICK. Create the mock protocol provider
@ -127,27 +135,29 @@ private void fillMockContactList(MockProvider provider)
class.getName());
MockContactGroup root =
(MockContactGroup)mockOpSet.getServerStoredContactListRoot();
root.addContact( new MockContact("Ivan Ivanov", provider, root) );
root.addContact( new MockContact("Martin Dupont", provider, root) );
root.addContact( new MockContact("Joe Bloggs", provider, root) );
root.addContact( new MockContact("Ivan Ivanov", provider) );
root.addContact( new MockContact("Martin Dupont", provider) );
root.addContact( new MockContact("Joe Bloggs", provider) );
topLevelMockGroup = new MockContactGroup(topLevelGroupName, provider);
MockContactGroup group1 = new MockContactGroup(THE_NAME_OF_A_GROUP, provider);
subLevelContact = new MockContact(subLevelContactName, provider);
topLevelMockGroup.addContact( subLevelContact );
topLevelMockGroup.addContact( new MockContact("Pencho", provider) );
topLevelMockGroup.addContact( new MockContact("Toto", provider) );
THE_CONTACT = new MockContact(THE_NAME_OF_A_CONTACT, provider,
group1);
group1.addContact( THE_CONTACT );
group1.addContact( new MockContact("Pencho", provider, group1) );
group1.addContact( new MockContact("Toto", provider, group1) );
subLevelGroup
= new MockContactGroup("SubSubGroup", provider);
MockContactGroup group2 = new MockContactGroup("SubSubGroup", provider);
subsubContact = new MockContact("SContact1", provider);
group2.addContact( new MockContact("SContact1", provider, group2));
group2.addContact( new MockContact("SContact2", provider, group2));
group2.addContact( new MockContact("SContact3", provider, group2));
group2.addContact( new MockContact("SContact4", provider, group2));
subLevelGroup.addContact( subsubContact );
subLevelGroup.addContact( new MockContact("SContact2", provider));
subLevelGroup.addContact( new MockContact("SContact3", provider));
subLevelGroup.addContact( new MockContact("SContact4", provider));
group1.addSubGroup(group2);
topLevelMockGroup.addSubGroup(subLevelGroup);
root.addSubGroup(group1);
root.addSubGroup(topLevelMockGroup);
}
}

@ -44,7 +44,7 @@ protected void setUp() throws Exception
super.setUp();
fixture.setUp();
mockContact = MetaContactListServiceLick.THE_CONTACT;
mockContact = MetaContactListServiceLick.subLevelContact;
metaContact = fixture.metaClService.findMetaContactByContact(
mockContact);
@ -138,7 +138,6 @@ public void testGetDefaultContact()
assertSame("getDefaultContact() did not return the right proto group."
, actualReturn, mockContact);
}
/**

@ -53,7 +53,7 @@ protected void setUp() throws Exception
.getServerStoredContactListRoot();
mockGroup = (MockContactGroup)mockGroup
.getGroup(MetaContactListServiceLick.THE_NAME_OF_A_GROUP);
.getGroup(MetaContactListServiceLick.topLevelGroupName);
metaGroup = fixture.metaClService.getRoot()
.getMetaContactSubgroup(mockGroup.getGroupName());
@ -171,7 +171,7 @@ public void testGetContactGroupsForProvider()
public void testGetGroupName()
{
assertEquals("grp: " + metaGroup + " had the wrong name."
, MetaContactListServiceLick.THE_NAME_OF_A_GROUP
, MetaContactListServiceLick.topLevelGroupName
, metaGroup.getGroupName());
}
@ -221,6 +221,35 @@ public void testGetMetaContact2()
, expectedChild, actualChild);
}
/**
* Verifies whether getMetaContact(string, provider) returns proper results.
*/
public void testGetMetaContact3()
{
MetaContactGroup metaContactGroup1 = fixture.metaClService
.findMetaContactGroupByContactGroup(MetaContactListServiceLick
.topLevelMockGroup);
MetaContact metaContact = metaContactGroup1.getMetaContact(
fixture.mockProvider
, MetaContactListServiceLick.subLevelContactName);
//do as best as we can to determine whether this is the right meta
//contact
assertNotNull(
"getMetaCont(prov, contactID) returned a MetaC that didn't "
+ "contain our contact"
, metaContact.getContact(
MetaContactListServiceLick.subLevelContactName
, fixture.mockProvider));
assertEquals(
"getMetaCont(prov, contactID) returned a MetaC with a wrong name "
, metaContact.getDisplayName()
, MetaContactListServiceLick.subLevelContactName);
}
/**
* test.
*/
@ -253,9 +282,43 @@ public void testGetMetaContactSubgroup2()
//make sure that what we just got is not null.
assertNotNull("getMetaContact(String) returned null for group 0"
, actualGroup);
}
/**
* Tests MetaContact.contains(MetaContact)
*/
public void testContains()
{
MetaContactGroup metaContactGroup1 = fixture.metaClService
.findMetaContactGroupByContactGroup(MetaContactListServiceLick
.topLevelMockGroup);
MetaContact metaContact = fixture.metaClService.findMetaContactByContact(
MetaContactListServiceLick.subLevelContact);
assertTrue(metaContactGroup1.contains(metaContact));
}
/**
* Tests MetaContact.contains(MetaContact)
*/
public void testContains2()
{
MetaContactGroup metaContactGroup1 = fixture.metaClService
.findMetaContactGroupByContactGroup(MetaContactListServiceLick
.topLevelMockGroup);
MetaContactGroup metaContactGroup2 = metaContactGroup1
.getMetaContactSubgroup(MetaContactListServiceLick
.subLevelGroup.getGroupName());
assertTrue(metaContactGroup1.contains(metaContactGroup2));
}
/**
* Tests MetaContactGroup.getSubgroups();
*/
public void testGetSubgroups()
{
Iterator subgroupsIter = metaGroup.getSubgroups();
@ -268,6 +331,5 @@ public void testGetSubgroups()
//i don't think we could test anything else here without becoming
//redundant with TestMetaContactList
}
}

@ -25,6 +25,14 @@
* stored contact lists and modifying server stored contact lists through the
* meta contact list service. Testing is done against the MockProvider which
* is directly accessible throughout the tests.
* <p>
* What we still need to test here:<br>
* 1. Test that groups are automatically created when proto contacts are moved.
* <br>
* 2. Test that events are generated when creating moving and removing groups
* from the metacontact list itself.
* <br>
*
* @author Emil Ivov
*/
public class TestMetaContactList
@ -40,18 +48,11 @@ public class TestMetaContactList
*/
private String newSubscriptionName = "NewSubscription";
/**
* The name of the new contat group that we create during testing.
*/
private String newGroupName = "NewContactGroup";
/**
* The name to use when renaming the new contat group.
*/
private String renamedGroupName = "RenamedContactGroup";
private static final Logger logger =
Logger.getLogger(TestMetaContactList.class);
@ -474,6 +475,7 @@ public void testSubscriptionHandling() throws Exception
*/
public void testGroupChangeEventHandling() throws Exception
{
String newGroupName = "testGroupChangeEventHandling.NewContactGroup";
//add a group and check for the event
MclEventCollector mclEvtCollector = new MclEventCollector();
@ -588,25 +590,366 @@ public void testGroupChangeEventHandling() throws Exception
mclEvtCollector.collectedEvents.clear();
}
/**
* Perform manipulations of moving protocol contacts in and outside of a
* meta contact and verify that they complete properly.
*/
public void testAddMoveRemoveContactToMetaContact()
{
/**@todo implement testAddMoveRemoveContactToMetaContact() */
// fail("@todo implement testAddMoveRemoveContactToMetaContact()");
String newContactID = "TestyPesty";
//get a ref to 2 contacts the we will experiment with.
MetaContact metaContact = fixture.metaClService.getRoot()
.getMetaContact(0);
MetaContact dstMetaContact = fixture.metaClService.getRoot()
.getMetaContact(1);
MclEventCollector evtCollector = new MclEventCollector();
fixture.metaClService.addContactListListener(evtCollector);
//add a new mock contact to a meta contact
fixture.metaClService.addNewContactToMetaContact(
fixture.mockProvider
, metaContact
, newContactID);
fixture.metaClService.removeContactListListener(evtCollector);
//verify that the contact has been added to the meta contact.
assertEquals("Dest. meta Contact did not seem to contain an "
+"extra proto contact."
, 2
, metaContact.getContactCount());
MockContact newContact = (MockContact)metaContact
.getContact(newContactID, fixture.mockProvider);
assertNotNull("newContact", newContact);
//verify that a mock contact has been created in the mock contact list.
//and that it is the same as the one added in the MetaContact
assertSame("Proto specific contact in mock contact list."
, newContact
, opSetPersPresence.getServerStoredContactListRoot()
.getContact(newContactID));
//verify that events have been properly delivered.
assertTrue("No events delivered while adding a new contact to a "
+"meta contact", evtCollector.collectedEvents.size() == 1);
MetaContactEvent event = (MetaContactEvent)evtCollector
.collectedEvents.get(0);
evtCollector.collectedEvents.clear();
assertSame ( "Source contact in MetaContactEvent gen. upon add."
, metaContact , event.getSourceContact());
assertSame ( "Source provider in MetaContactEvent gen. upon add."
, fixture.mockProvider, event.getSourceProvider());
assertEquals ( "Event ID in MetaContactEvent gen. upon add."
, MetaContactEvent.PROTO_CONTACT_ADDED, event.getEventID());
//move the mock contact to another meta contact
fixture.metaClService.addContactListListener(evtCollector);
fixture.metaClService.moveContact(newContact, dstMetaContact);
fixture.metaClService.removeContactListListener(evtCollector);
//verify that the old meta contact does not contain it anymore.
assertEquals("Orig. Meta Contact did not seem restored after removing "
+"the newly added contact."
, 1
, metaContact.getContactCount());
//verify that the new meta contact contains it.
assertEquals("A Meta Contact did not seem updated after moving a "
+"contact inside it."
, 2
, dstMetaContact.getContactCount());
newContact = (MockContact)dstMetaContact
.getContact(newContactID, fixture.mockProvider);
assertNotNull("newContact", newContact);
//verify that events have been properly delivered.
assertTrue("No events delivered while adding a moving a proto contact. "
, evtCollector.collectedEvents.size() == 1);
event = (MetaContactEvent) evtCollector.collectedEvents.get(0);
evtCollector.collectedEvents.clear();
assertSame("Source contact in MetaContactEvent gen. upon move."
, dstMetaContact, event.getSourceContact());
assertSame("Source provider in MetaContactEvent gen. upon move."
, fixture.mockProvider, event.getSourceProvider());
assertEquals("Event ID in MetaContactEvent gen. upon add."
, MetaContactEvent.PROTO_CONTACT_MOVED, event.getEventID());
//remove the meta contact
fixture.metaClService.addContactListListener(evtCollector);
fixture.metaClService.removeContact(newContact);
fixture.metaClService.removeContactListListener(evtCollector);
//verify that it is no more in the meta contact
assertEquals("Dest. Meta Contact did not seem restored after removing "
+"the newly added contact."
, 1
, dstMetaContact.getContactCount());
//verify that it is no more in the mock contact list
assertNull( "The MetaContactList did not remove a contact from the "
+ "MockList on del."
, opSetPersPresence.getServerStoredContactListRoot()
.getContact(newContactID));
//verify that events have been properly delivered.
assertTrue("No events delivered while adding a new contact to a "
+"meta contact", evtCollector.collectedEvents.size() == 1);
event = (MetaContactEvent)evtCollector
.collectedEvents.get(0);
evtCollector.collectedEvents.clear();
assertSame ( "Source contact in MetaContactEvent gen. upon remove."
, dstMetaContact, event.getSourceContact());
assertSame ( "Source provider in MetaContactEvent gen. upon remove."
, fixture.mockProvider, event.getSourceProvider());
assertEquals ( "Event ID in MetaContactEvent gen. upon remove."
, MetaContactEvent.PROTO_CONTACT_REMOVED
, event.getEventID());
}
/**
* Tests methods for creating moving and removing meta contacts.
*/
public void testCreateMoveRemoveMetaContact()
{
/**@todo implement testCreateMoveRemoveMetaContact() */
// fail("@todo implement testCreateMoveRemoveMetaContact()");
String newContactID ="testCreateMoveRemoveMetaContact.ContactID";
MetaContactGroup parentMetaGroup = fixture.metaClService.getRoot()
.getMetaContactSubgroup(MetaContactListServiceLick.topLevelGroupName);
//create a new metacontact and, hence mock contact, in the meta
//"SomePeople" non-toplevel group
fixture.metaClService.createMetaContact(fixture.mockProvider
, parentMetaGroup
, newContactID);
//check that the contact has been successfully created in the meta cl
MetaContact newMetaContact =
parentMetaGroup.getMetaContact(fixture.mockProvider, newContactID);
assertNotNull("create failed. couldn't find the new contact."
, newMetaContact);
//check that the contact has been successfully created in the mock cl
assertEquals("create() created a meta contact with the wrong name."
, newContactID, newMetaContact.getDisplayName());
//move the meta contact somewhere else
fixture.metaClService.moveMetaContact(
newMetaContact, fixture.metaClService.getRoot());
//check that the meta contact has moved.
assertNull(newMetaContact.getDisplayName()
+ " was still in its old location after moving it."
,parentMetaGroup.getMetaContact( newMetaContact.getMetaUID()));
assertNotNull(newMetaContact.getDisplayName()
+ " was not in the new location after moving it."
,fixture.metaClService.getRoot()
.getMetaContact(newMetaContact.getMetaUID()));
//check that the mock contact has moved as well.
assertNull("The mock contact corresponding to: "
+ newMetaContact.getDisplayName()
+ " was still in its old location after its "
+"encapsulating meta contact was moved"
,MetaContactListServiceLick.topLevelMockGroup
.getContact(newContactID));
//assert that the mock contact has indeed moved to its new parent.
assertNotNull("The mock contact corresponding to: "
+ newMetaContact.getDisplayName()
+ " was not moved to its new location after its "
+"encapsulating meta contact was."
,opSetPersPresence.getServerStoredContactListRoot()
.getContact(newContactID));
//remove the contact
fixture.metaClService.removeMetaContact(newMetaContact);
//check that the meta contact has been removed.
assertNull(newMetaContact.getDisplayName()
+ " was still in its old location after it was removed."
,fixture.metaClService.getRoot().getMetaContact(
newMetaContact.getMetaUID()));
//check that the mock contact has been removed.
assertNull("The mock contact corresponding to: "
+ newMetaContact.getDisplayName()
+ " was not removed after its encapsulating meta contact was."
,opSetPersPresence.getServerStoredContactListRoot()
.getContact(newContactID));
}
public void testCreateRemoveMetaContactGroup()
/**
* Tests operations on meta groups.
*/
public void testCreateRenameRemoveMetaContactGroup()
{
/**@todo implement testCreateRemoveMetaContactGroup() */
// fail("@todo implement testCreateRemoveMetaContactGroup()");
String newGroupName = "testCRRMetaContactGroup.NewContactGroup";
String newContactID = "testCRRMetaContactGroup.NewContactID";
//create a new meta contact group
fixture.metaClService.createMetaContactGroup(
fixture.metaClService.getRoot(), newGroupName);
//check that the group exists in the meta contact list but not yet in
//the mock provider
MetaContactGroup newMetaGroup = fixture.metaClService.getRoot()
.getMetaContactSubgroup(newGroupName);
assertNotNull(
"createMetaContactGroup failed - no group was created."
, newMetaGroup);
assertNull(
"createMetaContactGroup tried to create a proto group too early."
,opSetPersPresence.getServerStoredContactListRoot()
.getGroup(newGroupName));
//create a mock contcat through the meta contact list.
fixture.metaClService.createMetaContact(
fixture.mockProvider, newMetaGroup, newContactID);
//check that the mock group was created and added to the right meta grp.
MockContactGroup newMockGroup = (MockContactGroup)opSetPersPresence
.getServerStoredContactListRoot().getGroup(newGroupName);
assertNotNull(
"createMetaContact did not create a parent proto group "
+ "when it had to."
, newMockGroup);
assertSame(
"createMetaContact created a proto group but did not add it to the "
+ "right meta contact group."
, newMockGroup
, newMetaGroup.getContactGroup(newGroupName, fixture.mockProvider));
//check that the contact was added
MetaContact newMetaContact = newMetaGroup
.getMetaContact(fixture.mockProvider, newContactID);
assertNotNull("createMetaContact failed", newMetaContact);
//rename the meta contact group
String renamedGroupName = "new" + newGroupName;
fixture.metaClService.renameMetaContactGroup(newMetaGroup,
renamedGroupName);
//check that the meta group changed its name.
assertEquals ( "renameMetaContactGroup failed"
, newMetaGroup.getGroupName(), renamedGroupName);
//check that the mock group did not change name
assertEquals ( "renameMetaContactGroup renamed a proto group!"
, newMockGroup.getGroupName(), newGroupName);
//remove the meta contact group
fixture.metaClService.removeMetaContactGroup(newMetaGroup);
//check that the meta group is removed
assertNull(
"removeMetaContactGroup failed - group not removed."
, fixture.metaClService.getRoot()
.getMetaContactSubgroup(newGroupName));
//check that the mock group is removed
assertNull(
"removeMetaContact did not remove the corresp. proto group."
, opSetPersPresence.getServerStoredContactListRoot()
.getGroup(newGroupName));
}
/**
* Tests the MetaContactListService.findParentMetaContactGroup(MetaContact)
* method for two different meta contacts.
*/
public void testFindParentMetaContactGroup()
{
MetaContact metaContact1 = fixture.metaClService
.findMetaContactByContact(MetaContactListServiceLick
.subLevelContact);
MetaContact metaContact2 = fixture.metaClService
.findMetaContactByContact(MetaContactListServiceLick.subsubContact);
//do testing for the first contact
MetaContactGroup metaGroup = fixture.metaClService
.findParentMetaContactGroup(metaContact1);
assertNotNull("find failed for contact " + metaContact1, metaGroup);
assertEquals("find failed (wrong group) for contact "
+ metaContact1.getDisplayName()
, MetaContactListServiceLick.topLevelGroupName
, metaGroup.getGroupName());
//do testing for the first contact
metaGroup = fixture.metaClService.findParentMetaContactGroup(metaContact2);
assertNotNull("find failed for contact " + metaContact2, metaGroup);
assertEquals("find failed (wrong group) for contact "
+ metaContact2.getDisplayName()
, MetaContactListServiceLick.subLevelGroup.getGroupName()
, metaGroup.getGroupName());
}
/**
* Tests the MetaContactListService
* .findParentMetaContactGroup(MetaContactGroup)
* method for two different meta contact groups.
*/
public void testFindParentMetaContactGroup2()
{
MetaContactGroup metaContactGroup1 = fixture.metaClService
.findMetaContactGroupByContactGroup(MetaContactListServiceLick
.topLevelMockGroup);
MetaContactGroup metaContactGroup2 = fixture.metaClService
.findMetaContactGroupByContactGroup(MetaContactListServiceLick
.subLevelGroup);
//do testing for the first contact
MetaContactGroup metaGroup = fixture.metaClService
.findParentMetaContactGroup(metaContactGroup1);
assertNotNull("find failed for contact " + metaContactGroup1, metaGroup);
assertEquals("find failed (wrong group) for group "
+ metaContactGroup1.getGroupName()
, fixture.metaClService.getRoot().getGroupName()
, metaGroup.getGroupName());
//do testing for the first contact
metaGroup = fixture.metaClService.findParentMetaContactGroup(metaContactGroup2);
assertNotNull("find failed for contact " + metaContactGroup2, metaGroup);
assertEquals("find failed (wrong group) for group "
+ metaContactGroup2.getGroupName()
, MetaContactListServiceLick.topLevelGroupName
, metaGroup.getGroupName());
}
private class MclEventCollector implements MetaContactListListener
{
public Vector collectedEvents = new Vector();

@ -28,18 +28,26 @@ public class MockContact
* as a name and identifier.
*
* @param id the identifier of this contact (also used as a name).
* @param parentGroup the group that contains the contact
* @param parentProvider the provider that created us.
*/
public MockContact(String id,
MockProvider parentProvider,
MockContactGroup parentGroup)
MockProvider parentProvider)
{
this.parentGroup = parentGroup;
this.contactID = id;
this.parentProvider = parentProvider;
}
/**
* This method is only called when the contact is added to a new
* <tt>MockContactGroup</tt> by the MockContactGroup itself.
* @param newParentGroup the <tt>MockContactGroup</tt> that is now parent
* of this <tt>MockContact</tt>
*/
void setParentGroup(MockContactGroup newParentGroup)
{
this.parentGroup = newParentGroup;
}
/**
* Returns a String that can be used for identifying the contact.
*

@ -76,6 +76,7 @@ public Iterator contacts()
public void addContact(MockContact contactToAdd)
{
this.contacts.add(contactToAdd);
contactToAdd.setParentGroup(this);
}
/**
@ -155,6 +156,31 @@ public MockContactGroup findGroupParent(MockContactGroup mockGroup)
return null;
}
/**
* Returns the group that is parent of the specified mockContact or null
* if no parent was found.
* @param mockContact the contact whose parent we're looking for.
* @return the MockContactGroup instance that mockContact belongs to or null
* if no parent was found.
*/
public MockContactGroup findContactParent(MockContact mockContact)
{
if ( contacts.contains(mockContact) )
return this;
Iterator subGroupsIter = subGroups();
while (subGroupsIter.hasNext())
{
MockContactGroup subgroup = (MockContactGroup) subGroupsIter.next();
MockContactGroup parent = subgroup.findContactParent(mockContact);
if(parent != null)
return parent;
}
return null;
}
/**
* Returns the <tt>Contact</tt> with the specified address or identifier.

@ -284,7 +284,15 @@ public Iterator getSupportedStatusSet()
public void moveContactToGroup(Contact contactToMove,
ContactGroup newParent)
{
/** @todo implement moveContactToGroup() */
MockContact mockContact = (MockContact)contactToMove;
MockContactGroup parentMockGroup = findContactParent(mockContact);
parentMockGroup.removeContact(mockContact);
((MockContactGroup)newParent).addContact(mockContact);
/** @todo fire an event (we probably need to create a new family of move events) */
}
/**
@ -367,6 +375,19 @@ public MockContactGroup findGroupParent(MockContactGroup mockGroup)
return contactListRoot.findGroupParent(mockGroup);
}
/**
* Returns the group that is parent of the specified mockContact or null
* if no parent was found.
* @param mockContact the contact whose parent we're looking for.
* @return the MockContactGroup instance that mockContact belongs to or null
* if no parent was found.
*/
public MockContactGroup findContactParent(MockContact mockContact)
{
return contactListRoot.findContactParent(mockContact);
}
/**
* Removes the specified group from the server stored contact list.
*
@ -412,7 +433,7 @@ public void removeServerStoredGroupChangeListener(ServerStoredGroupListener
*
* @param listener the listener to remove.
*/
public void removeSubsciptionListener(SubscriptionListener listener)
public void removeSubscriptionListener(SubscriptionListener listener)
{
this.subscriptionListeners.remove(listener);
}
@ -468,14 +489,13 @@ public void subscribe(ContactGroup parent, String contactIdentifier) throws
OperationFailedException
{
MockContact contact = new MockContact(contactIdentifier
, parentProvider
, (MockContactGroup)parent);
, parentProvider);
((MockContactGroup)parent).addContact(contact);
fireSubscriptionEvent(contact,
parent,
SubscriptionEvent.SUBSCRIPTION_CREATED);
parent,
SubscriptionEvent.SUBSCRIPTION_CREATED);
}
@ -498,8 +518,7 @@ public void subscribe(String contactIdentifier) throws
OperationFailedException
{
MockContact contact = new MockContact(contactIdentifier
, parentProvider
, contactListRoot);
, parentProvider);
contactListRoot.addContact(contact);

@ -102,31 +102,29 @@ public boolean register(String password)
return true;
DefaultAppSession session = new DefaultAppSession();
System.out.println("1");
AimSession aimSession =
session.openAimSession(icqUIN);
aimSession.openConnection(
new AimConnectionProperties(
icqUIN, password));
System.out.println("2");
conn = aimSession.getConnection();
System.out.println("3");
conn.addStateListener(new AimConnStateListener());
conn.getBuddyInfoManager().addGlobalBuddyInfoListener(new GlobalBuddyListener());
System.out.println("4");
conn.connect();
System.out.println("5");
conn.connect();
synchronized(connectionLock){
try{connectionLock.wait(10000);}catch(InterruptedException ex){}
}
System.out.println("6");
if (icbmService == null){
//maybe throw an exception here
return (registered = false);
}
System.out.println("7");
//conn.getSsiService()
// .getBuddyList().addRetroactiveLayoutListener(new RetroListener());
conn.getBuddyService().addBuddyListener(new BuddyListener());

@ -189,7 +189,7 @@ public void postTestPersistentSubscribe()
evtCollector.waitForEvent(10000);
opSetPersPresence.removeSubsciptionListener(evtCollector);
opSetPersPresence.removeSubscriptionListener(evtCollector);
//make sure the event delivery went as expected
assertEquals("Number of dispatched events",
@ -243,7 +243,7 @@ public void postTestPersistentUnsubscribe()
evtCollector.waitForEvent(10000);
opSetPersPresence.removeSubsciptionListener(evtCollector);
opSetPersPresence.removeSubscriptionListener(evtCollector);
//make sure the event delivery went as expected
assertEquals("Number of dispatched events",

@ -428,7 +428,7 @@ public void postTestSubscribe()
operationSetPresence.subscribe(fixture.testerAgent.getIcqUIN());
subEvtCollector.waitForEvent(10000);
//don't want any more events
operationSetPresence.removeSubsciptionListener(subEvtCollector);
operationSetPresence.removeSubscriptionListener(subEvtCollector);
}
assertEquals("Subscription event dispatching failed."
@ -543,7 +543,7 @@ public void postTestUnsubscribe()
operationSetPresence.unsubscribe(icqTesterAgentContact);
subEvtCollector.waitForEvent(10000);
//don't want any more events
operationSetPresence.removeSubsciptionListener(subEvtCollector);
operationSetPresence.removeSubscriptionListener(subEvtCollector);
}
assertEquals("Subscription event dispatching failed."

Loading…
Cancel
Save