1   /*
2    * $Id: SmtpNamespaceHandlerTestCase.java 11110 2008-02-28 13:55:36Z acooke $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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      protected String getConfigResources()
21      {
22          return "smtp-namespace-config.xml";
23      }
24  
25      public void testConfig() throws Exception
26      {
27          SmtpConnector c = (SmtpConnector)muleContext.getRegistry().lookupConnector("smtpConnector");
28          assertNotNull(c);
29  
30          assertEquals("abc@example.com", c.getBccAddresses());
31          assertEquals("bcd@example.com", c.getCcAddresses());
32          assertEquals("foo/bar", c.getContentType());
33          Properties headers = c.getCustomHeaders();
34          assertEquals(2, headers.size());
35          assertEquals("bar", headers.getProperty("foo"));
36          assertEquals("boz", headers.getProperty("baz"));
37          assertEquals("cde@example.com", c.getFromAddress());
38          assertEquals("def@example.com", c.getReplyToAddresses());
39          assertEquals("subject", c.getSubject());
40  
41          // authenticator?
42  
43          assertTrue(c.isConnected());
44          assertTrue(c.isStarted());
45      }
46  
47      public void testSecureConfig() throws Exception
48      {
49          SmtpsConnector c = (SmtpsConnector)muleContext.getRegistry().lookupConnector("smtpsConnector");
50          assertNotNull(c);
51  
52          assertEquals("abc@example.com", c.getBccAddresses());
53          assertEquals("bcd@example.com", c.getCcAddresses());
54          assertEquals("foo/bar", c.getContentType());
55          Properties headers = c.getCustomHeaders();
56          assertEquals(2, headers.size());
57          assertEquals("bar", headers.getProperty("foo"));
58          assertEquals("boz", headers.getProperty("baz"));
59          assertEquals("cde@example.com", c.getFromAddress());
60          assertEquals("def@example.com", c.getReplyToAddresses());
61          assertEquals("subject", c.getSubject());
62  
63          // authenticator?
64  
65          //The full path gets resolved, we're just checkng that the property got set
66          assertTrue(c.getClientKeyStore().endsWith("/greenmail-truststore"));
67          assertEquals("password", c.getClientKeyStorePassword());
68          //The full path gets resolved, we're just checkng that the property got set
69          assertTrue(c.getTrustStore().endsWith("/greenmail-truststore"));
70          assertEquals("password", c.getTrustStorePassword());
71  
72          assertTrue(c.isConnected());
73          assertTrue(c.isStarted());
74      }
75  
76      public void testEndpoint() throws MuleException
77      {
78          testEndpoint("global1", SmtpConnector.SMTP);
79          testEndpoint("global2", SmtpConnector.SMTP);
80          testEndpoint("global1s", SmtpsConnector.SMTPS);
81          testEndpoint("global2s", SmtpsConnector.SMTPS);
82      }
83  }