Skip to content

Commit

Permalink
New test with WebTestClient
Browse files Browse the repository at this point in the history
  • Loading branch information
vicziani committed Jun 12, 2022
1 parent 7ec027c commit f1fcc3f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.learnwebservices.services.hello;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.reactive.server.WebTestClient;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class HelloWebClientIT {

@Autowired
WebTestClient webClient;

@Test
void testHello() {
String request = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:hel=\"http://learnwebservices.com/services/hello\">\n" +
" <soapenv:Header/>\n" +
" <soapenv:Body>\n" +
" <hel:HelloRequest>\n" +
" <hel:Name>John Doe</hel:Name>\n" +
" </hel:HelloRequest>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";

String response = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
" <soap:Body>\n" +
" <HelloResponse xmlns=\"http://learnwebservices.com/services/hello\">\n" +
" <Message>Hello John Doe!</Message>\n" +
" </HelloResponse>\n" +
" </soap:Body>\n" +
"</soap:Envelope>";

webClient
.post()
.uri("/services/hello")
.contentType(MediaType.APPLICATION_XML)
.header("SOAPAction", "")
.bodyValue(request)
.exchange()
.expectStatus().isOk()
.expectBody().xml(response);
}
}

0 comments on commit f1fcc3f

Please sign in to comment.