1+ package sample .ws ;
2+
3+ import org .junit .Before ;
4+ import org .junit .Test ;
5+ import org .junit .runner .RunWith ;
6+ import org .springframework .beans .factory .annotation .Value ;
7+ import org .springframework .boot .test .IntegrationTest ;
8+ import org .springframework .boot .test .SpringApplicationConfiguration ;
9+ import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
10+ import org .springframework .test .context .web .WebAppConfiguration ;
11+ import org .springframework .ws .client .core .WebServiceTemplate ;
12+
13+ import javax .xml .transform .stream .StreamResult ;
14+ import javax .xml .transform .stream .StreamSource ;
15+ import java .io .StringReader ;
16+
17+ /**
18+ * Tests handling SOAP message
19+ *
20+ * @author Maciej Walkowiak
21+ */
22+ @ RunWith (SpringJUnit4ClassRunner .class )
23+ @ SpringApplicationConfiguration (classes = SampleWsApplication .class )
24+ @ WebAppConfiguration
25+ @ IntegrationTest
26+ public class SampleWsApplicationTests {
27+ private WebServiceTemplate webServiceTemplate = new WebServiceTemplate ();
28+
29+ @ Value ("${local.server.port}" )
30+ private int serverPort ;
31+
32+ @ Before
33+ public void setUp () {
34+ webServiceTemplate .setDefaultUri ("http://localhost:" + serverPort + "/services/" );
35+ }
36+
37+ @ Test
38+ public void testSendingHolidayRequest () {
39+ final String request = "<hr:HolidayRequest xmlns:hr=\" http://mycompany.com/hr/schemas\" >"
40+ + " <hr:Holiday>"
41+ + " <hr:StartDate>2013-10-20</hr:StartDate>"
42+ + " <hr:EndDate>2013-11-22</hr:EndDate>"
43+ + " </hr:Holiday>"
44+ + " <hr:Employee>"
45+ + " <hr:Number>1</hr:Number>"
46+ + " <hr:FirstName>John</hr:FirstName>"
47+ + " <hr:LastName>Doe</hr:LastName>"
48+ + " </hr:Employee>"
49+ + "</hr:HolidayRequest>" ;
50+
51+ StreamSource source = new StreamSource (new StringReader (request ));
52+ StreamResult result = new StreamResult (System .out );
53+
54+ webServiceTemplate .sendSourceAndReceiveToResult (source , result );
55+ }
56+ }
0 commit comments