View Javadoc

1   /*
2    * $Id: SmtpNamespaceHandlerTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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  package org.mule.transport.email.config;
11  
12  import org.mule.api.MuleException;
13  import org.mule.transport.email.SmtpConnector;
14  import org.mule.transport.email.SmtpsConnector;
15  
16  import java.util.Properties;
17  
18  public class SmtpNamespaceHandlerTestCase extends AbstractEmailNamespaceHandlerTestCase
19  {
20      @Override
21      protected String getConfigResources()
22      {
23          return "smtp-namespace-config.xml";
24      }
25  
26      public void testConfig() throws Exception
27      {
28          SmtpConnector c = (SmtpConnector)muleContext.getRegistry().lookupConnector("smtpConnector");
29          assertNotNull(c);
30  
31          assertEquals("abc@example.com", c.getBccAddresses());
32          assertEquals("bcd@example.com", c.getCcAddresses());
33          assertEquals("foo/bar", c.getContentType());
34          Properties headers = c.getCustomHeaders();
35          assertEquals(2, headers.size());
36          assertEquals("bar", headers.getProperty("foo"));
37          assertEquals("boz", headers.getProperty("baz"));
38          assertEquals("cde@example.com", c.getFromAddress());
39          assertEquals("def@example.com", c.getReplyToAddresses());
40          assertEquals("subject", c.getSubject());
41  
42          // authenticator?
43  
44          assertTrue(c.isConnected());
45          assertTrue(c.isStarted());
46      }
47  
48      public void testSecureConfig() throws Exception
49      {
50          SmtpsConnector c = (SmtpsConnector)muleContext.getRegistry().lookupConnector("smtpsConnector");
51          assertNotNull(c);
52  
53          assertEquals("abc@example.com", c.getBccAddresses());
54          assertEquals("bcd@example.com", c.getCcAddresses());
55          assertEquals("foo/bar", c.getContentType());
56          Properties headers = c.getCustomHeaders();
57          assertEquals(2, headers.size());
58          assertEquals("bar", headers.getProperty("foo"));
59          assertEquals("boz", headers.getProperty("baz"));
60          assertEquals("cde@example.com", c.getFromAddress());
61          assertEquals("def@example.com", c.getReplyToAddresses());
62          assertEquals("subject", c.getSubject());
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  
77      public void testEndpoint() throws MuleException
78      {
79          testOutboundEndpoint("global1", SmtpConnector.SMTP);
80          testOutboundEndpoint("global2", SmtpConnector.SMTP);
81          testOutboundEndpoint("global1s", SmtpsConnector.SMTPS);
82          testOutboundEndpoint("global2s", SmtpsConnector.SMTPS);
83      }
84  }