Typing OpSet and tests

cusax-fix
Damian Minkov 20 years ago
parent 546b84dee2
commit 8309924a65

Binary file not shown.

@ -11,6 +11,9 @@
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
import net.sf.jml.*;
import net.sf.jml.message.*;
import net.sf.jml.event.*;
/**
* Maps SIP Communicator typing notifications to those going and coming from
@ -40,6 +43,8 @@ public class OperationSetTypingNotificationsMsnImpl
*/
private OperationSetPersistentPresenceMsnImpl opSetPersPresence = null;
private MsnMessenger messenger = null;
/**
* @param provider a ref to the <tt>ProtocolProviderServiceImpl</tt>
* that created us and that we'll use for retrieving the underlying aim
@ -49,6 +54,7 @@ public class OperationSetTypingNotificationsMsnImpl
ProtocolProviderServiceMsnImpl provider)
{
this.msnProvider = provider;
provider.addRegistrationStateChangeListener(new ProviderRegListener());
}
/**
@ -129,6 +135,30 @@ public void sendTypingNotification(Contact notifiedContact, int typingState)
throws IllegalStateException, IllegalArgumentException
{
assertConnected();
if( !(notifiedContact instanceof ContactMsnImpl) )
throw new IllegalArgumentException(
"The specified contact is not an msn contact." + notifiedContact);
if(typingState == OperationSetTypingNotifications.STATE_TYPING)
{
MsnControlMessage msg = new MsnControlMessage();
msg.setTypingUser(messenger.getOwner().getEmail().getEmailAddress());
Email targetContactEmail =
( (ContactMsnImpl) notifiedContact).getSourceContact().getEmail();
MsnSwitchboard[] activSB = messenger.getActiveSwitchboards();
MsnSwitchboard tempSB = null;
for (int i = 0; i < activSB.length; i++)
{
tempSB = activSB[i];
if (tempSB.containContact(targetContactEmail))
tempSB.sendMessage(msg, true);
}
}
}
/**
@ -148,4 +178,65 @@ private void assertConnected() throws IllegalStateException
"The msn provider must be signed on the service before "
+"being able to communicate.");
}
/**
* Sets the messenger instance impl of the lib
* which comunicates with the server
* @param messenger MsnMessenger
*/
void setMessenger(MsnMessenger messenger)
{
this.messenger = messenger;
messenger.addMessageListener(new TypingListener());
}
private class TypingListener
extends MsnAdapter
{
public void controlMessageReceived(MsnSwitchboard switchboard,
MsnControlMessage message,
MsnContact contact)
{
String typingUserID = message.getTypingUser();
if(typingUserID != null)
{
Contact sourceContact = opSetPersPresence.findContactByID(typingUserID);
if(sourceContact == null)
return;
fireTypingNotificationsEvent(sourceContact, STATE_TYPING);
}
}
}
/**
* Our listener that will tell us when we're registered and
* ready to accept us as a listener.
*/
private class ProviderRegListener
implements RegistrationStateChangeListener
{
/**
* The method is called by a ProtocolProvider implementation whenver
* a change in the registration state of the corresponding provider had
* occurred.
* @param evt ProviderStatusChangeEvent the event describing the status
* change.
*/
public void registrationStateChanged(RegistrationStateChangeEvent evt)
{
logger.debug("The provider changed state from: "
+ evt.getOldState()
+ " to: " + evt.getNewState());
if (evt.getNewState() == RegistrationState.REGISTERED)
{
opSetPersPresence = (OperationSetPersistentPresenceMsnImpl)
msnProvider.getSupportedOperationSets()
.get(OperationSetPersistentPresence.class.getName());
}
}
}
}

@ -62,6 +62,8 @@ public class ProtocolProviderServiceMsnImpl
private OperationSetPersistentPresenceMsnImpl persistentPresence = null;
private OperationSetTypingNotificationsMsnImpl typingNotifications = null;
/**
* Returns the state of the registration of this protocol provider
* @return the <tt>RegistrationState</tt> that this provider is
@ -157,6 +159,7 @@ private void connectAndLogin(SecurityAuthority authority)
messenger.addMessengerListener(new MsnConnectionListener());
persistentPresence.setMessenger(messenger);
typingNotifications.setMessenger(messenger);
messenger.login();
}
@ -279,7 +282,7 @@ protected void initialize(String screenname,
basicInstantMessaging);
//initialize the typing notifications operation set
OperationSetTypingNotifications typingNotifications =
typingNotifications =
new OperationSetTypingNotificationsMsnImpl(this);
supportedOperationSets.put(

@ -728,7 +728,10 @@ public void contactListInitCompleted(MsnMessenger messenger)
{
logger.trace("contactListInitCompleted");
isInitialized = true;
// printList();
if(logger.isDebugEnabled())
printList();
// first init groups
MsnContactList contactList = messenger.getContactList();
MsnGroup[] groups = contactList.getGroups();
@ -1228,7 +1231,7 @@ public void printList()
c[i].getBelongGroups().length);
}
System.out.println("Number of groups : " + messenger.getContactList().getGroups().length);
logger.info("Number of groups : " + messenger.getContactList().getGroups().length);
MsnGroup[] groups = messenger.getContactList().getGroups();
for(int j = 0; j < groups.length; j++)
{

@ -80,14 +80,13 @@ public void start(BundleContext context)
//the following should only be run when we want online testing.
if(!MsnSlickFixture.onlineTestingDisabled)
{
// addTest(TestOperationSetPersistentPresence.suite());
//
addTest(TestOperationSetPersistentPresence.suite());
addTest(TestOperationSetBasicInstantMessaging.suite());
//
// addTest(TestOperationSetTypingNotifications.suite());
addTest(TestOperationSetTypingNotifications.suite());
}
//
//
addTest(TestAccountUninstallation.suite());
addTestSuite(TestAccountUninstallationPersistence.class);

@ -159,7 +159,10 @@ public void testRetrievingServerStoredContactList()
// the sever creates a group NotInContactList,
// beacuse the buddy we are sending message to is not in
// the contactlist. So this group must be ignored
if(!group.getGroupName().equals("NotInContactList"))
// Also we must ignore the group created by default
// from the msn lib
if(!group.getGroupName().equals("NotInContactList") &&
!group.getGroupName().equals("Default group"))
{
assertNotNull("Group " + group.getGroupName() +
" was returned by "
@ -203,11 +206,7 @@ public void postTestCreateGroup()
// first clear the list
fixture.clearProvidersLists();
Object o = new Object();
synchronized(o)
{
o.wait(3000);
}
waitFor(5000);
logger.trace("testing creation of server stored groups");
//first add a listener
@ -247,7 +246,7 @@ public void postTestCreateGroup()
{
opSetPersPresence1.subscribe(group, fixture.userID2);
synchronized(o){o.wait(1500);}
waitFor(1500);
}
catch (Exception ex)
{
@ -272,10 +271,10 @@ public void postTestRemoveGroup()
opSetPersPresence1
.addServerStoredGroupChangeListener(groupChangeCollector);
//create the group
//remove the group
opSetPersPresence1.removeServerStoredContactGroup(
opSetPersPresence1.getServerStoredContactListRoot()
.getGroup(testGroupName2));
.getGroup(testGroupName));
groupChangeCollector.waitForEvent(10000);
@ -286,13 +285,13 @@ public void postTestRemoveGroup()
assertEquals("Collected Group Change event",
1, groupChangeCollector.collectedEvents.size());
assertEquals("Group name.", testGroupName2,
assertEquals("Group name.", testGroupName,
((ServerStoredGroupEvent)groupChangeCollector.collectedEvents
.get(0)).getSourceGroup().getGroupName());
// check whether the group is still on the contact list
ContactGroup group = opSetPersPresence1.getServerStoredContactListRoot()
.getGroup(testGroupName2);
.getGroup(testGroupName);
assertNull("A freshly removed group was still on the contact list.",
group);
@ -356,11 +355,7 @@ public void prepareContactList()
{
fixture.clearProvidersLists();
Object o = new Object();
synchronized(o)
{
o.wait(3000);
}
waitFor(3000);
String contactList = System.getProperty(
MsnProtocolProviderServiceLick.CONTACT_LIST_PROPERTY_NAME, null);
@ -420,6 +415,9 @@ public void prepareContactList()
// now init the list
Enumeration newGroupsEnum = contactListToCreate.keys();
GroupChangeCollector groupChangeCollector = new GroupChangeCollector();
opSetPersPresence1.addServerStoredGroupChangeListener(groupChangeCollector);
//go over all groups in the contactsToAdd table
while (newGroupsEnum.hasMoreElements())
{
@ -429,6 +427,8 @@ public void prepareContactList()
opSetPersPresence1.createServerStoredContactGroup(
opSetPersPresence1.getServerStoredContactListRoot(), groupName);
groupChangeCollector.waitForEvent(3000);
ContactGroup newlyCreatedGroup =
opSetPersPresence1.getServerStoredContactListRoot().getGroup(groupName);
@ -443,10 +443,22 @@ public void prepareContactList()
}
}
waitFor(2000);
//store the created contact list for later reference
MsnSlickFixture.preInstalledBuddyList = contactListToCreate;
}
private void waitFor(long time)
throws Exception
{
Object o = new Object();
synchronized(o)
{
o.wait(time);
}
}
/**
* The class would listen for and store received events delivered to
* <tt>ServerStoredGroupListener</tt>s.
@ -677,6 +689,5 @@ public void contactModified(ContactPropertyChangeEvent evt)
notifyAll();
}
}
}
}

@ -216,6 +216,9 @@ public void testTypingNotificationsEventDelivery()
Contact contactToNotify =
opSetPresence2.findContactByID(fixture.userID1);
opSetBasicIM2.sendInstantMessage(contactToNotify,
opSetBasicIM2.createMessage("pong"));
opSetTypingNotifs2.sendTypingNotification(
contactToNotify, OperationSetTypingNotifications.STATE_TYPING);
@ -237,31 +240,6 @@ public void testTypingNotificationsEventDelivery()
assertEquals("Source of the typing notification event"
, OperationSetTypingNotifications.STATE_TYPING
, evt.getTypingState());
evtCollector.collectedEvents.clear();
opSetTypingNotifs1.addTypingNotificationsListener(evtCollector);
opSetTypingNotifs2.sendTypingNotification(
contactToNotify, OperationSetTypingNotifications.STATE_STOPPED);
evtCollector.waitForEvent(10000);
opSetTypingNotifs1.removeTypingNotificationsListener(evtCollector);
//check event dispatching
assertTrue("Number of typing events received was zero."
, evtCollector.collectedEvents.size() > 0);
evt = (TypingNotificationEvent)evtCollector.collectedEvents.get(0);
assertEquals("Source of the typing notification event"
, fixture.userID2
, evt.getSourceContact().getAddress() );
assertEquals("Source of the typing notification event"
, OperationSetTypingNotifications.STATE_STOPPED
, evt.getTypingState());
}
/**

Loading…
Cancel
Save