View Javadoc

1   /*
2    * $Id: ImapMessageRequesterTestCase.java 19873 2010-10-08 23:54:59Z 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  
19  import com.icegreen.greenmail.util.GreenMail;
20  import com.icegreen.greenmail.util.ServerSetup;
21  
22  public class ImapMessageRequesterTestCase extends DynamicPortTestCase
23  {
24      private static final String EMAIL = "bob@example.com";
25      private static final String MESSAGE = "Test email message";
26      private static final String PASSWORD = "password";
27      private static int PORT = -1;
28      private static final String USER = "bob";
29      
30      private GreenMail server;
31      
32      @Override
33      protected void doSetUp() throws Exception
34      {
35          super.doSetUp();
36          PORT = getPorts().get(0);
37          startGreenmailServer();
38      }
39  
40      private void startGreenmailServer() throws Exception
41      {
42          ServerSetup setup = new ServerSetup(PORT, null, ImapConnector.IMAP);
43          server = new GreenMail(setup);
44          server.start();
45  
46          GreenMailUtilities.storeEmail(server.getManagers().getUserManager(), EMAIL, USER, PASSWORD,
47              GreenMailUtilities.toMessage(MESSAGE, EMAIL, null));
48      }
49      
50      @Override
51      protected void doTearDown() throws Exception
52      {
53          server.stop();
54          super.doTearDown();
55      }
56  
57      @Override
58      protected String getConfigResources()
59      {
60          return "imap-message-requester.xml";
61      }
62  
63      public void testMessageRequester() throws Exception
64      {
65          String imapUri = String.format("imap://%1s:%2s@localhost:%3d/INBOX", USER, PASSWORD, PORT);
66          
67          MuleClient client = new MuleClient(muleContext);
68          MuleMessage message = client.request(imapUri, RECEIVE_TIMEOUT);
69          
70          assertNotNull(message);
71          assertEquals(MESSAGE, message.getPayload());
72      }
73  
74      @Override
75      protected int getNumPortsToFind()
76      {
77          return 1;
78      }
79  }
80  
81