Testing for the meta contact list service

cusax-fix
Emil Ivov 20 years ago
parent 88184fac97
commit 5299ed8b5f

@ -34,6 +34,12 @@ public class MetaContactListServiceLick
*/
private ServiceRegistration mockProviderRegistration = null;
static final String THE_NAME_OF_A_GROUP = "SomePeople";
static final String THE_NAME_OF_A_CONTACT = "Spencer";
static MockContact THE_CONTACT = null;
/**
* Start, init and register the SLICK. Create the mock protocol provider
* and register it as a service.
@ -56,6 +62,8 @@ public void start(BundleContext context)
//add the meta contact list tests.
addTestSuite(TestMetaContactList.class);
addTestSuite(TestMetaContact.class);
addTestSuite(TestMetaContactGroup.class);
//register the slick itself
context.registerService(getClass().getName(), this, slickServiceProperties);
@ -119,15 +127,26 @@ private void fillMockContactList(MockProvider provider)
class.getName());
MockContactGroup root =
(MockContactGroup)mockOpSet.getServerStoredContactListRoot();
root.addContact( new MockContact("Ivan Ivanov", provider) );
root.addContact( new MockContact("Martin Dupont", provider) );
root.addContact( new MockContact("Joe Bloggs", provider) );
root.addContact( new MockContact("Ivan Ivanov", provider, root) );
root.addContact( new MockContact("Martin Dupont", provider, root) );
root.addContact( new MockContact("Joe Bloggs", provider, root) );
MockContactGroup group1 = new MockContactGroup(THE_NAME_OF_A_GROUP, 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) );
MockContactGroup group2 = new MockContactGroup("SubSubGroup", provider);
MockContactGroup group1 = new MockContactGroup("SomePeople", 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));
group1.addContact( new MockContact("Spencer", provider) );
group1.addContact( new MockContact("Pencho", provider) );
group1.addContact( new MockContact("Toto", provider) );
group1.addSubGroup(group2);
root.addSubGroup(group1);
}

@ -0,0 +1,163 @@
/*
* 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.contactlist;
import junit.framework.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.slick.contactlist.mockprovider.*;
import net.java.sip.communicator.service.protocol.*;
import java.util.*;
/**
* @todo comment
* @author Emil Ivov
*/
public class TestMetaContact extends TestCase
{
/**
* A reference to the SLICK fixture.
*/
MclSlickFixture fixture = new MclSlickFixture(getClass().getName());
/**
* The MetaContact that we're doing the testing aginst.
*/
MetaContact metaContact = null;
/**
* The mock contact that we're doing the testing against.
*/
MockContact mockContact = null;
public TestMetaContact(String name)
{
super(name);
}
protected void setUp() throws Exception
{
super.setUp();
fixture.setUp();
mockContact = MetaContactListServiceLick.THE_CONTACT;
metaContact = fixture.metaClService.findMetaContactByContact(
mockContact);
}
protected void tearDown() throws Exception
{
fixture.tearDown();
fixture = null;
super.tearDown();
}
/**
* Tests getContact()
*/
public void testGetContact()
{
Contact actualReturn = metaContact.getContact(
mockContact.getAddress(), fixture.mockProvider);
assertNotNull("getContact() return null.", actualReturn);
assertSame("getContact() did not return the right proto group."
, mockContact, actualReturn);
}
/**
* Test getContactCount()
*/
public void testGetContactCount()
{
//we only have mock provider registered so the count should be one.
assertEquals("getContactCount()", 1, metaContact.getContactCount());
}
/**
* Test getContacts()
*/
public void testGetContacts()
{
Iterator childContacts = metaContact.getContacts();
assertNotNull("getContacts() returned a null iterator."
, childContacts);
assertTrue("getContacts() returned an empty iterator."
, childContacts.hasNext());
assertSame("The iterator returned by getContacts() ("
+ mockContact.getAddress()
+")did not contain the "
+"right mock contact"
, mockContact, childContacts.next());
}
/**
* Test getContactsForProvider
*/
public void testGetContactsForProvider()
{
Iterator childContacts = metaContact.getContactsForProvider(
fixture.mockProvider);
assertNotNull("getContactsForProvider() returned a null iterator."
, childContacts);
assertTrue("getContactsForProvider() returned an empty iterator."
, childContacts.hasNext());
assertSame("The iterator returned by getContactsForProvider() ("
+ mockContact.getAddress()
+")did not contain the "
+"right mock contact"
, mockContact, childContacts.next());
}
/**
* Tests that getDefaultContact() returns the contact that is currently the
* best choice for communication with the tested meta contact.
*/
public void testGetDefaultContact()
{
Contact actualReturn = metaContact.getDefaultContact();
assertNotNull("getDefaultContact() return null.", actualReturn);
assertSame("getDefaultContact() did not return the right proto group."
, actualReturn, mockContact);
}
/**
* Checks whether the display name matches the one in th mock contact.
*/
public void testGetDisplayName()
{
assertEquals("getDisplayName()",
mockContact.getDisplayName(),
metaContact.getDisplayName());
}
public void testGetMetaUID()
{
String metaUID = metaContact.getMetaUID();
assertNotNull( "getMetaUID() did not seem to return a valid UID"
, metaUID);
assertTrue( "getMetaUID() did not seem to return a valid UID"
, metaUID.trim().length() > 0);
}
}

