From 42aba41d6bf4505bd77dc43232e73f73d576f9a8 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Sat, 12 Oct 2013 11:29:12 +0100 Subject: [PATCH] Make it easier to use test utils --- pom.xml | 5 ++ testsuite/README.md | 54 ----------------- testsuite/integration/README.md | 57 ++++++++++++++++++ testsuite/integration/pom.xml | 59 +++++++++++++------ .../keycloak/testutils/KeycloakServer.java | 4 ++ .../org/keycloak/testutils/MailServer.java | 3 + 6 files changed, 110 insertions(+), 72 deletions(-) delete mode 100644 testsuite/README.md create mode 100644 testsuite/integration/README.md diff --git a/pom.xml b/pom.xml index ed404ba617..61503c50f2 100755 --- a/pom.xml +++ b/pom.xml @@ -400,6 +400,11 @@ maven-jar-plugin 2.2 + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + diff --git a/testsuite/README.md b/testsuite/README.md deleted file mode 100644 index 00d5c0c85c..0000000000 --- a/testsuite/README.md +++ /dev/null @@ -1,54 +0,0 @@ -Executing testsuite -=================== - -Browser -------- - -The testsuite uses Sellenium. By default it uses the HtmlUnit WebDriver, but can also be executed with Chrome or Firefox. - -To run the tests with Firefox add `-Dbrowser=firefox` or for Chrome add `-Dbrowser=chrome` - - -Test utils -========== - -Keycloak server ---------------- - -To start a basic Keycloak server for testing run: - - mvn exec:java -Dexec.mainClass=org.keycloak.testutils.KeycloakServer - -or just run KeycloakServer from your favourite IDE! - -When starting the server it can also import a realm from a json file: - - mvn exec:java -Dexec.mainClass=org.keycloak.testutils.KeycloakServer -Dexec.args="-import testrealm.json" - -You can also change the host and port the server is bound to: - - mvn exec:java -Dexec.mainClass=org.keycloak.testutils.KeycloakServer -Dexec.args="-b host -p 8080" - -TOTP codes ----------- - -To generate totp codes without Google authenticator run: - - mvn exec:java -Dexec.mainClass=org.keycloak.testutils.TotpGenerator -Dexec.args="PJBX GURY NZIT C2JX I44T S3D2 JBKD G6SB" - -or just run TotpGenerator from your favourite IDE! - -Replace value of -Dexec.args with the secret from the totp configuration page - -Mail server ------------ - -To start a test mail server for testing email sending run: - - mvn exec:java -Dexec.mainClass=org.keycloak.testutils.MailServer - -or just run MailServer from your favourite IDE! - -To configure Keycloak to use the above server add: - - -Dkeycloak.mail.smtp.from=auto@keycloak.org -Dkeycloak.mail.smtp.host=localhost -Dkeycloak.mail.smtp.port=3025 diff --git a/testsuite/integration/README.md b/testsuite/integration/README.md new file mode 100644 index 0000000000..3145d38ee7 --- /dev/null +++ b/testsuite/integration/README.md @@ -0,0 +1,57 @@ +Executing testsuite +=================== + +Browser +------- + +The testsuite uses Sellenium. By default it uses the HtmlUnit WebDriver, but can also be executed with Chrome or Firefox. + +To run the tests with Firefox add `-Dbrowser=firefox` or for Chrome add `-Dbrowser=chrome` + + +Test utils +========== + +Keycloak server +--------------- + +To start a basic Keycloak server for testing run: + + mvn exec:java -Pkeycloak-server + +or run org.keycloak.testutils.KeycloakServer from your favourite IDE! + +When starting the server it can also import a realm from a json file: + + mvn exec:java -Pkeycloak-server -Dimport=testrealm.json + +TOTP codes +---------- + +To generate totp codes without Google authenticator run: + + mvn exec:java -Ptotp -Dsecret='PJBX GURY NZIT C2JX I44T S3D2 JBKD G6SB' + +or run org.keycloak.testutils.TotpGenerator from your favourite IDE! + +Replace value of -Dsecret with the secret from the totp configuration page (remember quotes!) + +Mail server +----------- + +To start a test mail server for testing email sending run: + + mvn exec:java -Pmail-server + +or run org.keycloak.testutils.MailServer from your favourite IDE! + +To configure Keycloak to use the above server add the following system properties: + + keycloak.mail.smtp.from=auto@keycloak.org + keycloak.mail.smtp.host=localhost + keycloak.mail.smtp.port=3025 + +For example if using the test utils Keycloak server start it with: + + mvn exec:java -Pkeycloak-server -Dkeycloak.mail.smtp.from=auto@keycloak.org -Dkeycloak.mail.smtp.host=localhost -Dkeycloak.mail.smtp.port=3025 + diff --git a/testsuite/integration/pom.xml b/testsuite/integration/pom.xml index 3184758b69..f0f3eeab35 100644 --- a/testsuite/integration/pom.xml +++ b/testsuite/integration/pom.xml @@ -205,26 +205,49 @@ - jboss-managed - - - org.jboss.as - jboss-as-arquillian-container-managed - test - 7.1.1.Final - - + keycloak-server + + + + org.codehaus.mojo + exec-maven-plugin + + org.keycloak.testutils.KeycloakServer + + + + - jboss-remote - - - org.jboss.as - jboss-as-arquillian-container-remote - test - 7.1.1.Final - - + mail-server + + + + org.codehaus.mojo + exec-maven-plugin + + org.keycloak.testutils.MailServer + + + + + + + totp + + + + org.codehaus.mojo + exec-maven-plugin + + org.keycloak.testutils.TotpGenerator + + ${secret} + + + + + \ No newline at end of file diff --git a/testsuite/integration/src/main/java/org/keycloak/testutils/KeycloakServer.java b/testsuite/integration/src/main/java/org/keycloak/testutils/KeycloakServer.java index 66192b0edc..afcedbee78 100644 --- a/testsuite/integration/src/main/java/org/keycloak/testutils/KeycloakServer.java +++ b/testsuite/integration/src/main/java/org/keycloak/testutils/KeycloakServer.java @@ -121,6 +121,10 @@ public class KeycloakServer { } } + if (System.getProperties().containsKey("import")) { + keycloak.importRealm(new FileInputStream(System.getProperty("import"))); + } + Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { diff --git a/testsuite/integration/src/main/java/org/keycloak/testutils/MailServer.java b/testsuite/integration/src/main/java/org/keycloak/testutils/MailServer.java index 42302e3575..8ba730a012 100644 --- a/testsuite/integration/src/main/java/org/keycloak/testutils/MailServer.java +++ b/testsuite/integration/src/main/java/org/keycloak/testutils/MailServer.java @@ -13,6 +13,9 @@ public class MailServer { GreenMail greenMail = new GreenMail(setup); greenMail.start(); + + System.out.println("Started mail server (localhost:3025)"); + System.out.println(); while (true) { int c = greenMail.getReceivedMessages().length;