Stop using Constants utility in CustomizableTraceInterceptor
See gh-30851
This commit is contained in:
parent
5e31856aaa
commit
f01fb19318
|
|
@ -23,7 +23,6 @@ import java.util.regex.Pattern;
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import org.springframework.core.Constants;
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
@ -153,8 +152,15 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor {
|
||||||
/**
|
/**
|
||||||
* The {@code Set} of allowed placeholders.
|
* The {@code Set} of allowed placeholders.
|
||||||
*/
|
*/
|
||||||
private static final Set<Object> ALLOWED_PLACEHOLDERS =
|
static final Set<String> ALLOWED_PLACEHOLDERS = Set.of(
|
||||||
new Constants(CustomizableTraceInterceptor.class).getValues("PLACEHOLDER_");
|
PLACEHOLDER_METHOD_NAME,
|
||||||
|
PLACEHOLDER_TARGET_CLASS_NAME,
|
||||||
|
PLACEHOLDER_TARGET_CLASS_SHORT_NAME,
|
||||||
|
PLACEHOLDER_RETURN_VALUE,
|
||||||
|
PLACEHOLDER_ARGUMENT_TYPES,
|
||||||
|
PLACEHOLDER_ARGUMENTS,
|
||||||
|
PLACEHOLDER_EXCEPTION,
|
||||||
|
PLACEHOLDER_INVOCATION_TIME);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,17 @@
|
||||||
|
|
||||||
package org.springframework.aop.interceptor;
|
package org.springframework.aop.interceptor;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
|
@ -27,6 +34,7 @@ import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.springframework.aop.interceptor.CustomizableTraceInterceptor.ALLOWED_PLACEHOLDERS;
|
||||||
import static org.springframework.aop.interceptor.CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENTS;
|
import static org.springframework.aop.interceptor.CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENTS;
|
||||||
import static org.springframework.aop.interceptor.CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENT_TYPES;
|
import static org.springframework.aop.interceptor.CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENT_TYPES;
|
||||||
import static org.springframework.aop.interceptor.CustomizableTraceInterceptor.PLACEHOLDER_EXCEPTION;
|
import static org.springframework.aop.interceptor.CustomizableTraceInterceptor.PLACEHOLDER_EXCEPTION;
|
||||||
|
|
@ -164,6 +172,34 @@ class CustomizableTraceInterceptorTests {
|
||||||
verify(log, times(2)).trace(anyString());
|
verify(log, times(2)).trace(anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test effectively verifies that the internal ALLOWED_PLACEHOLDERS set
|
||||||
|
* is properly configured in {@link CustomizableTraceInterceptor}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
void supportedPlaceholderValues() {
|
||||||
|
assertThat(ALLOWED_PLACEHOLDERS).containsAll(getPlaceholderConstantValues());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getPlaceholderConstantValues() {
|
||||||
|
return Arrays.stream(CustomizableTraceInterceptor.class.getFields())
|
||||||
|
.filter(ReflectionUtils::isPublicStaticFinal)
|
||||||
|
.filter(field -> field.getName().startsWith("PLACEHOLDER_"))
|
||||||
|
.map(this::getFieldValue)
|
||||||
|
.map(String.class::cast)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getFieldValue(Field field) {
|
||||||
|
try {
|
||||||
|
return field.get(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
private static class StubCustomizableTraceInterceptor extends CustomizableTraceInterceptor {
|
private static class StubCustomizableTraceInterceptor extends CustomizableTraceInterceptor {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue