Attempts the fix the tests broken when the loading of the stored accounts was moved into a background thread.

cusax-fix
Lyubomir Marinov 17 years ago
parent fb6c84388c
commit a1801e9f3c

@ -0,0 +1,103 @@
/*
* 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.service.protocol;
import net.java.sip.communicator.service.protocol.event.*;
import org.osgi.framework.*;
/**
* Provides utilities to aid the manipulation of {@link AccountManager}.
*
* @author Lubomir Marinov
*/
public final class AccountManagerUtils
{
private static AccountManager getAccountManager(BundleContext bundleContext)
{
return (AccountManager) bundleContext.getService(bundleContext
.getServiceReference(AccountManager.class.getName()));
}
/**
* Starts a specific <code>Bundle</code> and wait for the
* <code>AccountManager</code> available in a specific
* <code>BundleContext</code> to load the stored accounts of a
* <code>ProtocolProviderFactory</code> with a specific protocol name.
*
* @param bundleContextWithAccountManager the <code>BundleContext</code> in
* which an <code>AccountManager</code> service is registered
* @param bundleToStart the <code>Bundle</code> to be started
* @param protocolNameToWait the protocol name of a
* <code>ProtocolProviderFactory</code> to wait the end of the
* loading of the stored accounts for
* @throws BundleException
* @throws InterruptedException if any thread interrupted the current thread
* before or while the current thread was waiting for the
* loading of the stored accounts
*/
public static void startBundleAndWaitStoredAccountsLoaded(
BundleContext bundleContextWithAccountManager, Bundle bundleToStart,
final String protocolNameToWait)
throws BundleException,
InterruptedException
{
AccountManager accountManager =
getAccountManager(bundleContextWithAccountManager);
final boolean[] storedAccountsAreLoaded = new boolean[1];
AccountManagerListener listener = new AccountManagerListener()
{
public void handleAccountManagerEvent(AccountManagerEvent event)
{
if (AccountManagerEvent.STORED_ACCOUNTS_LOADED == event
.getType())
{
ProtocolProviderFactory factory = event.getFactory();
if ((factory == null)
|| protocolNameToWait.equals(factory.getProtocolName()))
{
synchronized (storedAccountsAreLoaded)
{
storedAccountsAreLoaded[0] = true;
storedAccountsAreLoaded.notify();
}
}
}
}
};
accountManager.addListener(listener);
try
{
bundleToStart.start();
while (true)
{
synchronized (storedAccountsAreLoaded)
{
if (storedAccountsAreLoaded[0])
{
break;
}
storedAccountsAreLoaded.wait();
}
}
}
finally
{
accountManager.removeListener(listener);
}
}
/**
* Prevents the creation of <code>AccountManagerUtils</code> instances.
*/
private AccountManagerUtils()
{
}
}

@ -601,7 +601,7 @@ protected abstract AccountID createAccountID(String userID,
* <code>ProtocolProviderService</code>s with and to be placed in
* the properties of the accounts created by this factory
*/
protected String getProtocolName()
public String getProtocolName()
{
return protocolName;
}

@ -6,14 +6,15 @@
*/
package net.java.sip.communicator.slick.protocol.gibberish;
import org.osgi.framework.*;
import junit.framework.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
/**
* Tests whether accaounts are uninstalled properly. It is important that
* Tests whether accounts are uninstalled properly. It is important that
* tests from this class be called last since they will install the accounts
* that have been used to test the implementations. Apart from uninstallation
* tests the class also contains tests that remove and reinstall the protocol
@ -153,7 +154,8 @@ public void testInstallationPersistency() throws Exception
assertEquals("Couldn't re-install protocol provider bundle."
, Bundle.INSTALLED, providerBundle.getState());
providerBundle.start();
AccountManagerUtils.startBundleAndWaitStoredAccountsLoaded(
GibberishSlickFixture.bc, providerBundle, "Gibberish");
assertEquals("Couldn't re-start protocol provider bundle."
, Bundle.ACTIVE, providerBundle.getState());

@ -64,7 +64,8 @@ public void testAccountUninstallationPersistence()
assertEquals("Couldn't re-install protocol provider bundle."
, Bundle.INSTALLED, providerBundle.getState());
providerBundle.start();
AccountManagerUtils.startBundleAndWaitStoredAccountsLoaded(
GibberishSlickFixture.bc, providerBundle, "Gibberish");
assertEquals("Couldn't re-start protocol provider bundle."
, Bundle.ACTIVE, providerBundle.getState());

@ -217,7 +217,8 @@ public void testInstallationPersistency()
assertEquals("Couldn't re-install protocol provider bundle."
, Bundle.INSTALLED, providerBundle.getState());
providerBundle.start();
AccountManagerUtils.startBundleAndWaitStoredAccountsLoaded(
IcqSlickFixture.bc, providerBundle, ProtocolNames.ICQ);
assertEquals("Couldn't re-start protocol provider bundle."
, Bundle.ACTIVE, providerBundle.getState());

@ -63,7 +63,8 @@ public void testAccountUninstallationPersistency()
assertEquals("Couldn't re-install protocol provider bundle."
, Bundle.INSTALLED, providerBundle.getState());
providerBundle.start();
AccountManagerUtils.startBundleAndWaitStoredAccountsLoaded(
IcqSlickFixture.bc, providerBundle, ProtocolNames.ICQ);
assertEquals("Couldn't re-start protocol provider bundle."
, Bundle.ACTIVE, providerBundle.getState());

@ -151,7 +151,8 @@ public void testInstallationPersistency() throws Exception
assertEquals("Couldn't re-install protocol provider bundle."
, Bundle.INSTALLED, providerBundle.getState());
providerBundle.start();
AccountManagerUtils.startBundleAndWaitStoredAccountsLoaded(
JabberSlickFixture.bc, providerBundle, ProtocolNames.JABBER);
assertEquals("Couldn't re-start protocol provider bundle."
, Bundle.ACTIVE, providerBundle.getState());

@ -63,7 +63,8 @@ public void testAccountUninstallationPersistence()
assertEquals("Couldn't re-install protocol provider bundle."
, Bundle.INSTALLED, providerBundle.getState());
providerBundle.start();
AccountManagerUtils.startBundleAndWaitStoredAccountsLoaded(
JabberSlickFixture.bc, providerBundle, ProtocolNames.JABBER);
assertEquals("Couldn't re-start protocol provider bundle."
, Bundle.ACTIVE, providerBundle.getState());

@ -151,7 +151,8 @@ public void testInstallationPersistency() throws Exception
assertEquals("Couldn't re-install protocol provider bundle."
, Bundle.INSTALLED, providerBundle.getState());
providerBundle.start();
AccountManagerUtils.startBundleAndWaitStoredAccountsLoaded(fixture.bc,
providerBundle, ProtocolNames.MSN);
assertEquals("Couldn't re-start protocol provider bundle."
, Bundle.ACTIVE, providerBundle.getState());

@ -63,7 +63,8 @@ public void testAccountUninstallationPersistence()
assertEquals("Couldn't re-install protocol provider bundle."
, Bundle.INSTALLED, providerBundle.getState());
providerBundle.start();
AccountManagerUtils.startBundleAndWaitStoredAccountsLoaded(
MsnSlickFixture.bc, providerBundle, ProtocolNames.MSN);
assertEquals("Couldn't re-start protocol provider bundle."
, Bundle.ACTIVE, providerBundle.getState());

@ -132,7 +132,9 @@ public void testInstallationPersistence() throws Exception
assertTrue("Couldn't reinstall provider bundle",
providerBundle.getState() == Bundle.INSTALLED);
providerBundle.start();
AccountManagerUtils.startBundleAndWaitStoredAccountsLoaded(fixture.bc,
providerBundle, ProtocolNames.RSS);
assertTrue("Couldn't start provider",
providerBundle.getState() == Bundle.ACTIVE);

@ -59,8 +59,9 @@ public void testAccountUninstallationPersistence()
providerBundle.getLocation());
assertEquals("Couldn't reinstall protocol provider bundle.",
providerBundle.getState(), Bundle.INSTALLED);
providerBundle.start();
AccountManagerUtils.startBundleAndWaitStoredAccountsLoaded(
RssSlickFixture.bc, providerBundle, ProtocolNames.RSS);
assertEquals("Couldn't restart protocol provider bundle.",
providerBundle.getState(), Bundle.ACTIVE);

@ -202,7 +202,8 @@ public void testInstallationPersistency() throws Exception
assertEquals("Couldn't re-install protocol provider bundle."
, Bundle.INSTALLED, providerBundle.getState());
providerBundle.start();
AccountManagerUtils.startBundleAndWaitStoredAccountsLoaded(fixture.bc,
providerBundle, ProtocolNames.SIP);
assertEquals("Couldn't re-start protocol provider bundle."
, Bundle.ACTIVE, providerBundle.getState());

@ -63,7 +63,8 @@ public void testAccountUninstallationPersistence()
assertEquals("Couldn't re-install protocol provider bundle."
, Bundle.INSTALLED, providerBundle.getState());
providerBundle.start();
AccountManagerUtils.startBundleAndWaitStoredAccountsLoaded(
SipSlickFixture.bc, providerBundle, ProtocolNames.SIP);
assertEquals("Couldn't re-start protocol provider bundle."
, Bundle.ACTIVE, providerBundle.getState());

@ -151,7 +151,8 @@ public void testInstallationPersistency() throws Exception
assertEquals("Couldn't re-install protocol provider bundle."
, Bundle.INSTALLED, providerBundle.getState());
providerBundle.start();
AccountManagerUtils.startBundleAndWaitStoredAccountsLoaded(fixture.bc,
providerBundle, ProtocolNames.YAHOO);
assertEquals("Couldn't re-start protocol provider bundle."
, Bundle.ACTIVE, providerBundle.getState());

@ -63,7 +63,8 @@ public void testAccountUninstallationPersistence()
assertEquals("Couldn't re-install protocol provider bundle."
, Bundle.INSTALLED, providerBundle.getState());
providerBundle.start();
AccountManagerUtils.startBundleAndWaitStoredAccountsLoaded(
YahooSlickFixture.bc, providerBundle, ProtocolNames.YAHOO);
assertEquals("Couldn't re-start protocol provider bundle."
, Bundle.ACTIVE, providerBundle.getState());

Loading…
Cancel
Save