Include WebFilter beans in WebFluxTest slice
See gh-17601
This commit is contained in:
		
							parent
							
								
									9f69b61d49
								
							
						
					
					
						commit
						9d052bbe5e
					
				| 
						 | 
					@ -31,6 +31,7 @@ import org.springframework.util.ObjectUtils;
 | 
				
			||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
 | 
					import org.springframework.web.bind.annotation.ControllerAdvice;
 | 
				
			||||||
import org.springframework.web.reactive.config.WebFluxConfigurer;
 | 
					import org.springframework.web.reactive.config.WebFluxConfigurer;
 | 
				
			||||||
import org.springframework.web.server.WebExceptionHandler;
 | 
					import org.springframework.web.server.WebExceptionHandler;
 | 
				
			||||||
 | 
					import org.springframework.web.server.WebFilter;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * {@link TypeExcludeFilter} for {@link WebFluxTest @WebFluxTest}.
 | 
					 * {@link TypeExcludeFilter} for {@link WebFluxTest @WebFluxTest}.
 | 
				
			||||||
| 
						 | 
					@ -51,6 +52,7 @@ class WebFluxTypeExcludeFilter extends StandardAnnotationCustomizableTypeExclude
 | 
				
			||||||
		includes.add(Converter.class);
 | 
							includes.add(Converter.class);
 | 
				
			||||||
		includes.add(GenericConverter.class);
 | 
							includes.add(GenericConverter.class);
 | 
				
			||||||
		includes.add(WebExceptionHandler.class);
 | 
							includes.add(WebExceptionHandler.class);
 | 
				
			||||||
 | 
							includes.add(WebFilter.class);
 | 
				
			||||||
		DEFAULT_INCLUDES = Collections.unmodifiableSet(includes);
 | 
							DEFAULT_INCLUDES = Collections.unmodifiableSet(includes);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,6 +19,7 @@ package org.springframework.boot.test.autoconfigure.web.reactive;
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.junit.jupiter.api.Test;
 | 
					import org.junit.jupiter.api.Test;
 | 
				
			||||||
 | 
					import reactor.core.publisher.Mono;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.springframework.context.annotation.ComponentScan.Filter;
 | 
					import org.springframework.context.annotation.ComponentScan.Filter;
 | 
				
			||||||
import org.springframework.context.annotation.FilterType;
 | 
					import org.springframework.context.annotation.FilterType;
 | 
				
			||||||
| 
						 | 
					@ -30,6 +31,9 @@ import org.springframework.stereotype.Repository;
 | 
				
			||||||
import org.springframework.stereotype.Service;
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
 | 
					import org.springframework.web.bind.annotation.ControllerAdvice;
 | 
				
			||||||
import org.springframework.web.reactive.config.WebFluxConfigurer;
 | 
					import org.springframework.web.reactive.config.WebFluxConfigurer;
 | 
				
			||||||
 | 
					import org.springframework.web.server.ServerWebExchange;
 | 
				
			||||||
 | 
					import org.springframework.web.server.WebFilter;
 | 
				
			||||||
 | 
					import org.springframework.web.server.WebFilterChain;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import static org.assertj.core.api.Assertions.assertThat;
 | 
					import static org.assertj.core.api.Assertions.assertThat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -52,6 +56,7 @@ class WebFluxTypeExcludeFilterTests {
 | 
				
			||||||
		assertThat(excludes(filter, ExampleWeb.class)).isFalse();
 | 
							assertThat(excludes(filter, ExampleWeb.class)).isFalse();
 | 
				
			||||||
		assertThat(excludes(filter, ExampleService.class)).isTrue();
 | 
							assertThat(excludes(filter, ExampleService.class)).isTrue();
 | 
				
			||||||
		assertThat(excludes(filter, ExampleRepository.class)).isTrue();
 | 
							assertThat(excludes(filter, ExampleRepository.class)).isTrue();
 | 
				
			||||||
 | 
							assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
| 
						 | 
					@ -63,6 +68,7 @@ class WebFluxTypeExcludeFilterTests {
 | 
				
			||||||
		assertThat(excludes(filter, ExampleWeb.class)).isFalse();
 | 
							assertThat(excludes(filter, ExampleWeb.class)).isFalse();
 | 
				
			||||||
		assertThat(excludes(filter, ExampleService.class)).isTrue();
 | 
							assertThat(excludes(filter, ExampleService.class)).isTrue();
 | 
				
			||||||
		assertThat(excludes(filter, ExampleRepository.class)).isTrue();
 | 
							assertThat(excludes(filter, ExampleRepository.class)).isTrue();
 | 
				
			||||||
 | 
							assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
| 
						 | 
					@ -74,6 +80,7 @@ class WebFluxTypeExcludeFilterTests {
 | 
				
			||||||
		assertThat(excludes(filter, ExampleWeb.class)).isTrue();
 | 
							assertThat(excludes(filter, ExampleWeb.class)).isTrue();
 | 
				
			||||||
		assertThat(excludes(filter, ExampleService.class)).isTrue();
 | 
							assertThat(excludes(filter, ExampleService.class)).isTrue();
 | 
				
			||||||
		assertThat(excludes(filter, ExampleRepository.class)).isTrue();
 | 
							assertThat(excludes(filter, ExampleRepository.class)).isTrue();
 | 
				
			||||||
 | 
							assertThat(excludes(filter, ExampleWebFilter.class)).isTrue();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
| 
						 | 
					@ -85,6 +92,7 @@ class WebFluxTypeExcludeFilterTests {
 | 
				
			||||||
		assertThat(excludes(filter, ExampleWeb.class)).isFalse();
 | 
							assertThat(excludes(filter, ExampleWeb.class)).isFalse();
 | 
				
			||||||
		assertThat(excludes(filter, ExampleService.class)).isTrue();
 | 
							assertThat(excludes(filter, ExampleService.class)).isTrue();
 | 
				
			||||||
		assertThat(excludes(filter, ExampleRepository.class)).isFalse();
 | 
							assertThat(excludes(filter, ExampleRepository.class)).isFalse();
 | 
				
			||||||
 | 
							assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
| 
						 | 
					@ -96,6 +104,7 @@ class WebFluxTypeExcludeFilterTests {
 | 
				
			||||||
		assertThat(excludes(filter, ExampleWeb.class)).isFalse();
 | 
							assertThat(excludes(filter, ExampleWeb.class)).isFalse();
 | 
				
			||||||
		assertThat(excludes(filter, ExampleService.class)).isTrue();
 | 
							assertThat(excludes(filter, ExampleService.class)).isTrue();
 | 
				
			||||||
		assertThat(excludes(filter, ExampleRepository.class)).isTrue();
 | 
							assertThat(excludes(filter, ExampleRepository.class)).isTrue();
 | 
				
			||||||
 | 
							assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private boolean excludes(WebFluxTypeExcludeFilter filter, Class<?> type) throws IOException {
 | 
						private boolean excludes(WebFluxTypeExcludeFilter filter, Class<?> type) throws IOException {
 | 
				
			||||||
| 
						 | 
					@ -157,4 +166,13 @@ class WebFluxTypeExcludeFilterTests {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						static class ExampleWebFilter implements WebFilter {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							@Override
 | 
				
			||||||
 | 
							public Mono<Void> filter(ServerWebExchange serverWebExchange, WebFilterChain webFilterChain) {
 | 
				
			||||||
 | 
								return null;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue