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

Updates to SmackTestCase to properly provide the username and password for each connection. Test cases manually logging in now use these methods instead of wrongly assuming the username/password pattern.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@13453 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
rcollier 2013-02-07 03:47:49 +00:00
parent d1e9d81769
commit 8c0b062629
6 changed files with 70 additions and 39 deletions

View file

@ -199,7 +199,7 @@ public class MessageTest extends SmackTestCase {
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
XMPPConnection conn3 = new XMPPConnection(connectionConfiguration);
conn3.connect();
conn3.login(getUsername(0), getUsername(0), "Home");
conn3.login(getUsername(0), getPassword(0), "Home");
// Set this connection as highest priority
Presence presence = new Presence(Presence.Type.available);
presence.setPriority(10);
@ -248,7 +248,7 @@ public class MessageTest extends SmackTestCase {
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
XMPPConnection conn3 = new XMPPConnection(connectionConfiguration);
conn3.connect();
conn3.login(getUsername(0), getUsername(0), "Home");
conn3.login(getUsername(0), getPassword(0), "Home");
// Set this connection as highest priority
Presence presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.away);
@ -297,7 +297,7 @@ public class MessageTest extends SmackTestCase {
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
XMPPConnection conn3 = new XMPPConnection(connectionConfiguration);
conn3.connect();
conn3.login(getUsername(0), getUsername(0), "Home");
conn3.login(getUsername(0), getPassword(0), "Home");
// Set this connection as highest priority
Presence presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available);
@ -313,7 +313,7 @@ public class MessageTest extends SmackTestCase {
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
XMPPConnection conn4 = new XMPPConnection(connectionConfiguration);
conn4.connect();
conn4.login(getUsername(0), getUsername(0), "Home2");
conn4.login(getUsername(0), getPassword(0), "Home2");
presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available);
presence.setPriority(4);

View file

@ -20,11 +20,11 @@
package org.jivesoftware.smack;
import java.util.Iterator;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.test.SmackTestCase;
import java.util.Iterator;
/**
* Ensure that the server is delivering messages to the correct client based on the client's
* presence priority.
@ -95,7 +95,7 @@ public class PresenceTest extends SmackTestCase {
// User_1 will log in again using another resource
conn = createConnection();
conn.connect();
conn.login(getUsername(1), getUsername(1), "OtherPlace");
conn.login(getUsername(1), getPassword(1), "OtherPlace");
conn.sendPacket(new Presence(Presence.Type.available, null, 1,
Presence.Mode.available));
chat2 = conn.getChatManager().createChat(getBareJID(0), chat0.getThreadID(), null);
@ -147,7 +147,7 @@ public class PresenceTest extends SmackTestCase {
// User_1 will log in again using another resource (that is going to be available)
XMPPConnection conn = createConnection();
conn.connect();
conn.login(getUsername(1), getUsername(1), "OtherPlace");
conn.login(getUsername(1), getPassword(1), "OtherPlace");
// Create chats between participants
Chat chat0 = getConnection(0).getChatManager().createChat(getFullJID(1), null);
@ -174,7 +174,7 @@ public class PresenceTest extends SmackTestCase {
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
XMPPConnection conn4 = new XMPPConnection(connectionConfiguration);
conn4.connect();
conn4.login(getUsername(1), getUsername(1), "Home");
conn4.login(getUsername(1), getPassword(1), "Home");
// Add a new roster entry
Roster roster = getConnection(0).getRoster();

View file

@ -49,7 +49,7 @@ public class ReconnectionTest extends SmackTestCase {
// Connect to the server
connection.connect();
// Log into the server
connection.login(getUsername(0), getUsername(0), "MyOtherResource");
connection.login(getUsername(0), getPassword(0), "MyOtherResource");
assertTrue("Failed to use compression", connection.isUsingCompression());

View file

@ -52,14 +52,14 @@
package org.jivesoftware.smack;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smack.util.StringUtils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smack.util.StringUtils;
/**
* Tests the Roster functionality by creating and removing roster entries.
*
@ -482,7 +482,7 @@ public class RosterSmackTest extends SmackTestCase {
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
XMPPConnection conn4 = new XMPPConnection(connectionConfiguration);
conn4.connect();
conn4.login(getUsername(1), getUsername(1), "Home");
conn4.login(getUsername(1), getPassword(1), "Home");
// Add a new roster entry
Roster roster = getConnection(0).getRoster();
@ -555,7 +555,7 @@ public class RosterSmackTest extends SmackTestCase {
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
XMPPConnection conn4 = new XMPPConnection(connectionConfiguration);
conn4.connect();
conn4.login(getUsername(1), getUsername(1), "Home");
conn4.login(getUsername(1), getPassword(1), "Home");
// Add a new roster entry
Roster roster = conn4.getRoster();
@ -620,7 +620,7 @@ public class RosterSmackTest extends SmackTestCase {
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
XMPPConnection conn2 = new XMPPConnection(connectionConfiguration);
conn2.connect();
conn2.login(getUsername(0), getUsername(0), "Home");
conn2.login(getUsername(0), getPassword(0), "Home");
// Retrieve roster and verify that new contact is there and nickname is correct
Roster roster2 = conn2.getRoster();

View file

@ -19,20 +19,22 @@
*/
package org.jivesoftware.smack.test;
import junit.framework.TestCase;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.xmlpull.mxp1.MXParser;
import org.xmlpull.v1.XmlPullParser;
import javax.net.SocketFactory;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.net.SocketFactory;
import junit.framework.TestCase;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.xmlpull.mxp1.MXParser;
import org.xmlpull.v1.XmlPullParser;
/**
* Base class for all the test cases which provides a pre-configured execution context. This
* means that any test case that subclassifies this base class will have access to a pool of
@ -59,6 +61,9 @@ public abstract class SmackTestCase extends TestCase {
private boolean samePassword;
private List<Integer> createdUserIdx = new ArrayList<Integer>();
private String[] usernames;
private String[] passwords;
private String chatDomain = "chat";
private String mucDomain = "conference";
@ -155,10 +160,18 @@ public abstract class SmackTestCase extends TestCase {
* @return the user of the user (e.g. johndoe).
*/
protected String getUsername(int index) {
if (index > getMaxConnections()) {
throw new IllegalArgumentException("Index out of bounds");
}
return usernamePrefix + (index + 1);
return usernames[index];
}
/**
* Returns the password of the user (e.g. johndoe) that is using the connection
* located at the requested position.
*
* @param index the position in the pool of the connection to look for.
* @return the password of the user (e.g. johndoe).
*/
protected String getPassword(int index) {
return passwords[index];
}
/**
@ -220,6 +233,9 @@ public abstract class SmackTestCase extends TestCase {
return;
}
connections = new XMPPConnection[getMaxConnections()];
usernames = new String[getMaxConnections()];
passwords = new String[getMaxConnections()];
try {
// Connect to the server
for (int i = 0; i < getMaxConnections(); i++) {
@ -235,14 +251,17 @@ public abstract class SmackTestCase extends TestCase {
if (!createOfflineConnections()) {
for (int i = 0; i < getMaxConnections(); i++) {
String password = usernamePrefix + (i+1);
String currentUser = password;
String currentPassword = usernamePrefix + (i+1);
String currentUser = currentPassword;
if (passwordPrefix != null)
password = (samePassword ? passwordPrefix : passwordPrefix + (i+1));
currentPassword = (samePassword ? passwordPrefix : passwordPrefix + (i+1));
usernames[i] = currentUser;
passwords[i] = currentPassword;
try {
getConnection(i).login(currentUser, password, "Smack");
getConnection(i).login(currentUser, currentPassword, "Smack");
} catch (XMPPException e) {
e.printStackTrace();
@ -253,7 +272,7 @@ public abstract class SmackTestCase extends TestCase {
// Create the account and try logging in again as the
// same user.
try {
createAccount(i, currentUser, password);
createAccount(i, currentUser, currentPassword);
} catch (Exception e1) {
e1.printStackTrace();
fail("Could not create user: " + currentUser);

View file

@ -52,7 +52,22 @@
package org.jivesoftware.smackx.muc;
import org.jivesoftware.smack.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.TimeZone;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManagerListener;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Presence;
@ -65,9 +80,6 @@ import org.jivesoftware.smackx.packet.DelayInformation;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.XHTMLExtension;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* Tests the new MUC functionalities.
*
@ -1762,7 +1774,7 @@ public class MultiUserChatTest extends SmackTestCase {
connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
conns[i] = new XMPPConnection(connectionConfiguration);
conns[i].connect();
conns[i].login(getUsername(1), getUsername(1), "resource-" + i);
conns[i].login(getUsername(1), getPassword(1), "resource-" + i);
Thread.sleep(20);
}