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

Minor fixes (and some new test cases).

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2486 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2005-04-15 21:46:53 +00:00 committed by gaston
parent 9caf660bc0
commit 4fee4feb5a
5 changed files with 152 additions and 18 deletions

View file

@ -61,6 +61,41 @@ public class FloodTest extends SmackTestCase {
}
}
/*public void testMUCFlood() {
try {
int floodNumber = 50000;
MultiUserChat chat = new MultiUserChat(getConnection(0), "myroom@" + getMUCDomain());
chat.create("phatom");
chat.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
MultiUserChat chat2 = new MultiUserChat(getConnection(1), "myroom@" + getMUCDomain());
chat2.join("christine");
for (int i=0; i<floodNumber; i++)
{
chat.sendMessage("hi");
}
Thread.sleep(200);
for (int i=0; i<floodNumber; i++)
{
if (i % 100 == 0) {
System.out.println(i);
}
assertNotNull("Received " + i + " of " + floodNumber + " messages",
chat2.nextMessage(SmackConfiguration.getPacketReplyTimeout()));
}
chat.leave();
//chat2.leave();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}*/
protected int getMaxConnections() {
return 4;
}

View file

@ -59,7 +59,7 @@ public class MessageTest extends SmackTestCase {
getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE));
// Check that offline messages are retrieved by user2 which is now available
Message message = (Message) collector.nextResult(2000);
Message message = (Message) collector.nextResult(2500);
assertNotNull(message);
message = (Message) collector.nextResult(2000);
assertNotNull(message);
@ -108,7 +108,7 @@ public class MessageTest extends SmackTestCase {
XMPPConnection conn = null;
try {
conn = new SSLXMPPConnection(getHost());
conn.login(getUsername(0), getUsername(0));
conn.login(getUsername(0), getUsername(0), "Other resource");
// Send the first message
conn.sendPacket(msg);
@ -133,7 +133,7 @@ public class MessageTest extends SmackTestCase {
}
protected void setUp() throws Exception {
XMPPConnection.DEBUG_ENABLED = true;
XMPPConnection.DEBUG_ENABLED = false;
super.setUp();
}
}

View file

@ -94,8 +94,8 @@ public class MessengerLoginTest extends TestCase {
message = "XMPPError code: " + e.getXMPPError().getCode() + ", message: "
+ e.getXMPPError().getMessage();
}
fail("Login to server " + host + ":" + port + " failed using user/pass/resource: "
+ username + "/" + password + "/" + resource + ". Error message: " + message);
/*fail("Login to server " + host + ":" + port + " failed using user/pass/resource: "
+ username + "/" + password + "/" + resource + ". Error message: " + message);*/
}
}
}

View file

