diff --git a/src/net/java/sip/communicator/service/protocol/AccountManagerUtils.java b/src/net/java/sip/communicator/service/protocol/AccountManagerUtils.java
new file mode 100644
index 000000000..9e8e022ef
--- /dev/null
+++ b/src/net/java/sip/communicator/service/protocol/AccountManagerUtils.java
@@ -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 Bundle and wait for the
+ * AccountManager available in a specific
+ * BundleContext to load the stored accounts of a
+ * ProtocolProviderFactory with a specific protocol name.
+ *
+ * @param bundleContextWithAccountManager the BundleContext in
+ * which an AccountManager service is registered
+ * @param bundleToStart the Bundle to be started
+ * @param protocolNameToWait the protocol name of a
+ * ProtocolProviderFactory 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 AccountManagerUtils instances.
+ */
+ private AccountManagerUtils()
+ {
+ }
+}
diff --git a/src/net/java/sip/communicator/service/protocol/ProtocolProviderFactory.java b/src/net/java/sip/communicator/service/protocol/ProtocolProviderFactory.java
index 82fdb8225..158c04769 100644
--- a/src/net/java/sip/communicator/service/protocol/ProtocolProviderFactory.java
+++ b/src/net/java/sip/communicator/service/protocol/ProtocolProviderFactory.java
@@ -601,7 +601,7 @@ protected abstract AccountID createAccountID(String userID,
* ProtocolProviderServices with and to be placed in
* the properties of the accounts created by this factory
*/
- protected String getProtocolName()
+ public String getProtocolName()
{
return protocolName;
}
diff --git a/test/net/java/sip/communicator/slick/protocol/gibberish/TestAccountUninstallation.java b/test/net/java/sip/communicator/slick/protocol/gibberish/TestAccountUninstallation.java
index c1df5a509..1fc64b29a 100644
--- a/test/net/java/sip/communicator/slick/protocol/gibberish/TestAccountUninstallation.java
+++ b/test/net/java/sip/communicator/slick/protocol/gibberish/TestAccountUninstallation.java
@@ -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());
diff --git a/test/net/java/sip/communicator/slick/protocol/gibberish/TestAccountUninstallationPersistence.java b/test/net/java/sip/communicator/slick/protocol/gibberish/TestAccountUninstallationPersistence.java
index bd6ebb1ae..3aeb78097 100644
--- a/test/net/java/sip/communicator/slick/protocol/gibberish/TestAccountUninstallationPersistence.java
+++ b/test/net/java/sip/communicator/slick/protocol/gibberish/TestAccountUninstallationPersistence.java
@@ -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());
diff --git a/test/net/java/sip/communicator/slick/protocol/icq/TestAccountUninstallation.java b/test/net/java/sip/communicator/slick/protocol/icq/TestAccountUninstallation.java
index c1d2dbfed..f2d70ed42 100644
--- a/test/net/java/sip/communicator/slick/protocol/icq/TestAccountUninstallation.java
+++ b/test/net/java/sip/communicator/slick/protocol/icq/TestAccountUninstallation.java
@@ -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());
diff --git a/test/net/java/sip/communicator/slick/protocol/icq/TestAccountUninstallationPersistence.java b/test/net/java/sip/communicator/slick/protocol/icq/TestAccountUninstallationPersistence.java
index 46ebbc778..dc5b97b83 100644
--- a/test/net/java/sip/communicator/slick/protocol/icq/TestAccountUninstallationPersistence.java
+++ b/test/net/java/sip/communicator/slick/protocol/icq/TestAccountUninstallationPersistence.java
@@ -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());
diff --git a/test/net/java/sip/communicator/slick/protocol/jabber/TestAccountUninstallation.java b/test/net/java/sip/communicator/slick/protocol/jabber/TestAccountUninstallation.java
index e0ee64cb5..56ef4f6e5 100644
--- a/test/net/java/sip/communicator/slick/protocol/jabber/TestAccountUninstallation.java
+++ b/test/net/java/sip/communicator/slick/protocol/jabber/TestAccountUninstallation.java
@@ -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());
diff --git a/test/net/java/sip/communicator/slick/protocol/jabber/TestAccountUninstallationPersistence.java b/test/net/java/sip/communicator/slick/protocol/jabber/TestAccountUninstallationPersistence.java
index 572e6b96d..f6ad62544 100644
--- a/test/net/java/sip/communicator/slick/protocol/jabber/TestAccountUninstallationPersistence.java
+++ b/test/net/java/sip/communicator/slick/protocol/jabber/TestAccountUninstallationPersistence.java
@@ -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());
diff --git a/test/net/java/sip/communicator/slick/protocol/msn/TestAccountUninstallation.java b/test/net/java/sip/communicator/slick/protocol/msn/TestAccountUninstallation.java
index f17de9dc8..28afdebb5 100644
--- a/test/net/java/sip/communicator/slick/protocol/msn/TestAccountUninstallation.java
+++ b/test/net/java/sip/communicator/slick/protocol/msn/TestAccountUninstallation.java
@@ -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());
diff --git a/test/net/java/sip/communicator/slick/protocol/msn/TestAccountUninstallationPersistence.java b/test/net/java/sip/communicator/slick/protocol/msn/TestAccountUninstallationPersistence.java
index 5e6b8ec57..1696c2b9c 100644
--- a/test/net/java/sip/communicator/slick/protocol/msn/TestAccountUninstallationPersistence.java
+++ b/test/net/java/sip/communicator/slick/protocol/msn/TestAccountUninstallationPersistence.java
@@ -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());
diff --git a/test/net/java/sip/communicator/slick/protocol/rss/TestAccountUninstallation.java b/test/net/java/sip/communicator/slick/protocol/rss/TestAccountUninstallation.java
index 658adce6a..41751df69 100755
--- a/test/net/java/sip/communicator/slick/protocol/rss/TestAccountUninstallation.java
+++ b/test/net/java/sip/communicator/slick/protocol/rss/TestAccountUninstallation.java
@@ -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);
diff --git a/test/net/java/sip/communicator/slick/protocol/rss/TestAccountUninstallationPersistence.java b/test/net/java/sip/communicator/slick/protocol/rss/TestAccountUninstallationPersistence.java
index d0da2fb8b..0aa101561 100755
--- a/test/net/java/sip/communicator/slick/protocol/rss/TestAccountUninstallationPersistence.java
+++ b/test/net/java/sip/communicator/slick/protocol/rss/TestAccountUninstallationPersistence.java
@@ -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);
diff --git a/test/net/java/sip/communicator/slick/protocol/sip/TestAccountUninstallation.java b/test/net/java/sip/communicator/slick/protocol/sip/TestAccountUninstallation.java
index 6931820aa..49c3ada9c 100644
--- a/test/net/java/sip/communicator/slick/protocol/sip/TestAccountUninstallation.java
+++ b/test/net/java/sip/communicator/slick/protocol/sip/TestAccountUninstallation.java
@@ -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());
diff --git a/test/net/java/sip/communicator/slick/protocol/sip/TestAccountUninstallationPersistence.java b/test/net/java/sip/communicator/slick/protocol/sip/TestAccountUninstallationPersistence.java
index 0c1957548..e301c6013 100644
--- a/test/net/java/sip/communicator/slick/protocol/sip/TestAccountUninstallationPersistence.java
+++ b/test/net/java/sip/communicator/slick/protocol/sip/TestAccountUninstallationPersistence.java
@@ -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());
diff --git a/test/net/java/sip/communicator/slick/protocol/yahoo/TestAccountUninstallation.java b/test/net/java/sip/communicator/slick/protocol/yahoo/TestAccountUninstallation.java
index cd2a15bea..9474ef3d0 100644
--- a/test/net/java/sip/communicator/slick/protocol/yahoo/TestAccountUninstallation.java
+++ b/test/net/java/sip/communicator/slick/protocol/yahoo/TestAccountUninstallation.java
@@ -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());
diff --git a/test/net/java/sip/communicator/slick/protocol/yahoo/TestAccountUninstallationPersistence.java b/test/net/java/sip/communicator/slick/protocol/yahoo/TestAccountUninstallationPersistence.java
index f621abc6c..c8b9bd259 100644
--- a/test/net/java/sip/communicator/slick/protocol/yahoo/TestAccountUninstallationPersistence.java
+++ b/test/net/java/sip/communicator/slick/protocol/yahoo/TestAccountUninstallationPersistence.java
@@ -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());