diff options
author | Emil Ivov <emcho@jitsi.org> | 2007-03-02 21:39:20 +0000 |
---|---|---|
committer | Emil Ivov <emcho@jitsi.org> | 2007-03-02 21:39:20 +0000 |
commit | 634f16d889f27727d94b58e693e7374f13770db0 (patch) | |
tree | 5ab18875eb03d25442d76e49c40f395d1e0c9695 /test/net/java | |
parent | d6f76f56be6d2fdb73686334a0643b5752d941ce (diff) | |
download | jitsi-634f16d889f27727d94b58e693e7374f13770db0.zip jitsi-634f16d889f27727d94b58e693e7374f13770db0.tar.gz jitsi-634f16d889f27727d94b58e693e7374f13770db0.tar.bz2 |
gibberish slck (Issue #241) and a better meta contact list ordering policy (Issue #316)
utility methods and global vars for the gibberish slick
Diffstat (limited to 'test/net/java')
-rw-r--r-- | test/net/java/sip/communicator/slick/protocol/gibberish/GibberishSlickFixture.java | 322 |
1 files changed, 322 insertions, 0 deletions
diff --git a/test/net/java/sip/communicator/slick/protocol/gibberish/GibberishSlickFixture.java b/test/net/java/sip/communicator/slick/protocol/gibberish/GibberishSlickFixture.java new file mode 100644 index 0000000..301135d --- /dev/null +++ b/test/net/java/sip/communicator/slick/protocol/gibberish/GibberishSlickFixture.java @@ -0,0 +1,322 @@ +/* + * 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.gibberish; + +import org.osgi.framework.*; +import junit.framework.*; +import net.java.sip.communicator.service.protocol.*; +import java.util.Map; +import java.util.*; + +/** + * Contains fields and methods used by most or all tests in the Gibberish slick. + * + * @author Emil Ivov + */ +public class GibberishSlickFixture + 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 first testing account. + */ + public ProtocolProviderService provider2 = null; + + /** + * The user ID associated with testing account 2. + */ + public String userID2 = null; + + + /** + * The tested protocol provider factory. + */ + 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 initialise the ss contact list before the tested implementation has + * actually done so. + */ + public static Hashtable preInstalledBuddyList = null; + + + /** + * Initializes protocol provider references and whatever else there is to + * initialize. + * + * @throws java.lang.Exception in case we meet problems while retriving + * protocol providers through OSGI + */ + public void setUp() + throws Exception + { + // first obtain a reference to the provider factory + ServiceReference[] serRefs = null; + String osgiFilter = "(" + ProtocolProviderFactory.PROTOCOL + + "=Gibberish)"; + try{ + serRefs = bc.getServiceReferences( + ProtocolProviderFactory.class.getName(), osgiFilter); + } + catch (InvalidSyntaxException ex){ + //this really shouldhn't occur as the filter expression is static. + fail(osgiFilter + " is not a valid osgi filter"); + } + + assertTrue( + "Failed to find a provider factory service for protocol Gibberish", + serRefs != null || serRefs.length > 0); + + //Keep the reference for later usage. + providerFactory = (ProtocolProviderFactory)bc.getService(serRefs[0]); + + userID1 = + System.getProperty( + GibberishProtocolProviderServiceLick.ACCOUNT_1_PREFIX + + ProtocolProviderFactory.USER_ID); + + userID2 = + System.getProperty( + GibberishProtocolProviderServiceLick.ACCOUNT_2_PREFIX + + ProtocolProviderFactory.USER_ID); + + //find the protocol providers exported for the two accounts + ServiceReference[] gibberishProvider1Refs + = bc.getServiceReferences( + ProtocolProviderService.class.getName(), + "(&" + +"("+ProtocolProviderFactory.PROTOCOL+"=Gibberish)" + +"("+ProtocolProviderFactory.USER_ID+"=" + + userID1 +")" + +")"); + + //make sure we found a service + assertNotNull("No Protocol Provider was found for Gibberish account1:" + + userID1 + , gibberishProvider1Refs); + assertTrue("No Protocol Provider was found for Gibberish account1:" + + userID1 + , gibberishProvider1Refs.length > 0); + + ServiceReference[] gibberishProvider2Refs + = bc.getServiceReferences( + ProtocolProviderService.class.getName(), + "(&" + +"("+ProtocolProviderFactory.PROTOCOL+"=Gibberish)" + +"("+ProtocolProviderFactory.USER_ID+"=" + + userID2 +")" + +")"); + + //again make sure we found a service. + assertNotNull("No Protocol Provider was found for Gibberish account2:" + + userID2 + , gibberishProvider2Refs); + assertTrue("No Protocol Provider was found for Gibberish account2:" + + userID2 + , gibberishProvider2Refs.length > 0); + + //save the service for other tests to use. + provider1ServiceRef = gibberishProvider1Refs[0]; + provider1 = (ProtocolProviderService)bc.getService(provider1ServiceRef); + provider2ServiceRef = gibberishProvider2Refs[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 supportedOperationSets1 = provider1.getSupportedOperationSets(); + + if ( supportedOperationSets1 == null + || supportedOperationSets1.size() < 1) + throw new NullPointerException( + "No OperationSet implementations are supported by " + +"this Gibberish 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 gibberish. + if (opSetPersPresence1 == null) + throw new NullPointerException( + "An implementation of the Gibberish 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 supportedOperationSets2 = provider2.getSupportedOperationSets(); + + if (supportedOperationSets2 == null + || supportedOperationSets2.size() < 1) + throw new NullPointerException( + "No OperationSet implementations are supported by " + + "this Gibberish 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 gibberish. + if (opSetPersPresence2 == null) + throw new NullPointerException( + "An implementation of the Gibberish service must provide an " + + "implementation of at least the one of the Presence " + + "Operation Sets"); + + ContactGroup rootGroup1 = opSetPersPresence1.getServerStoredContactListRoot(); + + // first delete the groups + Vector groupsToRemove = new Vector(); + Iterator iter = rootGroup1.subgroups(); + while (iter.hasNext()) + { + groupsToRemove.add(iter.next()); + } + + iter = groupsToRemove.iterator(); + while (iter.hasNext()) + { + ContactGroup item = (ContactGroup) iter.next(); + opSetPersPresence1.removeServerStoredContactGroup(item); + } + + //then delete contacts if any in root list + Vector contactsToRemove = new Vector(); + iter = rootGroup1.contacts(); + while (iter.hasNext()) + { + contactsToRemove.add(iter.next()); + } + iter = contactsToRemove.iterator(); + while (iter.hasNext()) + { + opSetPersPresence1.unsubscribe((Contact)iter.next()); + } + + ContactGroup rootGroup2 = opSetPersPresence2.getServerStoredContactListRoot(); + + // delete groups + groupsToRemove = new Vector(); + iter = rootGroup2.subgroups(); + while (iter.hasNext()) + { + groupsToRemove.add(iter.next()); + } + + iter = groupsToRemove.iterator(); + while (iter.hasNext()) + { + ContactGroup item = (ContactGroup) iter.next(); + opSetPersPresence2.removeServerStoredContactGroup(item); + } + + //then delete contacts if any in root list + contactsToRemove = new Vector(); + iter = rootGroup2.contacts(); + while (iter.hasNext()) + { + contactsToRemove.add(iter.next()); + } + iter = contactsToRemove.iterator(); + while (iter.hasNext()) + { + opSetPersPresence2.unsubscribe( (Contact) iter.next()); + } + } +} |