diff --git a/test/org/jivesoftware/smack/MessageTest.java b/test/org/jivesoftware/smack/MessageTest.java index bd102a91f..c1e412706 100644 --- a/test/org/jivesoftware/smack/MessageTest.java +++ b/test/org/jivesoftware/smack/MessageTest.java @@ -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); diff --git a/test/org/jivesoftware/smack/PresenceTest.java b/test/org/jivesoftware/smack/PresenceTest.java index 8da8fc545..9c24ce0fe 100644 --- a/test/org/jivesoftware/smack/PresenceTest.java +++ b/test/org/jivesoftware/smack/PresenceTest.java @@ -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(); diff --git a/test/org/jivesoftware/smack/ReconnectionTest.java b/test/org/jivesoftware/smack/ReconnectionTest.java index 3c21974ca..7fc8be8c5 100644 --- a/test/org/jivesoftware/smack/ReconnectionTest.java +++ b/test/org/jivesoftware/smack/ReconnectionTest.java @@ -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()); diff --git a/test/org/jivesoftware/smack/RosterSmackTest.java b/test/org/jivesoftware/smack/RosterSmackTest.java index 17f867257..cc56a1c73 100644 --- a/test/org/jivesoftware/smack/RosterSmackTest.java +++ b/test/org/jivesoftware/smack/RosterSmackTest.java @@ -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(); diff --git a/test/org/jivesoftware/smack/test/SmackTestCase.java b/test/org/jivesoftware/smack/test/SmackTestCase.java index 56c452ace..baf682e0c 100644 --- a/test/org/jivesoftware/smack/test/SmackTestCase.java +++ b/test/org/jivesoftware/smack/test/SmackTestCase.java @@ -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 createdUserIdx = new ArrayList(); + 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); diff --git a/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java b/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java index 8f7548cd6..5803ac721 100644 --- a/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java +++ b/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java @@ -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); }