Polish "Add @WebServiceServerTest slice test support"
See gh-27091
This commit is contained in:
@@ -771,7 +771,12 @@ include::{docs-java}/features/testing/springbootapplications/autoconfiguredsprin
|
||||
|
||||
[[features.testing.spring-boot-applications.autoconfigured-webservices]]
|
||||
==== Auto-configured Spring Web Services Tests
|
||||
You can use `@WebServiceClientTest` to test applications that use call web services using the Spring Web Services project.
|
||||
|
||||
|
||||
|
||||
[[features.testing.spring-boot-applications.autoconfigured-webservices.client]]
|
||||
===== Auto-configured Spring Web Services Client Tests
|
||||
You can use `@WebServiceClientTest` to test applications that call web services using the Spring Web Services project.
|
||||
By default, it configures a mock `WebServiceServer` bean and automatically customizes your `WebServiceTemplateBuilder`.
|
||||
(For more about using Web Services with Spring Boot, see "<<io#io.webservices>>", earlier in this chapter.)
|
||||
|
||||
@@ -782,7 +787,25 @@ The following example shows the `@WebServiceClientTest` annotation in use:
|
||||
|
||||
[source,java,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::{docs-java}/features/testing/springbootapplications/autoconfiguredwebservices/MyWebServiceClientTests.java[]
|
||||
include::{docs-java}/features/testing/springbootapplications/autoconfiguredwebservices/client/MyWebServiceClientTests.java[]
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[features.testing.spring-boot-applications.autoconfigured-webservices.server]]
|
||||
===== Auto-configured Spring Web Services Server Tests
|
||||
You can use `@WebServiceServerTest` to test applications that implement web services using the Spring Web Services project.
|
||||
By default, it configures a `MockWebServiceClient` bean that can be used to call your web service endpoints.
|
||||
(For more about using Web Services with Spring Boot, see "<<io#io.webservices>>", earlier in this chapter.)
|
||||
|
||||
|
||||
TIP: A list of the auto-configuration settings that are enabled by `@WebServiceServerTest` can be <<test-auto-configuration#test-auto-configuration,found in the appendix>>.
|
||||
|
||||
The following example shows the `@WebServiceServerTest` annotation in use:
|
||||
|
||||
[source,java,indent=0,subs="verbatim"]
|
||||
----
|
||||
include::{docs-java}/features/testing/springbootapplications/autoconfiguredwebservices/server/MyWebServiceServerTests.java[]
|
||||
----
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.features.testing.springbootapplications.autoconfiguredwebservices;
|
||||
package org.springframework.boot.docs.features.testing.springbootapplications.autoconfiguredwebservices.client;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.features.testing.springbootapplications.autoconfiguredwebservices;
|
||||
package org.springframework.boot.docs.features.testing.springbootapplications.autoconfiguredwebservices.client;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.features.testing.springbootapplications.autoconfiguredwebservices;
|
||||
package org.springframework.boot.docs.features.testing.springbootapplications.autoconfiguredwebservices.client;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.features.testing.springbootapplications.autoconfiguredwebservices;
|
||||
package org.springframework.boot.docs.features.testing.springbootapplications.autoconfiguredwebservices.client;
|
||||
|
||||
import org.springframework.boot.webservices.client.WebServiceTemplateBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.features.testing.springbootapplications.autoconfiguredwebservices.server;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.springframework.ws.server.endpoint.annotation.Endpoint;
|
||||
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
|
||||
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
@Endpoint
|
||||
public class ExampleEndpoint {
|
||||
|
||||
@PayloadRoot(localPart = "ExampleRequest")
|
||||
@ResponsePayload
|
||||
public Source handleRequest() throws Exception {
|
||||
return new StringSource("<ExampleResponse>42</ExampleResponse>");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.docs.features.testing.springbootapplications.autoconfiguredwebservices.server;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.webservices.server.WebServiceServerTest;
|
||||
import org.springframework.ws.test.server.MockWebServiceClient;
|
||||
import org.springframework.ws.test.server.RequestCreators;
|
||||
import org.springframework.ws.test.server.ResponseMatchers;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
@WebServiceServerTest(ExampleEndpoint.class)
|
||||
class MyWebServiceServerTests {
|
||||
|
||||
@Autowired
|
||||
private MockWebServiceClient client;
|
||||
|
||||
@Test
|
||||
void mockServerCall() {
|
||||
// @formatter:off
|
||||
this.client
|
||||
.sendRequest(RequestCreators.withPayload(new StringSource("<ExampleRequest/>")))
|
||||
.andExpect(ResponseMatchers.payload(new StringSource("<ExampleResponse>42</ExampleResponse>")));
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user