1
2
3
4
5
6
7
8
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 import org.junit.Test;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertTrue;
23
24 public class SmtpNamespaceHandlerTestCase extends AbstractEmailNamespaceHandlerTestCase
25 {
26
27 @Override
28 protected String getConfigResources()
29 {
30 return "smtp-namespace-config.xml";
31 }
32
33 @Test
34 public void testConfig() throws Exception
35 {
36 SmtpConnector c = (SmtpConnector)muleContext.getRegistry().lookupConnector("smtpConnector");
37 assertNotNull(c);
38
39 assertEquals("abc@example.com", c.getBccAddresses());
40 assertEquals("bcd@example.com", c.getCcAddresses());
41 assertEquals("foo/bar", c.getContentType());
42 Properties headers = c.getCustomHeaders();
43 assertEquals(2, headers.size());
44 assertEquals("bar", headers.getProperty("foo"));
45 assertEquals("boz", headers.getProperty("baz"));
46 assertEquals("cde@example.com", c.getFromAddress());
47 assertEquals("def@example.com", c.getReplyToAddresses());
48 assertEquals("subject", c.getSubject());
49
50
51
52 assertTrue(c.isConnected());
53 assertTrue(c.isStarted());
54 }
55
56 @Test
57 public void testSecureConfig() throws Exception
58 {
59 SmtpsConnector c = (SmtpsConnector)muleContext.getRegistry().lookupConnector("smtpsConnector");
60 assertNotNull(c);
61
62 assertEquals("abc@example.com", c.getBccAddresses());
63 assertEquals("bcd@example.com", c.getCcAddresses());
64 assertEquals("foo/bar", c.getContentType());
65 Properties headers = c.getCustomHeaders();
66 assertEquals(2, headers.size());
67 assertEquals("bar", headers.getProperty("foo"));
68 assertEquals("boz", headers.getProperty("baz"));
69 assertEquals("cde@example.com", c.getFromAddress());
70 assertEquals("def@example.com", c.getReplyToAddresses());
71 assertEquals("subject", c.getSubject());
72
73
74
75
76 assertTrue(c.getClientKeyStore().endsWith("/empty.jks"));
77 assertEquals("password", c.getClientKeyStorePassword());
78
79 assertTrue(c.getTrustStore().endsWith("/empty.jks"));
80 assertEquals("password", c.getTrustStorePassword());
81
82 assertTrue(c.isConnected());
83 assertTrue(c.isStarted());
84 }
85
86 @Test
87 public void testEndpoint() throws MuleException
88 {
89 testOutboundEndpoint("global1", SmtpConnector.SMTP);
90 testOutboundEndpoint("global2", SmtpConnector.SMTP);
91 testOutboundEndpoint("global1s", SmtpsConnector.SMTPS);
92 testOutboundEndpoint("global2s", SmtpsConnector.SMTPS);
93 }
94 }