moved smtp server configuration to suiteContext

This commit is contained in:
vramik 2015-09-23 10:50:49 +02:00
parent 09488b8df3
commit e811b87679

View file

@ -3,6 +3,8 @@ package org.keycloak.testsuite.util;
import com.icegreen.greenmail.util.GreenMail; import com.icegreen.greenmail.util.GreenMail;
import com.icegreen.greenmail.util.ServerSetup; import com.icegreen.greenmail.util.ServerSetup;
import java.io.IOException; import java.io.IOException;
import java.lang.Thread.UncaughtExceptionHandler;
import java.net.SocketException;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
@ -42,7 +44,7 @@ public class MailServer {
log.info("-------------------------------------------------------"); log.info("-------------------------------------------------------");
} }
} }
} catch (IOException | InterruptedException | MessagingException ex) { } catch (IOException | MessagingException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} }
@ -53,18 +55,29 @@ public class MailServer {
greenMail = new GreenMail(setup); greenMail = new GreenMail(setup);
greenMail.start(); greenMail.start();
log.info("--Started mail server (" + HOST + ":" + PORT + ")--"); log.info("Started mail server (" + HOST + ":" + PORT + ")");
} }
public static void stop() { public static void stop() {
if (greenMail != null) { if (greenMail != null) {
log.info("--Stopping mail server (localhost:3025)--"); log.info("Stopping mail server (localhost:3025)");
// Suppress error from GreenMail on shutdown
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
if (!(e.getCause() instanceof SocketException && e.getStackTrace()[0].getClassName()
.equals("com.icegreen.greenmail.smtp.SmtpHandler"))) {
log.error("Exception in thread \"" + t.getName() + "\" ");
log.error(e.getMessage(), e);
}
}
});
greenMail.stop(); greenMail.stop();
} }
} }
public static void createEmailAccount(String email, String password) { public static void createEmailAccount(String email, String password) {
log.debug("--Creating email account " + email + "--"); log.debug("Creating email account " + email);
greenMail.setUser(email, password); greenMail.setUser(email, password);
} }