3 Replies Latest reply on Nov 19, 2009 11:31 PM by ifischer

    Testing the EmailTemplate using SeamTest

      Hi Guys,

      I want to test the Email functionality using the Seam test.

      My emailTemplate.xhtml is like

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <m:message xmlms = "http://www.w3.org/1999/xhtml"
      xmlns:m="http://jboss.com/products/seam/email"
      importance="normal">

      <m:header name="X-composed-By" value="Jboss Seam"/>
      <m:from name = "customer service" address="customerservice@test.dk"/>
      <m:replyTo address="webmaster@test.dk" />
      <m:to name="user"> test@test.com </m:to>
      <m:subject> New User Registration Information </m:subject>

      <m:body type="plain"> Hey User ,

      Welcome to the Skills website.
      Thanks for the registration.

      </m:body>

      </m:message>

      My RegistrationMailerTest.java

      @Test
              public void testSendWelcomeMail() throws Exception {
                      new FacesRequest() {
                             
                              @Override
                              protected void invokeApplication() throws Exception {
                                     
                                      MimeMessage renderedMessage = getRenderedMailMessage("/emailTemplate.xhtml");
                                      assert renderedMessage.getAllRecipients().length == 1;
                                      assert renderedMessage != null;
                                      System.out.println("The rendered message is : "+ renderedMessage);
                                      InternetAddress to = (InternetAddress) renderedMessage
                                                      .getAllRecipients()[0];
                                      assert to.getAddress().equals("webmaster@mathmagicians.dk");
                              }
                      }.run();
              }


      Running this test gives me Null pointer Exception. Actually the getRenderedMailMessage("/emailTemplate.xhtml") returns Null.

      I am just using the same build.xml generated by Seam-gen. How to fix this ??

      Any help is much appreciated as to how to test the emails.


      Best Regards,
      Sunil
        • 1. Re: Testing the EmailTemplate using SeamTest

          I'm having the same problem.
          Seam 2.2.0GA, project created with seam-gen.
          No matter what i try, the renderedMessage always becomes null in my test:




          @Test
          public void testRegistrieren() throws Exception {
               new FacesRequest() {
                    @Override 
                    protected void renderResponse() throws Exception {
                         MimeMessage renderedMessage = getRenderedMailMessage("mail/customer_activation_mail.xhtml");
                         // Throws a NullPointerException
                         assertEquals(renderedMessage.getAllRecipients().length, 1);
                    }
               }.run();
          }



          Anybody got a solution?

          • 2. Re: Testing the EmailTemplate using SeamTest

            Sorry, of course the getRenderedMailMessage has to be invoked in the invokeApplicationPhase. Anyway, still the same error (NullPointerException)

            • 3. Re: Testing the EmailTemplate using SeamTest

              Oh no, so simple ;)


              The jboss-seam-mail.jar was missing on the test classpath!