1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-12 10:39:38 +02:00

Phase 1 of large refactoring. Removing dead code, bug fixes, updates to JDK 1.5.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@4511 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2006-07-17 08:39:08 +00:00 committed by matt
parent 1a08715f67
commit bbbfe09c31
62 changed files with 291 additions and 3524 deletions

View file

@ -3,11 +3,11 @@
<testcase>
<!-- Host and port of the XMPP server to use -->
<host>localhost</host>
<host>zeushome2</host>
<port>5222</port>
<!-- Chat and MUC domain names to use -->
<chat>chat.localhost</chat>
<muc>conference.localhost</muc>
<chat>chat</chat>
<muc>conference</muc>
</testcase>

View file

@ -42,7 +42,7 @@ public class MessageTest extends SmackTestCase {
*/
public void testOfflineMessage() {
// Make user2 unavailable
getConnection(1).sendPacket(new Presence(Presence.Type.UNAVAILABLE));
getConnection(1).sendPacket(new Presence(Presence.Type.unavailable));
try {
Thread.sleep(500);
@ -56,7 +56,7 @@ public class MessageTest extends SmackTestCase {
// User2 becomes available again
PacketCollector collector = getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.CHAT));
getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE));
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(2500);

View file

@ -37,10 +37,10 @@ public class PresencePriorityTest extends SmackTestCase {
conn = new XMPPConnection(getHost(), getPort());
conn.login(getUsername(1), getUsername(1), "OtherPlace");
// Change the presence priorities of User_1
getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE, null, 1,
Presence.Mode.AVAILABLE));
conn.sendPacket(new Presence(Presence.Type.AVAILABLE, null, 2,
Presence.Mode.AVAILABLE));
getConnection(1).sendPacket(new Presence(Presence.Type.available, null, 1,
Presence.Mode.available));
conn.sendPacket(new Presence(Presence.Type.available, null, 2,
Presence.Mode.available));
Thread.sleep(150);
// Create the chats between the participants
Chat chat0 = new Chat(getConnection(0), getBareJID(1));
@ -55,10 +55,10 @@ public class PresencePriorityTest extends SmackTestCase {
chat1.nextMessage(1000));
// Invert the presence priorities of User_1
getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE, null, 2,
Presence.Mode.AVAILABLE));
conn.sendPacket(new Presence(Presence.Type.AVAILABLE, null, 1,
Presence.Mode.AVAILABLE));
getConnection(1).sendPacket(new Presence(Presence.Type.available, null, 2,
Presence.Mode.available));
conn.sendPacket(new Presence(Presence.Type.available, null, 1,
Presence.Mode.available));
Thread.sleep(150);
// Test delivery of message to the presence with highest priority
@ -78,14 +78,14 @@ public class PresencePriorityTest extends SmackTestCase {
assertNotNull("Resource with highest priority didn't receive the message",
chat1.nextMessage(2000));
getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE, null, 2,
Presence.Mode.AVAILABLE));
getConnection(1).sendPacket(new Presence(Presence.Type.available, null, 2,
Presence.Mode.available));
// User_1 will log in again using another resource
conn = new XMPPConnection(getHost(), getPort());
conn.login(getUsername(1), getUsername(1), "OtherPlace");
conn.sendPacket(new Presence(Presence.Type.AVAILABLE, null, 1,
Presence.Mode.AVAILABLE));
conn.sendPacket(new Presence(Presence.Type.available, null, 1,
Presence.Mode.available));
chat2 = new Chat(conn, getBareJID(0), chat0.getThreadID());
Thread.sleep(150);
@ -97,10 +97,10 @@ public class PresencePriorityTest extends SmackTestCase {
chat2.nextMessage(1000));
// Invert the presence priorities of User_1
getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE, null, 1,
Presence.Mode.AVAILABLE));
conn.sendPacket(new Presence(Presence.Type.AVAILABLE, null, 2,
Presence.Mode.AVAILABLE));
getConnection(1).sendPacket(new Presence(Presence.Type.available, null, 1,
Presence.Mode.available));
conn.sendPacket(new Presence(Presence.Type.available, null, 2,
Presence.Mode.available));
Thread.sleep(150);
// Test delivery of message to the presence with highest priority

View file

