1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.transport.mail;
18
19 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.context.support.GenericApplicationContext;
21 import org.springframework.test.context.ContextConfiguration;
22 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
23 import org.springframework.ws.client.core.WebServiceTemplate;
24 import org.springframework.xml.transform.StringResult;
25 import org.springframework.xml.transform.StringSource;
26
27 import org.custommonkey.xmlunit.XMLAssert;
28 import org.junit.After;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.jvnet.mock_javamail.Mailbox;
32
33 import static org.junit.Assert.assertEquals;
34
35 @RunWith(SpringJUnit4ClassRunner.class)
36 @ContextConfiguration("mail-applicationContext.xml")
37 public class MailIntegrationTest {
38
39 @Autowired
40 private WebServiceTemplate webServiceTemplate;
41
42 @Autowired
43 private GenericApplicationContext applicationContext;
44
45 @After
46 public void clearMailbox() throws Exception {
47 Mailbox.clearAll();
48 }
49
50
51 @Test
52 public void testMailTransport() throws Exception {
53 String content = "<root xmlns='http://springframework.org/spring-ws'><child/></root>";
54 StringResult result = new StringResult();
55 webServiceTemplate.sendSourceAndReceiveToResult(new StringSource(content), result);
56 applicationContext.close();
57 assertEquals("Server mail message not deleted", 0, Mailbox.get("[email protected]").size());
58 assertEquals("No client mail message received", 1, Mailbox.get("[email protected]").size());
59 XMLAssert.assertXMLEqual("Invalid content received", content, result.toString());
60
61 }
62
63 }