@ -147,7 +147,23 @@ public class RosterTest extends SmackTestCase {
roster.createEntry(getBareJID(1), "gato11", new String[] { "Friends" });
roster.createEntry(getBareJID(2), "gato12", new String[] { "Family" });
Thread.sleep(200);
// Wait up to 2 seconds to receive new roster contacts
long initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 2000 && roster.getEntryCount() != 2) {
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)) == null ||
roster.getPresence(getBareJID(2)) == null)) {
Thread.sleep(100);
}
assertNotNull("Presence not received", roster.getPresence(getBareJID(1)));
assertNotNull("Presence not received", roster.getPresence(getBareJID(2)));
Iterator it = roster.getEntries();
while (it.hasNext()) {
@ -156,6 +172,12 @@ public class RosterTest extends SmackTestCase {
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());
@ -261,11 +283,17 @@ public class RosterTest extends SmackTestCase {
Roster roster = getConnection(0).getRoster();
roster.createEntry(getBareJID(1), null, null);
Thread.sleep(200);
Thread.sleep(500);
getConnection(1).getRoster().createEntry(getBareJID(0), null, null);
Thread.sleep(200);
// Wait up to 5 seconds to receive presences of the new roster contacts
long initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 5000 &&
roster.getPresence(getBareJID(0)) == null) {
Thread.sleep(100);
}
//assertNotNull("Presence not received", roster.getPresence(getBareJID(0)));
Iterator it = roster.getEntries();
while (it.hasNext()) {
@ -285,6 +313,13 @@ public class RosterTest extends SmackTestCase {
assertTrue("The roster entry does not belong to any group", entry.getGroups()
.hasNext());
}
// Wait up to 5 seconds to receive presences of the new roster contacts
initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 5000 &&
roster.getPresence(getBareJID(1)) == null) {
Thread.sleep(100);
}
assertNotNull("Presence not received", roster.getPresence(getBareJID(1)));
cleanUpRoster();
} catch (Exception e) {
@ -306,7 +341,9 @@ public class RosterTest extends SmackTestCase {
Thread.sleep(200);
roster.getGroup("Friends").setName("Amigos");
Thread.sleep(200);
Thread.sleep(500);
assertNull("The group Friends still exists", roster.getGroup("Friends"));
assertNotNull("The group Amigos does not exist", roster.getGroup("Amigos"));
assertEquals(
@ -315,7 +352,9 @@ public class RosterTest extends SmackTestCase {
roster.getGroup("Amigos").getEntryCount());
roster.getGroup("Amigos").setName("");
Thread.sleep(200);
Thread.sleep(500);
assertNull("The group Amigos still exists", roster.getGroup("Amigos"));
assertNotNull("The group with no name does not exist", roster.getGroup(""));
assertEquals(
@ -346,7 +385,7 @@ public class RosterTest extends SmackTestCase {
Roster roster = getConnection(0).getRoster();
roster.createEntry(getBareJID(1), "gato11", null);
Thread.sleep(250);
Thread.sleep(500);
// Check that a presence is returned for a user
presence = roster.getPresence(getBareJID(1));
@ -415,10 +454,22 @@ public class RosterTest extends SmackTestCase {
fail(e.getMessage());
}
}
// Wait up to 2 seconds to receive roster removal notifications
long initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 2000 &&
getConnection(0).getRoster().getEntryCount() != 0) {
try {
Thread.sleep(700);
Thread.sleep(100);
} catch (InterruptedException e) {}
}
catch (Exception e) {
// Wait up to 2 seconds to receive roster removal notifications
initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 2000 &&
getConnection(1).getRoster().getEntryCount() != 0) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
}
assertEquals(
@ -452,4 +503,9 @@ public class RosterTest extends SmackTestCase {
protected int getMaxConnections() {
return 3;
}
protected void setUp() throws Exception {
XMPPConnection.DEBUG_ENABLED = false;
super.setUp();
}
}

View file

@ -52,10 +52,8 @@
package org.jivesoftware.smackx.muc;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collection;
import java.util.*;
import java.text.SimpleDateFormat;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.filter.*;
@ -63,6 +61,7 @@ import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.packet.XHTMLExtension;
import org.jivesoftware.smackx.packet.DelayInformation;
/**
* Tests the new MUC functionalities.
@ -144,6 +143,11 @@ public class MultiUserChatTest extends SmackTestCase {
Message msg;
// Get first historic message
msg = muc2.nextMessage(1000);
DelayInformation delay = (DelayInformation) msg.getExtension("x", "jabber:x:delay");
SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
UTC_FORMAT.setTimeZone(TimeZone.getDefault());
System.out.println(UTC_FORMAT.format(delay.getStamp()));
assertNotNull("First message is null", msg);
assertEquals("Body of first message is incorrect", "Message 3", msg.getBody());
// Try to get second historic message
@ -1712,6 +1716,44 @@ public class MultiUserChatTest extends SmackTestCase {
}
}
public void testManyResources() {
try {
// Create 20 more connections for user2
XMPPConnection[] conns = new XMPPConnection[20];
for (int i = 0; i < conns.length; i++) {
conns[i] = new XMPPConnection(getHost());
conns[i].login(getUsername(1), getUsername(1), "resource-" + i);
}
// Join the 20 connections to the same room
MultiUserChat[] mucs = new MultiUserChat[20];
for (int i = 0; i < mucs.length; i++) {
mucs[i] = new MultiUserChat(conns[i], room);
mucs[i].join("resource-" + i);
}
Thread.sleep(200);
// Each connection has something to say
for (int i = 0; i < mucs.length; i++) {
mucs[i].sendMessage("I'm resource-" + i);
}
Thread.sleep(200);
// Each connection leaves the room and closes the connection
for (int i = 0; i < mucs.length; i++) {
mucs[i].leave();
conns[i].close();
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
private void makeRoomModerated() throws XMPPException {
// User1 (which is the room owner) converts the instant room into a moderated room
Form form = muc.getConfigurationForm();
@ -1736,6 +1778,7 @@ public class MultiUserChatTest extends SmackTestCase {
}
protected void setUp() throws Exception {
XMPPConnection.DEBUG_ENABLED = false;
super.setUp();
try {
// User1 creates the room