@ -58,6 +58,7 @@ import org.jivesoftware.smack.util.StringUtils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Tests the Roster functionality by creating and removing roster entries.
@ -91,12 +92,8 @@ public class RosterTest extends SmackTestCase {
Thread.sleep(50);
}
Iterator it = roster.getEntries();
while (it.hasNext()) {
RosterEntry entry = (RosterEntry) it.next();
Iterator groups = entry.getGroups();
while (groups.hasNext()) {
RosterGroup rosterGroup = (RosterGroup) groups.next();
for (RosterEntry entry : roster.getEntries()) {
for (RosterGroup rosterGroup : entry.getGroups()) {
rosterGroup.removeEntry(entry);
}
}
@ -172,9 +169,7 @@ public class RosterTest extends SmackTestCase {
assertNotNull("Presence not received", roster.getPresence(getBareJID(1)));
assertNotNull("Presence not received", roster.getPresence(getBareJID(2)));
Iterator it = roster.getEntries();
while (it.hasNext()) {
RosterEntry entry = (RosterEntry) it.next();
for (RosterEntry entry : roster.getEntries()) {
roster.removeEntry(entry);
Thread.sleep(250);
}
@ -216,9 +211,7 @@ public class RosterTest extends SmackTestCase {
Thread.sleep(200);
Iterator it = roster.getEntries();
while (it.hasNext()) {
RosterEntry entry = (RosterEntry) it.next();
for (RosterEntry entry : roster.getEntries()) {
roster.removeEntry(entry);
Thread.sleep(250);
}
@ -256,18 +249,14 @@ public class RosterTest extends SmackTestCase {
Thread.sleep(200);
// Change the roster entry name and check if the change was made
Iterator it = roster.getEntries();
while (it.hasNext()) {
RosterEntry entry = (RosterEntry) it.next();
for (RosterEntry entry : roster.getEntries()) {
entry.setName("gato11");
assertEquals("gato11", entry.getName());
}
// Reload the roster and check the name again
roster.reload();
Thread.sleep(2000);
it = roster.getEntries();
while (it.hasNext()) {
RosterEntry entry = (RosterEntry) it.next();
for (RosterEntry entry : roster.getEntries()) {
assertEquals("gato11", entry.getName());
}
@ -302,10 +291,8 @@ public class RosterTest extends SmackTestCase {
}
//assertNotNull("Presence not received", roster.getPresence(getBareJID(0)));
Iterator it = roster.getEntries();
while (it.hasNext()) {
RosterEntry entry = (RosterEntry) it.next();
assertFalse("The roster entry belongs to a group", entry.getGroups().hasNext());
for (RosterEntry entry : roster.getEntries()) {
assertFalse("The roster entry belongs to a group", !entry.getGroups().isEmpty());
}
// Change the roster entry name and check if the change was made
@ -313,12 +300,9 @@ public class RosterTest extends SmackTestCase {
// Reload the roster and check the name again
Thread.sleep(200);
it = roster.getEntries();
while (it.hasNext()) {
RosterEntry entry = (RosterEntry) it.next();
for (RosterEntry entry : roster.getEntries()) {
assertEquals("Name of roster entry is wrong", "NewName", entry.getName());
assertTrue("The roster entry does not belong to any group", entry.getGroups()
.hasNext());
assertTrue("The roster entry does not belong to any group", !entry.getGroups().isEmpty());
}
// Wait up to 5 seconds to receive presences of the new roster contacts
initial = System.currentTimeMillis();
@ -372,12 +356,12 @@ public class RosterTest extends SmackTestCase {
RosterEntry entry = roster2.getEntry(getBareJID(1));
assertNotNull("No entry for user 1 was found", entry);
ArrayList groups = new ArrayList();
Iterator groupsItr = entry.getGroups();
groups.add(((RosterGroup)groupsItr.next()).getName());
groups.add(((RosterGroup)groupsItr.next()).getName());
assertTrue("Friends group was not found", groups.contains("Friends"));
assertTrue("NewGroup group was not found", groups.contains("NewGroup"));
List<String> groupNames = new ArrayList<String>();
for (RosterGroup rosterGroup : entry.getGroups()) {
groupNames.add(rosterGroup.getName());
}
assertTrue("Friends group was not found", groupNames.contains("Friends"));
assertTrue("NewGroup group was not found", groupNames.contains("NewGroup"));
// Close the new connection
con2.close();
@ -584,12 +568,11 @@ public class RosterTest extends SmackTestCase {
private void cleanUpRoster() {
for (int i=0; i<getMaxConnections(); i++) {
// Delete all the entries from the roster
Iterator it = getConnection(i).getRoster().getEntries();
while (it.hasNext()) {
RosterEntry entry = (RosterEntry) it.next();
for (RosterEntry entry : getConnection(i).getRoster().getEntries()) {
try {
getConnection(i).getRoster().removeEntry(entry);
} catch (XMPPException e) {
}
catch (XMPPException e) {
e.printStackTrace();
fail(e.getMessage());
}

View file

@ -55,8 +55,8 @@ public abstract class SmackTestCase extends TestCase {
private String serviceName = "localhost";
private int port = 5222;
private String chatDomain = "chat.localhost";
private String mucDomain = "conference.localhost";
private String chatDomain = "chat";
private String mucDomain = "conference";
private XMPPConnection[] connections = null;
@ -172,7 +172,7 @@ public abstract class SmackTestCase extends TestCase {
* @return the default MUC service domain.
*/
protected String getMUCDomain() {
return mucDomain;
return mucDomain + "." + serviceName;
}
protected void setUp() throws Exception {

View file

@ -58,7 +58,7 @@ public class OfflineMessageManagerTest extends SmackTestCase {
*/
public void testReadAndDelete() {
// Make user2 unavailable
getConnection(1).sendPacket(new Presence(Presence.Type.UNAVAILABLE));
getConnection(1).sendPacket(new Presence(Presence.Type.unavailable));
try {
Thread.sleep(500);
@ -103,7 +103,7 @@ public class OfflineMessageManagerTest extends SmackTestCase {
// User2 becomes available again
PacketCollector collector = getConnection(1).createPacketCollector(
new MessageTypeFilter(Message.Type.CHAT));
getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE));
getConnection(1).sendPacket(new Presence(Presence.Type.available));
// Check that no offline messages was sent to the user
Message message = (Message) collector.nextResult(2500);
@ -127,7 +127,7 @@ public class OfflineMessageManagerTest extends SmackTestCase {
*/
public void testFetchAndPurge() {
// Make user2 unavailable
getConnection(1).sendPacket(new Presence(Presence.Type.UNAVAILABLE));
getConnection(1).sendPacket(new Presence(Presence.Type.unavailable));
try {
Thread.sleep(500);
@ -161,7 +161,7 @@ public class OfflineMessageManagerTest extends SmackTestCase {
// User2 becomes available again
PacketCollector collector = getConnection(1).createPacketCollector(
new MessageTypeFilter(Message.Type.CHAT));
getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE));
getConnection(1).sendPacket(new Presence(Presence.Type.available));
// Check that no offline messages was sent to the user
Message message = (Message) collector.nextResult(2500);

View file

@ -104,10 +104,10 @@ public class RosterExchangeManagerTest extends SmackTestCase {
public void testSendRosterGroup() {
// Send user1's RosterGroups to user2
try {
RosterExchangeManager rosterExchangeManager =
new RosterExchangeManager(getConnection(0));
for (Iterator it = getConnection(0).getRoster().getGroups(); it.hasNext();)
rosterExchangeManager.send((RosterGroup) it.next(), getBareJID(1));
RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(getConnection(0));
for (RosterGroup rosterGroup : getConnection(0).getRoster().getGroups()) {
rosterExchangeManager.send(rosterGroup, getBareJID(1));
}
}
catch (Exception e) {
e.printStackTrace();

View file

@ -91,7 +91,9 @@ public class MultiUserChatTest extends SmackTestCase {
* protocol.
*/
public void testGroupchatCompatibility() {
try {
// TODO: this test needs to be re-written so that it manually emulates the old-style
// TODO: group chat protocol. Tne GroupChat class was deleted for Smack 3.0.
/*try {
Message message;
GroupChat groupchat = new GroupChat(getConnection(1), room);
@ -103,7 +105,7 @@ public class MultiUserChatTest extends SmackTestCase {
assertNotNull("Presence of user2 in room is missing", presence);
assertEquals(
"Presence mode of user2 is wrong",
Presence.Mode.AVAILABLE,
Presence.Mode.available,
presence.getMode());
// User using old client send a message
@ -126,7 +128,7 @@ public class MultiUserChatTest extends SmackTestCase {
catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}*/
}
public void testDiscussionHistory() {
@ -202,16 +204,16 @@ public class MultiUserChatTest extends SmackTestCase {
assertNotNull("Presence of user2 in room is missing", presence);
assertEquals(
"Presence mode of user2 is wrong",
Presence.Mode.AVAILABLE,
Presence.Mode.available,
presence.getMode());
// User2 changes his availability to AWAY
muc2.changeAvailabilityStatus("Gone to have lunch", Presence.Mode.AWAY);
muc2.changeAvailabilityStatus("Gone to have lunch", Presence.Mode.away);
Thread.sleep(200);
// User1 checks the presence of user2 in the room
presence = muc.getOccupantPresence(room + "/testbot2");
assertNotNull("Presence of user2 in room is missing", presence);
assertEquals("Presence mode of user2 is wrong", Presence.Mode.AWAY, presence.getMode());
assertEquals("Presence mode of user2 is wrong", Presence.Mode.away, presence.getMode());
assertEquals(
"Presence status of user2 is wrong",
"Gone to have lunch",
@ -258,7 +260,7 @@ public class MultiUserChatTest extends SmackTestCase {
assertNotNull("Presence of user2 in room is missing", presence);
assertEquals(
"Presence mode of user2 is wrong",
Presence.Mode.AVAILABLE,
Presence.Mode.available,
presence.getMode());
// Anonymous user leaves the room