@ -0,0 +1,273 @@
/*
* 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.contactlist;
import junit.framework.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.slick.contactlist.mockprovider.*;
import net.java.sip.communicator.service.protocol.*;
import java.util.*;
/**
* Tests methods and behaviour of MetaContactGroup implementations.
*
* @author Emil Ivov
*/
public class TestMetaContactGroup extends TestCase
{
/**
* A reference to the SLICK fixture.
*/
MclSlickFixture fixture = new MclSlickFixture(getClass().getName());
/**
* The MetaContactGroup that we're doing the testing aginst.
*/
MetaContactGroup metaGroup = null;
/**
* The mock contact group that we're doing the testing against.
*/
MockContactGroup mockGroup = null;
public TestMetaContactGroup(String name)
{
super(name);
}
protected void setUp() throws Exception
{
super.setUp();
fixture.setUp();
OperationSetPersistentPresence opSetPresence
= (OperationSetPersistentPresence)fixture.mockProvider
.getSupportedOperationSets().get(
OperationSetPersistentPresence.class.getName());
mockGroup = (MockContactGroup)opSetPresence
.getServerStoredContactListRoot();
mockGroup = (MockContactGroup)mockGroup
.getGroup(MetaContactListServiceLick.THE_NAME_OF_A_GROUP);
metaGroup = fixture.metaClService.getRoot()
.getMetaContactSubgroup(mockGroup.getGroupName());
}
protected void tearDown() throws Exception
{
fixture.tearDown();
fixture = null;
super.tearDown();
}
/**
* Verifies whehter the returned number of contacts corresponds to the
* children of the corresponding mock contact group.
*/
public void testCountChildContacts()
{
assertEquals("MetaContactGroup.countChildContacts failed"
, metaGroup.countChildContacts()
, mockGroup.countContacts());
}
/**
* Verifies whehter the returned number of subgroups corresponds to the
* subgroups of the corresponding mock contact group.
*/
public void testCountSubgroups()
{
assertEquals("MetaContactGroup.countChildContacts failed"
, metaGroup.countSubgroups()
, mockGroup.countSubgroups());
}
/**
* Goes through the iterator returned by the getChildContacts() method
* and tries to make sure that it looks sane.
*/
public void testGetChildContacts()
{
Iterator childContactsIter = metaGroup.getChildContacts();
assertNotNull("getChildContacts() returned a null iterator."
, childContactsIter);
assertTrue("getChildContacts() returned an empty iterator."
, childContactsIter.hasNext());
//i don't think we could test anything else here without becoming
//redundant with TestMetaContactList
}
/**
* Tests getContactGroup()
*/
public void testGetContactGroup()
{
ContactGroup actualReturn = metaGroup.getContactGroup(
mockGroup.getGroupName(), fixture.mockProvider);
assertNotNull("getContactGroup() return null.", actualReturn);
assertSame("getContactGroup() did not return the right proto group."
, actualReturn, mockGroup);
}
/**
* Tests getContactGroups()
*/
public void testGetContactGroups()
{
Iterator contactGroups = metaGroup.getContactGroups();
assertNotNull("contact groups iterator", contactGroups);
assertTrue("The contact groups iterator was empty."
, contactGroups.hasNext());
MockContactGroup actualMockGroup
= (MockContactGroup)contactGroups.next();
assertSame("Iterator did not contain the right contact group"
, mockGroup
, actualMockGroup);
}
/**
* Tests testGetContactGroupsForProvider()
*/
public void testGetContactGroupsForProvider()
{
Iterator contactGroups = metaGroup.getContactGroups();
assertNotNull("contact groups for provider iterator", contactGroups);
assertTrue("The contact groups iterator was empty for a mock provider."
, contactGroups.hasNext());
MockContactGroup actualMockGroup
= (MockContactGroup)contactGroups.next();
assertSame("A prov. iterator did not contain the right contact group"
, mockGroup
, actualMockGroup);
}
/**
* Checks whether the name of the meta group has been properly initialized.
*/
public void testGetGroupName()
{
assertEquals("grp: " + metaGroup + " had the wrong name."
, MetaContactListServiceLick.THE_NAME_OF_A_GROUP
, metaGroup.getGroupName());
}
/**
* Verifies whether getMetaContact() returns proper results.
*/
public void testGetMetaContact()
{
//firt obtain references to 2 contacts.
MetaContact firstContact = metaGroup.getMetaContact(0);
MetaContact lastContact = metaGroup.getMetaContact(
metaGroup.countChildContacts() - 1);
//make sure that what we just got is not null.
assertNotNull("getMetaContact(int) returned null for contact 0"
, firstContact);
assertNotNull("getMetaContact(int) returned null for its last contact "
+ (metaGroup.countChildContacts() - 1)
, lastContact);
//I don't see what else we could add here without copying code from
//test meta contact
}
/**
* Tests the method.
*/
public void testGetMetaContact2()
{
//firt obtain a reference to a contact through iteration.
Iterator childContactsIter = metaGroup.getChildContacts();
//make sure the returned ref is ok.
assertNotNull("getChildContacts() returned a null iterator."
, childContactsIter);
assertTrue("getChildContacts() returned an empty iterator."
, childContactsIter.hasNext());
MetaContact expectedChild = (MetaContact)childContactsIter.next();
MetaContact actualChild = metaGroup.getMetaContact(
expectedChild.getMetaUID());
assertSame("getMetaContact(metaUID) did not return as expected."
, expectedChild, actualChild);
}
/**
* test.
*/
public void testGetMetaContactSubgroup()
{
//firt obtain references to a group.
MetaContactGroup actualGroup = metaGroup.getMetaContactSubgroup(0);
//make sure that what we just got is not null.
assertNotNull("getMetaContact(int) returned null for group 0"
, actualGroup);
//check whether this
assertNotNull("The returned group does not appear to really exist"
,mockGroup.getGroup(actualGroup.getGroupName()));
assertNotNull("Group encapsulated in the returned group did not match"
, mockGroup.getGroup(((MockContactGroup)actualGroup
.getContactGroups().next()).getGroupName()));
}
/**
* test.
*/
public void testGetMetaContactSubgroup2()
{
//firt obtain references to a group.
MetaContactGroup actualGroup = metaGroup.getMetaContactSubgroup(
((MetaContactGroup)metaGroup.getSubgroups().next()).getGroupName());
//make sure that what we just got is not null.
assertNotNull("getMetaContact(String) returned null for group 0"
, actualGroup);
}
public void testGetSubgroups()
{
Iterator subgroupsIter = metaGroup.getSubgroups();
assertNotNull("getSubgroup() returned a null iterator."
, subgroupsIter);
assertTrue("getSubgroups() returned an empty iterator."
, subgroupsIter.hasNext());
//i don't think we could test anything else here without becoming
//redundant with TestMetaContactList
}
}

@ -1,3 +1,9 @@
/*
* 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.contactlist;
import java.util.Hashtable;
@ -7,16 +13,18 @@
import junit.framework.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.protocol.Contact;
import net.java.sip.communicator.service.protocol.ContactGroup;
import net.java.sip.communicator.service.protocol.OperationSetPersistentPresence;
import net.java.sip.communicator.slick.contactlist.mockprovider.MockContactGroup;
import net.java.sip.communicator.slick.protocol.icq.TestOperationSetPersistentPresence;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.Logger;
import net.java.sip.communicator.slick.contactlist.mockprovider.*;
import net.java.sip.communicator.service.contactlist.event.*;
import java.util.*;
/**
* Test basic meta contact list functionality such as filling in the contact
* list from existing protocol provider implementations and others.
* Test meta contact list functionality such as filling in the contact list from
* existing protocol providers, properly handling events of modified server
* 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.
* @author Emil Ivov
*/
public class TestMetaContactList
@ -25,7 +33,24 @@ public class TestMetaContactList
/**
* A reference to the SLICK fixture.
*/
MclSlickFixture fixture = new MclSlickFixture(getClass().getName());
private MclSlickFixture fixture = new MclSlickFixture(getClass().getName());
/**
* The name of the new subscripiton that we create during testing.
*/
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);
@ -89,14 +114,14 @@ protected void tearDown() throws Exception
*/
public void testContactListRetrieving()
{
ContactGroup expectedRoot
= opSetPersPresence.getServerStoredContactListRoot();
MockContactGroup expectedRoot = (MockContactGroup)opSetPersPresence
.getServerStoredContactListRoot();
logger.debug("============== Predefined contact List ==============");
logger.debug("rootGroup="+expectedRoot.getGroupName()
+" rootGroup.childContacts="+expectedRoot.countContacts()
+ "rootGroup.childGroups="+expectedRoot.countSubGroups()
+ "rootGroup.childGroups="+expectedRoot.countSubgroups()
+ " Printing rootGroupContents=\n"+expectedRoot.toString());
MetaContactGroup actualRoot = fixture.metaClService.getRoot();
@ -108,57 +133,548 @@ public void testContactListRetrieving()
+ " rootGroup.childGroups="+actualRoot.countSubgroups()
+ " Printing rootGroupContents=\n"+actualRoot.toString());
Iterator expectedSubgroups = expectedRoot.subGroups();
assertGroupEquals(expectedRoot, actualRoot);
}
//loop over mock groups and check whether they've all been added
//to the meta contact list.
/**
* Makes sure that the specified actualGroup contains the same contacts
* and subgroups as the expectedGroup. (Method operates recursively).
* @param expectedGroup a MockContactGroup instance used as a reference.
* @param actualGroup the MetaContactGroup retrieved from the metacontact
* list.
*/
private void assertGroupEquals(MockContactGroup expectedGroup,
MetaContactGroup actualGroup)
{
assertNotNull("Group " + expectedGroup.getGroupName() + " was "
+ "returned by the MetaContactListService implementation "
+ "but was not in the expected contact list."
, actualGroup);
assertEquals("Group " + expectedGroup.getGroupName()
+ " did not have the expected number of member contacts"
, expectedGroup.countContacts()
, actualGroup.countChildContacts());
assertEquals("Group " + expectedGroup.getGroupName()
+ " did not have the expected number of member contacts"
, expectedGroup.countContacts()
, actualGroup.countChildContacts());
assertEquals("Group " + expectedGroup.getGroupName()
+ " did not have the expected number of sub groups"
, expectedGroup.countSubgroups()
, actualGroup.countSubgroups());
//go over the subgroups and check that they've been all added to the
//meta contact list.
Iterator expectedSubgroups = expectedGroup.subGroups();
while (expectedSubgroups.hasNext() ){
ContactGroup expectedGroup = (ContactGroup)expectedSubgroups.next();
MockContactGroup expectedSubGroup
= (MockContactGroup)expectedSubgroups.next();
MetaContactGroup actualGroup
= actualRoot
.getMetaContactSubgroup(expectedGroup.getGroupName());
MetaContactGroup actualSubGroup
= actualGroup
.getMetaContactSubgroup(expectedSubGroup.getGroupName());
assertNotNull("Group " + expectedGroup.getGroupName() + " was "
+ "returned by the MetaContactListService implementation "
+ "but was not in the expected contact list."
, actualGroup );
assertEquals("Group " + expectedGroup.getGroupName()
+ " did not have the expected number of member contacts"
, expectedGroup.countContacts()
, actualGroup.countChildContacts() );
assertEquals("Group " + expectedGroup.getGroupName()
+ " did not have the expected number of member contacts"
, expectedGroup.countContacts()
, actualGroup.countChildContacts() );
assertEquals("Group " + expectedGroup.getGroupName()
+ " did not have the expected number of sub groups"
, expectedGroup.countSubGroups()
, actualGroup.countSubgroups() );
Iterator actualContactsIter = actualGroup.getChildContacts();
//check whether every contact in the meta list exists in the source
//mock provider contact list.
while (actualContactsIter.hasNext()){
MetaContact actualMetaContact
= (MetaContact)actualContactsIter.next();
Contact actualProtoContact
= actualMetaContact.getContactForProvider(
MclSlickFixture.mockProvider);
Contact expectedProtoContact
= expectedGroup.getContact(actualProtoContact.getAddress());
assertNotNull("Contact " + actualMetaContact.getDisplayName()
assertGroupEquals(expectedSubGroup, actualSubGroup);
}
Iterator actualContactsIter = actualGroup.getChildContacts();
//check whether every contact in the meta list exists in the source
//mock provider contact list.
while (actualContactsIter.hasNext())
{
MetaContact actualMetaContact
= (MetaContact) actualContactsIter.next();
assertEquals("Number of protocol specific contacts in a MetaContact"
, 1, actualMetaContact.getContactCount());
assertTrue(
"No contacts were encapsulated by MetaContact: "
+ actualMetaContact
, actualMetaContact.getContacts().hasNext());
Contact actualProtoContact
= (Contact)actualMetaContact.getContacts().next();
assertNotNull("getContactForProvider returned null for MockProvider"
, actualProtoContact);
Contact expectedProtoContact
= expectedGroup.getContact(actualProtoContact.getAddress());
assertNotNull("Contact " + actualMetaContact.getDisplayName()
+ " was returned by "
+ "the MetaContactListService implementation but was "
+ "not in the expected contact list."
, expectedProtoContact );
}
, expectedProtoContact);
}
}
/**
* Performs several tests in order to verify that the findMetaContactByID
* method of the tested implementation is working properly. We'll first
* try to locate by using iterators a couple of contacts in different
* levels. Once e get their references, we'll try to locate them through
* the findMetaContactByMetaUID method.
*/
public void testFindMetaContactByMetaUID()
{
MetaContactGroup root = fixture.metaClService.getRoot();
//get a top level contact and then try to find it through the tested
//findMetaContactByMetaUID method.
Iterator contactsIter = root.getChildContacts();
assertTrue(
"No contacts were found in the meta contact list"
, contactsIter.hasNext());
MetaContact expectedContact = (MetaContact)contactsIter.next();
MetaContact actualResult = fixture.metaClService
.findMetaContactByMetaUID(expectedContact.getMetaUID());
assertEquals("find failed for contact "+expectedContact.getDisplayName()
, expectedContact, actualResult);
// get one of the subgroups, extract one of its child contacts and
// repeat the same test.
Iterator subgroupsIter = root.getSubgroups();
assertTrue(
"No sub groups were found in the meta contact list"
, subgroupsIter.hasNext());
MetaContactGroup subgroup = (MetaContactGroup)subgroupsIter.next();
contactsIter = subgroup.getChildContacts();
assertTrue(
"No contacts were found in the meta group: "
+ subgroup.getGroupName()
, contactsIter.hasNext());
expectedContact = (MetaContact)contactsIter.next();
actualResult = fixture.metaClService
.findMetaContactByMetaUID(expectedContact.getMetaUID());
assertEquals("find failed for contact "+expectedContact.getDisplayName()
, expectedContact, actualResult);
}
/**
* Performs several tests in order to verify that the findMetaContactByContact
* method of the tested implementation is working properly. We'll first
* try to locate by using iterators a couple of contacts in different
* levels. Once we get their references, we'll try to locate them through
* the findMetaContactByContact method.
*/
public void testFindMetaContactByContact()
{
MetaContactGroup root = fixture.metaClService.getRoot();
//get a top level contact and then try to find it through the tested
//findMetaContactByContact method.
Iterator contactsIter = root.getChildContacts();
assertTrue(
"No contacts were found in the meta contact list"
, contactsIter.hasNext());
MetaContact expectedMetaContact = (MetaContact)contactsIter.next();
assertTrue(
"No contacts are encapsulated by MetaContact: "
+ expectedMetaContact.getDisplayName()
, expectedMetaContact.getContacts().hasNext());
Contact mockContact = (Contact)expectedMetaContact.getContacts().next();
MetaContact actualResult = fixture.metaClService
.findMetaContactByContact(mockContact);
assertEquals("find failed for contact "+expectedMetaContact.getDisplayName()
, expectedMetaContact, actualResult);
// get one of the subgroups, extract one of its child contacts and
// repeat the same test.
Iterator subgroupsIter = root.getSubgroups();
assertTrue(
"No sub groups were found in the meta contact list"
, subgroupsIter.hasNext());
MetaContactGroup subgroup = (MetaContactGroup)subgroupsIter.next();
contactsIter = subgroup.getChildContacts();
assertTrue(
"No contacts were found in MetaContactGroup: "
+ subgroup.getGroupName()
, contactsIter.hasNext());
expectedMetaContact = (MetaContact)contactsIter.next();
assertTrue(
"No contacts were encapsulated by meta contact: "
+ expectedMetaContact.getDisplayName()
, expectedMetaContact.getContacts().hasNext());
mockContact = (Contact)expectedMetaContact.getContacts().next();
actualResult = fixture.metaClService
.findMetaContactByContact(mockContact);
assertEquals("find failed for contact "
+ expectedMetaContact.getDisplayName()
, expectedMetaContact, actualResult);
}
/**
* Performs several tests in order to verify that the
* <tt>findMetaContactGroupByContactGroup</tt> method of the tested
* implementation is working properly. We'll first try to locate by using
* iterators a couple of protocol specific groups in different levels.
* Once we get their references, we'll try to locate them through
* the findMetaContactGroupByContactGroup method.
*/
public void testFindMetaContactGroupByContactGroup()
{
MetaContactGroup root = fixture.metaClService.getRoot();
//get a group, extract its proto group and then try to obtain a
//reference through the tested find method.
Iterator groupsIter = root.getSubgroups();
assertTrue(
"No sub groups were found in the meta contact list"
, groupsIter.hasNext());
MetaContactGroup expectedMetaContactGroup
= (MetaContactGroup)groupsIter.next();
assertTrue(
"There were no contact groups encapsulated in MetaContactGroup: "
+ expectedMetaContactGroup
, expectedMetaContactGroup.getContactGroups().hasNext());
assertTrue(
"No ContactGroups are encapsulated by MetaContactGroup: "
+ expectedMetaContactGroup
, expectedMetaContactGroup.getContactGroups().hasNext());
ContactGroup mockContactGroup = (ContactGroup)expectedMetaContactGroup
.getContactGroups().next();
MetaContactGroup actualMetaContactGroup = fixture.metaClService
.findMetaContactGroupByContactGroup(mockContactGroup);
assertSame("find failed for contact group " + mockContactGroup
, expectedMetaContactGroup, actualMetaContactGroup);
}
/**
* In this test we'll add and remove users to the mock provider, and check
* whether the meta contact list dispatches the corresponding meta contact
* list event.
*
* @throws java.lang.Exception if anything goes wrong.
*/
public void testSubscriptionHandling() throws Exception
{
//add a subscription and check that the corresponding event is generated
MclEventCollector mclEvtCollector = new MclEventCollector();
fixture.metaClService.addContactListListener(mclEvtCollector);
opSetPersPresence.subscribe(newSubscriptionName);
fixture.metaClService.removeContactListListener(mclEvtCollector);
//first check that the newly created contact was really added
MockContact newProtoContact = (MockContact)opSetPersPresence
.findContactByID(newSubscriptionName);
MetaContact newMetaContact = fixture.metaClService
.findMetaContactByContact(newProtoContact);
assertNotNull("The meta contact list was not updated after adding "
+"contact "+ newProtoContact +" to the mock provider."
, newMetaContact);
assertEquals("Number of evts dispatched while adding a contact"
, 1
, mclEvtCollector.collectedEvents.size());
MetaContactEvent evt = (MetaContactEvent)mclEvtCollector
.collectedEvents.get(0);
assertEquals("ID of the generated event",
MetaContactEvent.META_CONTACT_ADDED,
evt.getEventID());
assertEquals("Parent group of the source contact"
, fixture.metaClService.getRoot()
, evt.getParentGroup());
assertEquals("Source meta contact."
, newMetaContact, evt.getSourceContact());
assertEquals("Source provider"
, fixture.mockProvider, evt.getSourceProvider());
//remove the subscirption and check for the event
mclEvtCollector.collectedEvents.clear();
fixture.metaClService.addContactListListener(mclEvtCollector);
opSetPersPresence.unsubscribe(newProtoContact);
fixture.metaClService.removeContactListListener(mclEvtCollector);
//first check that the newly created contact was really added
assertNull(
"The impl contact list did not update after a subscr. was removed."
,fixture.metaClService.findMetaContactByContact(newProtoContact));
assertEquals("Number of evts dispatched while adding a contact"
, 1
, mclEvtCollector.collectedEvents.size());
evt = (MetaContactEvent)mclEvtCollector.collectedEvents.get(0);
assertEquals("ID of the generated event",
MetaContactEvent.META_CONTACT_REMOVED,
evt.getEventID());
assertEquals("Parent group of the source contact"
, fixture.metaClService.getRoot()
, evt.getParentGroup());
assertEquals("Source meta contact."
, newMetaContact, evt.getSourceContact());
assertEquals("Source provider"
, fixture.mockProvider, evt.getSourceProvider());
}
/**
* In this test we'll add and remove groups to the mock provider, and check
* whether the meta contact list dispatches the corresponding meta contact
* list events and whether it gets properly updated.
*
* @throws java.lang.Exception if anything goes wrong.
*/
public void testGroupChangeEventHandling() throws Exception
{
//add a group and check for the event
MclEventCollector mclEvtCollector = new MclEventCollector();
fixture.metaClService.addContactListListener(mclEvtCollector);
opSetPersPresence.createServerStoredContactGroup(
opSetPersPresence.getServerStoredContactListRoot(), newGroupName);
fixture.metaClService.removeContactListListener(mclEvtCollector);
// first check whether event delivery went ok.
assertEquals("Number of evts dispatched while adding a contact group"
, 1
, mclEvtCollector.collectedEvents.size());
MetaContactGroupEvent evt = (MetaContactGroupEvent)mclEvtCollector
.collectedEvents.get(0);
assertEquals("ID of the generated event",
MetaContactGroupEvent.META_CONTACT_GROUP_ADDED,
evt.getEventID());
assertEquals("Source group of the AddEvent."
, newGroupName
, evt.getSourceMetaContactGroup().getGroupName());
//first check that the newly created group was really added
MetaContactGroup newMetaGroup = evt.getSourceMetaContactGroup();
assertEquals("Source provider for the add event."
, fixture.mockProvider, evt.getSourceProvider());
ContactGroup newProtoGroup = newMetaGroup.getContactGroup(
newGroupName, fixture.mockProvider);
assertNotNull("The new meta contact group did not contain a proto group"
, newProtoGroup);
assertEquals("The new meta contact group did not seem to contain "
+ "the right protocol contact group."
, newProtoGroup.getGroupName()
, newGroupName);
assertEquals("The new meta contact group did not seem to contain "
+ "the right protocol contact group."
, newProtoGroup.getProtocolProvider()
, fixture.mockProvider);
mclEvtCollector.collectedEvents.clear();
//rename the group and see that the corresponding events are handled
//properly
fixture.metaClService.addContactListListener(mclEvtCollector);
opSetPersPresence.renameServerStoredContactGroup(
newProtoGroup, renamedGroupName);
fixture.metaClService.removeContactListListener(mclEvtCollector);
//first check that the group was really renamed
assertEquals("Number of evts dispatched while renaming a contact group"
, 1
, mclEvtCollector.collectedEvents.size());
evt = (MetaContactGroupEvent)mclEvtCollector.collectedEvents.get(0);
assertEquals("ID of the generated event",
MetaContactGroupEvent.CONTACT_GROUP_RENAMED_IN_META_GROUP,
evt.getEventID());
assertEquals("Source group for the RemoveEvent."
, newMetaGroup
, evt.getSourceMetaContactGroup());
assertEquals("Source provider for the remove event."
, fixture.mockProvider, evt.getSourceProvider());
//check whether the group was indeed renamed.
Iterator groupsIter = evt.getSourceMetaContactGroup()
.getContactGroupsForProvider(fixture.mockProvider);
assertTrue("A proto group was unexplicably removed after renaming.",
groupsIter.hasNext());
assertEquals("The name of a protocol group after renaming."
, renamedGroupName
, ((MockContactGroup)groupsIter.next()).getGroupName());
mclEvtCollector.collectedEvents.clear();
//remove the group and check for the event.
fixture.metaClService.addContactListListener(mclEvtCollector);
opSetPersPresence.removeServerStoredContactGroup(newProtoGroup);
fixture.metaClService.removeContactListListener(mclEvtCollector);
//first check that the group was really removed
assertEquals("Number of evts dispatched while removing a contact group"
, 1
, mclEvtCollector.collectedEvents.size());
evt = (MetaContactGroupEvent)mclEvtCollector.collectedEvents.get(0);
assertEquals("ID of the generated event",
MetaContactGroupEvent.CONTACT_GROUP_REMOVED_FROM_META_GROUP,
evt.getEventID());
assertEquals("Source group for the RemoveEvent."
, newMetaGroup
, evt.getSourceMetaContactGroup());
assertEquals("Source provider for the remove event."
, fixture.mockProvider, evt.getSourceProvider());
mclEvtCollector.collectedEvents.clear();
}
public void testAddMoveRemoveContactToMetaContact()
{
/**@todo implement testAddMoveRemoveContactToMetaContact() */
// fail("@todo implement testAddMoveRemoveContactToMetaContact()");
}
public void testCreateMoveRemoveMetaContact()
{
/**@todo implement testCreateMoveRemoveMetaContact() */
// fail("@todo implement testCreateMoveRemoveMetaContact()");
}
public void testCreateRemoveMetaContactGroup()
{
/**@todo implement testCreateRemoveMetaContactGroup() */
// fail("@todo implement testCreateRemoveMetaContactGroup()");
}
private class MclEventCollector implements MetaContactListListener
{
public Vector collectedEvents = new Vector();
/**
* Indicates that a MetaContact has been successfully added
* to the MetaContact list.
* @param evt the MetaContactListEvent containing the corresponding contact
*/
public void metaContactAdded(MetaContactEvent evt)
{
collectedEvents.add(evt);
}
/**
* Indicates that a MetaContactGroup has been successfully added
* to the MetaContact list.
* @param evt the MetaContactListEvent containing the corresponding
* contact
*/
public void metaContactGroupAdded(MetaContactGroupEvent evt)
{
collectedEvents.add(evt);
}
/**
* Indicates that a MetaContactGroup has been removed from the
* MetaContact list.
* @param evt the MetaContactListEvent containing the corresponding
* contact
*/
public void metaContactGroupRemoved(MetaContactGroupEvent evt)
{
collectedEvents.add(evt);
}
/**
* Indicates that a MetaContact has been removed from the MetaContact
* list.
* @param evt the MetaContactListEvent containing the corresponding
* contact
*/
public void metaContactRemoved(MetaContactEvent evt)
{
collectedEvents.add(evt);
}
/**
* Indicates that a MetaContact has been modified.
* @param evt the MetaContactListEvent containing the corresponding
* contact
*/
public void metaContactModified(MetaContactEvent evt)
{
collectedEvents.add(evt);
}
/**
* Indicates that a MetaContactGroup has been modified (e.g. a proto
* contact group was removed).
*
* @param evt the MetaContactListEvent containing the corresponding
* contact
*/
public void metaContactGroupModified(MetaContactGroupEvent evt)
{
collectedEvents.add(evt);
}
}
}

@ -4,6 +4,7 @@ Bundle-Description: An SLI compatibility kit for the MetaContactList service.
Bundle-Vendor: sip-communicator.org
Bundle-Version: 0.0.1
Import-Package: net.java.sip.communicator.service.contactlist,
net.java.sip.communicator.service.contactlist.event,
org.osgi.framework,
junit.framework,
net.java.sip.communicator.util,

Loading…
Cancel
Save