Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -37,13 +37,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public class ErrorTests {
|
class ErrorTests {
|
||||||
|
|
||||||
private final WebTestClient client = WebTestClient.bindToController(new TestController()).build();
|
private final WebTestClient client = WebTestClient.bindToController(new TestController()).build();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notFound(){
|
void notFound(){
|
||||||
this.client.get().uri("/invalid")
|
this.client.get().uri("/invalid")
|
||||||
.exchange()
|
.exchange()
|
||||||
.expectStatus().isNotFound()
|
.expectStatus().isNotFound()
|
||||||
@@ -51,7 +51,7 @@ public class ErrorTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void serverException() {
|
void serverException() {
|
||||||
this.client.get().uri("/server-error")
|
this.client.get().uri("/server-error")
|
||||||
.exchange()
|
.exchange()
|
||||||
.expectStatus().isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR)
|
.expectStatus().isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
@@ -59,7 +59,7 @@ public class ErrorTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // SPR-17363
|
@Test // SPR-17363
|
||||||
public void badRequestBeforeRequestBodyConsumed() {
|
void badRequestBeforeRequestBodyConsumed() {
|
||||||
EntityExchangeResult<Void> result = this.client.post()
|
EntityExchangeResult<Void> result = this.client.post()
|
||||||
.uri("/post")
|
.uri("/post")
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -18,7 +18,6 @@ package org.springframework.test.web.reactive.server.samples;
|
|||||||
|
|
||||||
import java.security.Principal;
|
import java.security.Principal;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
@@ -37,23 +36,18 @@ import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Samples tests that demonstrate applying ServerWebExchange initialization.
|
* Samples tests that demonstrate applying ServerWebExchange initialization.
|
||||||
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class ExchangeMutatorTests {
|
class ExchangeMutatorTests {
|
||||||
|
|
||||||
private WebTestClient webTestClient;
|
private final WebTestClient webTestClient = WebTestClient.bindToController(new TestController())
|
||||||
|
.apply(identity("Pablo"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
|
|
||||||
this.webTestClient = WebTestClient.bindToController(new TestController())
|
|
||||||
.apply(identity("Pablo"))
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void useGloballyConfiguredIdentity() throws Exception {
|
void useGloballyConfiguredIdentity() {
|
||||||
this.webTestClient.get().uri("/userIdentity")
|
this.webTestClient.get().uri("/userIdentity")
|
||||||
.exchange()
|
.exchange()
|
||||||
.expectStatus().isOk()
|
.expectStatus().isOk()
|
||||||
@@ -61,8 +55,7 @@ public class ExchangeMutatorTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void useLocallyConfiguredIdentity() throws Exception {
|
void useLocallyConfiguredIdentity() {
|
||||||
|
|
||||||
this.webTestClient
|
this.webTestClient
|
||||||
.mutateWith(identity("Giovanni"))
|
.mutateWith(identity("Giovanni"))
|
||||||
.get().uri("/userIdentity")
|
.get().uri("/userIdentity")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2021 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -96,4 +96,5 @@ public class GlobalEntityResultConsumerTests {
|
|||||||
return Arrays.asList(new Person("Joe"), new Person("Joseph"));
|
return Arrays.asList(new Person("Joe"), new Person("Joseph"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -29,16 +29,17 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests with headers and cookies.
|
* Tests with headers and cookies.
|
||||||
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public class HeaderAndCookieTests {
|
class HeaderAndCookieTests {
|
||||||
|
|
||||||
private final WebTestClient client = WebTestClient.bindToController(new TestController()).build();
|
private final WebTestClient client = WebTestClient.bindToController(new TestController()).build();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestResponseHeaderPair() throws Exception {
|
void requestResponseHeaderPair() {
|
||||||
this.client.get().uri("/header-echo").header("h1", "in")
|
this.client.get().uri("/header-echo").header("h1", "in")
|
||||||
.exchange()
|
.exchange()
|
||||||
.expectStatus().isOk()
|
.expectStatus().isOk()
|
||||||
@@ -46,7 +47,7 @@ public class HeaderAndCookieTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void headerMultipleValues() throws Exception {
|
void headerMultipleValues() {
|
||||||
this.client.get().uri("/header-multi-value")
|
this.client.get().uri("/header-multi-value")
|
||||||
.exchange()
|
.exchange()
|
||||||
.expectStatus().isOk()
|
.expectStatus().isOk()
|
||||||
@@ -54,7 +55,7 @@ public class HeaderAndCookieTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setCookies() {
|
void setCookies() {
|
||||||
this.client.get().uri("/cookie-echo")
|
this.client.get().uri("/cookie-echo")
|
||||||
.cookies(cookies -> cookies.add("k1", "v1"))
|
.cookies(cookies -> cookies.add("k1", "v1"))
|
||||||
.exchange()
|
.exchange()
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ import static org.hamcrest.Matchers.containsString;
|
|||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public class JsonContentTests {
|
class JsonContentTests {
|
||||||
|
|
||||||
private final WebTestClient client = WebTestClient.bindToController(new PersonController()).build();
|
private final WebTestClient client = WebTestClient.bindToController(new PersonController()).build();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jsonContentWithDefaultLenientMode() {
|
void jsonContentWithDefaultLenientMode() {
|
||||||
this.client.get().uri("/persons")
|
this.client.get().uri("/persons")
|
||||||
.accept(MediaType.APPLICATION_JSON)
|
.accept(MediaType.APPLICATION_JSON)
|
||||||
.exchange()
|
.exchange()
|
||||||
@@ -59,7 +59,7 @@ public class JsonContentTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jsonContentWithStrictMode() {
|
void jsonContentWithStrictMode() {
|
||||||
this.client.get().uri("/persons")
|
this.client.get().uri("/persons")
|
||||||
.accept(MediaType.APPLICATION_JSON)
|
.accept(MediaType.APPLICATION_JSON)
|
||||||
.exchange()
|
.exchange()
|
||||||
@@ -72,7 +72,7 @@ public class JsonContentTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jsonContentWithStrictModeAndMissingAttributes() {
|
void jsonContentWithStrictModeAndMissingAttributes() {
|
||||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> this.client.get().uri("/persons")
|
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> this.client.get().uri("/persons")
|
||||||
.accept(MediaType.APPLICATION_JSON)
|
.accept(MediaType.APPLICATION_JSON)
|
||||||
.exchange()
|
.exchange()
|
||||||
@@ -85,7 +85,7 @@ public class JsonContentTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jsonPathIsEqualTo() {
|
void jsonPathIsEqualTo() {
|
||||||
this.client.get().uri("/persons")
|
this.client.get().uri("/persons")
|
||||||
.accept(MediaType.APPLICATION_JSON)
|
.accept(MediaType.APPLICATION_JSON)
|
||||||
.exchange()
|
.exchange()
|
||||||
@@ -97,7 +97,7 @@ public class JsonContentTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jsonPathMatches() {
|
void jsonPathMatches() {
|
||||||
this.client.get().uri("/persons/John/Smith")
|
this.client.get().uri("/persons/John/Smith")
|
||||||
.accept(MediaType.APPLICATION_JSON)
|
.accept(MediaType.APPLICATION_JSON)
|
||||||
.exchange()
|
.exchange()
|
||||||
@@ -107,7 +107,7 @@ public class JsonContentTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void postJsonContent() {
|
void postJsonContent() {
|
||||||
this.client.post().uri("/persons")
|
this.client.post().uri("/persons")
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
.bodyValue("{\"firstName\":\"John\",\"lastName\":\"Smith\"}")
|
.bodyValue("{\"firstName\":\"John\",\"lastName\":\"Smith\"}")
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -49,7 +49,7 @@ import static org.springframework.http.MediaType.TEXT_EVENT_STREAM;
|
|||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public class ResponseEntityTests {
|
class ResponseEntityTests {
|
||||||
|
|
||||||
private final WebTestClient client = WebTestClient.bindToController(new PersonController())
|
private final WebTestClient client = WebTestClient.bindToController(new PersonController())
|
||||||
.configureClient()
|
.configureClient()
|
||||||
@@ -58,7 +58,7 @@ public class ResponseEntityTests {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entity() {
|
void entity() {
|
||||||
this.client.get().uri("/John")
|
this.client.get().uri("/John")
|
||||||
.exchange()
|
.exchange()
|
||||||
.expectStatus().isOk()
|
.expectStatus().isOk()
|
||||||
@@ -67,7 +67,7 @@ public class ResponseEntityTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entityMatcher() {
|
void entityMatcher() {
|
||||||
this.client.get().uri("/John")
|
this.client.get().uri("/John")
|
||||||
.exchange()
|
.exchange()
|
||||||
.expectStatus().isOk()
|
.expectStatus().isOk()
|
||||||
@@ -76,7 +76,7 @@ public class ResponseEntityTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entityWithConsumer() {
|
void entityWithConsumer() {
|
||||||
this.client.get().uri("/John")
|
this.client.get().uri("/John")
|
||||||
.exchange()
|
.exchange()
|
||||||
.expectStatus().isOk()
|
.expectStatus().isOk()
|
||||||
@@ -86,8 +86,7 @@ public class ResponseEntityTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entityList() {
|
void entityList() {
|
||||||
|
|
||||||
List<Person> expected = Arrays.asList(
|
List<Person> expected = Arrays.asList(
|
||||||
new Person("Jane"), new Person("Jason"), new Person("John"));
|
new Person("Jane"), new Person("Jason"), new Person("John"));
|
||||||
|
|
||||||
@@ -99,8 +98,7 @@ public class ResponseEntityTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entityListWithConsumer() {
|
void entityListWithConsumer() {
|
||||||
|
|
||||||
this.client.get()
|
this.client.get()
|
||||||
.exchange()
|
.exchange()
|
||||||
.expectStatus().isOk()
|
.expectStatus().isOk()
|
||||||
@@ -111,8 +109,7 @@ public class ResponseEntityTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entityMap() {
|
void entityMap() {
|
||||||
|
|
||||||
Map<String, Person> map = new LinkedHashMap<>();
|
Map<String, Person> map = new LinkedHashMap<>();
|
||||||
map.put("Jane", new Person("Jane"));
|
map.put("Jane", new Person("Jane"));
|
||||||
map.put("Jason", new Person("Jason"));
|
map.put("Jason", new Person("Jason"));
|
||||||
@@ -125,8 +122,7 @@ public class ResponseEntityTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void entityStream() {
|
void entityStream() {
|
||||||
|
|
||||||
FluxExchangeResult<Person> result = this.client.get()
|
FluxExchangeResult<Person> result = this.client.get()
|
||||||
.accept(TEXT_EVENT_STREAM)
|
.accept(TEXT_EVENT_STREAM)
|
||||||
.exchange()
|
.exchange()
|
||||||
@@ -143,7 +139,7 @@ public class ResponseEntityTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void postEntity() {
|
void postEntity() {
|
||||||
this.client.post()
|
this.client.post()
|
||||||
.bodyValue(new Person("John"))
|
.bodyValue(new Person("John"))
|
||||||
.exchange()
|
.exchange()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -41,15 +41,13 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
import static org.hamcrest.Matchers.startsWith;
|
import static org.hamcrest.Matchers.startsWith;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Samples of tests using {@link WebTestClient} with XML content.
|
* Samples of tests using {@link WebTestClient} with XML content.
|
||||||
*
|
*
|
||||||
* @author Eric Deandrea
|
* @author Eric Deandrea
|
||||||
* @since 5.1
|
* @since 5.1
|
||||||
*/
|
*/
|
||||||
public class XmlContentTests {
|
class XmlContentTests {
|
||||||
|
|
||||||
private static final String persons_XML =
|
private static final String persons_XML =
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||||
@@ -64,7 +62,7 @@ public class XmlContentTests {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void xmlContent() {
|
void xmlContent() {
|
||||||
this.client.get().uri("/persons")
|
this.client.get().uri("/persons")
|
||||||
.accept(MediaType.APPLICATION_XML)
|
.accept(MediaType.APPLICATION_XML)
|
||||||
.exchange()
|
.exchange()
|
||||||
@@ -73,7 +71,7 @@ public class XmlContentTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void xpathIsEqualTo() {
|
void xpathIsEqualTo() {
|
||||||
this.client.get().uri("/persons")
|
this.client.get().uri("/persons")
|
||||||
.accept(MediaType.APPLICATION_XML)
|
.accept(MediaType.APPLICATION_XML)
|
||||||
.exchange()
|
.exchange()
|
||||||
@@ -89,7 +87,7 @@ public class XmlContentTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void xpathMatches() {
|
void xpathMatches() {
|
||||||
this.client.get().uri("/persons")
|
this.client.get().uri("/persons")
|
||||||
.accept(MediaType.APPLICATION_XML)
|
.accept(MediaType.APPLICATION_XML)
|
||||||
.exchange()
|
.exchange()
|
||||||
@@ -99,7 +97,7 @@ public class XmlContentTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void xpathContainsSubstringViaRegex() {
|
void xpathContainsSubstringViaRegex() {
|
||||||
this.client.get().uri("/persons/John")
|
this.client.get().uri("/persons/John")
|
||||||
.accept(MediaType.APPLICATION_XML)
|
.accept(MediaType.APPLICATION_XML)
|
||||||
.exchange()
|
.exchange()
|
||||||
@@ -109,8 +107,7 @@ public class XmlContentTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void postXmlContent() {
|
void postXmlContent() {
|
||||||
|
|
||||||
String content =
|
String content =
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
|
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
|
||||||
"<person><name>John</name></person>";
|
"<person><name>John</name></person>";
|
||||||
|
|||||||
Reference in New Issue
Block a user