1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-13 11:09:39 +02:00

Added support for configuring the connection. SMACK-113 SMACK-114

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3311 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2006-01-17 20:05:31 +00:00 committed by gato
parent c00abdeffd
commit 39eca6ec5b
3 changed files with 99 additions and 89 deletions

View file

@ -27,6 +27,7 @@ import javax.net.SocketFactory;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.xmlpull.v1.*;
import org.xmlpull.mxp1.MXParser;
@ -184,11 +185,16 @@ 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(host, port);
connections[i] = new XMPPConnection(config);
}
else {
connections[i] = new XMPPConnection(host, port, host, getSocketFactory());
connections[i] = new XMPPConnection(config, getSocketFactory());
}
}
// Use the host name that the server reports. This is a good idea in most
@ -206,13 +212,10 @@ public abstract class SmackTestCase extends TestCase {
getConnection(i).getAccountManager().createAccount("user" + i, "user" + i);
} catch (XMPPException e) {
// Do nothing if the accout already exists
if (e.getXMPPError().getCode() != 409) {
if (e.getXMPPError() == null || e.getXMPPError().getCode() != 409) {
throw e;
}
}
if (Boolean.getBoolean("test.compressionEnabled")) {
getConnection(i).useCompression();
}
// Login with the new test account
getConnection(i).login("user" + i, "user" + i);
}

View file

@ -23,6 +23,8 @@ package org.jivesoftware.smackx;
import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.SmackConfiguration;
/**
* Ensure that stream compression (JEP-138) is correctly supported by Smack.
@ -40,11 +42,14 @@ public class CompressionTest extends SmackTestCase {
* stream compression enabled.
*/
public void testSuccessCompression() throws XMPPException {
XMPPConnection connection = new XMPPConnection(getHost(), getPort());
assertTrue("Server doesn't support stream compression", connection.getServerSupportsCompression());
// Create the configuration for this new connection
ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());
config.setTLSEnabled(true);
config.setCompressionEnabled(true);
config.setSASLAuthenticationEnabled(true);
assertTrue("Failed to negotiate stream compression", connection.useCompression());
XMPPConnection connection = new XMPPConnection(config);
assertTrue("Connection is not using stream compression", connection.isUsingCompression());