From e40320a8eda1b3cab945ac6258ecbd9761b00d62 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Mon, 9 Jun 2014 18:08:16 +0200 Subject: [PATCH] Added integration test for Spring Web Services Sample project --- .../sample/ws/SampleWsApplicationTests.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java diff --git a/spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java b/spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java new file mode 100644 index 0000000000..da2c3554eb --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java @@ -0,0 +1,56 @@ +package sample.ws; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.ws.client.core.WebServiceTemplate; + +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import java.io.StringReader; + +/** + * Tests handling SOAP message + * + * @author Maciej Walkowiak + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SampleWsApplication.class) +@WebAppConfiguration +@IntegrationTest +public class SampleWsApplicationTests { + private WebServiceTemplate webServiceTemplate = new WebServiceTemplate(); + + @Value("${local.server.port}") + private int serverPort; + + @Before + public void setUp() { + webServiceTemplate.setDefaultUri("http://localhost:" + serverPort + "/services/"); + } + + @Test + public void testSendingHolidayRequest() { + final String request = "" + + " " + + " 2013-10-20" + + " 2013-11-22" + + " " + + " " + + " 1" + + " John" + + " Doe" + + " " + + ""; + + StreamSource source = new StreamSource(new StringReader(request)); + StreamResult result = new StreamResult(System.out); + + webServiceTemplate.sendSourceAndReceiveToResult(source, result); + } +} \ No newline at end of file