mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02:00
Add Integration Test Framework
and resurrect a few integration tests.
This commit is contained in:
parent
4e6fbe7293
commit
b8f046706b
34 changed files with 2333 additions and 100 deletions
|
@ -11,7 +11,7 @@ dependencies {
|
|||
compile "org.jxmpp:jxmpp-core:$jxmppVersion"
|
||||
compile "org.jxmpp:jxmpp-jid:$jxmppVersion"
|
||||
testCompile "org.jxmpp:jxmpp-jid:$jxmppVersion:tests"
|
||||
testCompile 'junit:junit:4.11'
|
||||
testCompile "junit:junit:$junitVersion"
|
||||
testCompile 'xmlunit:xmlunit:1.5'
|
||||
testCompile 'org.powermock:powermock-module-junit4:1.5.5'
|
||||
testCompile 'org.powermock:powermock-api-mockito:1.5.5'
|
||||
|
|
|
@ -31,35 +31,6 @@ public class LoginTest extends SmackTestCase {
|
|||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the server is returning the correct error when trying to login using an invalid
|
||||
* (i.e. non-existent) user.
|
||||
*/
|
||||
public void testInvalidLogin() {
|
||||
try {
|
||||
XMPPTCPConnection connection = createConnection();
|
||||
connection.connect();
|
||||
try {
|
||||
// Login with an invalid user
|
||||
connection.login("invaliduser" , "invalidpass");
|
||||
connection.disconnect();
|
||||
fail("Invalid user was able to log into the server");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
if (e.getXMPPError() != null) {
|
||||
assertEquals("Incorrect error code while login with an invalid user", 401,
|
||||
e.getXMPPError().getCode());
|
||||
}
|
||||
}
|
||||
// Wait here while trying tests with exodus
|
||||
//Thread.sleep(300);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the server handles anonymous users correctly.
|
||||
*/
|
||||
|
|
|
@ -50,6 +50,7 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
|
|||
import org.jivesoftware.smack.SmackException.ConnectionException;
|
||||
import org.jivesoftware.smack.SmackException.ResourceBindingNotOfferedException;
|
||||
import org.jivesoftware.smack.SmackException.SecurityRequiredException;
|
||||
import org.jivesoftware.smack.XMPPException.StreamErrorException;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.compress.packet.Compress;
|
||||
import org.jivesoftware.smack.compression.XMPPInputOutputStream;
|
||||
|
@ -68,6 +69,7 @@ import org.jivesoftware.smack.packet.Presence;
|
|||
import org.jivesoftware.smack.packet.Session;
|
||||
import org.jivesoftware.smack.packet.StartTls;
|
||||
import org.jivesoftware.smack.packet.PlainStreamElement;
|
||||
import org.jivesoftware.smack.packet.StreamError;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
|
||||
import org.jivesoftware.smack.parsing.UnparsablePacket;
|
||||
|
@ -1195,7 +1197,19 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
|||
}
|
||||
|
||||
protected void callConnectionClosedOnErrorListener(Exception e) {
|
||||
LOGGER.log(Level.WARNING, "Connection closed with error", e);
|
||||
boolean logWarning = true;
|
||||
if (e instanceof StreamErrorException) {
|
||||
StreamErrorException see = (StreamErrorException) e;
|
||||
if (see.getStreamError().getCondition() == StreamError.Condition.not_authorized
|
||||
&& wasAuthenticated) {
|
||||
logWarning = false;
|
||||
LOGGER.log(Level.FINE,
|
||||
"Connection closed with not-authorized stream error after it was already authenticated. The account was likely deleted/unregistered on the server");
|
||||
}
|
||||
}
|
||||
if (logWarning) {
|
||||
LOGGER.log(Level.WARNING, "Connection closed with error", e);
|
||||
}
|
||||
for (ConnectionListener listener : connectionListeners) {
|
||||
try {
|
||||
listener.connectionClosedOnError(e);
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package org.jivesoftware.smack.util;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Async {
|
||||
|
||||
/**
|
||||
|
@ -50,4 +53,30 @@ public class Async {
|
|||
thread.setDaemon(true);
|
||||
return thread;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@link Runnable}, but allows the <code>runOrThrow()</code> method to throw an exception.
|
||||
* <p>
|
||||
* If the exception is an instance of {@link RuntimeException}, then it will be re-thrown, otherwise <b>it will be
|
||||
* simply logged.</b>
|
||||
*/
|
||||
public static abstract class ThrowingRunnable implements Runnable {
|
||||
|
||||
public static final Logger LOGGER = Logger.getLogger(ThrowingRunnable.class.getName());
|
||||
|
||||
@Override
|
||||
public final void run() {
|
||||
try {
|
||||
runOrThrow();
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (e instanceof RuntimeException) {
|
||||
throw (RuntimeException) e;
|
||||
}
|
||||
LOGGER.log(Level.WARNING, "Catched Exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void runOrThrow() throws Exception;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,4 +24,8 @@ public class Objects {
|
|||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static <T> T requireNonNull(T obj) {
|
||||
return requireNonNull(obj, null);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue