diff --git a/.github/workflows/quickstart_mail_ci.yml b/.github/workflows/quickstart_mail_ci.yml index 5d602100ad..2e68ee06ea 100644 --- a/.github/workflows/quickstart_mail_ci.yml +++ b/.github/workflows/quickstart_mail_ci.yml @@ -1,11 +1,13 @@ name: WildFly Mail Quickstart CI -on: - pull_request: - types: [opened, synchronize, reopened, ready_for_review] - paths: - - 'mail/**' - - '.github/workflows/quickstart_ci.yml' +#on: +# pull_request: +# types: [opened, synchronize, reopened, ready_for_review] +# paths: +# - 'mail/**' +# - '.github/workflows/quickstart_ci.yml' + +on: workflow_dispatch jobs: call-quickstart_ci: uses: ./.github/workflows/quickstart_ci.yml @@ -13,3 +15,4 @@ jobs: QUICKSTART_PATH: mail TEST_PROVISIONED_SERVER: true TEST_OPENSHIFT: false + MATRIX_OS: '"ubuntu-20.04"' diff --git a/.github/workflows/quickstart_mail_ci_before.sh b/.github/workflows/quickstart_mail_ci_before.sh new file mode 100755 index 0000000000..66cf6ff715 --- /dev/null +++ b/.github/workflows/quickstart_mail_ci_before.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# Start apache James with the required configuration +docker run -d --rm --name "apache-james" \ + -p 1465:465 \ + -p 1993:993 \ + -p 1025:25 \ + -p 1110:110 \ + -p 1587:587 \ + -p 1143:143 \ + -v ${GITHUB_WORKSPACE}/quickstarts/mail/mail-server-conf/imapserver.xml:/root/conf/imapserver.xml \ + -v ${GITHUB_WORKSPACE}/quickstarts/mail/mail-server-conf/pop3server.xml:/root/conf/pop3server.xml \ + -v ${GITHUB_WORKSPACE}/quickstarts/mail/mail-server-conf/smtpserver.xml:/root/conf/smtpserver.xml \ + apache/james:demo-3.8.0 diff --git a/mail/Dockerfile b/mail/Dockerfile deleted file mode 100644 index 4e78f68f7e..0000000000 --- a/mail/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM linagora/james-jpa-sample:3.0.1 - -RUN chgrp -R 0 /root /logs /var && \ - chmod -R g=u /root /logs /var && \ - sed -i s/:143/:1143/g /root/conf/imapserver.xml && \ - sed -i s/:993/:1993/g /root/conf/imapserver.xml && \ - sed -i s/:110/:1110/g /root/conf/pop3server.xml && \ - sed -i s/:25/:1025/g /root/conf/smtpserver.xml && \ - sed -i s/:465/:1465/g /root/conf/smtpserver.xml && \ - sed -i s/:587/:1587/g /root/conf/smtpserver.xml - -RUN echo "touch /root/done.mark" >> /root/initialdata.sh - -ENTRYPOINT ["/root/startup.sh"] \ No newline at end of file diff --git a/mail/docker-compose.yaml b/mail/docker-compose.yaml index e70e4049e8..f20af5c8a5 100644 --- a/mail/docker-compose.yaml +++ b/mail/docker-compose.yaml @@ -11,6 +11,12 @@ services: - "1587:587" - "1143:143" volumes: - - "./mail-server-conf/imapserver.xml:/root/conf/imapserver.xml" - - "./mail-server-conf/pop3server.xml:/root/conf/pop3server.xml" - - "./mail-server-conf/smtpserver.xml:/root/conf/smtpserver.xml" + - ./mail-server-conf/imapserver.xml:/root/conf/imapserver.xml + - ./mail-server-conf/pop3server.xml:/root/conf/pop3server.xml + - ./mail-server-conf/smtpserver.xml:/root/conf/smtpserver.xml + healthcheck: + test: [ "CMD-SHELL", "/bin/james-cli -h 127.0.0.1 -p 9999 ListUsers | grep -q 'user03@james.local'" ] + interval: 5s + timeout: 1m + retries: 5 + start_period: 20s diff --git a/mail/pom.xml b/mail/pom.xml index 6cccd019bd..69b557d8ec 100644 --- a/mail/pom.xml +++ b/mail/pom.xml @@ -49,6 +49,9 @@ ${version.server} 4.2.0.Final + + 4.15.0 + 5.6.2 @@ -148,6 +151,18 @@ junit test + + org.seleniumhq.selenium + selenium-java + ${version.org.seleniumhq.selenium} + test + + + + io.github.bonigarcia + webdrivermanager + ${version.webdrivermanager} + @@ -191,6 +206,7 @@ + core-tools core-server mail jsf diff --git a/mail/src/main/java/org/jboss/as/quickstarts/mail/Email.java b/mail/src/main/java/org/jboss/as/quickstarts/mail/Email.java index c97758ba48..0e76b078da 100644 --- a/mail/src/main/java/org/jboss/as/quickstarts/mail/Email.java +++ b/mail/src/main/java/org/jboss/as/quickstarts/mail/Email.java @@ -17,9 +17,9 @@ package org.jboss.as.quickstarts.mail; import jakarta.annotation.Resource; +import jakarta.enterprise.context.SessionScoped; import jakarta.faces.application.FacesMessage; import jakarta.faces.context.FacesContext; -import jakarta.faces.view.ViewScoped; import jakarta.inject.Named; import jakarta.mail.Address; import jakarta.mail.Folder; @@ -31,6 +31,7 @@ import jakarta.mail.internet.InternetAddress; import jakarta.mail.internet.MimeMessage; +import java.io.IOException; import java.io.Serializable; /** @@ -51,7 +52,7 @@ */ @Named -@ViewScoped +@SessionScoped public class Email implements Serializable { private static final long serialVersionUID = 1544680932114626710L; @@ -72,7 +73,9 @@ public class Email implements Serializable { private String body; private String pop3User = "user02@james.local"; + private String pop3Password = "1234"; + private String pop3Emails; private String imapEmails; @@ -111,9 +114,14 @@ public void resetSmtp() { public void retrievePop3() throws Exception { try { pop3Emails = retrieveEmails("pop3", pop3User, pop3Password); + if (pop3Emails == null) { + FacesContext context = FacesContext.getCurrentInstance(); + FacesMessage facesMessage = new FacesMessage("No message found."); + context.addMessage(null, facesMessage); + } } catch (Exception e) { FacesContext context = FacesContext.getCurrentInstance(); - FacesMessage facesMessage = new FacesMessage("Error retrieving emails using Pop3. " + e.getMessage()); + FacesMessage facesMessage = new FacesMessage("Error retrieving emails using POP3. " + e.getMessage()); context.addMessage(null, facesMessage); } } @@ -127,9 +135,14 @@ public void resetPop3() { public void retrieveImap() throws Exception { try { imapEmails = retrieveEmails("imap"); + if (imapEmails == null) { + FacesContext context = FacesContext.getCurrentInstance(); + FacesMessage facesMessage = new FacesMessage("No message found."); + context.addMessage(null, facesMessage); + } } catch (Exception e) { FacesContext context = FacesContext.getCurrentInstance(); - FacesMessage facesMessage = new FacesMessage("Error retrieving emails using Pop3. " + e.getMessage()); + FacesMessage facesMessage = new FacesMessage("Error retrieving emails using IMAP. " + e.getMessage()); context.addMessage(null, facesMessage); } } @@ -138,11 +151,11 @@ public void resetImap() { imapEmails = null; } - private String retrieveEmails(String protocol) throws MessagingException { + private String retrieveEmails(String protocol) throws MessagingException, IOException { return retrieveEmails(protocol, null, null); } - private String retrieveEmails(String protocol, String user, String password) throws MessagingException { + private String retrieveEmails(String protocol, String user, String password) throws MessagingException, IOException { Store store = mySession.getStore(protocol); if (user != null && !user.trim().isEmpty()) { store.connect(user, password); @@ -158,10 +171,6 @@ private String retrieveEmails(String protocol, String user, String password) thr Message[] messages = inbox.getMessages(); if (messages.length == 0) { - FacesContext context = FacesContext.getCurrentInstance(); - FacesMessage facesMessage = new FacesMessage("No message found for " + user); - context.addMessage(null, facesMessage); - return null; } @@ -176,6 +185,7 @@ private String retrieveEmails(String protocol, String user, String password) thr sb.append("Message ").append((i + 1)).append("\n"); sb.append("From : ").append(messages[i].getFrom()[0]).append("\n"); sb.append("Subject : ").append(messages[i].getSubject()).append("\n"); + sb.append("Body : ").append(messages[i].getContent().toString()).append("\n"); sb.append("Sent Date : ").append(messages[i].getSentDate()).append("\n"); sb.append("----------------------------------").append("\n"); } diff --git a/mail/src/main/webapp/home.xhtml b/mail/src/main/webapp/home.xhtml index e25c871526..4179bafde5 100644 --- a/mail/src/main/webapp/home.xhtml +++ b/mail/src/main/webapp/home.xhtml @@ -36,39 +36,39 @@
- - - + + +
- - - + + +
- - - + + +
- - - + + +
- + - +
- + @@ -79,32 +79,32 @@
- - - + + +
- - - + + +
- - + +
- + - +
- +
@@ -115,20 +115,20 @@
- - + +
- + - +
- +
\ No newline at end of file diff --git a/mail/src/test/java/org/jboss/as/quickstarts/mail/MailTestCase.java b/mail/src/test/java/org/jboss/as/quickstarts/mail/MailTestCase.java deleted file mode 100644 index c702f93207..0000000000 --- a/mail/src/test/java/org/jboss/as/quickstarts/mail/MailTestCase.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.jboss.as.quickstarts.mail; - -public class MailTestCase { -} diff --git a/mail/src/test/java/org/jboss/as/quickstarts/mail/MailTestCaseIT.java b/mail/src/test/java/org/jboss/as/quickstarts/mail/MailTestCaseIT.java new file mode 100644 index 0000000000..dd84723c0e --- /dev/null +++ b/mail/src/test/java/org/jboss/as/quickstarts/mail/MailTestCaseIT.java @@ -0,0 +1,143 @@ +package org.jboss.as.quickstarts.mail; + +import io.github.bonigarcia.wdm.WebDriverManager; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; +import org.openqa.selenium.By; +import org.openqa.selenium.StaleElementReferenceException; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.support.ui.Wait; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.time.Duration; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class MailTestCaseIT { + + private static final String DEFAULT_SERVER_HOST = "http://localhost:8080/mail"; + + private WebDriver driver; + + @Before + public void testSetup() { + WebDriverManager.chromedriver().setup(); + + ChromeOptions options = new ChromeOptions(); + options.addArguments("--no-sandbox"); + options.addArguments("--disable-dev-shm-usage"); + options.addArguments("--headless"); + + driver = new ChromeDriver(options); + driver.manage().window().maximize(); + + String serverHost = System.getenv("SERVER_HOST"); + if (serverHost == null) { + serverHost = System.getProperty("server.host"); + } + if (serverHost == null) { + serverHost = DEFAULT_SERVER_HOST; + } + + driver.get(serverHost); + driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500)); + } + + @After + public void cleanUp() { + if (driver != null) { + driver.close(); + } + } + + @Test + public void a_testSMTP() { + Wait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); + + WebElement from = driver.findElement(By.id("smtp_from")); + WebElement to = driver.findElement(By.id("smtp_to")); + WebElement subject = driver.findElement(By.id("smtp_subject")); + WebElement body = driver.findElement(By.id("smtp_body")); + + from.clear(); + from.sendKeys("user01@james.local"); + + to.clear(); + to.sendKeys("user02@james.local"); + + subject.clear(); + subject.sendKeys("This is a test"); + + body.clear(); + body.sendKeys("Hello user02, I've sent an email."); + + WebElement submitButton = driver.findElement(By.id("smtp_send_btn")); + submitButton.click(); + + WebElement message = driver.findElement(By.xpath("//ul[@id='smtp_messages']/li")); + wait.until(d -> message.isDisplayed()); + + Assert.assertEquals("Unexpected result messages after sending an email via SMTP.", "Email sent to user02@james.local", message.getText()); + } + + @Test + public void b_retrievePOP3() { + Wait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); + + WebElement user = driver.findElement(By.id("pop3_user")); + WebElement password = driver.findElement(By.id("pop3_password")); + + user.clear(); + user.sendKeys("user02@james.local"); + + password.clear(); + password.sendKeys("1234"); + + WebElement submitButton = driver.findElement(By.id("pop3_get_emails_btn")); + submitButton.click(); + + wait.until(d -> { + try { + WebElement emails = driver.findElement(By.id("pop3_emails")); + return !emails.getText().isEmpty(); + } catch (StaleElementReferenceException sere) { + return false; + } + }); + + WebElement emails = driver.findElement(By.id("pop3_emails")); + Assert.assertTrue("Expected From not found: " + emails.getText(), emails.getText().contains("From : user01@james.local")); + Assert.assertTrue("Expected Subject not found: " + emails.getText(), emails.getText().contains("Subject : This is a test")); + Assert.assertTrue("Expected Body not found : " + emails.getText(), emails.getText().contains("Body : Hello user02, I've sent an email.")); + } + + + @Test + public void c_retrieveIMAP() { + Wait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); + + WebElement submitButton = driver.findElement(By.id("imap_get_emails_btn")); + submitButton.click(); + + wait.until(d -> { + try { + WebElement emails = driver.findElement(By.id("imap_emails")); + return !emails.getText().isEmpty(); + } catch (StaleElementReferenceException sere) { + return false; + } + }); + + WebElement emails = driver.findElement(By.id("imap_emails")); + Assert.assertNotNull("IMAP No messages found.", emails.getText()); + Assert.assertTrue("Expected email not found.", emails.getText().contains("From : user01@james.local")); + Assert.assertTrue("Expected email not found.", emails.getText().contains("Subject : This is a test")); + Assert.assertTrue("Expected email not found.", emails.getText().contains("Body : Hello user02, I've sent an email.")); + } +}