Skip to content

Commit 9b41bbd

Browse files
committed
Polish Spring-WS smoke test
This commit polishes the smoke test for Spring Web Services, namely clearing unused dependencies and clarify the necessary configuration: 1. No need to extend from `WsConfigurationAdapter` if no advanced configuration is required 2. Spring Web Services creates a `XsdSchema` bean whose name matches the name of the file. Added a `@Qualifier("hr")` to make that more obvious as it would break if an additional schema was to be added. Closes gh-44515
1 parent 05082ce commit 9b41bbd

File tree

7 files changed

+50
-47
lines changed

7 files changed

+50
-47
lines changed

Diff for: spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/build.gradle

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ dependencies {
1010

1111
runtimeOnly("jaxen:jaxen")
1212
runtimeOnly("wsdl4j:wsdl4j")
13-
runtimeOnly("jakarta.activation:jakarta.activation-api")
14-
runtimeOnly("org.glassfish.jaxb:jaxb-runtime")
15-
13+
1614
testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
1715
testImplementation("org.springframework.ws:spring-ws-test")
1816
}

Diff for: spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/WebServiceConfig.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,22 +16,22 @@
1616

1717
package smoketest.webservices;
1818

19+
import org.springframework.beans.factory.annotation.Qualifier;
1920
import org.springframework.context.annotation.Bean;
2021
import org.springframework.context.annotation.Configuration;
21-
import org.springframework.ws.config.annotation.WsConfigurerAdapter;
2222
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
2323
import org.springframework.xml.xsd.XsdSchema;
2424

2525
@Configuration(proxyBeanMethods = false)
26-
public class WebServiceConfig extends WsConfigurerAdapter {
26+
class WebServiceConfig {
2727

2828
@Bean(name = "holiday")
29-
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
29+
DefaultWsdl11Definition defaultWsdl11Definition(@Qualifier("hr") XsdSchema hrSchema) {
3030
DefaultWsdl11Definition wsdl = new DefaultWsdl11Definition();
3131
wsdl.setPortTypeName("HumanResource");
3232
wsdl.setLocationUri("/holidayService/");
3333
wsdl.setTargetNamespace("https://company.example.com/hr/definitions");
34-
wsdl.setSchema(countriesSchema);
34+
wsdl.setSchema(hrSchema);
3535
return wsdl;
3636
}
3737

Diff for: spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/endpoint/HolidayEndpoint.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
1616

1717
package smoketest.webservices.endpoint;
1818

19-
import java.text.SimpleDateFormat;
20-
import java.util.Date;
19+
import java.time.LocalDate;
2120

2221
import org.jdom2.Element;
2322
import org.jdom2.Namespace;
@@ -54,10 +53,9 @@ public HolidayEndpoint(HumanResourceService humanResourceService) {
5453
}
5554

5655
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "HolidayRequest")
57-
public void handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception {
58-
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
59-
Date startDate = dateFormat.parse(this.startDateExpression.evaluateFirst(holidayRequest).getText());
60-
Date endDate = dateFormat.parse(this.endDateExpression.evaluateFirst(holidayRequest).getText());
56+
public void handleHolidayRequest(@RequestPayload Element holidayRequest) {
57+
LocalDate startDate = LocalDate.parse(this.startDateExpression.evaluateFirst(holidayRequest).getText());
58+
LocalDate endDate = LocalDate.parse(this.endDateExpression.evaluateFirst(holidayRequest).getText());
6159
String name = this.nameExpression.evaluateFirst(holidayRequest);
6260
this.humanResourceService.bookHoliday(startDate, endDate, name);
6361
}

Diff for: spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/service/HumanResourceService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,10 +16,10 @@
1616

1717
package smoketest.webservices.service;
1818

19-
import java.util.Date;
19+
import java.time.LocalDate;
2020

2121
public interface HumanResourceService {
2222

23-
void bookHoliday(Date startDate, Date endDate, String name);
23+
void bookHoliday(LocalDate startDate, LocalDate endDate, String name);
2424

2525
}

Diff for: spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/main/java/smoketest/webservices/service/StubHumanResourceService.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,21 +16,21 @@
1616

1717
package smoketest.webservices.service;
1818

19-
import java.util.Date;
19+
import java.time.LocalDate;
2020

2121
import org.apache.commons.logging.Log;
2222
import org.apache.commons.logging.LogFactory;
2323

2424
import org.springframework.stereotype.Service;
2525

2626
@Service
27-
public class StubHumanResourceService implements HumanResourceService {
27+
class StubHumanResourceService implements HumanResourceService {
2828

29-
private final Log logger = LogFactory.getLog(StubHumanResourceService.class);
29+
private static final Log logger = LogFactory.getLog(StubHumanResourceService.class);
3030

3131
@Override
32-
public void bookHoliday(Date startDate, Date endDate, String name) {
33-
this.logger.info("Booking holiday for [" + startDate + " - " + endDate + "] for [" + name + "]");
32+
public void bookHoliday(LocalDate startDate, LocalDate endDate, String name) {
33+
logger.info("Booking holiday for [" + startDate + " - " + endDate + "] for [" + name + "]");
3434
}
3535

3636
}

Diff for: spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webservices/src/test/java/smoketest/webservices/SampleWsApplicationTests.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,11 +50,18 @@ void setUp() {
5050

5151
@Test
5252
void testSendingHolidayRequest(CapturedOutput output) {
53-
final String request = "<hr:HolidayRequest xmlns:hr=\"https://company.example.com/hr/schemas\">"
54-
+ " <hr:Holiday> <hr:StartDate>2013-10-20</hr:StartDate>"
55-
+ " <hr:EndDate>2013-11-22</hr:EndDate> </hr:Holiday> <hr:Employee>"
56-
+ " <hr:Number>1</hr:Number> <hr:FirstName>John</hr:FirstName>"
57-
+ " <hr:LastName>Doe</hr:LastName> </hr:Employee></hr:HolidayRequest>";
53+
String request = """
54+
<hr:HolidayRequest xmlns:hr="https://company.example.com/hr/schemas">
55+
<hr:Holiday>
56+
<hr:StartDate>2013-10-20</hr:StartDate>
57+
<hr:EndDate>2013-11-22</hr:EndDate>
58+
</hr:Holiday>
59+
<hr:Employee>
60+
<hr:Number>1</hr:Number>
61+
<hr:FirstName>John</hr:FirstName>
62+
<hr:LastName>Doe</hr:LastName>
63+
</hr:Employee>
64+
</hr:HolidayRequest>""";
5865
StreamSource source = new StreamSource(new StringReader(request));
5966
StreamResult result = new StreamResult(System.out);
6067
this.webServiceTemplate.sendSourceAndReceiveToResult(source, result);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,21 +17,16 @@
1717
package smoketest.webservices;
1818

1919
import java.io.StringReader;
20-
import java.text.DateFormat;
21-
import java.text.ParseException;
22-
import java.text.SimpleDateFormat;
20+
import java.time.LocalDate;
2321

2422
import javax.xml.transform.stream.StreamSource;
2523

2624
import org.junit.jupiter.api.Test;
27-
import org.junit.jupiter.api.extension.ExtendWith;
2825
import smoketest.webservices.service.HumanResourceService;
2926

3027
import org.springframework.beans.factory.annotation.Autowired;
3128
import org.springframework.boot.test.autoconfigure.webservices.server.WebServiceServerTest;
3229
import org.springframework.boot.test.mock.mockito.MockBean;
33-
import org.springframework.boot.test.system.CapturedOutput;
34-
import org.springframework.boot.test.system.OutputCaptureExtension;
3530
import org.springframework.ws.test.server.MockWebServiceClient;
3631
import org.springframework.ws.test.server.RequestCreators;
3732
import org.springframework.ws.test.server.ResponseMatchers;
@@ -43,9 +38,9 @@
4338
* {@link MockWebServiceClient}.
4439
*
4540
* @author Andy Wilkinson
41+
* @author Stephane Nicoll
4642
*/
4743
@WebServiceServerTest
48-
@ExtendWith(OutputCaptureExtension.class)
4944
class WebServiceServerTestSampleWsApplicationTests {
5045

5146
@MockBean
@@ -55,17 +50,22 @@ class WebServiceServerTestSampleWsApplicationTests {
5550
private MockWebServiceClient client;
5651

5752
@Test
58-
void testSendingHolidayRequest(CapturedOutput output) throws ParseException {
59-
String request = "<hr:HolidayRequest xmlns:hr=\"https://company.example.com/hr/schemas\">"
60-
+ " <hr:Holiday> <hr:StartDate>2013-10-20</hr:StartDate>"
61-
+ " <hr:EndDate>2013-11-22</hr:EndDate> </hr:Holiday> <hr:Employee>"
62-
+ " <hr:Number>1</hr:Number> <hr:FirstName>John</hr:FirstName>"
63-
+ " <hr:LastName>Doe</hr:LastName> </hr:Employee></hr:HolidayRequest>";
53+
void testSendingHolidayRequest() {
54+
String request = """
55+
<hr:HolidayRequest xmlns:hr="https://company.example.com/hr/schemas">
56+
<hr:Holiday>
57+
<hr:StartDate>2013-10-20</hr:StartDate>
58+
<hr:EndDate>2013-11-22</hr:EndDate>
59+
</hr:Holiday>
60+
<hr:Employee>
61+
<hr:Number>1</hr:Number>
62+
<hr:FirstName>John</hr:FirstName>
63+
<hr:LastName>Doe</hr:LastName>
64+
</hr:Employee>
65+
</hr:HolidayRequest>""";
6466
StreamSource source = new StreamSource(new StringReader(request));
6567
this.client.sendRequest(RequestCreators.withPayload(source)).andExpect(ResponseMatchers.noFault());
66-
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
67-
then(this.service).should()
68-
.bookHoliday(dateFormat.parse("2013-10-20"), dateFormat.parse("2013-11-22"), "John Doe");
68+
then(this.service).should().bookHoliday(LocalDate.of(2013, 10, 20), LocalDate.of(2013, 11, 22), "John Doe");
6969
}
7070

7171
}

0 commit comments

Comments
 (0)