1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 01:29:38 +02:00

Initial cut of constructor re-factor (SMACK-184).

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@6532 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2007-01-04 23:00:58 +00:00 committed by matt
parent 3915eae215
commit 92d1de2dce
12 changed files with 81 additions and 292 deletions

View file

@ -31,7 +31,7 @@ public class LoginTest extends SmackTestCase {
*/
public void testInvalidLogin() {
try {
XMPPConnection connection = new XMPPConnection(getHost(), getPort());
XMPPConnection connection = createConnection();
connection.connect();
try {
// Login with an invalid user
@ -59,8 +59,8 @@ public class LoginTest extends SmackTestCase {
*/
public void testSASLAnonymousLogin() {
try {
XMPPConnection conn1 = new XMPPConnection(getHost(), getPort());
XMPPConnection conn2 = new XMPPConnection(getHost(), getPort());
XMPPConnection conn1 = createConnection();
XMPPConnection conn2 = createConnection();
conn1.connect();
conn2.connect();
try {
@ -133,7 +133,7 @@ public class LoginTest extends SmackTestCase {
*/
public void testLoginWithNoResource() {
try {
XMPPConnection conn = new XMPPConnection(getHost(), getPort());
XMPPConnection conn = createConnection();
conn.connect();
try {
conn.getAccountManager().createAccount("user_1", "user_1");

View file

@ -1,102 +0,0 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
* ====================================================================
* The Jive Software License (based on Apache Software License, Version 1.1)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by
* Jive Software (http://www.jivesoftware.com)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Smack" and "Jive Software" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please
* contact webmaster@jivesoftware.com.
*
* 5. Products derived from this software may not be called "Smack",
* nor may "Smack" appear in their name, without prior written
* permission of Jive Software.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*/
package org.jivesoftware.smack;
import junit.framework.TestCase;
public class MessengerLoginTest extends TestCase {
private String host;
private int port;
public void setUp() {
// override default settings from system properties
if (System.getProperty("smack.test.host") != null) {
host = System.getProperty("smack.test.host");
}
if (System.getProperty("smack.test.port") != null) {
try {
port = Integer.parseInt(System.getProperty("smack.test.port"));
}
catch (Exception ignored) {}
}
}
public void testAdminLogin() {
String username = System.getProperty("smack.test.admin.username");
String password = System.getProperty("smack.test.admin.password");
String resource = System.getProperty("smack.test.admin.resource");
boolean debug = false;
try {
debug = Boolean.valueOf(System.getProperty("smack.debug")).booleanValue();
}
catch (Exception ignored) {}
XMPPConnection.DEBUG_ENABLED = debug;
try {
XMPPConnection con = new XMPPConnection(host, port);
con.connect();
con.login(username, password, resource);
}
catch (XMPPException e) {
String message = e.getMessage();
if (e.getXMPPError() != null) {
message = "XMPPError code: " + e.getXMPPError().getCode() + ", message: "
+ e.getXMPPError().getMessage();
}
/*fail("Login to server " + host + ":" + port + " failed using user/pass/resource: "
+ username + "/" + password + "/" + resource + ". Error message: " + message);*/
}
}
}

View file

@ -36,7 +36,7 @@ public class PresenceTest extends SmackTestCase {
XMPPConnection conn = null;
try {
// User_1 will log in again using another resource
conn = new XMPPConnection(getHost(), getPort());
conn = createConnection();
conn.connect();
conn.login(getUsername(1), getUsername(1), "OtherPlace");
// Change the presence priorities of User_1
@ -84,7 +84,7 @@ public class PresenceTest extends SmackTestCase {
Presence.Mode.available));
// User_1 will log in again using another resource
conn = new XMPPConnection(getHost(), getPort());
conn = createConnection();
conn.connect();
conn.login(getUsername(1), getUsername(1), "OtherPlace");
conn.sendPacket(new Presence(Presence.Type.available, null, 1,
@ -136,7 +136,7 @@ public class PresenceTest extends SmackTestCase {
getConnection(1).sendPacket(new Presence(Presence.Type.unavailable));
// User_1 will log in again using another resource (that is going to be available)
XMPPConnection conn = new XMPPConnection(getHost(), getPort());
XMPPConnection conn = createConnection();
conn.connect();
conn.login(getUsername(1), getUsername(1), "OtherPlace");

View file

@ -153,14 +153,14 @@ public class ReconnectionTest extends SmackTestCase {
assertEquals("Failed the manual connection", true, connection.isAnonymous());
}
private XMPPConnection createConnection() throws Exception {
private XMPPConnection createXMPPConnection() throws Exception {
XMPPConnection connection;
// Create the configuration
ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());
config.setTLSEnabled(true);
config.setCompressionEnabled(Boolean.getBoolean("test.compressionEnabled"));
config.setSASLAuthenticationEnabled(true);
connection = new XMPPConnection(config, getSocketFactory());
connection = new XMPPConnection(config);
return connection;
}

View file

@ -366,7 +366,7 @@ public class RosterTest extends SmackTestCase {
// Log in from another resource so we can test the roster
XMPPConnection con2 = new XMPPConnection(getHost(), getPort());
XMPPConnection con2 = createConnection();
con2.connect();
con2.login(getUsername(0), getUsername(0), "MyNewResource");

View file

@ -107,6 +107,24 @@ public abstract class SmackTestCase extends TestCase {
return connections[index];
}
/**
* Creates a new XMPPConnection using the connection preferences. This is useful when
* not using a connection from the connection pool in a test case.
*
* @return a new XMPP connection.
*/
protected XMPPConnection createConnection() {
// Create the configuration for this new connection
ConnectionConfiguration config = new ConnectionConfiguration(host, port);
config.setTLSEnabled(true);
config.setCompressionEnabled(Boolean.getBoolean("test.compressionEnabled"));
config.setSASLAuthenticationEnabled(true);
if (getSocketFactory() == null) {
config.setSocketFactory(getSocketFactory());
}
return new XMPPConnection(config);
}
/**
* Returns the name of the user (e.g. johndoe) that is using the connection
* located at the requested position.
@ -183,17 +201,7 @@ public abstract class SmackTestCase extends TestCase {
try {
// Connect to the server
for (int i = 0; i < getMaxConnections(); i++) {
// Create the configuration for this new connection
ConnectionConfiguration config = new ConnectionConfiguration(host, port);
config.setTLSEnabled(true);
config.setCompressionEnabled(Boolean.getBoolean("test.compressionEnabled"));
config.setSASLAuthenticationEnabled(true);
if (getSocketFactory() == null) {
connections[i] = new XMPPConnection(config);
}
else {
connections[i] = new XMPPConnection(config, getSocketFactory());
}
connections[i] = createConnection();
connections[i].connect();
}
// Use the host name that the server reports. This is a good idea in most

View file

@ -69,7 +69,7 @@ public class CompressionTest extends SmackTestCase {
*/
protected void setUp() throws Exception {
super.setUp();
XMPPConnection setupConnection = new XMPPConnection(getHost(), getPort());
XMPPConnection setupConnection = new XMPPConnection(getServiceName());
setupConnection.connect();
if (!setupConnection.getAccountManager().supportsAccountCreation())
fail("Server does not support account creation");
@ -90,7 +90,7 @@ public class CompressionTest extends SmackTestCase {
*/
protected void tearDown() throws Exception {
super.tearDown();
XMPPConnection setupConnection = new XMPPConnection(getHost(), getPort());
XMPPConnection setupConnection = createConnection();
setupConnection.connect();
setupConnection.login("user0", "user0");
// Delete the created account for the test
@ -98,5 +98,4 @@ public class CompressionTest extends SmackTestCase {
// Close the setupConnection
setupConnection.disconnect();
}
}
}

View file

@ -242,7 +242,7 @@ public class MultiUserChatTest extends SmackTestCase {
public void testAnonymousParticipant() {
try {
// Anonymous user joins the new room
XMPPConnection anonConnection = new XMPPConnection(getHost(), getPort());
XMPPConnection anonConnection = new XMPPConnection(getServiceName());
anonConnection.connect();
anonConnection.loginAnonymously();
MultiUserChat muc2 = new MultiUserChat(anonConnection, room);