diff --git a/test/net/java/sip/communicator/slick/protocol/icq/IcqProtocolProviderSlick.java b/test/net/java/sip/communicator/slick/protocol/icq/IcqProtocolProviderSlick.java
index b3be7834a..8f93a6ccb 100644
--- a/test/net/java/sip/communicator/slick/protocol/icq/IcqProtocolProviderSlick.java
+++ b/test/net/java/sip/communicator/slick/protocol/icq/IcqProtocolProviderSlick.java
@@ -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);
diff --git a/test/net/java/sip/communicator/slick/protocol/icq/IcqSlickFixture.java b/test/net/java/sip/communicator/slick/protocol/icq/IcqSlickFixture.java
index 127786a0c..0d1730fcd 100644
--- a/test/net/java/sip/communicator/slick/protocol/icq/IcqSlickFixture.java
+++ b/test/net/java/sip/communicator/slick/protocol/icq/IcqSlickFixture.java
@@ -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;
+ }
+ }
}
diff --git a/test/net/java/sip/communicator/slick/protocol/icq/IcqTesterAgent.java b/test/net/java/sip/communicator/slick/protocol/icq/IcqTesterAgent.java
index 91db54e91..c2f152e02 100644
--- a/test/net/java/sip/communicator/slick/protocol/icq/IcqTesterAgent.java
+++ b/test/net/java/sip/communicator/slick/protocol/icq/IcqTesterAgent.java
@@ -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 body to buddy 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);
+ }
+ }
+}
diff --git a/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetBasicInstantMessaging.java b/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetBasicInstantMessaging.java
index 8d368908f..d06e8fc2b 100644
--- a/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetBasicInstantMessaging.java
+++ b/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetBasicInstantMessaging.java
@@ -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());
+ }
}
diff --git a/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetPersistentPresence.java b/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetPersistentPresence.java
index 2dd1cc032..b1127c199 100644
--- a/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetPersistentPresence.java
+++ b/test/net/java/sip/communicator/slick/protocol/icq/TestOperationSetPersistentPresence.java
@@ -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,
diff --git a/test/net/java/sip/communicator/slick/protocol/icq/TestProtocolProviderServiceIcqImpl.java b/test/net/java/sip/communicator/slick/protocol/icq/TestProtocolProviderServiceIcqImpl.java
index d21055a36..e97714a44 100644
--- a/test/net/java/sip/communicator/slick/protocol/icq/TestProtocolProviderServiceIcqImpl.java
+++ b/test/net/java/sip/communicator/slick/protocol/icq/TestProtocolProviderServiceIcqImpl.java
@@ -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