1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 12:02:05 +01:00

Fix StreamManagementTest in smack-integration

Since 6c637d5784 connect() does not longer
automatically perform a login.

Also verify the message bodies in the test.
This commit is contained in:
Florian Schmaus 2015-04-22 22:32:19 +02:00
parent 0efdc4018f
commit 00a7556bfe

View file

@ -16,6 +16,9 @@
*/
package org.jivesoftware.smack;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
@ -25,6 +28,9 @@ import org.igniterealtime.smack.inttest.Configuration;
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
import org.igniterealtime.smack.inttest.TestNotPossibleException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.FromMatchesFilter;
import org.jivesoftware.smack.filter.MessageWithBodiesFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.junit.AfterClass;
@ -60,17 +66,32 @@ public class StreamManagementTest extends AbstractSmackLowLevelIntegrationTest {
public void testStreamManagement(XMPPTCPConnection conOne, XMPPTCPConnection conTwo) throws InterruptedException, KeyManagementException,
NoSuchAlgorithmException, SmackException, IOException, XMPPException,
TestNotPossibleException {
send("Hi, what's up?", conOne, conTwo);
final String body1 = "Hi, what's up? " + testRunId;
final String body2 = "Hi, what's up? I've been just instantly shutdown" + testRunId;
final String body3 = "Hi, what's up? I've been just resumed" + testRunId;
conOne.instantShutdown();
final PacketCollector collector = conTwo.createPacketCollector(new AndFilter(
MessageWithBodiesFilter.INSTANCE,
FromMatchesFilter.createFull(conOne.getUser())));
send("Hi, what's up? I've been just instantly shutdown", conOne, conTwo);
try {
send(body1, conOne, conTwo);
assertMessageWithBodyReceived(body1, collector);
// Reconnect with xep198
conOne.connect();
conOne.instantShutdown();
send("Hi, what's up? I've been just resumed", conOne, conTwo);
// TODO check that all messages where received
send(body2, conOne, conTwo);
// Reconnect with xep198
conOne.connect().login();
assertMessageWithBodyReceived(body2, collector);
send(body3, conOne, conTwo);
assertMessageWithBodyReceived(body3, collector);
}
finally {
collector.cancel();
}
}
private static void send(String messageString, XMPPConnection from, XMPPConnection to)
@ -79,4 +100,10 @@ public class StreamManagementTest extends AbstractSmackLowLevelIntegrationTest {
message.setBody(messageString);
from.sendStanza(message);
}
private static void assertMessageWithBodyReceived(String body, PacketCollector collector) throws InterruptedException {
Message message = collector.nextResult();
assertNotNull(message);
assertEquals(body, message.getBody());
}
}