SOAP Virtualization
Both examples use an application generated from WSDL by Spring Boot called HelloWorldClient, that uses SOAP. This client is set to receive a SOAP request with name and surname and responds with a greeting that includes these details.
TestRealService shows the request created by HelloWorldClient as it hits the real WebService, and as it sends back a simple greeting.
In TestVirtualService, a virtual service is configured to catch a request before it reaches the real WebService, and to send back a defined response. Although the same method is used with the same parameters, the request never gets to the endpoint. Instead, this is answered by our virtual service. POST requests are caught to virtualize the SOAP call.
SOAP request
@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) public class SpringWsApplicationTests { @Autowired private HelloWorldClient helloWorldClient; @Rule public VirtualServerRule serverRule = new VirtualServerRule(); @Before public void setUp() throws Exception { Thread.sleep(5000); } @Test public void testRealService() throws InterruptedException { assertThat(helloWorldClient.sayHello("John", "Doe")).isEqualTo("Hello John Doe!"); } @Test public void testVirtualizedService() { String virtualizedResponse = "Greeting from virtualized service, John Doe!"; String body = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" + " <SOAP-ENV:Header/>\n" + " <SOAP-ENV:Body>\n" + " <ns2:greeting xmlns:ns2=\"http://codesv.ca.com/types/greeting\">\n" + " <ns2:greeting>Greeting from virtualized service, John Doe!\n" + " </ns2:greeting>\n" + " </SOAP-ENV:Body>\n" + "</SOAP-ENV:Envelope>"; forPost("http://localhost:9090/codesv/ws/greeting").doReturn( okMessage() .withContentType("text/xml; charset=utf-8") .withBody(body.getBytes()) ); String responseGreeting = helloWorldClient.sayHello("John", "Doe"); assertEquals(responseGreeting, vitrualizedResponse); } }
For a complete example see: SOAPExample