moved smtp server configuration to suiteContext
This commit is contained in:
parent
09488b8df3
commit
e811b87679
1 changed files with 17 additions and 4 deletions
|
@ -3,6 +3,8 @@ package org.keycloak.testsuite.util;
|
|||
import com.icegreen.greenmail.util.GreenMail;
|
||||
import com.icegreen.greenmail.util.ServerSetup;
|
||||
import java.io.IOException;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.net.SocketException;
|
||||
import javax.mail.MessagingException;
|
||||
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
@ -42,7 +44,7 @@ public class MailServer {
|
|||
log.info("-------------------------------------------------------");
|
||||
}
|
||||
}
|
||||
} catch (IOException | InterruptedException | MessagingException ex) {
|
||||
} catch (IOException | MessagingException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
@ -53,18 +55,29 @@ public class MailServer {
|
|||
greenMail = new GreenMail(setup);
|
||||
greenMail.start();
|
||||
|
||||
log.info("--Started mail server (" + HOST + ":" + PORT + ")--");
|
||||
log.info("Started mail server (" + HOST + ":" + PORT + ")");
|
||||
}
|
||||
|
||||
public static void stop() {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
public static void createEmailAccount(String email, String password) {
|
||||
log.debug("--Creating email account " + email + "--");
|
||||
log.debug("Creating email account " + email);
|
||||
greenMail.setUser(email, password);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue