Added Tests for receiving offline messages

cusax-fix
Damian Minkov 20 years ago
parent e96ae1fa45
commit 56ea23decc

@ -80,6 +80,19 @@ public void start(BundleContext bundleContext) throws Exception
//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!";
IcqSlickFixture.offlineMsgCollector =
new IcqSlickFixture.OfflineMsgCollector();
IcqSlickFixture.offlineMsgCollector.setMessageText(offlineMsgBody);
IcqSlickFixture.testerAgent.sendOfflineMessage(
System.getProperty(TESTED_IMPL_ACCOUNT_ID_PROP_NAME, null),
offlineMsgBody
);
//First test account installation so that the service that has been
//installed by it gets tested by the rest of the tests.
addTestSuite(TestAccountInstallation.class);

@ -4,6 +4,10 @@
import org.osgi.framework.*;
import junit.framework.*;
import java.util.*;
import net.java.sip.communicator.service.protocol.event.MessageListener;
import net.java.sip.communicator.service.protocol.event.MessageReceivedEvent;
import net.java.sip.communicator.service.protocol.event.MessageDeliveredEvent;
import net.java.sip.communicator.service.protocol.event.MessageDeliveryFailedEvent;
/**
* Provides utility code, such as locating and obtaining references towards
@ -45,6 +49,8 @@ public class IcqSlickFixture extends TestCase
public AccountManager accManager = null;
public String ourAccountID = null;
public static OfflineMsgCollector offlineMsgCollector = null;
public void setUp() throws Exception
{
// first obtain a reference to the account manager
@ -99,4 +105,54 @@ public void tearDown()
bc.ungetService(icqServiceRef);
}
//used in Offline Message receive test
//this MessageReceiver is created in IcqProtocolProviderSlick
//registered as listener in TestProtocolProviderServiceIcqImpl
// as soon tested account has been registed
//There is only one offline message send. And this message is the first message
// received after the successful regitration, so this listener is removed
// after receiving one message. This message is tested in TestOperationSetBasicInstantMessaging
// whether it is the one that has been send
static class OfflineMsgCollector implements MessageListener
{
private String offlineMessageToBeDelivered = null;
private OperationSetBasicInstantMessaging imOper = null;
private Message receivedMessage = null;
public void messageReceived(MessageReceivedEvent evt)
{
receivedMessage = evt.getSourceMessage();
imOper.removeMessageListener(this);
}
public void messageDelivered(MessageDeliveredEvent evt)
{
}
public void messageDeliveryFailed(MessageDeliveryFailedEvent evt)
{
}
public void setMessageText(String txt)
{
this.offlineMessageToBeDelivered = txt;
}
public String getMessageText()
{
return offlineMessageToBeDelivered;
}
public void register(OperationSetBasicInstantMessaging imOper)
{
this.imOper = imOper;
imOper.addMessageListener(this);
}
public Message getReceivedMessage()
{
return receivedMessage;
}
}
}

@ -25,6 +25,8 @@
import net.kano.joustsim.oscar.oscar.service.bos.*;
import net.java.sip.communicator.service.protocol.icqconstants.*;
import java.io.*;
import net.kano.joscar.snaccmd.icbm.SendImIcbm;
import net.kano.joscar.tlv.Tlv;
/**
* An utility that we use to test AIM/ICQ implementations of the
@ -1174,7 +1176,32 @@ public void writeData(OutputStream out) throws IOException
{
}
}
/**
* Sends <tt>body</tt> to <tt>buddy</tt> as an offline instant message
* @param buddy the screenname of the budy that we'd like to send our msg to.
* @param body the content of the message to send.
*/
public void sendOfflineMessage(String buddy, String body)
{
conn.sendSnac(new OfflineSnacCmd(buddy, body));
}
}
private class OfflineSnacCmd extends SendImIcbm
{
private static final int TYPE_OFFLINE = 0x0006;
protected OfflineSnacCmd(String sn, String message)
{
super(sn, message);
}
protected void writeChannelData(OutputStream out)
throws IOException
{
super.writeChannelData(out);
new Tlv(TYPE_OFFLINE).write(out);
}
}
}

@ -15,6 +15,7 @@
import net.kano.joustsim.oscar.oscar.service.icbm.*;
import net.kano.joustsim.*;
import java.net.*;
import net.java.sip.communicator.service.protocol.Message;
/**
* Performs testing of the basic instant messaging operation set. Tests include
@ -473,4 +474,19 @@ public void testSendFunMessages()
fixture.testerAgent.sendMessage(tokenizer.nextToken(), message);
}
}
/**
* Tests whether there is a offline message received
* and whether is the one we have send
*/
public void testReceiveOfflineMessages()
{
String messageText =
fixture.offlineMsgCollector.getMessageText();
Message receiveMessage = fixture.offlineMsgCollector.getReceivedMessage();
assertNotNull("No Offline messages have been received", receiveMessage);
assertEquals("message body", messageText, receiveMessage.getContent());
}
}

@ -135,19 +135,30 @@ public void testRetrievingServerStoredContactList()
List expectedContactsInGroup
= (List)expectedContactList.get(group.getGroupName());
assertNotNull("Group " + group.getGroupName() + " was returned by "
+"the server but was not in the expected contact list."
, expectedContactsInGroup );
Iterator contactsIter = group.contacts();
while (contactsIter.hasNext()){
String contactID = ((Contact)contactsIter.next()).getAddress();
expectedContactsInGroup.remove(contactID);
}
// When sending the offline message
// 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"))
{
assertNotNull("Group " + group.getGroupName() +
" was returned by "
+
"the server but was not in the expected contact list."
, expectedContactsInGroup);
Iterator contactsIter = group.contacts();
while(contactsIter.hasNext())
{
String contactID = ((Contact)contactsIter.next()).
getAddress();
expectedContactsInGroup.remove(contactID);
}
//If we've removed all the sub contacts, remove the group too.
if (expectedContactsInGroup.size() == 0 )
expectedContactList.remove(group.getGroupName());
//If we've removed all the sub contacts, remove the group too.
if(expectedContactsInGroup.size() == 0)
expectedContactList.remove(group.getGroupName());
}
}
//whatever we now have in the expected contact list snapshot are groups,

@ -124,6 +124,16 @@ public void testRegister()
logger.debug("We got thrown out while waiting for registration", t);
}
// Here is registered the listner which will receive the first message
// This message is supposed to be offline message and as one is tested
// in TestOperationSetBasicInstantMessaging.testReceiveOfflineMessages()
Map supportedOperationSets =
fixture.provider.getSupportedOperationSets();
OperationSetBasicInstantMessaging opSetBasicIM =
(OperationSetBasicInstantMessaging)supportedOperationSets.get(
OperationSetBasicInstantMessaging.class.getName());
fixture.offlineMsgCollector.register(opSetBasicIM);
//give time for the AIM server to notify everyone of our arrival
//simply waitinf is really not a reliable way of doing things but I
//can't think of anything better

Loading…
Cancel
Save