mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
Delete accounts created by LowLevelIntegrationTest performCheck()
those where created but not deleted.
This commit is contained in:
parent
fcc62ad131
commit
221b81a627
3 changed files with 51 additions and 36 deletions
|
@ -60,7 +60,7 @@ public abstract class AbstractSmackLowLevelIntegrationTest extends AbstractSmack
|
|||
try {
|
||||
callback.connectionCallback(connection);
|
||||
} finally {
|
||||
connection.disconnect();
|
||||
IntTestUtil.disconnectAndMaybeDelete(connection, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,19 +16,27 @@
|
|||
*/
|
||||
package org.igniterealtime.smack.inttest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.iqregister.AccountManager;
|
||||
|
||||
public class IntTestUtil {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(IntTestUtil.class.getName());
|
||||
|
||||
public static UsernameAndPassword registerAccount(XMPPConnection connection)
|
||||
throws NoResponseException, XMPPErrorException, NotConnectedException,
|
||||
InterruptedException {
|
||||
|
@ -64,4 +72,42 @@ public class IntTestUtil {
|
|||
this.password = password;
|
||||
}
|
||||
}
|
||||
|
||||
public static void disconnectAndMaybeDelete(XMPPTCPConnection connection, boolean delete)
|
||||
throws InterruptedException {
|
||||
try {
|
||||
if (delete) {
|
||||
final int maxAttempts = 3;
|
||||
AccountManager am = AccountManager.getInstance(connection);
|
||||
int attempts;
|
||||
for (attempts = 0; attempts < maxAttempts; attempts++) {
|
||||
try {
|
||||
am.deleteAccount();
|
||||
}
|
||||
catch (XMPPErrorException | NoResponseException e) {
|
||||
LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
|
||||
continue;
|
||||
}
|
||||
catch (NotConnectedException e) {
|
||||
LOGGER.log(Level.WARNING, "Exception deleting account for " + connection, e);
|
||||
try {
|
||||
connection.connect().login();
|
||||
}
|
||||
catch (XMPPException | SmackException | IOException e2) {
|
||||
LOGGER.log(Level.WARNING, "Exception while trying to re-connect " + connection, e);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
LOGGER.info("Successfully deleted account of " + connection);
|
||||
break;
|
||||
}
|
||||
if (attempts > maxAttempts) {
|
||||
LOGGER.log(Level.SEVERE, "Could not delete account for connection: " + connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,6 @@ import org.jivesoftware.smack.SmackException;
|
|||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration.Builder;
|
||||
|
@ -425,7 +424,7 @@ public class SmackIntegrationTestFramework {
|
|||
}
|
||||
}
|
||||
|
||||
private void invokeLowLevel(Method testMethod, AbstractSmackIntTest test) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
private void invokeLowLevel(Method testMethod, AbstractSmackIntTest test) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InterruptedException {
|
||||
// We have checked before that every parameter, if any, is of type XMPPTCPConnection
|
||||
final int numberOfConnections = testMethod.getParameterTypes().length;
|
||||
XMPPTCPConnection[] connections = null;
|
||||
|
@ -451,43 +450,13 @@ public class SmackIntegrationTestFramework {
|
|||
}
|
||||
finally {
|
||||
for (int i = 0; i < numberOfConnections; ++i) {
|
||||
try {
|
||||
AccountManager.getInstance(connections[i]).deleteAccount();
|
||||
LOGGER.info("Successfully deleted account of" + connections[i]);
|
||||
}
|
||||
catch (NoResponseException | XMPPErrorException | NotConnectedException
|
||||
| InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not delete account of " + connections[i], e);
|
||||
}
|
||||
connections[i].disconnect();
|
||||
IntTestUtil.disconnectAndMaybeDelete(connections[i], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void disconnectAndMaybeDelete(XMPPTCPConnection connection)
|
||||
throws InterruptedException, XMPPException, SmackException, IOException {
|
||||
if (config.registerAccounts) {
|
||||
final int maxAttempts = 3;
|
||||
AccountManager am = AccountManager.getInstance(connection);
|
||||
int attempts;
|
||||
for (attempts = 0; attempts < maxAttempts; attempts++) {
|
||||
try {
|
||||
am.deleteAccount();
|
||||
} catch (NoResponseException | InterruptedException e) {
|
||||
LOGGER.log(Level.WARNING, "Exception deleting account for " + connection , e);
|
||||
continue;
|
||||
} catch (NotConnectedException e) {
|
||||
LOGGER.log(Level.WARNING, "Exception deleting account for " + connection , e);
|
||||
connection.connect().login();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (attempts > maxAttempts) {
|
||||
LOGGER.log(Level.SEVERE, "Could not delete account for connection: " + connection);
|
||||
}
|
||||
}
|
||||
connection.disconnect();
|
||||
protected void disconnectAndMaybeDelete(XMPPTCPConnection connection) throws InterruptedException {
|
||||
IntTestUtil.disconnectAndMaybeDelete(connection, config.registerAccounts);
|
||||
}
|
||||
|
||||
protected SmackIntegrationTestEnvironment prepareEnvironment() throws SmackException,
|
||||
|
|
Loading…
Reference in a new issue