1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-07 13:41:08 +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

@ -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);