From f1fcc3f145614bbc748968786cb26755056c0f11 Mon Sep 17 00:00:00 2001 From: Istvan Viczian Date: Sun, 12 Jun 2022 22:41:17 +0200 Subject: [PATCH] New test with WebTestClient --- pom.xml | 5 +++ .../services/hello/HelloWebClientIT.java | 44 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/test/java/com/learnwebservices/services/hello/HelloWebClientIT.java diff --git a/pom.xml b/pom.xml index fcc2633..c5605c6 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,11 @@ spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-webflux + + org.springframework.boot spring-boot-starter-validation diff --git a/src/test/java/com/learnwebservices/services/hello/HelloWebClientIT.java b/src/test/java/com/learnwebservices/services/hello/HelloWebClientIT.java new file mode 100644 index 0000000..e1eec01 --- /dev/null +++ b/src/test/java/com/learnwebservices/services/hello/HelloWebClientIT.java @@ -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 = "\n" + + " \n" + + " \n" + + " \n" + + " John Doe\n" + + " \n" + + " \n" + + ""; + + String response = "\n" + + " \n" + + " \n" + + " Hello John Doe!\n" + + " \n" + + " \n" + + ""; + + webClient + .post() + .uri("/services/hello") + .contentType(MediaType.APPLICATION_XML) + .header("SOAPAction", "") + .bodyValue(request) + .exchange() + .expectStatus().isOk() + .expectBody().xml(response); + } +}