View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.email.config;
8   
9   import org.mule.api.MuleException;
10  import org.mule.transport.email.ImapConnector;
11  import org.mule.transport.email.ImapsConnector;
12  
13  import javax.mail.Flags;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertEquals;
18  import static org.junit.Assert.assertFalse;
19  import static org.junit.Assert.assertNotNull;
20  import static org.junit.Assert.assertNull;
21  import static org.junit.Assert.assertTrue;
22  
23  public class ImapNamespaceHandlerTestCase extends AbstractEmailNamespaceHandlerTestCase
24  {
25      
26      @Override
27      protected String getConfigResources()
28      {
29          return "imap-namespace-config.xml";
30      }
31  
32      @Test
33      public void testConfig() throws Exception
34      {
35          ImapConnector c = (ImapConnector)muleContext.getRegistry().lookupConnector("imapConnector");
36          assertNotNull(c);
37  
38          assertTrue(c.isBackupEnabled());
39          assertEquals("newBackup", c.getBackupFolder());
40          assertEquals(1234, c.getCheckFrequency());
41          assertEquals("newMailbox", c.getMailboxFolder());
42          assertEquals(false, c.isDeleteReadMessages());
43  
44          // authenticator?
45  
46          assertTrue(c.isConnected());
47          assertTrue(c.isStarted());
48          
49          assertEquals(Flags.Flag.SEEN, c.getDefaultProcessMessageAction());
50      }
51  
52      @Test
53      public void testSecureConfig() throws Exception
54      {
55          ImapsConnector c = (ImapsConnector)muleContext.getRegistry().lookupConnector("imapsConnector");
56          assertNotNull(c);
57  
58          assertFalse(c.isBackupEnabled());
59          assertEquals("newBackup", c.getBackupFolder());
60          assertEquals(1234, c.getCheckFrequency());
61          assertEquals("newMailbox", c.getMailboxFolder());
62          assertEquals(false, c.isDeleteReadMessages());
63  
64          // authenticator?
65  
66          //The full path gets resolved, we're just checkng that the property got set
67          assertTrue(c.getClientKeyStore().endsWith("/empty.jks"));
68          assertEquals("password", c.getClientKeyStorePassword());
69          //The full path gets resolved, we're just checkng that the property got set
70          assertTrue(c.getTrustStore().endsWith("/empty.jks"));
71          assertEquals("password", c.getTrustStorePassword());
72  
73          assertTrue(c.isConnected());
74          assertTrue(c.isStarted());
75          
76          assertNull(c.getDefaultProcessMessageAction());
77      }
78  
79      @Test
80      public void testEndpoint() throws MuleException
81      {
82          testInboundEndpoint("global1", ImapConnector.IMAP);
83          testInboundEndpoint("global2", ImapConnector.IMAP);
84          testInboundEndpoint("global1s", ImapsConnector.IMAPS);
85          testInboundEndpoint("global2s", ImapsConnector.IMAPS);
86      }
87  
88  }