1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.email;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16
17 import org.mule.api.MuleContext;
18 import org.mule.api.MuleException;
19 import org.mule.api.MuleMessage;
20 import org.mule.module.client.MuleClient;
21 import org.mule.tck.AbstractServiceAndFlowTestCase;
22 import org.mule.tck.AbstractServiceAndFlowTestCase.ConfigVariant;
23 import org.mule.tck.junit4.rule.DynamicPort;
24 import org.mule.transport.email.functional.AbstractEmailFunctionalTestCase;
25
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.Collection;
29 import java.util.List;
30
31 import javax.mail.internet.MimeMessage;
32
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.runners.Parameterized.Parameters;
36
37
38
39
40
41
42
43
44
45
46 public class EmailRoundTripTestCase extends AbstractServiceAndFlowTestCase
47 {
48
49 public EmailRoundTripTestCase(ConfigVariant variant, String configResources)
50 {
51 super(variant, configResources);
52 }
53
54 private AbstractGreenMailSupport greenMailSupport = null;
55
56 @Rule
57 public DynamicPort dynamicPort1 = new DynamicPort("port1");
58
59 @Rule
60 public DynamicPort dynamicPort2 = new DynamicPort("port2");
61
62 @Rule
63 public DynamicPort dynamicPort3 = new DynamicPort("port3");
64
65 @Rule
66 public DynamicPort dynamicPort4 = new DynamicPort("port4");
67
68 @Rule
69 public DynamicPort dynamicPort5 = new DynamicPort("port5");
70
71 @Rule
72 public DynamicPort dynamicPort6 = new DynamicPort("port6");
73
74 @Parameters
75 public static Collection<Object[]> parameters()
76 {
77 return Arrays.asList(new Object[][]{
78 {ConfigVariant.SERVICE, "email-round-trip-test-service.xml"},
79 {ConfigVariant.FLOW, "email-round-trip-test-flow.xml"}
80 });
81 }
82
83 @Override
84 protected MuleContext createMuleContext() throws Exception
85 {
86 startServer();
87 return super.createMuleContext();
88 }
89
90
91
92
93
94 public void startServer() throws Exception
95 {
96
97
98 greenMailSupport = new FixedPortGreenMailSupport(dynamicPort2.getNumber());
99
100 List<Integer> ports = new ArrayList<Integer>(6);
101 ports.add(dynamicPort1.getNumber());
102 ports.add(dynamicPort2.getNumber());
103 ports.add(dynamicPort3.getNumber());
104 ports.add(dynamicPort4.getNumber());
105 ports.add(dynamicPort5.getNumber());
106 ports.add(dynamicPort6.getNumber());
107
108 greenMailSupport.startServers(ports);
109 greenMailSupport.createBobAndStoreEmail(greenMailSupport.getValidMessage(AbstractGreenMailSupport.ALICE_EMAIL));
110 }
111
112
113
114
115
116 protected void doTearDown() throws Exception
117 {
118 greenMailSupport.stopServers();
119 super.doTearDown();
120 }
121
122 @Test
123 public void testRoundTrip() throws MuleException, InterruptedException
124 {
125
126
127 MuleClient client = new MuleClient(muleContext);
128 MuleMessage message = client.request("vm://rfc822", RECEIVE_TIMEOUT);
129 assertTrue(message.getPayload() instanceof byte[]);
130
131
132 greenMailSupport.getServers().waitForIncomingEmail(AbstractEmailFunctionalTestCase.DELIVERY_DELAY_MS, 1);
133 MimeMessage[] messages = greenMailSupport.getServers().getReceivedMessages();
134 assertNotNull("did not receive any messages", messages);
135 assertEquals("did not receive 1 mail", 1, messages.length);
136 }
137
138 }