/**
* Ensures that replying to packets is ok.
*/
public void testReplying() throws XMPPException {
PacketCollector collector0 =
getConnection(0).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
PacketCollector collector1 =
getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
PacketCollector collector2 =
getConnection(2).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
PacketCollector collector3 =
getConnection(3).createPacketCollector(new MessageTypeFilter(Message.Type.normal));
// Send the intial message with multiple recipients
Message message = new Message();
message.setBody("Hola");
List to = Arrays.asList(new String[]{getBareJID(1)});
List cc = Arrays.asList(new String[]{getBareJID(2)});
List bcc = Arrays.asList(new String[]{getBareJID(3)});
MultipleRecipientManager.send(getConnection(0), message, to, cc, bcc);
// Get the message and ensure it's ok
Message message1 =
(Message) collector1.nextResult(SmackConfiguration.getPacketReplyTimeout());
assertNotNull("Connection 1 never received the message", message1);
MultipleRecipientInfo info = MultipleRecipientManager.getMultipleRecipientInfo(message1);
assertNotNull("Message 1 does not contain MultipleRecipientInfo", info);
assertFalse("Message 1 should be 'replyable'", info.shouldNotReply());
assertEquals("Incorrect number of TO addresses", 1, info.getTOAddresses().size());
assertEquals("Incorrect number of CC addresses", 1, info.getCCAddresses().size());
// Prepare and send the reply
Message reply1 = new Message();
reply1.setBody("This is my reply");
MultipleRecipientManager.reply(getConnection(1), message1, reply1);
// Get the reply and ensure it's ok
reply1 = (Message) collector0.nextResult(SmackConfiguration.getPacketReplyTimeout());
assertNotNull("Connection 0 never received the reply", reply1);
info = MultipleRecipientManager.getMultipleRecipientInfo(reply1);
assertNotNull("Replied message does not contain MultipleRecipientInfo", info);
assertFalse("Replied message should be 'replyable'", info.shouldNotReply());
assertEquals("Incorrect number of TO addresses", 1, info.getTOAddresses().size());
assertEquals("Incorrect number of CC addresses", 1, info.getCCAddresses().size());
// Send a reply to the reply
Message reply2 = new Message();
reply2.setBody("This is my reply to your reply");
reply2.setFrom(getBareJID(0));
MultipleRecipientManager.reply(getConnection(0), reply1, reply2);
// Get the reply and ensure it's ok
reply2 = (Message) collector1.nextResult(SmackConfiguration.getPacketReplyTimeout());
assertNotNull("Connection 1 never received the reply", reply2);
info = MultipleRecipientManager.getMultipleRecipientInfo(reply2);
assertNotNull("Replied message does not contain MultipleRecipientInfo", info);
assertFalse("Replied message should be 'replyable'", info.shouldNotReply());
assertEquals("Incorrect number of TO addresses", 1, info.getTOAddresses().size());
assertEquals("Incorrect number of CC addresses", 1, info.getCCAddresses().size());
// Check that connection2 recevied 3 messages
message1 = (Message) collector2.nextResult(SmackConfiguration.getPacketReplyTimeout());
assertNotNull("Connection2 didn't receive the 1 message", message1);
message1 = (Message) collector2.nextResult(SmackConfiguration.getPacketReplyTimeout());
assertNotNull("Connection2 didn't receive the 2 message", message1);
message1 = (Message) collector2.nextResult(SmackConfiguration.getPacketReplyTimeout());
assertNotNull("Connection2 didn't receive the 3 message", message1);
message1 = (Message) collector2.nextResult(SmackConfiguration.getPacketReplyTimeout());
assertNull("Connection2 received 4 messages", message1);
// Check that connection3 recevied only 1 message (was BCC in the first message)
message1 = (Message) collector3.nextResult(SmackConfiguration.getPacketReplyTimeout());
assertNotNull("Connection3 didn't receive the 1 message", message1);
message1 = (Message) collector3.nextResult(SmackConfiguration.getPacketReplyTimeout());
assertNull("Connection2 received 2 messages", message1);
collector0.cancel();
collector1.cancel();
collector2.cancel();
collector3.cancel();
}