gracefully handle missing icq account.properties file during unit testing.

cusax-fix
Brian Burch 20 years ago
parent b42af765db
commit 700daa00ca

@ -111,9 +111,12 @@ public void start(BundleContext context)
*/ */
public void stop(BundleContext context) public void stop(BundleContext context)
{ {
MclSlickFixture.mockPrServiceRegistration.unregister(); if (MclSlickFixture.mockPrServiceRegistration != null)
MclSlickFixture.mockP1ServiceRegistration.unregister(); MclSlickFixture.mockPrServiceRegistration.unregister();
MclSlickFixture.mockP2ServiceRegistration.unregister(); if (MclSlickFixture.mockP1ServiceRegistration != null)
MclSlickFixture.mockP1ServiceRegistration.unregister();
if (MclSlickFixture.mockP2ServiceRegistration != null)
MclSlickFixture.mockP2ServiceRegistration.unregister();
} }
/** /**

@ -65,55 +65,69 @@ public void start(BundleContext bundleContext) throws Exception
//store the bundle cache reference for usage by other others //store the bundle cache reference for usage by other others
IcqSlickFixture.bc = bundleContext; IcqSlickFixture.bc = bundleContext;
//register our testing agent on icq. //identify our testing agent on icq - it MUST be defined.
IcqSlickFixture.testerAgent = String icqTestAgentName = System.getProperty(
new IcqTesterAgent(System.getProperty( TESTING_IMPL_ACCOUNT_ID_PROP_NAME, null);
TESTING_IMPL_ACCOUNT_ID_PROP_NAME, null));
if (!IcqSlickFixture.testerAgent.register(System.getProperty( // we can only set up the real icq test suites when the
TESTING_IMPL_PWD_PROP_NAME, null))) // accounts.properties file defines the two test accounts
throw new Exception( if (icqTestAgentName != null) {
"Registering the IcqTesterAgent on icq has failed.(Possible " //it is defined, so register our testing agent on icq.
+"reasons: authetification failed, or Connection rate limit " IcqSlickFixture.testerAgent =
+"exceeded.)"); new IcqTesterAgent(icqTestAgentName);
IcqSlickFixture.testerAgent.setAuthorizationRequired(); if (!IcqSlickFixture.testerAgent.register(System.getProperty(
TESTING_IMPL_PWD_PROP_NAME, null)))
//initialize the tested account's contact list so that it could be ready throw new Exception(
//when testing starts. "Registering the IcqTesterAgent on icq has failed."
initializeTestedContactList(); +"(Possible reasons: authentification failed, or "
+"Connection rate limit exceeded.)");
IcqSlickFixture.testerAgent.setAuthorizationRequired();
//As Tested account is not registered here we send him a message.
//Message will be delivered offline //initialize the tested account's contact list so that
//receive test is in TestOperationSetBasicInstantMessaging.testReceiveOfflineMessages() //it could be ready when testing starts.
String offlineMsgBody = "This is a Test Message. Supposed to be delivered as offline message!"; initializeTestedContactList();
IcqSlickFixture.offlineMsgCollector =
new IcqSlickFixture.OfflineMsgCollector();
IcqSlickFixture.offlineMsgCollector.setMessageText(offlineMsgBody); //As Tested account is not registered here we send him a message.
IcqSlickFixture.testerAgent.sendOfflineMessage( //Message will be delivered offline
System.getProperty(TESTED_IMPL_ACCOUNT_ID_PROP_NAME, null), //receive test is in TestOperationSetBasicInstantMessaging.testReceiveOfflineMessages()
offlineMsgBody String offlineMsgBody =
); "This is a Test Message. Supposed to be delivered as offline message!";
IcqSlickFixture.offlineMsgCollector =
//First test account installation so that the service that has been new IcqSlickFixture.OfflineMsgCollector();
//installed by it gets tested by the rest of the tests. IcqSlickFixture.offlineMsgCollector.setMessageText(offlineMsgBody);
addTest(TestAccountInstallation.suite()); IcqSlickFixture.testerAgent.sendOfflineMessage(
System.getProperty(TESTED_IMPL_ACCOUNT_ID_PROP_NAME, null),
//This must remain second as that's where the protocol would be made offlineMsgBody
//to login/authenticate/signon its service provider. );
addTest(TestProtocolProviderServiceIcqImpl.suite());
//First test account installation so that the service that has
addTest(TestOperationSetPresence.suite()); //been installed by it gets tested by the rest of the tests.
addTest(TestAccountInstallation.suite());
addTest(TestOperationSetPersistentPresence.suite());
//This must remain second as that's where the protocol would be
addTest(TestOperationSetBasicInstantMessaging.suite()); //made to login/authenticate/signon its service provider.
addTest(TestProtocolProviderServiceIcqImpl.suite());
addTest(TestOperationSetTypingNotifications.suite());
addTest(TestOperationSetPresence.suite());
//This must remain last since it tests account uninstallation and
//the accounts we use for testing won't be available after that. addTest(TestOperationSetPersistentPresence.suite());
addTest(TestAccountUninstallation.suite());
addTest(TestOperationSetBasicInstantMessaging.suite());
addTest(TestOperationSetTypingNotifications.suite());
//This must remain last since it tests account uninstallation and
//the accounts we use for testing won't be available after that.
addTest(TestAccountUninstallation.suite());
}
else {
//install a single test to fail in a meaningful way
addTest(
new TestAccountInvalidNotification("failIcqTesterAgentMissing"));
}
bundleContext.registerService(getClass().getName(), this, properties); bundleContext.registerService(getClass().getName(), this, properties);
logger.debug("Successfully registered " + getClass().getName()); logger.debug("Successfully registered " + getClass().getName());
@ -127,7 +141,8 @@ public void start(BundleContext bundleContext) throws Exception
*/ */
public void stop(BundleContext bundleContext) throws Exception public void stop(BundleContext bundleContext) throws Exception
{ {
IcqSlickFixture.testerAgent.unregister(); if (IcqSlickFixture.testerAgent != null )
IcqSlickFixture.testerAgent.unregister();
} }
/** /**

@ -30,7 +30,9 @@ public class IcqSlickFixture extends TestCase
/** /**
* The agent that we use to verify whether the tested implementation is * The agent that we use to verify whether the tested implementation is
* being honest with us. The icq tester agent is instantiated and registered * being honest with us. The icq tester agent is instantiated and registered
* by the icq slick activator. * by the icq slick activator. If it is still null when a test is running,
* it means there was something seriously wrong with the test account
* properties file.
*/ */
static IcqTesterAgent testerAgent = null; static IcqTesterAgent testerAgent = null;

@ -0,0 +1,78 @@
/*
* 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.icq;
import junit.framework.*;
import net.java.sip.communicator.service.protocol.*;
import java.util.*;
import org.osgi.framework.*;
import net.java.sip.communicator.service.protocol.event.RegistrationStateChangeListener;
import net.java.sip.communicator.service.protocol.event.RegistrationStateChangeEvent;
import net.java.sip.communicator.util.Logger;
/**
* Phoney tests to signal specific problems with the
* accounts.properties file
* @author Brian Burch
*/
public class TestAccountInvalidNotification extends TestCase
{
private static final Logger logger =
Logger.getLogger(TestAccountInstallation.class);
/**
* The lock that we wait on until registration is finalized.
*/
private Object registrationLock = new Object();
AccountManager icqAccountManager = null;
public TestAccountInvalidNotification(String name)
{
super(name);
}
protected void setUp() throws Exception
{
super.setUp();
}
protected void tearDown() throws Exception
{
super.tearDown();
}
/**
* It is not meaningful to define a test suite. Each of the
* pseudo-tests reports a different setup failure, so the
* appropriate test should be added individually.
*
* As a safety measure, we add an empty test suite which
* will generate a "no tests found" failure.
*/
public static Test suite()
{
TestSuite suite = new TestSuite();
// will generate a jUnit "no tests found" error condition
return suite;
}
/**
* The icq test suites MUST have an accounts.properties file
* that defines two icq test accounts. This test is ONLY
* executed when icqProtocolProviderSlick.start() has failed
* to load the Properties and it deliberately fails with a
* meaningful message.
*/
public void failIcqTesterAgentMissing()
{
fail("The IcqTesterAgent on icq was not defined. "
+"(Possible reasons: account.properties file not found "
+"in lib directory. Please see wiki for advice on unit "
+"test setup.)");
}
}
Loading…
Cancel
Save