This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-email.git
commit bc95895e2cf3e6d7fca06aeeb86c4508c3aea2da Author: Robert Munteanu <[email protected]> AuthorDate: Fri Jun 9 14:54:05 2017 +0000 SLING-6949 - Create testing utilities for email-enabled applications Implement message removal git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1798232 13f79535-47bb-0310-9956-ffa450edef68 --- .../sling/testing/email/impl/EMailServlet.java | 9 ++++- .../sling/testing/email/impl/EmailServletTest.java | 41 ++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/sling/testing/email/impl/EMailServlet.java b/src/main/java/org/apache/sling/testing/email/impl/EMailServlet.java index 25ff6ac..986adbd 100644 --- a/src/main/java/org/apache/sling/testing/email/impl/EMailServlet.java +++ b/src/main/java/org/apache/sling/testing/email/impl/EMailServlet.java @@ -46,6 +46,7 @@ import org.osgi.service.component.annotations.Reference; * a JSON object containing the configuration properties of the {@link SmtpServerWrapper}</li> * <li><tt>GET /system/sling/testing/email/messages</tt>, which returns the messages * currently held by the {@link SmtpServerWrapper}</li> + * <li><tt>DELETE /system/sling/testing/email</tt>, which removes all messages.</li> * </ol> */ @Component(service = Servlet.class, @@ -103,7 +104,13 @@ public class EMailServlet extends HttpServlet { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); break; } - + } + + @Override + protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + wiser.clearMessages(); + + resp.setStatus(HttpServletResponse.SC_NO_CONTENT); } } diff --git a/src/test/java/org/apache/sling/testing/email/impl/EmailServletTest.java b/src/test/java/org/apache/sling/testing/email/impl/EmailServletTest.java index f07d2d4..017fa3f 100644 --- a/src/test/java/org/apache/sling/testing/email/impl/EmailServletTest.java +++ b/src/test/java/org/apache/sling/testing/email/impl/EmailServletTest.java @@ -122,6 +122,47 @@ public class EmailServletTest { String readBody = JsonPath.read(new ByteArrayInputStream(out), "$.messages[0].['-Content-']"); assertThat("body", readBody, equalTo(body1)); } + + @Test + public void getMessages_empty() throws ServletException, IOException { + + // SLING-6947 + MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(ctx.resourceResolver()) { + @Override + public String getPathInfo() { + return "/messages"; + } + }; + + MockSlingHttpServletResponse response = new MockSlingHttpServletResponse(); + servlet.service(request, response); + + assertEquals("response.status", HttpServletResponse.SC_OK, response.getStatus()); + + // SLING-6948 + byte[] out = response.getOutputAsString().getBytes(); + int messageCount = JsonPath.read(new ByteArrayInputStream(out), "$.messages.length()"); + + assertThat("messages.length", messageCount, Matchers.equalTo(0)); + } + + @Test + public void deleteMessages() throws MessagingException, ServletException, IOException { + + // send an email + sendEmail("Test email", "A long message \r\nbody"); + + // delete all messages + MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(ctx.resourceResolver()); + request.setMethod("DELETE"); + MockSlingHttpServletResponse response = new MockSlingHttpServletResponse(); + servlet.service(request, response); + + assertEquals("response.status", HttpServletResponse.SC_NO_CONTENT, response.getStatus()); + + // validate that no messages are stored + getMessages_empty(); + } private void sendEmail(String subject, String body) throws MessagingException, AddressException { -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
