Add unit tests for Yahoo! ad-hoc multi-user chat (but not enabled yet).

cusax-fix
Valentin Martinet 16 years ago
parent 24038c7b17
commit 4ee7bef666

@ -82,6 +82,8 @@ public void testInstallAccount()
YahooProtocolProviderServiceLick.ACCOUNT_1_PREFIX);
Hashtable<String, String> yahooAccount2Properties = getAccountProperties(
YahooProtocolProviderServiceLick.ACCOUNT_2_PREFIX);
Hashtable<String, String> yahooAccount3Properties = getAccountProperties(
YahooProtocolProviderServiceLick.ACCOUNT_3_PREFIX);
//try to install an account with a null account id
try{
@ -101,6 +103,9 @@ public void testInstallAccount()
yahooProviderFactory.installAccount(
yahooAccount2Properties.get(ProtocolProviderFactory.USER_ID)
, yahooAccount2Properties);
yahooProviderFactory.installAccount(
yahooAccount3Properties.get(ProtocolProviderFactory.USER_ID)
, yahooAccount3Properties);
//try to install one of the accounts one more time and verify that an
@ -122,7 +127,7 @@ public void testInstallAccount()
assertTrue(
"The newly installed account was not in the acc man's "
+"registered accounts!",
yahooProviderFactory.getRegisteredAccounts().size() == 2);
yahooProviderFactory.getRegisteredAccounts().size() == 3);
//Verify protocol providers corresponding to the new account have
//been properly registered with the osgi framework.

@ -18,6 +18,7 @@
* provider bundle in order to verify that accounts are persistent.
*
* @author Emil Ivov
* @author Valentin Martinet
*/
public class TestAccountUninstallation
extends TestCase
@ -208,7 +209,7 @@ public void testInstallationPersistency() throws Exception
}
/**
* Uinstalls our test account and makes sure it really has been removed.
* Uninstalls our test account and makes sure it really has been removed.
*
*/
public void testUninstallAccount()
@ -228,9 +229,14 @@ public void testUninstallAccount()
fixture.provider1.getAccountID()));
assertTrue(
"Failed to remove a provider corresponding to URI "
+ fixture.userID1
+ fixture.userID2
,fixture.providerFactory.uninstallAccount(
fixture.provider2.getAccountID()));
assertTrue(
"Failed to remove a provider corresponding to URI "
+ fixture.userID3
,fixture.providerFactory.uninstallAccount(
fixture.provider3.getAccountID()));
//make sure no providers have remained installed.
ServiceReference[] yahooProviderRefs = null;

