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

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

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

@ -65,27 +65,34 @@ public void start(BundleContext bundleContext) throws Exception
//store the bundle cache reference for usage by other others
IcqSlickFixture.bc = bundleContext;
//register our testing agent on icq.
//identify our testing agent on icq - it MUST be defined.
String icqTestAgentName = System.getProperty(
TESTING_IMPL_ACCOUNT_ID_PROP_NAME, null);
// we can only set up the real icq test suites when the
// accounts.properties file defines the two test accounts
if (icqTestAgentName != null) {
//it is defined, so register our testing agent on icq.
IcqSlickFixture.testerAgent =
new IcqTesterAgent(System.getProperty(
TESTING_IMPL_ACCOUNT_ID_PROP_NAME, null));
new IcqTesterAgent(icqTestAgentName);
if (!IcqSlickFixture.testerAgent.register(System.getProperty(
TESTING_IMPL_PWD_PROP_NAME, null)))
throw new Exception(
"Registering the IcqTesterAgent on icq has failed.(Possible "
+"reasons: authetification failed, or Connection rate limit "
+"exceeded.)");
"Registering the IcqTesterAgent on icq has failed."
+"(Possible reasons: authentification failed, or "
+"Connection rate limit exceeded.)");
IcqSlickFixture.testerAgent.setAuthorizationRequired();
//initialize the tested account's contact list so that it could be ready
//when testing starts.
//initialize the tested account's contact list so that
//it could be ready when testing starts.
initializeTestedContactList();
//As Tested account is not registered here we send him a message.
//Message will be delivered offline
//receive test is in TestOperationSetBasicInstantMessaging.testReceiveOfflineMessages()
String offlineMsgBody = "This is a Test Message. Supposed to be delivered as offline message!";
String offlineMsgBody =
"This is a Test Message. Supposed to be delivered as offline message!";
IcqSlickFixture.offlineMsgCollector =
new IcqSlickFixture.OfflineMsgCollector();
IcqSlickFixture.offlineMsgCollector.setMessageText(offlineMsgBody);
@ -94,12 +101,12 @@ public void start(BundleContext bundleContext) throws Exception
offlineMsgBody
);
//First test account installation so that the service that has been
//installed by it gets tested by the rest of the tests.
//First test account installation so that the service that has
//been installed by it gets tested by the rest of the tests.
addTest(TestAccountInstallation.suite());
//This must remain second as that's where the protocol would be made
//to login/authenticate/signon its service provider.
//This must remain second as that's where the protocol would be
//made to login/authenticate/signon its service provider.
addTest(TestProtocolProviderServiceIcqImpl.suite());
addTest(TestOperationSetPresence.suite());
@ -113,6 +120,13 @@ public void start(BundleContext bundleContext) throws Exception
//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);
@ -127,6 +141,7 @@ public void start(BundleContext bundleContext) throws Exception
*/
public void stop(BundleContext bundleContext) throws Exception
{
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
* 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;

@ -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