mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-26 16:22:06 +01:00
Fixed & improved test cases.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@8790 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
52958e64f7
commit
5d9d7a7b80
6 changed files with 113 additions and 77 deletions
|
@ -195,7 +195,9 @@ public class MessageTest extends SmackTestCase {
|
||||||
*/
|
*/
|
||||||
public void testHighestPriority() throws Exception {
|
public void testHighestPriority() throws Exception {
|
||||||
// Create another connection for the same user of connection 1
|
// Create another connection for the same user of connection 1
|
||||||
XMPPConnection conn3 = new XMPPConnection(getServiceName());
|
ConnectionConfiguration connectionConfiguration =
|
||||||
|
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||||
|
XMPPConnection conn3 = new XMPPConnection(connectionConfiguration);
|
||||||
conn3.connect();
|
conn3.connect();
|
||||||
conn3.login(getUsername(0), getUsername(0), "Home");
|
conn3.login(getUsername(0), getUsername(0), "Home");
|
||||||
// Set this connection as highest priority
|
// Set this connection as highest priority
|
||||||
|
@ -242,7 +244,9 @@ public class MessageTest extends SmackTestCase {
|
||||||
*/
|
*/
|
||||||
public void testHighestShow() throws Exception {
|
public void testHighestShow() throws Exception {
|
||||||
// Create another connection for the same user of connection 1
|
// Create another connection for the same user of connection 1
|
||||||
XMPPConnection conn3 = new XMPPConnection(getServiceName());
|
ConnectionConfiguration connectionConfiguration =
|
||||||
|
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||||
|
XMPPConnection conn3 = new XMPPConnection(connectionConfiguration);
|
||||||
conn3.connect();
|
conn3.connect();
|
||||||
conn3.login(getUsername(0), getUsername(0), "Home");
|
conn3.login(getUsername(0), getUsername(0), "Home");
|
||||||
// Set this connection as highest priority
|
// Set this connection as highest priority
|
||||||
|
@ -289,7 +293,9 @@ public class MessageTest extends SmackTestCase {
|
||||||
*/
|
*/
|
||||||
public void testMostRecentActive() throws Exception {
|
public void testMostRecentActive() throws Exception {
|
||||||
// Create another connection for the same user of connection 1
|
// Create another connection for the same user of connection 1
|
||||||
XMPPConnection conn3 = new XMPPConnection(getServiceName());
|
ConnectionConfiguration connectionConfiguration =
|
||||||
|
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||||
|
XMPPConnection conn3 = new XMPPConnection(connectionConfiguration);
|
||||||
conn3.connect();
|
conn3.connect();
|
||||||
conn3.login(getUsername(0), getUsername(0), "Home");
|
conn3.login(getUsername(0), getUsername(0), "Home");
|
||||||
// Set this connection as highest priority
|
// Set this connection as highest priority
|
||||||
|
@ -303,7 +309,9 @@ public class MessageTest extends SmackTestCase {
|
||||||
presence.setPriority(10);
|
presence.setPriority(10);
|
||||||
getConnection(0).sendPacket(presence);
|
getConnection(0).sendPacket(presence);
|
||||||
|
|
||||||
XMPPConnection conn4 = new XMPPConnection(getServiceName());
|
connectionConfiguration =
|
||||||
|
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||||
|
XMPPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||||
conn4.connect();
|
conn4.connect();
|
||||||
conn4.login(getUsername(0), getUsername(0), "Home2");
|
conn4.login(getUsername(0), getUsername(0), "Home2");
|
||||||
presence = new Presence(Presence.Type.available);
|
presence = new Presence(Presence.Type.available);
|
||||||
|
|
|
@ -170,7 +170,9 @@ public class PresenceTest extends SmackTestCase {
|
||||||
*/
|
*/
|
||||||
public void testMultipleResources() throws Exception {
|
public void testMultipleResources() throws Exception {
|
||||||
// Create another connection for the same user of connection 1
|
// Create another connection for the same user of connection 1
|
||||||
XMPPConnection conn4 = new XMPPConnection(getServiceName());
|
ConnectionConfiguration connectionConfiguration =
|
||||||
|
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||||
|
XMPPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||||
conn4.connect();
|
conn4.connect();
|
||||||
conn4.login(getUsername(1), getUsername(1), "Home");
|
conn4.login(getUsername(1), getUsername(1), "Home");
|
||||||
|
|
||||||
|
@ -252,8 +254,7 @@ public class PresenceTest extends SmackTestCase {
|
||||||
// Wait 500 ms
|
// Wait 500 ms
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
Presence presence = getConnection(0).getRoster().getPresence(getBareJID(1));
|
Presence presence = getConnection(0).getRoster().getPresence(getBareJID(1));
|
||||||
assertTrue("Offline presence status not received.",
|
assertEquals("Offline presence status not received.", "Offline test", presence.getStatus());
|
||||||
"Offline test".equals(presence.getStatus()));
|
|
||||||
|
|
||||||
// Sign out of conn0.
|
// Sign out of conn0.
|
||||||
getConnection(0).disconnect();
|
getConnection(0).disconnect();
|
||||||
|
|
|
@ -53,6 +53,9 @@ public class ReconnectionTest extends SmackTestCase {
|
||||||
|
|
||||||
assertTrue("Failed to use compression", connection.isUsingCompression());
|
assertTrue("Failed to use compression", connection.isUsingCompression());
|
||||||
|
|
||||||
|
// Executes some server interaction testing the connection
|
||||||
|
executeSomeServerInteraction(connection);
|
||||||
|
|
||||||
XMPPConnectionTestListener listener = new XMPPConnectionTestListener();
|
XMPPConnectionTestListener listener = new XMPPConnectionTestListener();
|
||||||
connection.addConnectionListener(listener);
|
connection.addConnectionListener(listener);
|
||||||
|
|
||||||
|
|
|
@ -148,58 +148,53 @@ public class RosterTest extends SmackTestCase {
|
||||||
* 2. Iterate on all the entries and remove them from the roster
|
* 2. Iterate on all the entries and remove them from the roster
|
||||||
* 3. Check that the number of entries and groups is zero
|
* 3. Check that the number of entries and groups is zero
|
||||||
*/
|
*/
|
||||||
public void testDeleteAllRosterEntries() {
|
public void testDeleteAllRosterEntries() throws Exception {
|
||||||
try {
|
// Add a new roster entry
|
||||||
// Add a new roster entry
|
Roster roster = getConnection(0).getRoster();
|
||||||
Roster roster = getConnection(0).getRoster();
|
roster.createEntry(getBareJID(1), "gato11", new String[] { "Friends" });
|
||||||
roster.createEntry(getBareJID(1), "gato11", new String[] { "Friends" });
|
roster.createEntry(getBareJID(2), "gato12", new String[] { "Family" });
|
||||||
roster.createEntry(getBareJID(2), "gato12", new String[] { "Family" });
|
|
||||||
|
|
||||||
// Wait up to 2 seconds to receive new roster contacts
|
// Wait up to 2 seconds to receive new roster contacts
|
||||||
long initial = System.currentTimeMillis();
|
long initial = System.currentTimeMillis();
|
||||||
while (System.currentTimeMillis() - initial < 2000 && roster.getEntryCount() != 2) {
|
while (System.currentTimeMillis() - initial < 2000 && roster.getEntryCount() != 2) {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals("Wrong number of entries in connection 0", 2, roster.getEntryCount());
|
|
||||||
|
|
||||||
// Wait up to 2 seconds to receive presences of the new roster contacts
|
|
||||||
initial = System.currentTimeMillis();
|
|
||||||
while (System.currentTimeMillis() - initial < 5000 &&
|
|
||||||
(!roster.getPresence(getBareJID(1)).isAvailable() ||
|
|
||||||
!roster.getPresence(getBareJID(2)).isAvailable()))
|
|
||||||
{
|
|
||||||
Thread.sleep(100);
|
|
||||||
}
|
|
||||||
assertTrue("Presence not received", roster.getPresence(getBareJID(1)).isAvailable());
|
|
||||||
assertTrue("Presence not received", roster.getPresence(getBareJID(2)).isAvailable());
|
|
||||||
|
|
||||||
for (RosterEntry entry : roster.getEntries()) {
|
|
||||||
roster.removeEntry(entry);
|
|
||||||
Thread.sleep(250);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait up to 2 seconds to receive roster removal notifications
|
|
||||||
initial = System.currentTimeMillis();
|
|
||||||
while (System.currentTimeMillis() - initial < 2000 && roster.getEntryCount() != 0) {
|
|
||||||
Thread.sleep(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertEquals("Wrong number of entries in connection 0", 0, roster.getEntryCount());
|
|
||||||
assertEquals("Wrong number of groups in connection 0", 0, roster.getGroupCount());
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
"Wrong number of entries in connection 1",
|
|
||||||
0,
|
|
||||||
getConnection(1).getRoster().getEntryCount());
|
|
||||||
assertEquals(
|
|
||||||
"Wrong number of groups in connection 1",
|
|
||||||
0,
|
|
||||||
getConnection(1).getRoster().getGroupCount());
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
|
||||||
fail(e.getMessage());
|
assertEquals("Wrong number of entries in connection 0", 2, roster.getEntryCount());
|
||||||
|
|
||||||
|
// Wait up to 2 seconds to receive presences of the new roster contacts
|
||||||
|
initial = System.currentTimeMillis();
|
||||||
|
while (System.currentTimeMillis() - initial < 5000 &&
|
||||||
|
(!roster.getPresence(getBareJID(1)).isAvailable() ||
|
||||||
|
!roster.getPresence(getBareJID(2)).isAvailable()))
|
||||||
|
{
|
||||||
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
|
assertTrue("Presence not received", roster.getPresence(getBareJID(1)).isAvailable());
|
||||||
|
assertTrue("Presence not received", roster.getPresence(getBareJID(2)).isAvailable());
|
||||||
|
|
||||||
|
for (RosterEntry entry : roster.getEntries()) {
|
||||||
|
roster.removeEntry(entry);
|
||||||
|
Thread.sleep(250);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait up to 2 seconds to receive roster removal notifications
|
||||||
|
initial = System.currentTimeMillis();
|
||||||
|
while (System.currentTimeMillis() - initial < 2000 && roster.getEntryCount() != 0) {
|
||||||
|
Thread.sleep(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals("Wrong number of entries in connection 0", 0, roster.getEntryCount());
|
||||||
|
assertEquals("Wrong number of groups in connection 0", 0, roster.getGroupCount());
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
"Wrong number of entries in connection 1",
|
||||||
|
0,
|
||||||
|
getConnection(1).getRoster().getEntryCount());
|
||||||
|
assertEquals(
|
||||||
|
"Wrong number of groups in connection 1",
|
||||||
|
0,
|
||||||
|
getConnection(1).getRoster().getGroupCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -489,7 +484,9 @@ public class RosterTest extends SmackTestCase {
|
||||||
Presence presence;
|
Presence presence;
|
||||||
|
|
||||||
// Create another connection for the same user of connection 1
|
// Create another connection for the same user of connection 1
|
||||||
XMPPConnection conn4 = new XMPPConnection(getServiceName());
|
ConnectionConfiguration connectionConfiguration =
|
||||||
|
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||||
|
XMPPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||||
conn4.connect();
|
conn4.connect();
|
||||||
conn4.login(getUsername(1), getUsername(1), "Home");
|
conn4.login(getUsername(1), getUsername(1), "Home");
|
||||||
|
|
||||||
|
@ -560,7 +557,9 @@ public class RosterTest extends SmackTestCase {
|
||||||
*/
|
*/
|
||||||
public void testMultipleResources() throws Exception {
|
public void testMultipleResources() throws Exception {
|
||||||
// Create another connection for the same user of connection 1
|
// Create another connection for the same user of connection 1
|
||||||
XMPPConnection conn4 = new XMPPConnection(getServiceName());
|
ConnectionConfiguration connectionConfiguration =
|
||||||
|
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||||
|
XMPPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||||
conn4.connect();
|
conn4.connect();
|
||||||
conn4.login(getUsername(1), getUsername(1), "Home");
|
conn4.login(getUsername(1), getUsername(1), "Home");
|
||||||
|
|
||||||
|
@ -623,7 +622,9 @@ public class RosterTest extends SmackTestCase {
|
||||||
assertEquals("Created entry was never received", 1, roster.getEntryCount());
|
assertEquals("Created entry was never received", 1, roster.getEntryCount());
|
||||||
|
|
||||||
// Create another connection for the same user of connection 0
|
// Create another connection for the same user of connection 0
|
||||||
XMPPConnection conn2 = new XMPPConnection(getServiceName());
|
ConnectionConfiguration connectionConfiguration =
|
||||||
|
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||||
|
XMPPConnection conn2 = new XMPPConnection(connectionConfiguration);
|
||||||
conn2.connect();
|
conn2.connect();
|
||||||
conn2.login(getUsername(0), getUsername(0), "Home");
|
conn2.login(getUsername(0), getUsername(0), "Home");
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,11 @@
|
||||||
|
|
||||||
package org.jivesoftware.smackx;
|
package org.jivesoftware.smackx;
|
||||||
|
|
||||||
import org.jivesoftware.smack.ConnectionConfiguration;
|
import org.jivesoftware.smack.*;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.test.SmackTestCase;
|
import org.jivesoftware.smack.test.SmackTestCase;
|
||||||
|
import org.jivesoftware.smackx.packet.Version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure that stream compression (JEP-138) is correctly supported by Smack.
|
* Ensure that stream compression (JEP-138) is correctly supported by Smack.
|
||||||
|
@ -55,6 +56,24 @@ public class CompressionTest extends SmackTestCase {
|
||||||
|
|
||||||
assertTrue("Connection is not using stream compression", connection.isUsingCompression());
|
assertTrue("Connection is not using stream compression", connection.isUsingCompression());
|
||||||
|
|
||||||
|
// Request the version of the server
|
||||||
|
Version version = new Version();
|
||||||
|
version.setType(IQ.Type.GET);
|
||||||
|
version.setTo(getServiceName());
|
||||||
|
|
||||||
|
// Create a packet collector to listen for a response.
|
||||||
|
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(version.getPacketID()));
|
||||||
|
|
||||||
|
connection.sendPacket(version);
|
||||||
|
|
||||||
|
// Wait up to 5 seconds for a result.
|
||||||
|
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
||||||
|
// Close the collector
|
||||||
|
collector.cancel();
|
||||||
|
|
||||||
|
assertNotNull("No reply was received from the server", result);
|
||||||
|
assertEquals("Incorrect IQ type from server", IQ.Type.RESULT, result.getType());
|
||||||
|
|
||||||
// Close connection
|
// Close connection
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,7 +245,9 @@ public class MultiUserChatTest extends SmackTestCase {
|
||||||
public void testAnonymousParticipant() {
|
public void testAnonymousParticipant() {
|
||||||
try {
|
try {
|
||||||
// Anonymous user joins the new room
|
// Anonymous user joins the new room
|
||||||
XMPPConnection anonConnection = new XMPPConnection(getServiceName());
|
ConnectionConfiguration connectionConfiguration =
|
||||||
|
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||||
|
XMPPConnection anonConnection = new XMPPConnection(connectionConfiguration);
|
||||||
anonConnection.connect();
|
anonConnection.connect();
|
||||||
anonConnection.loginAnonymously();
|
anonConnection.loginAnonymously();
|
||||||
MultiUserChat muc2 = new MultiUserChat(anonConnection, room);
|
MultiUserChat muc2 = new MultiUserChat(anonConnection, room);
|
||||||
|
@ -1753,18 +1755,21 @@ public class MultiUserChatTest extends SmackTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testManyResources() {
|
public void testManyResources() throws Exception {
|
||||||
try {
|
// Create 5 more connections for user2
|
||||||
// Create 20 more connections for user2
|
XMPPConnection[] conns = new XMPPConnection[5];
|
||||||
XMPPConnection[] conns = new XMPPConnection[20];
|
|
||||||
for (int i = 0; i < conns.length; i++) {
|
for (int i = 0; i < conns.length; i++) {
|
||||||
conns[i] = new XMPPConnection(getServiceName());
|
ConnectionConfiguration connectionConfiguration =
|
||||||
|
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||||
|
connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
|
||||||
|
conns[i] = new XMPPConnection(connectionConfiguration);
|
||||||
conns[i].connect();
|
conns[i].connect();
|
||||||
conns[i].login(getUsername(1), getUsername(1), "resource-" + i);
|
conns[i].login(getUsername(1), getUsername(1), "resource-" + i);
|
||||||
|
Thread.sleep(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join the 20 connections to the same room
|
// Join the 5 connections to the same room
|
||||||
MultiUserChat[] mucs = new MultiUserChat[20];
|
MultiUserChat[] mucs = new MultiUserChat[5];
|
||||||
for (int i = 0; i < mucs.length; i++) {
|
for (int i = 0; i < mucs.length; i++) {
|
||||||
mucs[i] = new MultiUserChat(conns[i], room);
|
mucs[i] = new MultiUserChat(conns[i], room);
|
||||||
mucs[i].join("resource-" + i);
|
mucs[i].join("resource-" + i);
|
||||||
|
@ -1780,16 +1785,15 @@ public class MultiUserChatTest extends SmackTestCase {
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
|
|
||||||
// Each connection leaves the room and closes the connection
|
// Each connection leaves the room and closes the connection
|
||||||
for (int i = 0; i < mucs.length; i++) {
|
for (MultiUserChat muc1 : mucs) {
|
||||||
mucs[i].leave();
|
muc1.leave();
|
||||||
conns[i].disconnect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
Thread.sleep(200);
|
||||||
e.printStackTrace();
|
|
||||||
fail(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for (int i = 0; i < mucs.length; i++) {
|
||||||
|
conns[i].disconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue