1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-06-30 15:26:46 +02:00

Test should now be correct again.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2134 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2003-10-05 15:23:18 +00:00 committed by mtucker
parent 33859481d2
commit 740a27e500

View file

@ -62,7 +62,7 @@ import junit.framework.TestCase;
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class RosterTest extends TestCase { public class RosterTest extends TestCase {
private XMPPConnection conn1 = null; private XMPPConnection conn1 = null;
private XMPPConnection conn2 = null; private XMPPConnection conn2 = null;
private XMPPConnection conn3 = null; private XMPPConnection conn3 = null;
@ -76,19 +76,17 @@ public class RosterTest extends TestCase {
} }
/** /**
* 1. Create entries in roster groups * 1. Create entries in roster groups
* 2. Iterate on the groups and remove the entry from each group * 2. Iterate on the groups and remove the entry from each group
* 3. Check that the entries are kept as unfiled entries * 3. Check that the entries are kept as unfiled entries
*/ */
public void testDeleteAllRosterGroupEntries() { public void testDeleteAllRosterGroupEntries() {
try { try {
// Add a new roster entry // Add a new roster entry
conn1.getRoster().createEntry("gato11@localhost", "gato11", conn1.getRoster().createEntry("gato11@" + conn1.getHost(), "gato11", new String[] {"Friends", "Family"});
new String[] {"Friends", "Family"}); conn1.getRoster().createEntry("gato12@" + conn1.getHost(), "gato12", new String[] {"Family"});
conn1.getRoster().createEntry("gato12@localhost", "gato12",
new String[] {"Family"});
Thread.sleep(100); Thread.sleep(200);
Iterator it = conn1.getRoster().getEntries(); Iterator it = conn1.getRoster().getEntries();
while (it.hasNext()) { while (it.hasNext()) {
@ -97,61 +95,51 @@ public class RosterTest extends TestCase {
while (groups.hasNext()) { while (groups.hasNext()) {
RosterGroup rosterGroup = (RosterGroup) groups.next(); RosterGroup rosterGroup = (RosterGroup) groups.next();
rosterGroup.removeEntry(entry); rosterGroup.removeEntry(entry);
Thread.sleep(100); Thread.sleep(250);
} }
} }
assertEquals("The number of entries in conn1 should be 2", 2, assertEquals("The number of entries in conn1 should be 2", 2, conn1.getRoster().getEntryCount());
conn1.getRoster().getEntryCount()); assertEquals("The number of groups in conn1 should be 0", 0, conn1.getRoster().getGroupCount());
assertEquals("The number of groups in conn1 should be 0", 0,
conn1.getRoster().getGroupCount());
assertEquals("The number of entries in conn2 should be 0", 0, assertEquals("The number of entries in conn2 should be 1", 1, conn2.getRoster().getEntryCount());
conn2.getRoster().getEntryCount()); assertEquals("The number of groups in conn2 should be 0", 0, conn2.getRoster().getGroupCount());
assertEquals("The number of groups in conn2 should be 0", 0,
conn2.getRoster().getGroupCount()); assertEquals("The number of entries in conn3 should be 1", 1, conn3.getRoster().getEntryCount());
assertEquals("The number of groups in conn3 should be 0", 0, conn3.getRoster().getGroupCount());
assertEquals("The number of entries in conn3 should be 0", 0,
conn3.getRoster().getEntryCount());
assertEquals("The number of groups in conn3 should be 0", 0,
conn3.getRoster().getGroupCount());
cleanUpRoster(); cleanUpRoster();
} }
catch (Exception e) { catch (Exception e) {
fail(e.getMessage()); fail(e.getMessage());
} }
} }
/** /**
* 1. Create entries in roster groups * 1. Create entries in roster groups
* 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() {
try { try {
// Add a new roster entry // Add a new roster entry
conn1.getRoster().createEntry("gato11@localhost", "gato11", new String[] {"Friends"}); conn1.getRoster().createEntry("gato11@" + conn1.getHost(), "gato11", new String[] {"Friends"});
conn1.getRoster().createEntry("gato12@localhost", "gato12", new String[] {"Family"}); conn1.getRoster().createEntry("gato12@" + conn1.getHost(), "gato12", new String[] {"Family"});
Thread.sleep(100); Thread.sleep(200);
Iterator it = conn1.getRoster().getEntries(); Iterator it = conn1.getRoster().getEntries();
while (it.hasNext()) { while (it.hasNext()) {
RosterEntry entry = (RosterEntry) it.next(); RosterEntry entry = (RosterEntry) it.next();
conn1.getRoster().removeEntry(entry); conn1.getRoster().removeEntry(entry);
Thread.sleep(250);
} }
Thread.sleep(100);
assertEquals("The number of entries in conn1 should be 0", 0, assertEquals("The number of entries in conn1 should be 0", 0, conn1.getRoster().getEntryCount());
conn1.getRoster().getEntryCount()); assertEquals("The number of groups in conn1 should be 0", 0, conn1.getRoster().getGroupCount());
assertEquals("The number of groups in conn1 should be 0", 0,
conn1.getRoster().getGroupCount());
assertEquals("The number of entries in conn2 should be 0", 0, assertEquals("The number of entries in conn2 should be 0", 0, conn2.getRoster().getEntryCount());
conn2.getRoster().getEntryCount()); assertEquals("The number of groups in conn2 should be 0", 0, conn2.getRoster().getGroupCount());
assertEquals("The number of groups in conn2 should be 0", 0,
conn2.getRoster().getGroupCount());
} }
catch (Exception e) { catch (Exception e) {
fail(e.getMessage()); fail(e.getMessage());
@ -161,32 +149,28 @@ public class RosterTest extends TestCase {
/** /**
* 1. Create unfiled entries * 1. Create unfiled entries
* 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 testDeleteAllUnfiledRosterEntries() { public void testDeleteAllUnfiledRosterEntries() {
try { try {
// Add a new roster entry // Add a new roster entry
conn1.getRoster().createEntry("gato11@localhost", "gato11", null); conn1.getRoster().createEntry("gato11@" + conn1.getHost(), "gato11", null);
conn1.getRoster().createEntry("gato12@localhost", "gato12", null); conn1.getRoster().createEntry("gato12@" + conn1.getHost(), "gato12", null);
Thread.sleep(100); Thread.sleep(200);
Iterator it = conn1.getRoster().getEntries(); Iterator it = conn1.getRoster().getEntries();
while (it.hasNext()) { while (it.hasNext()) {
RosterEntry entry = (RosterEntry) it.next(); RosterEntry entry = (RosterEntry) it.next();
conn1.getRoster().removeEntry(entry); conn1.getRoster().removeEntry(entry);
Thread.sleep(100); Thread.sleep(250);
} }
assertEquals("The number of entries in conn1 should be 0", 0, assertEquals("The number of entries in conn1 should be 0", 0, conn1.getRoster().getEntryCount());
conn1.getRoster().getEntryCount()); assertEquals("The number of groups in conn1 should be 0", 0, conn1.getRoster().getGroupCount());
assertEquals("The number of groups in conn1 should be 0", 0,
conn1.getRoster().getGroupCount());
assertEquals("The number of entries in conn2 should be 0", 0, assertEquals("The number of entries in conn2 should be 0", 0, conn2.getRoster().getEntryCount());
conn2.getRoster().getEntryCount()); assertEquals("The number of groups in conn2 should be 0", 0, conn2.getRoster().getGroupCount());
assertEquals("The number of groups in conn2 should be 0", 0,
conn2.getRoster().getGroupCount());
} }
catch (Exception e) { catch (Exception e) {
fail(e.getMessage()); fail(e.getMessage());
@ -203,9 +187,9 @@ public class RosterTest extends TestCase {
public void testChangeNameToUnfiledEntry() { public void testChangeNameToUnfiledEntry() {
try { try {
// Add a new roster entry // Add a new roster entry
conn1.getRoster().createEntry("gato11@localhost", null, null); conn1.getRoster().createEntry("gato11@" + conn1.getHost(), null, null);
Thread.sleep(100); Thread.sleep(200);
// Change the roster entry name and check if the change was made // Change the roster entry name and check if the change was made
Iterator it = conn1.getRoster().getEntries(); Iterator it = conn1.getRoster().getEntries();
@ -214,9 +198,9 @@ public class RosterTest extends TestCase {
entry.setName("gato11"); entry.setName("gato11");
assertEquals("gato11", entry.getName()); assertEquals("gato11", entry.getName());
} }
// Reload the roster and check the name again // Reload the roster and check the name again
conn1.getRoster().reload(); conn1.getRoster().reload();
Thread.sleep(100); Thread.sleep(2000);
it = conn1.getRoster().getEntries(); it = conn1.getRoster().getEntries();
while (it.hasNext()) { while (it.hasNext()) {
RosterEntry entry = (RosterEntry) it.next(); RosterEntry entry = (RosterEntry) it.next();
@ -230,36 +214,29 @@ public class RosterTest extends TestCase {
} }
} }
/** /**
* Clean up all the entries in the roster * Clean up all the entries in the roster
*/ */
private void cleanUpRoster() { private void cleanUpRoster() {
// Delete all the entries from the roster // Delete all the entries from the roster
Iterator it = conn1.getRoster().getEntries(); Iterator it = conn1.getRoster().getEntries();
while (it.hasNext()) { while (it.hasNext()) {
RosterEntry entry = (RosterEntry) it.next(); RosterEntry entry = (RosterEntry) it.next();
conn1.getRoster().removeEntry(entry); conn1.getRoster().removeEntry(entry);
} }
try { try {
Thread.sleep(100); Thread.sleep(700);
} }
catch (Exception e) {} catch (Exception e) {}
assertEquals("The number of entries in conn1 should be 0", 0, assertEquals("The number of entries in conn1 should be 0", 0, conn1.getRoster().getEntryCount());
conn1.getRoster().getEntryCount()); assertEquals("The number of groups in conn1 should be 0", 0, conn1.getRoster().getGroupCount());
assertEquals("The number of groups in conn1 should be 0", 0,
conn1.getRoster().getGroupCount()); assertEquals("The number of entries in conn2 should be 0", 0, conn2.getRoster().getEntryCount());
assertEquals("The number of groups in conn2 should be 0", 0, conn2.getRoster().getGroupCount());
assertEquals("The number of entries in conn2 should be 0", 0,
conn2.getRoster().getEntryCount()); assertEquals("The number of entries in conn3 should be 0", 0, conn3.getRoster().getEntryCount());
assertEquals("The number of groups in conn2 should be 0", 0, assertEquals("The number of groups in conn3 should be 0", 0, conn3.getRoster().getGroupCount());
conn2.getRoster().getGroupCount());
assertEquals("The number of entries in conn3 should be 0", 0,
conn3.getRoster().getEntryCount());
assertEquals("The number of groups in conn3 should be 0", 0,
conn3.getRoster().getGroupCount());
} }
/* /*
@ -270,17 +247,16 @@ public class RosterTest extends TestCase {
try { try {
// Connect to the server // Connect to the server
conn1 = new XMPPConnection("localhost"); conn1 = new XMPPConnection("localhost");
// Use a second connection to create and delete the entry that will be added and // Use a second connection to create and delete the entry that will be added and
// deleted from the roster // deleted from the roster
conn2 = new XMPPConnection("localhost"); conn2 = new XMPPConnection("localhost");
// Use a third connection to create and delete the entry that will be added and // Use a third connection to create and delete the entry that will be added and
// deleted from the roster // deleted from the roster
conn3 = new XMPPConnection("localhost"); conn3 = new XMPPConnection("localhost");
// Create the test accounts // Create the test accounts
if (!conn1.getAccountManager().supportsAccountCreation()) { if (!conn1.getAccountManager().supportsAccountCreation())
fail("Server does not support account creation"); fail("Server does not support account creation");
}
conn1.getAccountManager().createAccount("gato10", "gato10"); conn1.getAccountManager().createAccount("gato10", "gato10");
conn2.getAccountManager().createAccount("gato11", "gato11"); conn2.getAccountManager().createAccount("gato11", "gato11");
conn3.getAccountManager().createAccount("gato12", "gato12"); conn3.getAccountManager().createAccount("gato12", "gato12");
@ -294,6 +270,7 @@ public class RosterTest extends TestCase {
catch (Exception e) { catch (Exception e) {
fail(e.getMessage()); fail(e.getMessage());
} }
} }
/* /*
@ -301,12 +278,12 @@ public class RosterTest extends TestCase {
*/ */
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
super.tearDown(); super.tearDown();
// Delete the created accounts for the test // Delete the created accounts for the test
conn1.getAccountManager().deleteAccount(); conn1.getAccountManager().deleteAccount();
conn2.getAccountManager().deleteAccount(); conn2.getAccountManager().deleteAccount();
conn3.getAccountManager().deleteAccount(); conn3.getAccountManager().deleteAccount();
// Close all the connections // Close all the connections
conn1.close(); conn1.close();
conn2.close(); conn2.close();