View Javadoc

1   /*
2    * $Id: ImapMessageRequesterTestCase.java 20738 2010-12-15 02:42:53Z dzapata $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.email.functional;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.DynamicPortTestCase;
16  import org.mule.transport.email.GreenMailUtilities;
17  import org.mule.transport.email.ImapConnector;
18  import org.mule.transport.email.Pop3Connector;
19  
20  import com.icegreen.greenmail.util.GreenMail;
21  import com.icegreen.greenmail.util.ServerSetup;
22  
23  public class ImapMessageRequesterTestCase extends DynamicPortTestCase
24  {
25      private static final String EMAIL = "bob@example.com";
26      private static final String MESSAGE = "Test email message";
27      private static final String PASSWORD = "password";
28      private static int PORT = -1;
29      private static final String USER = "bob";
30      
31      private GreenMail server;
32  
33      public ImapMessageRequesterTestCase()
34      {
35          super();
36      }
37  
38      @Override
39      protected void suitePreSetUp() throws Exception
40      {
41          super.doSetUp();
42          PORT = getPorts().get(0);
43          startGreenmailServer();
44      }    
45      
46      private void startGreenmailServer() throws Exception
47      {
48          ServerSetup setup = new ServerSetup(PORT, null, ImapConnector.IMAP);
49          server = new GreenMail(setup);
50          server.start();
51          GreenMailUtilities.storeEmail(server.getManagers().getUserManager(), EMAIL, USER, PASSWORD,
52              GreenMailUtilities.toMessage(MESSAGE, EMAIL, null));
53      }
54              
55      @Override
56      protected void doTearDown() throws Exception
57      {
58          server.stop();
59          super.doTearDown();
60      }
61  
62      @Override
63      protected String getConfigResources()
64      {
65          return "imap-message-requester.xml";
66      }
67  
68      public void testMessageRequester() throws Exception
69      {
70          String imapUri = String.format("imap://%1s:%2s@localhost:%3d/INBOX", USER, PASSWORD, PORT);
71          
72          MuleClient client = new MuleClient(muleContext);
73          MuleMessage message = client.request(imapUri, RECEIVE_TIMEOUT);
74          
75          assertNotNull(message);
76          assertEquals(MESSAGE, message.getPayload());
77      }
78  
79      @Override
80      protected int getNumPortsToFind()
81      {
82          return 1;
83      }
84  }
85  
86