@ -0,0 +1,152 @@
/*
* 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.yahoo;
import java.util.*;
import junit.framework.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.slick.protocol.generic.*;
/**
* Tests for the Yahoo! ad-hoc multi-user chat operation set.
*
* @author Valentin Martinet
*/
public class TestOperationSetAdHocMultiUserChatYahooImpl
extends TestOperationSetAdHocMultiUserChat
{
/**
* Creates the test with the specified method name.
*
* @param name the name of the method to execute.
*/
public TestOperationSetAdHocMultiUserChatYahooImpl(String name)
{
super(name);
}
/**
* Creates a test suite containing tests of this class in a specific order.
*
* @return Test a testsuite containing all tests to execute.
*/
public static TestSuite suite()
{
TestSuite suite = new TestSuite();
// suite.addTest(new TestOperationSetAdHocMultiUserChatYahooImpl(
// "prepareContactList"));
// suite.addTest(new TestOperationSetAdHocMultiUserChatYahooImpl(
// "testCreateRoomWithParticipants"));
// suite.addTest(new TestOperationSetAdHocMultiUserChatYahooImpl(
// "testInvitations"));
// suite.addTest(new TestOperationSetAdHocMultiUserChatYahooImpl(
// "testSendIM"));
// suite.addTest(new TestOperationSetAdHocMultiUserChatYahooImpl(
// "testPeerLeaved"));
return suite;
}
/**
* JUnit setUp method.
* @throws Exception
*
* @throws Exception
*/
public void start() throws Exception
{
fixture = new YahooSlickFixture();
fixture.setUp();
// Supported operation sets by each protocol provider.
Map<String, OperationSet>
supportedOpSets1, supportedOpSets2, supportedOpSets3;
supportedOpSets1 = fixture.provider1.getSupportedOperationSets();
supportedOpSets2 = fixture.provider2.getSupportedOperationSets();
supportedOpSets3 = fixture.provider3.getSupportedOperationSets();
//
// Initialization of operation sets for the first testing account:
//
if (supportedOpSets1 == null || supportedOpSets1.size() < 1)
throw new NullPointerException(
"No OperationSet implementations are supported by " +
"this implementation. ");
opSetAHMUC1 = (OperationSetAdHocMultiUserChat) supportedOpSets1.get(
OperationSetAdHocMultiUserChat.class.getName());
if (opSetAHMUC1 == null)
throw new NullPointerException(
"No implementation for multi user chat was found");
opSetPresence1 = (OperationSetPresence) supportedOpSets1.get(
OperationSetPresence.class.getName());
if (opSetPresence1 == null)
throw new NullPointerException(
"An implementation of the service must provide an " +
"implementation of at least one of the PresenceOperationSets");
//
// Initialization of operation sets for the second testing account:
//
if (supportedOpSets2 == null || supportedOpSets2.size() < 1)
throw new NullPointerException(
"No OperationSet implementations are supported by " +
"this implementation. ");
opSetAHMUC2 = (OperationSetAdHocMultiUserChat) supportedOpSets2.get(
OperationSetAdHocMultiUserChat.class.getName());
if (opSetAHMUC2 == null)
throw new NullPointerException(
"No implementation for ad hoc multi user chat was found");
opSetPresence2 = (OperationSetPresence) supportedOpSets2.get(
OperationSetPresence.class.getName());
if (opSetPresence2 == null)
throw new NullPointerException(
"An implementation of the service must provide an " +
"implementation of at least one of the PresenceOperationSets");
//
// Initialization of operation sets for the third testing account:
//
if (supportedOpSets3 == null || supportedOpSets3.size() < 1)
throw new NullPointerException(
"No OperationSet implementations are supported by " +
"this implementation. ");
opSetAHMUC3 = (OperationSetAdHocMultiUserChat) supportedOpSets3.get(
OperationSetAdHocMultiUserChat.class.getName());
if (opSetAHMUC3 == null)
throw new NullPointerException(
"No implementation for ad hoc multi user chat was found");
opSetPresence3 = (OperationSetPresence) supportedOpSets3.get(
OperationSetPresence.class.getName());
if (opSetPresence3 == null)
throw new NullPointerException(
"An implementation of the service must provide an " +
"implementation of at least one of the PresenceOperationSets");
}
}

@ -37,6 +37,12 @@ public class TestProtocolProviderServiceYahooImpl
*/
public RegistrationEventCollector regEvtCollector2
= new RegistrationEventCollector();
/**
* An event adapter that would collec registation state change events
*/
public RegistrationEventCollector regEvtCollector3
= new RegistrationEventCollector();
/**
* Creates a test encapsulator for the method with the specified name.
@ -87,14 +93,18 @@ public void testRegister()
//they were properly dispatched.
fixture.provider1.addRegistrationStateChangeListener(regEvtCollector1);
fixture.provider2.addRegistrationStateChangeListener(regEvtCollector2);
fixture.provider3.addRegistrationStateChangeListener(regEvtCollector3);
//register both our providers
//register our three providers
fixture.provider1.register(new SecurityAuthorityImpl(
System.getProperty(YahooProtocolProviderServiceLick.ACCOUNT_1_PREFIX
+ ProtocolProviderFactory.PASSWORD).toCharArray()));
fixture.provider2.register(new SecurityAuthorityImpl(
System.getProperty(YahooProtocolProviderServiceLick.ACCOUNT_2_PREFIX
+ ProtocolProviderFactory.PASSWORD).toCharArray()));
fixture.provider3.register(new SecurityAuthorityImpl(
System.getProperty(YahooProtocolProviderServiceLick.ACCOUNT_3_PREFIX
+ ProtocolProviderFactory.PASSWORD).toCharArray()));
//give it enough time to register. We won't really have to wait all this
//time since the registration event collector would notify us the moment
@ -103,6 +113,7 @@ public void testRegister()
regEvtCollector1.waitForEvent(15000);
regEvtCollector2.waitForEvent(40000);
regEvtCollector3.waitForEvent(60000);
//make sure that the registration process trigerred the corresponding
//events.
@ -127,12 +138,26 @@ public void testRegister()
+"All events were: " + regEvtCollector2.collectedNewStates
,regEvtCollector2.collectedNewStates
.contains(RegistrationState.REGISTERED));
//now the same for provider 3
assertTrue(
"No events were dispatched during the registration process "
+"of provider3."
,regEvtCollector3.collectedNewStates.size() > 0);
assertTrue(
"No registration event notifying of registration was dispatched. "
+"All events were: " + regEvtCollector3.collectedNewStates
,regEvtCollector3.collectedNewStates
.contains(RegistrationState.REGISTERED));
fixture.provider1
.removeRegistrationStateChangeListener(regEvtCollector1);
fixture.provider2
.removeRegistrationStateChangeListener(regEvtCollector2);
fixture.provider3
. removeRegistrationStateChangeListener(regEvtCollector3);
}

@ -13,9 +13,10 @@
/**
* Yahoo specific testing for a Yahoo Protocol Provider Service implementation.
* The test suite registers two accounts for
* The test suite registers three accounts for
*
* @author Damian Minkov
* @author Valentin Martinet
*/
public class YahooProtocolProviderServiceLick
extends TestSuite
@ -34,6 +35,13 @@ public class YahooProtocolProviderServiceLick
*/
public static final String ACCOUNT_2_PREFIX
= "accounts.yahoo.account2.";
/**
* The prefix used for property names containing settings for our third
* testing account.
*/
public static final String ACCOUNT_3_PREFIX
= "accounts.yahoo.account3.";
/**
* The name of the property that indicates whether the user would like to
@ -87,6 +95,8 @@ public void start(BundleContext context)
addTest(TestOperationSetTypingNotifications.suite());
addTestSuite(TestOperationSetFileTransferImpl.class);
addTest(TestOperationSetAdHocMultiUserChatYahooImpl.suite());
}
addTest(TestAccountUninstallation.suite());

@ -7,95 +7,35 @@
package net.java.sip.communicator.slick.protocol.yahoo;
import org.osgi.framework.*;
import junit.framework.*;
import net.java.sip.communicator.service.protocol.*;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.slick.protocol.generic.*;
/**
* Contains fields and methods used by most or all tests in the yahoo slick.
*
* @author Damian Minkov
* @author Valentin Martinet
*/
public class YahooSlickFixture
extends TestCase
extends AdHocMultiUserChatSlickFixture
{
/**
* 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.
* Constructor
*/
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 initialize the ss contact list before the tested implementation has
* actually done so.
*/
public static Hashtable<String, List<String>> preInstalledBuddyList = null;
public YahooSlickFixture()
{
super();
}
/**
* Initializes protocol provider references and whatever else there is to
* initialize.
*
* @throws java.lang.Exception in case we meet problems while retrieving
*
* @throws InvalidSyntaxException in case we meet problems while retrieving
* protocol providers through OSGI
*/
public void setUp()
throws Exception
public void setUp() throws InvalidSyntaxException
{
// first obtain a reference to the provider factory
ServiceReference[] serRefs = null;
@ -126,8 +66,13 @@ public void setUp()
System.getProperty(
YahooProtocolProviderServiceLick.ACCOUNT_2_PREFIX
+ ProtocolProviderFactory.USER_ID);
userID3 =
System.getProperty(
YahooProtocolProviderServiceLick.ACCOUNT_3_PREFIX
+ ProtocolProviderFactory.USER_ID);
//find the protocol providers exported for the two accounts
//find the protocol providers exported for the three accounts
ServiceReference[] yahooProvider1Refs
= bc.getServiceReferences(
ProtocolProviderService.class.getName(),
@ -141,7 +86,7 @@ public void setUp()
assertNotNull("No Protocol Provider was found for yahoo account1:"
+ userID1
, yahooProvider1Refs);
assertTrue("No Protocol Provider was found for yahoo account1:"+ userID1,
assertTrue("No Protocol Provider was found for yahoo account1:"+userID1,
yahooProvider1Refs.length > 0);
ServiceReference[] yahooProvider2Refs
@ -157,141 +102,31 @@ public void setUp()
assertNotNull("No Protocol Provider was found for yahoo account2:"
+ userID2
, yahooProvider2Refs);
assertTrue("No Protocol Provider was found for yahoo account2:"+ userID2,
assertTrue("No Protocol Provider was found for yahoo account2:"+userID2,
yahooProvider2Refs.length > 0);
ServiceReference[] yahooProvider3Refs
= bc.getServiceReferences(
ProtocolProviderService.class.getName(),
"(&"
+"("+ProtocolProviderFactory.PROTOCOL+"="+ProtocolNames.YAHOO+")"
+"("+ProtocolProviderFactory.USER_ID+"="
+ userID3 +")"
+")");
//again make sure we found a service.
assertNotNull("No Protocol Provider was found for yahoo account3:"
+ userID3
, yahooProvider3Refs);
assertTrue("No Protocol Provider was found for yahoo account2:"+userID3,
yahooProvider3Refs.length > 0);
//save the service for other tests to use.
provider1ServiceRef = yahooProvider1Refs[0];
provider1 = (ProtocolProviderService)bc.getService(provider1ServiceRef);
provider2ServiceRef = yahooProvider2Refs[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<String, OperationSet> supportedOperationSets1 =
provider1.getSupportedOperationSets();
if ( supportedOperationSets1 == null
|| supportedOperationSets1.size() < 1)
throw new NullPointerException(
"No OperationSet implementations are supported by "
+"this yahoo 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 yahoo.
if (opSetPersPresence1 == null)
throw new NullPointerException(
"An implementation of the yahoo 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<String, OperationSet> supportedOperationSets2 =
provider2.getSupportedOperationSets();
if (supportedOperationSets2 == null
|| supportedOperationSets2.size() < 1)
throw new NullPointerException(
"No OperationSet implementations are supported by "
+ "this yahoo 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 yahoo.
if (opSetPersPresence2 == null)
throw new NullPointerException(
"An implementation of the yahoo service must provide an "
+ "implementation of at least the one of the Presence "
+ "Operation Sets");
ContactGroup rootGroup1 = opSetPersPresence1.getServerStoredContactListRoot();
// first delete the groups
Vector<ContactGroup> groupsToRemove = new Vector<ContactGroup>();
Iterator<ContactGroup> iter = rootGroup1.subgroups();
while (iter.hasNext())
{
groupsToRemove.add(iter.next());
}
iter = groupsToRemove.iterator();
while (iter.hasNext())
{
ContactGroup item = iter.next();
opSetPersPresence1.removeServerStoredContactGroup(item);
}
ContactGroup rootGroup2 = opSetPersPresence2.getServerStoredContactListRoot();
// delete groups
groupsToRemove = new Vector<ContactGroup>();
iter = rootGroup2.subgroups();
while (iter.hasNext())
{
groupsToRemove.add(iter.next());
}
iter = groupsToRemove.iterator();
while (iter.hasNext())
{
ContactGroup item = iter.next();
opSetPersPresence2.removeServerStoredContactGroup(item);
}
provider3ServiceRef = yahooProvider3Refs[0];
provider3 = (ProtocolProviderService)bc.getService(provider3ServiceRef);
}
}

Loading…
Cancel
Save