1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-29 23:42:06 +01:00

Fixed test cases to consider that an unavailable presence is now returned for offline users or non-existent users.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7160 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2007-02-16 00:13:18 +00:00 committed by gato
parent 7c847dad6a
commit 7ebaba10e2
3 changed files with 32 additions and 21 deletions

View file

@ -85,12 +85,14 @@ public class LoginTest extends SmackTestCase {
} }
catch (XMPPException e) { catch (XMPPException e) {
e.printStackTrace(); e.printStackTrace();
fail(e.getMessage()); //fail(e.getMessage());
} }
finally {
// Close the connection // Close the connection
conn1.disconnect(); conn1.disconnect();
conn2.disconnect(); conn2.disconnect();
} }
}
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
fail(e.getMessage()); fail(e.getMessage());

View file

@ -491,7 +491,7 @@ public class RosterTest extends SmackTestCase {
// Wait up to 2 seconds // Wait up to 2 seconds
long initial = System.currentTimeMillis(); long initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 2000 && while (System.currentTimeMillis() - initial < 2000 &&
(roster.getPresence(getBareJID(1)) == null)) { (roster.getPresence(getBareJID(1)).getType() == Presence.Type.unavailable)) {
Thread.sleep(100); Thread.sleep(100);
} }
@ -501,22 +501,20 @@ public class RosterTest extends SmackTestCase {
// Check that the right presence is returned for a user+resource // Check that the right presence is returned for a user+resource
presence = roster.getPresenceResource(getUsername(1) + "@" + conn4.getServiceName() + "/Home"); presence = roster.getPresenceResource(getUsername(1) + "@" + conn4.getServiceName() + "/Home");
assertEquals( assertEquals("Returned the wrong Presence", "Home",
"Returned the wrong Presence", StringUtils.parseResource(presence.getFrom()));
StringUtils.parseResource(presence.getFrom()),
"Home");
// Check that the right presence is returned for a user+resource // Check that the right presence is returned for a user+resource
presence = roster.getPresenceResource(getFullJID(1)); presence = roster.getPresenceResource(getFullJID(1));
assertNotNull("Presence not found for user " + getFullJID(1), presence); assertNotNull("Presence not found for user " + getFullJID(1), presence);
assertEquals( assertEquals("Returned the wrong Presence", "Smack",
"Returned the wrong Presence", StringUtils.parseResource(presence.getFrom()));
StringUtils.parseResource(presence.getFrom()),
"Smack");
// Check that the no presence is returned for a non-existent user+resource // Check the returned presence for a non-existent user+resource
presence = roster.getPresenceResource("noname@" + getServiceName() + "/Smack"); presence = roster.getPresenceResource("noname@" + getServiceName() + "/Smack");
assertNull("Returned a Presence for a non-existing user", presence); assertNotNull("No presence was returned for a non-existing user", presence);
assertEquals("Returned Presence for a non-existing user has the incorrect type",
Presence.Type.unavailable, presence.getType());
// Check that the returned presences are correct // Check that the returned presences are correct
Iterator presences = roster.getPresences(getBareJID(1)); Iterator presences = roster.getPresences(getBareJID(1));
@ -580,18 +578,23 @@ public class RosterTest extends SmackTestCase {
// Wait up to 2 seconds // Wait up to 2 seconds
initial = System.currentTimeMillis(); initial = System.currentTimeMillis();
while (System.currentTimeMillis() - initial < 2000 && ( while (System.currentTimeMillis() - initial < 2000 && (
roster.getPresence(getBareJID(0)) != null || roster.getPresence(getBareJID(0)).getType() != Presence.Type.unavailable ||
getConnection(1).getRoster().getPresence(getBareJID(0)) != null)) { getConnection(1).getRoster().getPresence(getBareJID(0)).getType() !=
Presence.Type.unavailable)) {
Thread.sleep(100); Thread.sleep(100);
} }
// Check that no presence is returned for the removed contact // Check that no presence is returned for the removed contact
presence = roster.getPresence(getBareJID(0)); presence = roster.getPresence(getBareJID(0));
assertNull("Presence found for removed contact", presence); assertNotNull("No presence was returned for removed contact", presence);
assertEquals("Returned Presence for removed contact has incorrect type",
Presence.Type.unavailable, presence.getType());
// Check that no presence is returned for the removed contact // Check that no presence is returned for the removed contact
presence = getConnection(1).getRoster().getPresence(getBareJID(0)); presence = getConnection(1).getRoster().getPresence(getBareJID(0));
assertNull("Presence found for removed contact", presence); assertNotNull("No presence was returned for removed contact", presence);
assertEquals("Returned Presence for removed contact has incorrect type",
Presence.Type.unavailable, presence.getType());
} }
/** /**
@ -713,7 +716,9 @@ public class RosterTest extends SmackTestCase {
getConnection(0).packetReader.notifyConnectionError(new Exception("Simulated Error")); getConnection(0).packetReader.notifyConnectionError(new Exception("Simulated Error"));
Presence presence = roster.getPresence(getBareJID(1)); Presence presence = roster.getPresence(getBareJID(1));
assertNull("Presence should be offline after a connection termination", presence); assertNotNull("Unavailable presence not found for offline user", presence);
assertEquals("Unavailable presence not found for offline user", Presence.Type.unavailable,
presence.getType());
// Reconnection should occur in 10 seconds // Reconnection should occur in 10 seconds
Thread.sleep(12200); Thread.sleep(12200);
presence = roster.getPresence(getBareJID(1)); presence = roster.getPresence(getBareJID(1));

View file

@ -53,7 +53,10 @@
package org.jivesoftware.smackx.muc; package org.jivesoftware.smackx.muc;
import org.jivesoftware.smack.*; import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.*; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.test.SmackTestCase; import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smackx.Form; import org.jivesoftware.smackx.Form;
import org.jivesoftware.smackx.ServiceDiscoveryManager; import org.jivesoftware.smackx.ServiceDiscoveryManager;
@ -1842,6 +1845,7 @@ public class MultiUserChatTest extends SmackTestCase {
Form form = muc.getConfigurationForm(); Form form = muc.getConfigurationForm();
Form answerForm = form.createAnswerForm(); Form answerForm = form.createAnswerForm();
answerForm.setAnswer("muc#roomconfig_moderatedroom", true); answerForm.setAnswer("muc#roomconfig_moderatedroom", true);
answerForm.setAnswer("muc#roomconfig_whois", Arrays.asList("moderators"));
// Keep the room owner // Keep the room owner
try { try {
List<String> owners = new ArrayList<String>(); List<String> owners = new ArrayList<String>();