Skip to content

Commit

Permalink
Merge branch '2.3.x' into 2.4.x
Browse files Browse the repository at this point in the history
Closes gh-25072
  • Loading branch information
wilkinsona committed Feb 1, 2021
2 parents 57f1f17 + 3585d20 commit 79c0597
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 19 deletions.
Expand Up @@ -84,6 +84,7 @@ dependencies {
testImplementation("org.testcontainers:mongodb")
testImplementation("org.testcontainers:neo4j")
testImplementation("org.testcontainers:testcontainers")
testImplementation("org.thymeleaf:thymeleaf")

testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,14 +21,13 @@
import java.util.LinkedHashSet;
import java.util.Set;

import com.fasterxml.jackson.databind.Module;

import org.springframework.boot.context.TypeExcludeFilter;
import org.springframework.boot.jackson.JsonComponent;
import org.springframework.boot.test.autoconfigure.filter.StandardAnnotationCustomizableTypeExcludeFilter;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.GenericConverter;
import org.springframework.stereotype.Controller;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.reactive.config.WebFluxConfigurer;
Expand All @@ -45,6 +44,9 @@ public final class WebFluxTypeExcludeFilter extends StandardAnnotationCustomizab

private static final Class<?>[] NO_CONTROLLERS = {};

private static final String[] OPTIONAL_INCLUDES = { "com.fasterxml.jackson.databind.Module",
"org.thymeleaf.dialect.IDialect" };

private static final Set<Class<?>> DEFAULT_INCLUDES;

static {
Expand All @@ -56,10 +58,13 @@ public final class WebFluxTypeExcludeFilter extends StandardAnnotationCustomizab
includes.add(GenericConverter.class);
includes.add(WebExceptionHandler.class);
includes.add(WebFilter.class);
try {
includes.add(Module.class);
}
catch (Throwable ex) {
for (String optionalInclude : OPTIONAL_INCLUDES) {
try {
includes.add(ClassUtils.forName(optionalInclude, null));
}
catch (Exception ex) {
// Ignore
}
}
DEFAULT_INCLUDES = Collections.unmodifiableSet(includes);
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,8 +21,6 @@
import java.util.LinkedHashSet;
import java.util.Set;

import com.fasterxml.jackson.databind.Module;

import org.springframework.boot.context.TypeExcludeFilter;
import org.springframework.boot.jackson.JsonComponent;
import org.springframework.boot.test.autoconfigure.filter.StandardAnnotationCustomizableTypeExcludeFilter;
Expand Down Expand Up @@ -51,9 +49,9 @@ public final class WebMvcTypeExcludeFilter extends StandardAnnotationCustomizabl

private static final Class<?>[] NO_CONTROLLERS = {};

private static final String[] OPTIONAL_INCLUDES = {
private static final String[] OPTIONAL_INCLUDES = { "com.fasterxml.jackson.databind.Module",
"org.springframework.security.config.annotation.web.WebSecurityConfigurer",
"org.springframework.security.web.SecurityFilterChain" };
"org.springframework.security.web.SecurityFilterChain", "org.thymeleaf.dialect.IDialect" };

private static final Set<Class<?>> DEFAULT_INCLUDES;

Expand All @@ -71,11 +69,6 @@ public final class WebMvcTypeExcludeFilter extends StandardAnnotationCustomizabl
includes.add(Converter.class);
includes.add(GenericConverter.class);
includes.add(HandlerInterceptor.class);
try {
includes.add(Module.class);
}
catch (Throwable ex) {
}
for (String optionalInclude : OPTIONAL_INCLUDES) {
try {
includes.add(ClassUtils.forName(optionalInclude, null));
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@

import com.fasterxml.jackson.databind.module.SimpleModule;
import org.junit.jupiter.api.Test;
import org.thymeleaf.dialect.IDialect;
import reactor.core.publisher.Mono;

import org.springframework.context.annotation.ComponentScan.Filter;
Expand Down Expand Up @@ -59,6 +60,7 @@ void matchWhenHasNoControllers() throws Exception {
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
assertThat(excludes(filter, ExampleModule.class)).isFalse();
assertThat(excludes(filter, ExampleDialect.class)).isFalse();
}

@Test
Expand All @@ -72,6 +74,7 @@ void matchWhenHasController() throws Exception {
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
assertThat(excludes(filter, ExampleModule.class)).isFalse();
assertThat(excludes(filter, ExampleDialect.class)).isFalse();
}

@Test
Expand All @@ -85,6 +88,7 @@ void matchNotUsingDefaultFilters() throws Exception {
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
assertThat(excludes(filter, ExampleWebFilter.class)).isTrue();
assertThat(excludes(filter, ExampleModule.class)).isTrue();
assertThat(excludes(filter, ExampleDialect.class)).isTrue();
}

@Test
Expand All @@ -98,6 +102,7 @@ void matchWithIncludeFilter() throws Exception {
assertThat(excludes(filter, ExampleRepository.class)).isFalse();
assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
assertThat(excludes(filter, ExampleModule.class)).isFalse();
assertThat(excludes(filter, ExampleDialect.class)).isFalse();
}

@Test
Expand All @@ -111,6 +116,7 @@ void matchWithExcludeFilter() throws Exception {
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
assertThat(excludes(filter, ExampleModule.class)).isFalse();
assertThat(excludes(filter, ExampleDialect.class)).isFalse();
}

private boolean excludes(WebFluxTypeExcludeFilter filter, Class<?> type) throws IOException {
Expand Down Expand Up @@ -185,4 +191,13 @@ static class ExampleModule extends SimpleModule {

}

static class ExampleDialect implements IDialect {

@Override
public String getName() {
return "example";
}

}

}
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@

import com.fasterxml.jackson.databind.module.SimpleModule;
import org.junit.jupiter.api.Test;
import org.thymeleaf.dialect.IDialect;

import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.FilterType;
Expand Down Expand Up @@ -61,6 +62,7 @@ void matchWhenHasNoControllers() throws Exception {
assertThat(excludes(filter, SecurityFilterChain.class)).isFalse();
assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse();
assertThat(excludes(filter, ExampleModule.class)).isFalse();
assertThat(excludes(filter, ExampleDialect.class)).isFalse();
}

@Test
Expand All @@ -77,6 +79,7 @@ void matchWhenHasController() throws Exception {
assertThat(excludes(filter, SecurityFilterChain.class)).isFalse();
assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse();
assertThat(excludes(filter, ExampleModule.class)).isFalse();
assertThat(excludes(filter, ExampleDialect.class)).isFalse();
}

@Test
Expand All @@ -93,6 +96,7 @@ void matchNotUsingDefaultFilters() throws Exception {
assertThat(excludes(filter, SecurityFilterChain.class)).isTrue();
assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isTrue();
assertThat(excludes(filter, ExampleModule.class)).isTrue();
assertThat(excludes(filter, ExampleDialect.class)).isTrue();
}

@Test
Expand All @@ -107,6 +111,7 @@ void matchWithIncludeFilter() throws Exception {
assertThat(excludes(filter, ExampleRepository.class)).isFalse();
assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse();
assertThat(excludes(filter, ExampleModule.class)).isFalse();
assertThat(excludes(filter, ExampleDialect.class)).isFalse();
}

@Test
Expand All @@ -123,6 +128,7 @@ void matchWithExcludeFilter() throws Exception {
assertThat(excludes(filter, SecurityFilterChain.class)).isFalse();
assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse();
assertThat(excludes(filter, ExampleModule.class)).isFalse();
assertThat(excludes(filter, ExampleDialect.class)).isFalse();
}

private boolean excludes(WebMvcTypeExcludeFilter filter, Class<?> type) throws IOException {
Expand Down Expand Up @@ -200,4 +206,13 @@ static class ExampleModule extends SimpleModule {

}

static class ExampleDialect implements IDialect {

@Override
public String getName() {
return "example";
}

}

}

0 comments on commit 79c0597

Please sign in to comment.