1   /*
2    * Copyright 2005-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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("server@example.com").size());
58          assertEquals("No client mail message received", 1, Mailbox.get("client@example.com").size());
59          XMLAssert.assertXMLEqual("Invalid content received", content, result.toString());
60  
61      }
62  
63  }