mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 17:49:38 +02:00
Refactoring: All connection classes begin with XMPP now
This commit renames classes as follows: * TCPConnection --> XMPPTCPConnection * BOSHConnection --> XMPPBOSHConnection There are two reasons for this rename. First, it is there to indicate that the classes actually _are_ XMPP connections, using different transport mechanisms. Second, it makes auto-completion in IDEs easier, the developer can type XMPP<complete> and choose the right backend.
This commit is contained in:
parent
c86d6e3b61
commit
ab70cfec24
31 changed files with 120 additions and 120 deletions
|
@ -37,7 +37,7 @@ public class LoginTest extends SmackTestCase {
|
|||
*/
|
||||
public void testInvalidLogin() {
|
||||
try {
|
||||
TCPConnection connection = createConnection();
|
||||
XMPPTCPConnection connection = createConnection();
|
||||
connection.connect();
|
||||
try {
|
||||
// Login with an invalid user
|
||||
|
@ -67,8 +67,8 @@ public class LoginTest extends SmackTestCase {
|
|||
if (!isTestAnonymousLogin()) return;
|
||||
|
||||
try {
|
||||
TCPConnection conn1 = createConnection();
|
||||
TCPConnection conn2 = createConnection();
|
||||
XMPPTCPConnection conn1 = createConnection();
|
||||
XMPPTCPConnection conn2 = createConnection();
|
||||
conn1.connect();
|
||||
conn2.connect();
|
||||
try {
|
||||
|
@ -106,12 +106,12 @@ public class LoginTest extends SmackTestCase {
|
|||
try {
|
||||
ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());
|
||||
config.setSASLAuthenticationEnabled(false);
|
||||
TCPConnection conn1 = new XMPPConnection(config);
|
||||
XMPPTCPConnection conn1 = new XMPPConnection(config);
|
||||
conn1.connect();
|
||||
|
||||
config = new ConnectionConfiguration(getHost(), getPort());
|
||||
config.setSASLAuthenticationEnabled(false);
|
||||
TCPConnection conn2 = new XMPPConnection(config);
|
||||
XMPPTCPConnection conn2 = new XMPPConnection(config);
|
||||
conn2.connect();
|
||||
|
||||
try {
|
||||
|
@ -143,7 +143,7 @@ public class LoginTest extends SmackTestCase {
|
|||
*/
|
||||
public void testLoginWithNoResource() {
|
||||
try {
|
||||
TCPConnection conn = createConnection();
|
||||
XMPPTCPConnection conn = createConnection();
|
||||
conn.connect();
|
||||
try {
|
||||
conn.getAccountManager().createAccount("user_1", "user_1", getAccountCreationParameters());
|
||||
|
|
|
@ -194,7 +194,7 @@ public class MessageTest extends SmackTestCase {
|
|||
// Create another connection for the same user of connection 1
|
||||
ConnectionConfiguration connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
TCPConnection conn3 = new XMPPConnection(connectionConfiguration);
|
||||
XMPPTCPConnection conn3 = new XMPPConnection(connectionConfiguration);
|
||||
conn3.connect();
|
||||
conn3.login(getUsername(0), getPassword(0), "Home");
|
||||
// Set this connection as highest priority
|
||||
|
@ -243,7 +243,7 @@ public class MessageTest extends SmackTestCase {
|
|||
// Create another connection for the same user of connection 1
|
||||
ConnectionConfiguration connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
TCPConnection conn3 = new XMPPConnection(connectionConfiguration);
|
||||
XMPPTCPConnection conn3 = new XMPPConnection(connectionConfiguration);
|
||||
conn3.connect();
|
||||
conn3.login(getUsername(0), getPassword(0), "Home");
|
||||
// Set this connection as highest priority
|
||||
|
@ -292,7 +292,7 @@ public class MessageTest extends SmackTestCase {
|
|||
// Create another connection for the same user of connection 1
|
||||
ConnectionConfiguration connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
TCPConnection conn3 = new XMPPConnection(connectionConfiguration);
|
||||
XMPPTCPConnection conn3 = new XMPPConnection(connectionConfiguration);
|
||||
conn3.connect();
|
||||
conn3.login(getUsername(0), getPassword(0), "Home");
|
||||
// Set this connection as highest priority
|
||||
|
@ -308,7 +308,7 @@ public class MessageTest extends SmackTestCase {
|
|||
|
||||
connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
TCPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||
XMPPTCPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||
conn4.connect();
|
||||
conn4.login(getUsername(0), getPassword(0), "Home2");
|
||||
presence = new Presence(Presence.Type.available);
|
||||
|
|
|
@ -39,7 +39,7 @@ public class PresenceTest extends SmackTestCase {
|
|||
* XMPPConnection(1) has logged from two different places with different presence priorities.
|
||||
*/
|
||||
public void testMessageToHighestPriority() {
|
||||
TCPConnection conn = null;
|
||||
XMPPTCPConnection conn = null;
|
||||
try {
|
||||
// User_1 will log in again using another resource
|
||||
conn = createConnection();
|
||||
|
@ -142,7 +142,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)
|
||||
TCPConnection conn = createConnection();
|
||||
XMPPTCPConnection conn = createConnection();
|
||||
conn.connect();
|
||||
conn.login(getUsername(1), getPassword(1), "OtherPlace");
|
||||
|
||||
|
@ -169,7 +169,7 @@ public class PresenceTest extends SmackTestCase {
|
|||
// Create another connection for the same user of connection 1
|
||||
ConnectionConfiguration connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
TCPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||
XMPPTCPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||
conn4.connect();
|
||||
conn4.login(getUsername(1), getPassword(1), "Home");
|
||||
|
||||
|
@ -257,7 +257,7 @@ public class PresenceTest extends SmackTestCase {
|
|||
getConnection(0).disconnect();
|
||||
|
||||
// See if conneciton 0 can get offline status.
|
||||
TCPConnection con0 = getConnection(0);
|
||||
XMPPTCPConnection con0 = getConnection(0);
|
||||
con0.connect();
|
||||
con0.login(getUsername(0), getUsername(0));
|
||||
|
||||
|
|
|
@ -40,9 +40,9 @@ public class ReconnectionTest extends SmackTestCase {
|
|||
*/
|
||||
|
||||
public void testAutomaticReconnection() throws Exception {
|
||||
TCPConnection connection = getConnection(0);
|
||||
XMPPTCPConnection connection = getConnection(0);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
TCPConnectionTestListener listener = new XMPPConnectionTestListener(latch);
|
||||
XMPPTCPConnectionTestListener listener = new XMPPConnectionTestListener(latch);
|
||||
connection.addConnectionListener(listener);
|
||||
|
||||
// Simulates an error in the connection
|
||||
|
@ -63,7 +63,7 @@ public class ReconnectionTest extends SmackTestCase {
|
|||
config.setCompressionEnabled(true);
|
||||
config.setSASLAuthenticationEnabled(true);
|
||||
|
||||
TCPConnection connection = new XMPPConnection(config);
|
||||
XMPPTCPConnection connection = new XMPPConnection(config);
|
||||
// Connect to the server
|
||||
connection.connect();
|
||||
// Log into the server
|
||||
|
@ -75,7 +75,7 @@ public class ReconnectionTest extends SmackTestCase {
|
|||
executeSomeServerInteraction(connection);
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
TCPConnectionTestListener listener = new XMPPConnectionTestListener(latch);
|
||||
XMPPTCPConnectionTestListener listener = new XMPPConnectionTestListener(latch);
|
||||
connection.addConnectionListener(listener);
|
||||
|
||||
// Simulates an error in the connection
|
||||
|
@ -95,9 +95,9 @@ public class ReconnectionTest extends SmackTestCase {
|
|||
* Simulates a connection error, disables the reconnection mechanism and then reconnects.
|
||||
*/
|
||||
public void testManualReconnectionWithCancelation() throws Exception {
|
||||
TCPConnection connection = getConnection(0);
|
||||
XMPPTCPConnection connection = getConnection(0);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
TCPConnectionTestListener listener = new XMPPConnectionTestListener(latch);
|
||||
XMPPTCPConnectionTestListener listener = new XMPPConnectionTestListener(latch);
|
||||
connection.addConnectionListener(listener);
|
||||
|
||||
// Produces a connection error
|
||||
|
@ -126,10 +126,10 @@ public class ReconnectionTest extends SmackTestCase {
|
|||
* Closes the connection and then reconnects.
|
||||
*/
|
||||
public void testCloseAndManualReconnection() throws Exception {
|
||||
TCPConnection connection = getConnection(0);
|
||||
XMPPTCPConnection connection = getConnection(0);
|
||||
String username = connection.getConfiguration().getUsername();
|
||||
String password = connection.getConfiguration().getPassword();
|
||||
TCPConnectionTestListener listener = new XMPPConnectionTestListener();
|
||||
XMPPTCPConnectionTestListener listener = new XMPPConnectionTestListener();
|
||||
connection.addConnectionListener(listener);
|
||||
|
||||
// Produces a normal disconnection
|
||||
|
@ -154,9 +154,9 @@ public class ReconnectionTest extends SmackTestCase {
|
|||
* Closes the connection and then reconnects.
|
||||
*/
|
||||
public void testAnonymousReconnection() throws Exception {
|
||||
TCPConnection connection = createConnection();
|
||||
XMPPTCPConnection connection = createConnection();
|
||||
connection.connect();
|
||||
TCPConnectionTestListener listener = new XMPPConnectionTestListener();
|
||||
XMPPTCPConnectionTestListener listener = new XMPPConnectionTestListener();
|
||||
connection.addConnectionListener(listener);
|
||||
|
||||
// Makes the anounymous login
|
||||
|
@ -172,13 +172,13 @@ public class ReconnectionTest extends SmackTestCase {
|
|||
assertEquals("Failed the manual connection", true, connection.isAnonymous());
|
||||
}
|
||||
|
||||
private TCPConnection createXMPPConnection() throws Exception {
|
||||
TCPConnection connection;
|
||||
private XMPPTCPConnection createXMPPConnection() throws Exception {
|
||||
XMPPTCPConnection connection;
|
||||
// Create the configuration
|
||||
ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());
|
||||
config.setCompressionEnabled(Boolean.getBoolean("test.compressionEnabled"));
|
||||
config.setSASLAuthenticationEnabled(true);
|
||||
connection = new TCPConnection(config);
|
||||
connection = new XMPPTCPConnection(config);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ public class ReconnectionTest extends SmackTestCase {
|
|||
return 1;
|
||||
}
|
||||
|
||||
private class TCPConnectionTestListener implements ConnectionListener {
|
||||
private class XMPPTCPConnectionTestListener implements ConnectionListener {
|
||||
|
||||
// Variables to support listener notifications verification
|
||||
private volatile boolean connectionClosed = false;
|
||||
|
@ -207,11 +207,11 @@ public class ReconnectionTest extends SmackTestCase {
|
|||
private volatile boolean reconnectionCanceled = false;
|
||||
private CountDownLatch countDownLatch;
|
||||
|
||||
private TCPConnectionTestListener(CountDownLatch latch) {
|
||||
private XMPPTCPConnectionTestListener(CountDownLatch latch) {
|
||||
countDownLatch = latch;
|
||||
}
|
||||
|
||||
private TCPConnectionTestListener() {
|
||||
private XMPPTCPConnectionTestListener() {
|
||||
}
|
||||
/**
|
||||
* Methods to test the listener.
|
||||
|
|
|
@ -35,7 +35,7 @@ public class RosterInitializedBeforeConnectTest extends RosterSmackTest {
|
|||
|
||||
// initialize all rosters before login
|
||||
for (int i = 0; i < getMaxConnections(); i++) {
|
||||
TCPConnection connection = getConnection(i);
|
||||
XMPPTCPConnection connection = getConnection(i);
|
||||
assertFalse(connection.isConnected());
|
||||
|
||||
Roster roster = connection.getRoster();
|
||||
|
|
|
@ -36,7 +36,7 @@ public class RosterListenerTest extends SmackTestCase {
|
|||
public void testAddingRosterListenerBeforeConnect() throws Exception {
|
||||
int inviterIndex = 0;
|
||||
int inviteeIndex = 1;
|
||||
TCPConnection inviterConnection = getConnection(inviterIndex);
|
||||
XMPPTCPConnection inviterConnection = getConnection(inviterIndex);
|
||||
connectAndLogin(inviterIndex);
|
||||
|
||||
assertTrue("Inviter is not online", inviterConnection.isConnected());
|
||||
|
@ -46,7 +46,7 @@ public class RosterListenerTest extends SmackTestCase {
|
|||
// add user1 to roster to create roster events stored at XMPP server
|
||||
inviterRoster.createEntry(getBareJID(inviteeIndex), getUsername(inviteeIndex), null);
|
||||
|
||||
TCPConnection inviteeConnection = getConnection(inviteeIndex);
|
||||
XMPPTCPConnection inviteeConnection = getConnection(inviteeIndex);
|
||||
assertFalse("Invitee is already online", inviteeConnection.isConnected());
|
||||
|
||||
// collector for added entries
|
||||
|
@ -88,7 +88,7 @@ public class RosterListenerTest extends SmackTestCase {
|
|||
public void testAddingRosterListenerAfterConnect() throws Exception {
|
||||
int inviterIndex = 0;
|
||||
int inviteeIndex = 1;
|
||||
TCPConnection inviterConnection = getConnection(inviterIndex);
|
||||
XMPPTCPConnection inviterConnection = getConnection(inviterIndex);
|
||||
connectAndLogin(inviterIndex);
|
||||
assertTrue("Inviter is not online", inviterConnection.isConnected());
|
||||
|
||||
|
@ -99,7 +99,7 @@ public class RosterListenerTest extends SmackTestCase {
|
|||
|
||||
Thread.sleep(500); // wait for XMPP server
|
||||
|
||||
TCPConnection inviteeConnection = getConnection(inviteeIndex);
|
||||
XMPPTCPConnection inviteeConnection = getConnection(inviteeIndex);
|
||||
connectAndLogin(inviteeIndex);
|
||||
assertTrue("Invitee is not online", inviteeConnection.isConnected());
|
||||
|
||||
|
|
|
@ -329,7 +329,7 @@ public class RosterSmackTest extends SmackTestCase {
|
|||
|
||||
|
||||
// Log in from another resource so we can test the roster
|
||||
TCPConnection con2 = createConnection();
|
||||
XMPPTCPConnection con2 = createConnection();
|
||||
con2.connect();
|
||||
con2.login(getUsername(0), getUsername(0), "MyNewResource");
|
||||
|
||||
|
@ -435,7 +435,7 @@ public class RosterSmackTest extends SmackTestCase {
|
|||
// Create another connection for the same user of connection 1
|
||||
ConnectionConfiguration connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
TCPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||
XMPPTCPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||
conn4.connect();
|
||||
conn4.login(getUsername(1), getPassword(1), "Home");
|
||||
|
||||
|
@ -502,7 +502,7 @@ public class RosterSmackTest extends SmackTestCase {
|
|||
// Create another connection for the same user of connection 1
|
||||
ConnectionConfiguration connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
TCPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||
XMPPTCPConnection conn4 = new XMPPConnection(connectionConfiguration);
|
||||
conn4.connect();
|
||||
conn4.login(getUsername(1), getPassword(1), "Home");
|
||||
|
||||
|
@ -567,7 +567,7 @@ public class RosterSmackTest extends SmackTestCase {
|
|||
// Create another connection for the same user of connection 0
|
||||
ConnectionConfiguration connectionConfiguration =
|
||||
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
|
||||
TCPConnection conn2 = new XMPPConnection(connectionConfiguration);
|
||||
XMPPTCPConnection conn2 = new XMPPConnection(connectionConfiguration);
|
||||
conn2.connect();
|
||||
conn2.login(getUsername(0), getPassword(0), "Home");
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ public abstract class SmackTestCase extends TestCase {
|
|||
private String chatDomain = "chat";
|
||||
private String mucDomain = "conference";
|
||||
|
||||
private TCPConnection[] connections = null;
|
||||
private XMPPTCPConnection[] connections = null;
|
||||
|
||||
/**
|
||||
* Constructor for SmackTestCase.
|
||||
|
@ -120,7 +120,7 @@ public abstract class SmackTestCase extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the TCPConnection located at the requested position. Each test case holds a
|
||||
* Returns the XMPPTCPConnection located at the requested position. Each test case holds a
|
||||
* pool of connections which is initialized while setting up the test case. The maximum
|
||||
* number of connections is controlled by the message {@link #getMaxConnections()} which
|
||||
* every subclass must implement.<p>
|
||||
|
@ -129,9 +129,9 @@ public abstract class SmackTestCase extends TestCase {
|
|||
* IllegalArgumentException will be thrown.
|
||||
*
|
||||
* @param index the position in the pool of the connection to look for.
|
||||
* @return the TCPConnection located at the requested position.
|
||||
* @return the XMPPTCPConnection located at the requested position.
|
||||
*/
|
||||
protected TCPConnection getConnection(int index) {
|
||||
protected XMPPTCPConnection getConnection(int index) {
|
||||
if (index > getMaxConnections()) {
|
||||
throw new IllegalArgumentException("Index out of bounds");
|
||||
}
|
||||
|
@ -139,12 +139,12 @@ public abstract class SmackTestCase extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a new TCPConnection using the connection preferences. This is useful when
|
||||
* Creates a new XMPPTCPConnection 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 TCPConnection createConnection() {
|
||||
protected XMPPTCPConnection createConnection() {
|
||||
// Create the configuration for this new connection
|
||||
ConnectionConfiguration config = new ConnectionConfiguration(host, port);
|
||||
config.setCompressionEnabled(compressionEnabled);
|
||||
|
@ -152,7 +152,7 @@ public abstract class SmackTestCase extends TestCase {
|
|||
if (getSocketFactory() == null) {
|
||||
config.setSocketFactory(getSocketFactory());
|
||||
}
|
||||
return new TCPConnection(config);
|
||||
return new XMPPTCPConnection(config);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -235,7 +235,7 @@ public abstract class SmackTestCase extends TestCase {
|
|||
if (getMaxConnections() < 1) {
|
||||
return;
|
||||
}
|
||||
connections = new TCPConnection[getMaxConnections()];
|
||||
connections = new XMPPTCPConnection[getMaxConnections()];
|
||||
usernames = new String[getMaxConnections()];
|
||||
passwords = new String[getMaxConnections()];
|
||||
|
||||
|
@ -340,7 +340,7 @@ public abstract class SmackTestCase extends TestCase {
|
|||
try {
|
||||
// If not connected, connect so that we can delete the account.
|
||||
if (!getConnection(i).isConnected()) {
|
||||
TCPConnection con = getConnection(i);
|
||||
XMPPTCPConnection con = getConnection(i);
|
||||
con.connect();
|
||||
con.login(getUsername(i), getUsername(i));
|
||||
}
|
||||
|
|
|
@ -55,13 +55,13 @@ import org.jivesoftware.smack.packet.Presence;
|
|||
/**
|
||||
* The abstract XMPPConnection class provides an interface for connections to a
|
||||
* XMPP server and implements shared methods which are used by the
|
||||
* different types of connections (e.g. TCPConnection or BoshConnection).
|
||||
* different types of connections (e.g. XMPPTCPConnection or XMPPBOSHConnection).
|
||||
*
|
||||
* To create a connection to a XMPP server a simple usage of this API might
|
||||
* look like the following:
|
||||
* <pre>
|
||||
* // Create a connection to the igniterealtime.org XMPP server.
|
||||
* XMPPConnection con = new TCPConnection("igniterealtime.org");
|
||||
* XMPPConnection con = new XMPPTCPConnection("igniterealtime.org");
|
||||
* // Connect to the server
|
||||
* con.connect();
|
||||
* // Most servers require you to login before performing other tasks.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue