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

1. Clean up code

2. Refactoring work
3. Optimization work. SMACK-153
4. Fixed roster test cases. SMACK-154
4. Fixed vCard issue. SMACK-152

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@4538 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2006-07-18 05:14:33 +00:00 committed by gato
parent 14b50d790a
commit f57ff10ad9
77 changed files with 995 additions and 932 deletions

View file

@ -20,12 +20,12 @@
package org.jivesoftware.smack;
import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.test.SmackTestCase;
/**
* Ensure that the server is handling IQ packets correctly.
@ -45,7 +45,7 @@ public class IQTest extends SmackTestCase {
public void testInvalidNamespace() {
IQ iq = new IQ() {
public String getChildElementXML() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"jabber:iq:anything\">");
buf.append("</query>");
return buf.toString();

View file

@ -20,10 +20,10 @@
package org.jivesoftware.smack;
import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.test.SmackTestCase;
/**
* Tests sending messages to other clients.
@ -82,7 +82,7 @@ public class MessageTest extends SmackTestCase {
// Create message with a body of 4K characters
Message msg = new Message(getFullJID(1), Message.Type.CHAT);
StringBuffer sb = new StringBuffer(5000);
StringBuilder sb = new StringBuilder(5000);
for (int i=0; i<=4000; i++) {
sb.append("X");
}

View file

@ -89,8 +89,10 @@ public class RosterTest extends SmackTestCase {
// Wait until the server confirms the new entries
long initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 2000 && roster.getEntryCount() != 2) {
Thread.sleep(50);
while (System.currentTimeMillis() - initial < 2000 && (
roster.getPresence(getBareJID(1)) == null ||
roster.getPresence(getBareJID(2)) == null)) {
Thread.sleep(100);
}
for (RosterEntry entry : roster.getEntries()) {
@ -210,11 +212,25 @@ public class RosterTest extends SmackTestCase {
roster.createEntry(getBareJID(1), "gato11", null);
roster.createEntry(getBareJID(2), "gato12", null);
// Wait up to 2 seconds to let the server process presence subscriptions
long initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 2000 && (
roster.getPresence(getBareJID(1)) == null ||
roster.getPresence(getBareJID(2)) == null)) {
Thread.sleep(100);
}
Thread.sleep(200);
for (RosterEntry entry : roster.getEntries()) {
roster.removeEntry(entry);
Thread.sleep(250);
Thread.sleep(100);
}
// 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());
@ -247,7 +263,12 @@ public class RosterTest extends SmackTestCase {
Roster roster = getConnection(0).getRoster();
roster.createEntry(getBareJID(1), null, null);
Thread.sleep(200);
// Wait up to 2 seconds to let the server process presence subscriptions
long initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 2000 &&
roster.getPresence(getBareJID(1)) == null) {
Thread.sleep(100);
}
// Change the roster entry name and check if the change was made
for (RosterEntry entry : roster.getEntries()) {
@ -388,12 +409,18 @@ public class RosterTest extends SmackTestCase {
roster.createEntry(getBareJID(1), "gato11", new String[] { "Friends" });
roster.createEntry(getBareJID(2), "gato12", new String[] { "Friends" });
Thread.sleep(200);
// Wait up to 2 seconds to let the server process presence subscriptions
long initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 2000 && (
roster.getPresence(getBareJID(1)) == null ||
roster.getPresence(getBareJID(2)) == null)) {
Thread.sleep(100);
}
roster.getGroup("Friends").setName("Amigos");
// Wait up to 2 seconds
long initial = System.currentTimeMillis();
initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 2000 &&
(roster.getGroup("Friends") != null)) {
Thread.sleep(100);
@ -440,77 +467,71 @@ public class RosterTest extends SmackTestCase {
/**
* Test presence management.
*/
public void testRosterPresences() {
try {
Thread.sleep(200);
public void testRosterPresences() throws Exception {
Thread.sleep(200);
Presence presence;
Presence presence;
// Create another connection for the same user of connection 1
XMPPConnection conn4 = new XMPPConnection(getServiceName());
conn4.login(getUsername(1), getUsername(1), "Home");
// Create another connection for the same user of connection 1
XMPPConnection conn4 = new XMPPConnection(getServiceName());
conn4.login(getUsername(1), getUsername(1), "Home");
// Add a new roster entry
Roster roster = getConnection(0).getRoster();
roster.createEntry(getBareJID(1), "gato11", null);
// Wait up to 2 seconds
long initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 2000 &&
(roster.getPresence(getBareJID(1)) == null)) {
Thread.sleep(100);
}
// Check that a presence is returned for a user
presence = roster.getPresence(getBareJID(1));
assertNotNull("Returned a null Presence for an existing user", presence);
// Check that the right presence is returned for a user+resource
presence = roster.getPresenceResource(getUsername(1) + "@" + conn4.getServiceName() + "/Home");
assertEquals(
"Returned the wrong Presence",
StringUtils.parseResource(presence.getFrom()),
"Home");
// Check that the right presence is returned for a user+resource
presence = roster.getPresenceResource(getFullJID(1));
assertEquals(
"Returned the wrong Presence",
StringUtils.parseResource(presence.getFrom()),
"Smack");
// Check that the no presence is returned for a non-existent user+resource
presence = roster.getPresenceResource("noname@" + getServiceName() + "/Smack");
assertNull("Returned a Presence for a non-existing user", presence);
// Check that the returned presences are correct
Iterator presences = roster.getPresences(getBareJID(1));
int count = 0;
while (presences.hasNext()) {
count++;
presences.next();
}
assertEquals("Wrong number of returned presences", count, 2);
// Close the connection so one presence must go
conn4.close();
// Check that the returned presences are correct
presences = roster.getPresences(getBareJID(1));
count = 0;
while (presences.hasNext()) {
count++;
presences.next();
}
assertEquals("Wrong number of returned presences", count, 1);
Thread.sleep(200);
cleanUpRoster();
// Add a new roster entry
Roster roster = getConnection(0).getRoster();
roster.createEntry(getBareJID(1), "gato11", null);
// Wait up to 2 seconds
long initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 2000 &&
(roster.getPresence(getBareJID(1)) == null)) {
Thread.sleep(100);
}
catch (Exception e) {
fail(e.getMessage());
// Check that a presence is returned for a user
presence = roster.getPresence(getBareJID(1));
assertNotNull("Returned a null Presence for an existing user", presence);
// Check that the right presence is returned for a user+resource
presence = roster.getPresenceResource(getUsername(1) + "@" + conn4.getServiceName() + "/Home");
assertEquals(
"Returned the wrong Presence",
StringUtils.parseResource(presence.getFrom()),
"Home");
// Check that the right presence is returned for a user+resource
presence = roster.getPresenceResource(getFullJID(1));
assertEquals(
"Returned the wrong Presence",
StringUtils.parseResource(presence.getFrom()),
"Smack");
// Check that the no presence is returned for a non-existent user+resource
presence = roster.getPresenceResource("noname@" + getServiceName() + "/Smack");
assertNull("Returned a Presence for a non-existing user", presence);
// Check that the returned presences are correct
Iterator presences = roster.getPresences(getBareJID(1));
int count = 0;
while (presences.hasNext()) {
count++;
presences.next();
}
assertEquals("Wrong number of returned presences", count, 2);
// Close the connection so one presence must go
conn4.close();
// Check that the returned presences are correct
presences = roster.getPresences(getBareJID(1));
count = 0;
while (presences.hasNext()) {
count++;
presences.next();
}
assertEquals("Wrong number of returned presences", count, 1);
Thread.sleep(200);
cleanUpRoster();
}
/**
@ -586,34 +607,17 @@ public class RosterTest extends SmackTestCase {
fail(e.getMessage());
}
}
// Wait up to 2 seconds to receive roster removal notifications
// Wait up to 6 seconds to receive roster removal notifications
long initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 2000 &&
getConnection(0).getRoster().getEntryCount() != 0) {
while (System.currentTimeMillis() - initial < 6000 && (
getConnection(0).getRoster().getEntryCount() != 0 ||
getConnection(1).getRoster().getEntryCount() != 0 ||
getConnection(2).getRoster().getEntryCount() != 0)) {
try {
Thread.sleep(100);
} catch (InterruptedException 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) {}
}
// Wait up to 2 seconds to receive roster removal notifications
initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 2000 &&
getConnection(2).getRoster().getEntryCount() != 0) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {}
}
assertEquals(
"Wrong number of entries in connection 0",
0,

View file

@ -51,11 +51,14 @@
*/
package org.jivesoftware.smackx.muc;
import java.util.*;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smackx.*;
import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.FormField;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Tests creating new MUC rooms.
@ -90,15 +93,15 @@ public class MultiUserChatCreationTest extends SmackTestCase {
// Create a new form to submit based on the original form
Form submitForm = form.createAnswerForm();
// Add default answers to the form to submit
for (Iterator fields = form.getFields(); fields.hasNext();) {
FormField field = (FormField) fields.next();
for (Iterator<FormField> fields = form.getFields(); fields.hasNext();) {
FormField field = fields.next();
if (!FormField.TYPE_HIDDEN.equals(field.getType())
&& field.getVariable() != null) {
// Sets the default value as the answer
submitForm.setDefaultAnswer(field.getVariable());
}
}
List owners = new ArrayList();
List<String> owners = new ArrayList<String>();
owners.add(getBareJID(0));
submitForm.setAnswer("muc#roomconfig_roomowners", owners);