Merge branch '5.3.x'
This commit is contained in:
commit
54565e95b5
|
|
@ -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.
|
||||||
|
|
@ -33,7 +33,6 @@ import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
|
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
|
||||||
import org.springframework.context.annotation.ScopeMetadata;
|
import org.springframework.context.annotation.ScopeMetadata;
|
||||||
import org.springframework.context.annotation.ScopeMetadataResolver;
|
|
||||||
import org.springframework.context.annotation.ScopedProxyMode;
|
import org.springframework.context.annotation.ScopedProxyMode;
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
import org.springframework.mock.web.MockHttpSession;
|
import org.springframework.mock.web.MockHttpSession;
|
||||||
|
|
@ -306,29 +305,25 @@ class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
|
||||||
GenericWebApplicationContext context = new GenericWebApplicationContext();
|
GenericWebApplicationContext context = new GenericWebApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||||
scanner.setIncludeAnnotationConfig(false);
|
scanner.setIncludeAnnotationConfig(false);
|
||||||
scanner.setScopeMetadataResolver(new ScopeMetadataResolver() {
|
scanner.setScopeMetadataResolver(definition -> {
|
||||||
@Override
|
ScopeMetadata metadata = new ScopeMetadata();
|
||||||
public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
|
if (definition instanceof AnnotatedBeanDefinition annDef) {
|
||||||
ScopeMetadata metadata = new ScopeMetadata();
|
for (String type : annDef.getMetadata().getAnnotationTypes()) {
|
||||||
if (definition instanceof AnnotatedBeanDefinition) {
|
if (type.equals(jakarta.inject.Singleton.class.getName())) {
|
||||||
AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;
|
metadata.setScopeName(BeanDefinition.SCOPE_SINGLETON);
|
||||||
for (String type : annDef.getMetadata().getAnnotationTypes()) {
|
break;
|
||||||
if (type.equals(jakarta.inject.Singleton.class.getName())) {
|
}
|
||||||
metadata.setScopeName(BeanDefinition.SCOPE_SINGLETON);
|
else if (annDef.getMetadata().getMetaAnnotationTypes(type).contains(jakarta.inject.Scope.class.getName())) {
|
||||||
break;
|
metadata.setScopeName(type.substring(type.length() - 13, type.length() - 6).toLowerCase());
|
||||||
}
|
metadata.setScopedProxyMode(scopedProxyMode);
|
||||||
else if (annDef.getMetadata().getMetaAnnotationTypes(type).contains(jakarta.inject.Scope.class.getName())) {
|
break;
|
||||||
metadata.setScopeName(type.substring(type.length() - 13, type.length() - 6).toLowerCase());
|
}
|
||||||
metadata.setScopedProxyMode(scopedProxyMode);
|
else if (type.startsWith("javax.inject")) {
|
||||||
break;
|
metadata.setScopeName(BeanDefinition.SCOPE_PROTOTYPE);
|
||||||
}
|
|
||||||
else if (type.startsWith("jakarta.inject")) {
|
|
||||||
metadata.setScopeName(BeanDefinition.SCOPE_PROTOTYPE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return metadata;
|
|
||||||
}
|
}
|
||||||
|
return metadata;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Scan twice in order to find errors in the bean definition compatibility check.
|
// Scan twice in order to find errors in the bean definition compatibility check.
|
||||||
|
|
|
||||||
|
|
@ -125,16 +125,7 @@ public class ConcurrencyThrottleInterceptorTests {
|
||||||
try {
|
try {
|
||||||
this.proxy.exceptional(this.ex);
|
this.proxy.exceptional(this.ex);
|
||||||
}
|
}
|
||||||
catch (RuntimeException ex) {
|
catch (RuntimeException | Error err) {
|
||||||
if (ex == this.ex) {
|
|
||||||
logger.debug("Expected exception thrown", ex);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// should never happen
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Error err) {
|
|
||||||
if (err == this.ex) {
|
if (err == this.ex) {
|
||||||
logger.debug("Expected exception thrown", err);
|
logger.debug("Expected exception thrown", err);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,13 +43,13 @@ public abstract class AbstractPropertyValuesTests {
|
||||||
m.put("forname", "Tony");
|
m.put("forname", "Tony");
|
||||||
m.put("surname", "Blair");
|
m.put("surname", "Blair");
|
||||||
m.put("age", "50");
|
m.put("age", "50");
|
||||||
for (int i = 0; i < ps.length; i++) {
|
for (PropertyValue element : ps) {
|
||||||
Object val = m.get(ps[i].getName());
|
Object val = m.get(element.getName());
|
||||||
assertThat(val != null).as("Can't have unexpected value").isTrue();
|
assertThat(val != null).as("Can't have unexpected value").isTrue();
|
||||||
boolean condition = val instanceof String;
|
boolean condition = val instanceof String;
|
||||||
assertThat(condition).as("Val i string").isTrue();
|
assertThat(condition).as("Val i string").isTrue();
|
||||||
assertThat(val.equals(ps[i].getValue())).as("val matches expected").isTrue();
|
assertThat(val.equals(element.getValue())).as("val matches expected").isTrue();
|
||||||
m.remove(ps[i].getName());
|
m.remove(element.getName());
|
||||||
}
|
}
|
||||||
assertThat(m.size() == 0).as("Map size is 0").isTrue();
|
assertThat(m.size() == 0).as("Map size is 0").isTrue();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -483,6 +483,7 @@ public class BeanFactoryUtilsTests {
|
||||||
return TestBean.class;
|
return TestBean.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public TestBean getObject() {
|
public TestBean getObject() {
|
||||||
// We don't really care if the actual instance is a singleton or prototype
|
// We don't really care if the actual instance is a singleton or prototype
|
||||||
// for the tests that use this factory.
|
// for the tests that use this factory.
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,6 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.MutablePropertyValues;
|
import org.springframework.beans.MutablePropertyValues;
|
||||||
import org.springframework.beans.NotWritablePropertyException;
|
import org.springframework.beans.NotWritablePropertyException;
|
||||||
import org.springframework.beans.PropertyEditorRegistrar;
|
|
||||||
import org.springframework.beans.PropertyEditorRegistry;
|
|
||||||
import org.springframework.beans.PropertyValue;
|
import org.springframework.beans.PropertyValue;
|
||||||
import org.springframework.beans.TypeConverter;
|
import org.springframework.beans.TypeConverter;
|
||||||
import org.springframework.beans.TypeMismatchException;
|
import org.springframework.beans.TypeMismatchException;
|
||||||
|
|
@ -78,7 +76,6 @@ import org.springframework.beans.testfixture.beans.factory.DummyFactory;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.core.ResolvableType;
|
import org.springframework.core.ResolvableType;
|
||||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||||
import org.springframework.core.convert.converter.Converter;
|
|
||||||
import org.springframework.core.convert.support.DefaultConversionService;
|
import org.springframework.core.convert.support.DefaultConversionService;
|
||||||
import org.springframework.core.convert.support.GenericConversionService;
|
import org.springframework.core.convert.support.GenericConversionService;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
@ -983,16 +980,13 @@ class DefaultListableBeanFactoryTests {
|
||||||
@Test
|
@Test
|
||||||
void customConverter() {
|
void customConverter() {
|
||||||
GenericConversionService conversionService = new DefaultConversionService();
|
GenericConversionService conversionService = new DefaultConversionService();
|
||||||
conversionService.addConverter(new Converter<String, Float>() {
|
conversionService.addConverter(String.class, Float.class, source -> {
|
||||||
@Override
|
try {
|
||||||
public Float convert(String source) {
|
NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
|
||||||
try {
|
return nf.parse(source).floatValue();
|
||||||
NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
|
}
|
||||||
return nf.parse(source).floatValue();
|
catch (ParseException ex) {
|
||||||
}
|
throw new IllegalArgumentException(ex);
|
||||||
catch (ParseException ex) {
|
|
||||||
throw new IllegalArgumentException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
lbf.setConversionService(conversionService);
|
lbf.setConversionService(conversionService);
|
||||||
|
|
@ -1007,12 +1001,9 @@ class DefaultListableBeanFactoryTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void customEditorWithBeanReference() {
|
void customEditorWithBeanReference() {
|
||||||
lbf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
|
lbf.addPropertyEditorRegistrar(registry -> {
|
||||||
@Override
|
NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
|
||||||
public void registerCustomEditors(PropertyEditorRegistry registry) {
|
registry.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, true));
|
||||||
NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
|
|
||||||
registry.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, nf, true));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||||
pvs.add("myFloat", new RuntimeBeanReference("myFloat"));
|
pvs.add("myFloat", new RuntimeBeanReference("myFloat"));
|
||||||
|
|
@ -2695,8 +2686,12 @@ class DefaultListableBeanFactoryTests {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
ConstructorDependency that = (ConstructorDependency) o;
|
ConstructorDependency that = (ConstructorDependency) o;
|
||||||
return spouseAge == that.spouseAge &&
|
return spouseAge == that.spouseAge &&
|
||||||
Objects.equals(spouse, that.spouse) &&
|
Objects.equals(spouse, that.spouse) &&
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.InvocationHandler;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -3638,11 +3637,8 @@ public class AutowiredAnnotationBeanPostProcessorTests {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T createMock(Class<T> toMock) {
|
public <T> T createMock(Class<T> toMock) {
|
||||||
return (T) Proxy.newProxyInstance(AutowiredAnnotationBeanPostProcessorTests.class.getClassLoader(), new Class<?>[] {toMock},
|
return (T) Proxy.newProxyInstance(AutowiredAnnotationBeanPostProcessorTests.class.getClassLoader(), new Class<?>[] {toMock},
|
||||||
new InvocationHandler() {
|
(InvocationHandler) (proxy, method, args) -> {
|
||||||
@Override
|
throw new UnsupportedOperationException("mocked!");
|
||||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
|
||||||
throw new UnsupportedOperationException("mocked!");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.MutablePropertyValues;
|
import org.springframework.beans.MutablePropertyValues;
|
||||||
import org.springframework.beans.PropertyEditorRegistrar;
|
import org.springframework.beans.PropertyEditorRegistrar;
|
||||||
import org.springframework.beans.PropertyEditorRegistry;
|
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
import org.springframework.beans.propertyeditors.CustomDateEditor;
|
import org.springframework.beans.propertyeditors.CustomDateEditor;
|
||||||
|
|
@ -50,12 +49,7 @@ public class CustomEditorConfigurerTests {
|
||||||
CustomEditorConfigurer cec = new CustomEditorConfigurer();
|
CustomEditorConfigurer cec = new CustomEditorConfigurer();
|
||||||
final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN);
|
final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN);
|
||||||
cec.setPropertyEditorRegistrars(new PropertyEditorRegistrar[] {
|
cec.setPropertyEditorRegistrars(new PropertyEditorRegistrar[] {
|
||||||
new PropertyEditorRegistrar() {
|
registry -> registry.registerCustomEditor(Date.class, new CustomDateEditor(df, true))});
|
||||||
@Override
|
|
||||||
public void registerCustomEditors(PropertyEditorRegistry registry) {
|
|
||||||
registry.registerCustomEditor(Date.class, new CustomDateEditor(df, true));
|
|
||||||
}
|
|
||||||
}});
|
|
||||||
cec.postProcessBeanFactory(bf);
|
cec.postProcessBeanFactory(bf);
|
||||||
|
|
||||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ public class MethodInvokingFactoryBeanTests {
|
||||||
mcfb = new MethodInvokingFactoryBean();
|
mcfb = new MethodInvokingFactoryBean();
|
||||||
mcfb.setTargetClass(TestClass1.class);
|
mcfb.setTargetClass(TestClass1.class);
|
||||||
mcfb.setTargetMethod("supertypes");
|
mcfb.setTargetMethod("supertypes");
|
||||||
mcfb.setArguments(new ArrayList<>(), new ArrayList<Object>(), "hello");
|
mcfb.setArguments(new ArrayList<>(), new ArrayList<>(), "hello");
|
||||||
mcfb.afterPropertiesSet();
|
mcfb.afterPropertiesSet();
|
||||||
mcfb.getObjectType();
|
mcfb.getObjectType();
|
||||||
|
|
||||||
|
|
@ -184,7 +184,7 @@ public class MethodInvokingFactoryBeanTests {
|
||||||
mcfb = new MethodInvokingFactoryBean();
|
mcfb = new MethodInvokingFactoryBean();
|
||||||
mcfb.setTargetClass(TestClass1.class);
|
mcfb.setTargetClass(TestClass1.class);
|
||||||
mcfb.setTargetMethod("supertypes");
|
mcfb.setTargetMethod("supertypes");
|
||||||
mcfb.setArguments(new ArrayList<>(), new ArrayList<Object>(), "hello");
|
mcfb.setArguments(new ArrayList<>(), new ArrayList<>(), "hello");
|
||||||
// should pass
|
// should pass
|
||||||
mcfb.afterPropertiesSet();
|
mcfb.afterPropertiesSet();
|
||||||
}
|
}
|
||||||
|
|
@ -194,7 +194,7 @@ public class MethodInvokingFactoryBeanTests {
|
||||||
MethodInvokingFactoryBean mcfb = new MethodInvokingFactoryBean();
|
MethodInvokingFactoryBean mcfb = new MethodInvokingFactoryBean();
|
||||||
mcfb.setTargetClass(TestClass1.class);
|
mcfb.setTargetClass(TestClass1.class);
|
||||||
mcfb.setTargetMethod("supertypes");
|
mcfb.setTargetMethod("supertypes");
|
||||||
mcfb.setArguments(new ArrayList<>(), new ArrayList<Object>(), "hello", "bogus");
|
mcfb.setArguments(new ArrayList<>(), new ArrayList<>(), "hello", "bogus");
|
||||||
assertThatExceptionOfType(NoSuchMethodException.class).as(
|
assertThatExceptionOfType(NoSuchMethodException.class).as(
|
||||||
"Matched method with wrong number of args").isThrownBy(
|
"Matched method with wrong number of args").isThrownBy(
|
||||||
mcfb::afterPropertiesSet);
|
mcfb::afterPropertiesSet);
|
||||||
|
|
@ -210,14 +210,14 @@ public class MethodInvokingFactoryBeanTests {
|
||||||
mcfb = new MethodInvokingFactoryBean();
|
mcfb = new MethodInvokingFactoryBean();
|
||||||
mcfb.setTargetClass(TestClass1.class);
|
mcfb.setTargetClass(TestClass1.class);
|
||||||
mcfb.setTargetMethod("supertypes2");
|
mcfb.setTargetMethod("supertypes2");
|
||||||
mcfb.setArguments(new ArrayList<>(), new ArrayList<Object>(), "hello", "bogus");
|
mcfb.setArguments(new ArrayList<>(), new ArrayList<>(), "hello", "bogus");
|
||||||
mcfb.afterPropertiesSet();
|
mcfb.afterPropertiesSet();
|
||||||
assertThat(mcfb.getObject()).isEqualTo("hello");
|
assertThat(mcfb.getObject()).isEqualTo("hello");
|
||||||
|
|
||||||
mcfb = new MethodInvokingFactoryBean();
|
mcfb = new MethodInvokingFactoryBean();
|
||||||
mcfb.setTargetClass(TestClass1.class);
|
mcfb.setTargetClass(TestClass1.class);
|
||||||
mcfb.setTargetMethod("supertypes2");
|
mcfb.setTargetMethod("supertypes2");
|
||||||
mcfb.setArguments(new ArrayList<>(), new ArrayList<Object>(), new Object());
|
mcfb.setArguments(new ArrayList<>(), new ArrayList<>(), new Object());
|
||||||
assertThatExceptionOfType(NoSuchMethodException.class).as(
|
assertThatExceptionOfType(NoSuchMethodException.class).as(
|
||||||
"Matched method when shouldn't have matched").isThrownBy(
|
"Matched method when shouldn't have matched").isThrownBy(
|
||||||
mcfb::afterPropertiesSet);
|
mcfb::afterPropertiesSet);
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.beans.factory.support;
|
package org.springframework.beans.factory.support;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.InvocationHandler;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
@ -34,8 +33,6 @@ import java.util.stream.Collectors;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import org.springframework.beans.PropertyEditorRegistrar;
|
|
||||||
import org.springframework.beans.PropertyEditorRegistry;
|
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
|
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
|
||||||
import org.springframework.beans.factory.ObjectProvider;
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
|
|
@ -409,12 +406,7 @@ class BeanFactoryGenericsTests {
|
||||||
@Test
|
@Test
|
||||||
void testGenericMapWithCollectionValueConstructor() {
|
void testGenericMapWithCollectionValueConstructor() {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
bf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
|
bf.addPropertyEditorRegistrar(registry -> registry.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false)));
|
||||||
@Override
|
|
||||||
public void registerCustomEditors(PropertyEditorRegistry registry) {
|
|
||||||
registry.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||||
|
|
||||||
Map<String, AbstractCollection<?>> input = new HashMap<>();
|
Map<String, AbstractCollection<?>> input = new HashMap<>();
|
||||||
|
|
@ -568,12 +560,7 @@ class BeanFactoryGenericsTests {
|
||||||
@Test
|
@Test
|
||||||
void testGenericMapWithCollectionValueFactoryMethod() {
|
void testGenericMapWithCollectionValueFactoryMethod() {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
bf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
|
bf.addPropertyEditorRegistrar(registry -> registry.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false)));
|
||||||
@Override
|
|
||||||
public void registerCustomEditors(PropertyEditorRegistry registry) {
|
|
||||||
registry.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||||
rbd.setFactoryMethodName("createInstance");
|
rbd.setFactoryMethodName("createInstance");
|
||||||
|
|
||||||
|
|
@ -1010,11 +997,8 @@ class BeanFactoryGenericsTests {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T createMock(Class<T> toMock) {
|
public <T> T createMock(Class<T> toMock) {
|
||||||
return (T) Proxy.newProxyInstance(BeanFactoryGenericsTests.class.getClassLoader(), new Class<?>[] {toMock},
|
return (T) Proxy.newProxyInstance(BeanFactoryGenericsTests.class.getClassLoader(), new Class<?>[] {toMock},
|
||||||
new InvocationHandler() {
|
(InvocationHandler) (proxy, method, args) -> {
|
||||||
@Override
|
throw new UnsupportedOperationException("mocked!");
|
||||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
|
||||||
throw new UnsupportedOperationException("mocked!");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,6 @@ package org.springframework.beans.factory.support;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
|
||||||
import org.springframework.beans.factory.ObjectFactory;
|
|
||||||
import org.springframework.beans.testfixture.beans.DerivedTestBean;
|
import org.springframework.beans.testfixture.beans.DerivedTestBean;
|
||||||
import org.springframework.beans.testfixture.beans.TestBean;
|
import org.springframework.beans.testfixture.beans.TestBean;
|
||||||
|
|
||||||
|
|
@ -40,12 +38,7 @@ public class DefaultSingletonBeanRegistryTests {
|
||||||
beanRegistry.registerSingleton("tb", tb);
|
beanRegistry.registerSingleton("tb", tb);
|
||||||
assertThat(beanRegistry.getSingleton("tb")).isSameAs(tb);
|
assertThat(beanRegistry.getSingleton("tb")).isSameAs(tb);
|
||||||
|
|
||||||
TestBean tb2 = (TestBean) beanRegistry.getSingleton("tb2", new ObjectFactory<Object>() {
|
TestBean tb2 = (TestBean) beanRegistry.getSingleton("tb2", () -> new TestBean());
|
||||||
@Override
|
|
||||||
public Object getObject() throws BeansException {
|
|
||||||
return new TestBean();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
assertThat(beanRegistry.getSingleton("tb2")).isSameAs(tb2);
|
assertThat(beanRegistry.getSingleton("tb2")).isSameAs(tb2);
|
||||||
|
|
||||||
assertThat(beanRegistry.getSingleton("tb")).isSameAs(tb);
|
assertThat(beanRegistry.getSingleton("tb")).isSameAs(tb);
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,9 @@ public class MustBeInitialized implements InitializingBean {
|
||||||
* managed the bean's lifecycle correctly
|
* managed the bean's lifecycle correctly
|
||||||
*/
|
*/
|
||||||
public void businessMethod() {
|
public void businessMethod() {
|
||||||
if (!this.inited)
|
if (!this.inited) {
|
||||||
throw new RuntimeException("Factory didn't call afterPropertiesSet() on MustBeInitialized object");
|
throw new RuntimeException("Factory didn't call afterPropertiesSet() on MustBeInitialized object");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,12 +39,18 @@ public class Pet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
final Pet pet = (Pet) o;
|
final Pet pet = (Pet) o;
|
||||||
|
|
||||||
if (name != null ? !name.equals(pet.name) : pet.name != null) return false;
|
if (name != null ? !name.equals(pet.name) : pet.name != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -178,14 +178,11 @@ public class CaffeineCacheManagerTests {
|
||||||
@Test
|
@Test
|
||||||
public void cacheLoaderUseLoadingCache() {
|
public void cacheLoaderUseLoadingCache() {
|
||||||
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
|
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
|
||||||
cm.setCacheLoader(new CacheLoader<Object, Object>() {
|
cm.setCacheLoader(key -> {
|
||||||
@Override
|
if ("ping".equals(key)) {
|
||||||
public Object load(Object key) throws Exception {
|
return "pong";
|
||||||
if ("ping".equals(key)) {
|
|
||||||
return "pong";
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException("I only know ping");
|
|
||||||
}
|
}
|
||||||
|
throw new IllegalArgumentException("I only know ping");
|
||||||
});
|
});
|
||||||
Cache cache1 = cm.getCache("c1");
|
Cache cache1 = cm.getCache("c1");
|
||||||
Cache.ValueWrapper value = cache1.get("ping");
|
Cache.ValueWrapper value = cache1.get("ping");
|
||||||
|
|
|
||||||
|
|
@ -181,12 +181,9 @@ public class JavaMailSenderTests {
|
||||||
|
|
||||||
final List<Message> messages = new ArrayList<>();
|
final List<Message> messages = new ArrayList<>();
|
||||||
|
|
||||||
MimeMessagePreparator preparator = new MimeMessagePreparator() {
|
MimeMessagePreparator preparator = mimeMessage -> {
|
||||||
@Override
|
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("you@mail.org"));
|
||||||
public void prepare(MimeMessage mimeMessage) throws MessagingException {
|
messages.add(mimeMessage);
|
||||||
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("you@mail.org"));
|
|
||||||
messages.add(mimeMessage);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
sender.send(preparator);
|
sender.send(preparator);
|
||||||
|
|
||||||
|
|
@ -207,19 +204,13 @@ public class JavaMailSenderTests {
|
||||||
|
|
||||||
final List<Message> messages = new ArrayList<>();
|
final List<Message> messages = new ArrayList<>();
|
||||||
|
|
||||||
MimeMessagePreparator preparator1 = new MimeMessagePreparator() {
|
MimeMessagePreparator preparator1 = mimeMessage -> {
|
||||||
@Override
|
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("he@mail.org"));
|
||||||
public void prepare(MimeMessage mimeMessage) throws MessagingException {
|
messages.add(mimeMessage);
|
||||||
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("he@mail.org"));
|
|
||||||
messages.add(mimeMessage);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
MimeMessagePreparator preparator2 = new MimeMessagePreparator() {
|
MimeMessagePreparator preparator2 = mimeMessage -> {
|
||||||
@Override
|
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("she@mail.org"));
|
||||||
public void prepare(MimeMessage mimeMessage) throws MessagingException {
|
messages.add(mimeMessage);
|
||||||
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("she@mail.org"));
|
|
||||||
messages.add(mimeMessage);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
sender.send(preparator1, preparator2);
|
sender.send(preparator1, preparator2);
|
||||||
|
|
||||||
|
|
@ -322,12 +313,7 @@ public class JavaMailSenderTests {
|
||||||
@Test
|
@Test
|
||||||
public void javaMailSenderWithParseExceptionOnMimeMessagePreparator() {
|
public void javaMailSenderWithParseExceptionOnMimeMessagePreparator() {
|
||||||
MockJavaMailSender sender = new MockJavaMailSender();
|
MockJavaMailSender sender = new MockJavaMailSender();
|
||||||
MimeMessagePreparator preparator = new MimeMessagePreparator() {
|
MimeMessagePreparator preparator = mimeMessage -> mimeMessage.setFrom(new InternetAddress(""));
|
||||||
@Override
|
|
||||||
public void prepare(MimeMessage mimeMessage) throws MessagingException {
|
|
||||||
mimeMessage.setFrom(new InternetAddress(""));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
try {
|
try {
|
||||||
sender.send(preparator);
|
sender.send(preparator);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -557,12 +557,7 @@ class TestBeanAdvisor extends StaticMethodMatcherPointcutAdvisor {
|
||||||
public int count;
|
public int count;
|
||||||
|
|
||||||
public TestBeanAdvisor() {
|
public TestBeanAdvisor() {
|
||||||
setAdvice(new MethodBeforeAdvice() {
|
setAdvice((MethodBeforeAdvice) (method, args, target) -> ++count);
|
||||||
@Override
|
|
||||||
public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -372,17 +372,14 @@ public abstract class AbstractAopProxyTests {
|
||||||
private void testContext(final boolean context) throws Throwable {
|
private void testContext(final boolean context) throws Throwable {
|
||||||
final String s = "foo";
|
final String s = "foo";
|
||||||
// Test return value
|
// Test return value
|
||||||
MethodInterceptor mi = new MethodInterceptor() {
|
MethodInterceptor mi = invocation -> {
|
||||||
@Override
|
if (!context) {
|
||||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
assertNoInvocationContext();
|
||||||
if (!context) {
|
|
||||||
assertNoInvocationContext();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
assertThat(ExposeInvocationInterceptor.currentInvocation()).as("have context").isNotNull();
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
assertThat(ExposeInvocationInterceptor.currentInvocation()).as("have context").isNotNull();
|
||||||
|
}
|
||||||
|
return s;
|
||||||
};
|
};
|
||||||
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||||
if (context) {
|
if (context) {
|
||||||
|
|
@ -422,11 +419,8 @@ public abstract class AbstractAopProxyTests {
|
||||||
public void testDeclaredException() throws Throwable {
|
public void testDeclaredException() throws Throwable {
|
||||||
final Exception expectedException = new Exception();
|
final Exception expectedException = new Exception();
|
||||||
// Test return value
|
// Test return value
|
||||||
MethodInterceptor mi = new MethodInterceptor() {
|
MethodInterceptor mi = invocation -> {
|
||||||
@Override
|
throw expectedException;
|
||||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
|
||||||
throw expectedException;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||||
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
||||||
|
|
@ -453,11 +447,8 @@ public abstract class AbstractAopProxyTests {
|
||||||
public void testUndeclaredCheckedException() throws Throwable {
|
public void testUndeclaredCheckedException() throws Throwable {
|
||||||
final Exception unexpectedException = new Exception();
|
final Exception unexpectedException = new Exception();
|
||||||
// Test return value
|
// Test return value
|
||||||
MethodInterceptor mi = new MethodInterceptor() {
|
MethodInterceptor mi = invocation -> {
|
||||||
@Override
|
throw unexpectedException;
|
||||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
|
||||||
throw unexpectedException;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||||
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
||||||
|
|
@ -477,11 +468,8 @@ public abstract class AbstractAopProxyTests {
|
||||||
public void testUndeclaredUncheckedException() throws Throwable {
|
public void testUndeclaredUncheckedException() throws Throwable {
|
||||||
final RuntimeException unexpectedException = new RuntimeException();
|
final RuntimeException unexpectedException = new RuntimeException();
|
||||||
// Test return value
|
// Test return value
|
||||||
MethodInterceptor mi = new MethodInterceptor() {
|
MethodInterceptor mi = invocation -> {
|
||||||
@Override
|
throw unexpectedException;
|
||||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
|
||||||
throw unexpectedException;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
|
||||||
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
|
||||||
|
|
@ -660,12 +648,7 @@ public abstract class AbstractAopProxyTests {
|
||||||
NopInterceptor di = new NopInterceptor();
|
NopInterceptor di = new NopInterceptor();
|
||||||
pc.addAdvice(di);
|
pc.addAdvice(di);
|
||||||
final long ts = 37;
|
final long ts = 37;
|
||||||
pc.addAdvice(new DelegatingIntroductionInterceptor(new TimeStamped() {
|
pc.addAdvice(new DelegatingIntroductionInterceptor((TimeStamped) () -> ts));
|
||||||
@Override
|
|
||||||
public long getTimeStamp() {
|
|
||||||
return ts;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
ITestBean proxied = (ITestBean) createProxy(pc);
|
ITestBean proxied = (ITestBean) createProxy(pc);
|
||||||
assertThat(proxied.getName()).isEqualTo(name);
|
assertThat(proxied.getName()).isEqualTo(name);
|
||||||
|
|
@ -1039,17 +1022,14 @@ public abstract class AbstractAopProxyTests {
|
||||||
ProxyFactory pc = new ProxyFactory(tb);
|
ProxyFactory pc = new ProxyFactory(tb);
|
||||||
pc.addInterface(ITestBean.class);
|
pc.addInterface(ITestBean.class);
|
||||||
|
|
||||||
MethodInterceptor twoBirthdayInterceptor = new MethodInterceptor() {
|
MethodInterceptor twoBirthdayInterceptor = mi -> {
|
||||||
@Override
|
// Clone the invocation to proceed three times
|
||||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
// "The Moor's Last Sigh": this technology can cause premature aging
|
||||||
// Clone the invocation to proceed three times
|
MethodInvocation clone1 = ((ReflectiveMethodInvocation) mi).invocableClone();
|
||||||
// "The Moor's Last Sigh": this technology can cause premature aging
|
MethodInvocation clone2 = ((ReflectiveMethodInvocation) mi).invocableClone();
|
||||||
MethodInvocation clone1 = ((ReflectiveMethodInvocation) mi).invocableClone();
|
clone1.proceed();
|
||||||
MethodInvocation clone2 = ((ReflectiveMethodInvocation) mi).invocableClone();
|
clone2.proceed();
|
||||||
clone1.proceed();
|
return mi.proceed();
|
||||||
clone2.proceed();
|
|
||||||
return mi.proceed();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
StaticMethodMatcherPointcutAdvisor advisor = new StaticMethodMatcherPointcutAdvisor(twoBirthdayInterceptor) {
|
StaticMethodMatcherPointcutAdvisor advisor = new StaticMethodMatcherPointcutAdvisor(twoBirthdayInterceptor) {
|
||||||
|
|
@ -1082,16 +1062,13 @@ public abstract class AbstractAopProxyTests {
|
||||||
/**
|
/**
|
||||||
* Changes the name, then changes it back.
|
* Changes the name, then changes it back.
|
||||||
*/
|
*/
|
||||||
MethodInterceptor nameReverter = new MethodInterceptor() {
|
MethodInterceptor nameReverter = mi -> {
|
||||||
@Override
|
MethodInvocation clone = ((ReflectiveMethodInvocation) mi).invocableClone();
|
||||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
String oldName = ((ITestBean) mi.getThis()).getName();
|
||||||
MethodInvocation clone = ((ReflectiveMethodInvocation) mi).invocableClone();
|
clone.getArguments()[0] = oldName;
|
||||||
String oldName = ((ITestBean) mi.getThis()).getName();
|
// Original method invocation should be unaffected by changes to argument list of clone
|
||||||
clone.getArguments()[0] = oldName;
|
mi.proceed();
|
||||||
// Original method invocation should be unaffected by changes to argument list of clone
|
return clone.proceed();
|
||||||
mi.proceed();
|
|
||||||
return clone.proceed();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class NameSaver implements MethodInterceptor {
|
class NameSaver implements MethodInterceptor {
|
||||||
|
|
@ -1347,8 +1324,9 @@ public abstract class AbstractAopProxyTests {
|
||||||
@Override
|
@Override
|
||||||
public void before(Method m, Object[] args, Object target) throws Throwable {
|
public void before(Method m, Object[] args, Object target) throws Throwable {
|
||||||
super.before(m, args, target);
|
super.before(m, args, target);
|
||||||
if (m.getName().startsWith("set"))
|
if (m.getName().startsWith("set")) {
|
||||||
throw rex;
|
throw rex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1563,13 +1541,10 @@ public abstract class AbstractAopProxyTests {
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
protected static class StringSetterNullReplacementAdvice extends DefaultPointcutAdvisor {
|
protected static class StringSetterNullReplacementAdvice extends DefaultPointcutAdvisor {
|
||||||
|
|
||||||
private static MethodInterceptor cleaner = new MethodInterceptor() {
|
private static MethodInterceptor cleaner = mi -> {
|
||||||
@Override
|
// We know it can only be invoked if there's a single parameter of type string
|
||||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
mi.getArguments()[0] = "";
|
||||||
// We know it can only be invoked if there's a single parameter of type string
|
return mi.proceed();
|
||||||
mi.getArguments()[0] = "";
|
|
||||||
return mi.proceed();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public StringSetterNullReplacementAdvice() {
|
public StringSetterNullReplacementAdvice() {
|
||||||
|
|
@ -1601,7 +1576,9 @@ public abstract class AbstractAopProxyTests {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method m, @Nullable Class<?> targetClass, Object... args) {
|
public boolean matches(Method m, @Nullable Class<?> targetClass, Object... args) {
|
||||||
boolean run = m.getName().contains(pattern);
|
boolean run = m.getName().contains(pattern);
|
||||||
if (run) ++count;
|
if (run) {
|
||||||
|
++count;
|
||||||
|
}
|
||||||
return run;
|
return run;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -1620,7 +1597,9 @@ public abstract class AbstractAopProxyTests {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method m, @Nullable Class<?> targetClass, Object... args) {
|
public boolean matches(Method m, @Nullable Class<?> targetClass, Object... args) {
|
||||||
boolean run = m.getName().contains(pattern);
|
boolean run = m.getName().contains(pattern);
|
||||||
if (run) ++count;
|
if (run) {
|
||||||
|
++count;
|
||||||
|
}
|
||||||
return run;
|
return run;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -1924,8 +1903,9 @@ public abstract class AbstractAopProxyTests {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void releaseTarget(Object pTarget) throws Exception {
|
public void releaseTarget(Object pTarget) throws Exception {
|
||||||
if (pTarget != this.target)
|
if (pTarget != this.target) {
|
||||||
throw new RuntimeException("Released wrong target");
|
throw new RuntimeException("Released wrong target");
|
||||||
|
}
|
||||||
++releases;
|
++releases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1934,8 +1914,9 @@ public abstract class AbstractAopProxyTests {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void verify() {
|
public void verify() {
|
||||||
if (gets != releases)
|
if (gets != releases) {
|
||||||
throw new RuntimeException("Expectation failed: " + gets + " gets and " + releases + " releases");
|
throw new RuntimeException("Expectation failed: " + gets + " gets and " + releases + " releases");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -198,10 +198,16 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Person person = (Person) o;
|
Person person = (Person) o;
|
||||||
if (!name.equals(person.name)) return false;
|
if (!name.equals(person.name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -304,11 +304,8 @@ public class ProxyFactoryBeanTests {
|
||||||
|
|
||||||
final Exception ex = new UnsupportedOperationException("invoke");
|
final Exception ex = new UnsupportedOperationException("invoke");
|
||||||
// Add evil interceptor to head of list
|
// Add evil interceptor to head of list
|
||||||
config.addAdvice(0, new MethodInterceptor() {
|
config.addAdvice(0, (MethodInterceptor) invocation -> {
|
||||||
@Override
|
throw ex;
|
||||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
assertThat(config.getAdvisors().length).as("Have correct advisor count").isEqualTo(2);
|
assertThat(config.getAdvisors().length).as("Have correct advisor count").isEqualTo(2);
|
||||||
|
|
||||||
|
|
@ -691,12 +688,9 @@ public class ProxyFactoryBeanTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PointcutForVoid() {
|
public PointcutForVoid() {
|
||||||
setAdvice(new MethodInterceptor() {
|
setAdvice((MethodInterceptor) invocation -> {
|
||||||
@Override
|
methodNames.add(invocation.getMethod().getName());
|
||||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
return invocation.proceed();
|
||||||
methodNames.add(invocation.getMethod().getName());
|
|
||||||
return invocation.proceed();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
setPointcut(new DynamicMethodMatcherPointcut() {
|
setPointcut(new DynamicMethodMatcherPointcut() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -17,8 +17,6 @@
|
||||||
package org.springframework.aop.framework.autoproxy;
|
package org.springframework.aop.framework.autoproxy;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.InvocationHandler;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInterceptor;
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
|
|
@ -434,6 +432,7 @@ public class AutoProxyCreatorTests {
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public static class IntroductionTestAutoProxyCreator extends TestAutoProxyCreator {
|
public static class IntroductionTestAutoProxyCreator extends TestAutoProxyCreator {
|
||||||
|
|
||||||
|
@Override
|
||||||
protected Object[] getAdvicesAndAdvisors() {
|
protected Object[] getAdvicesAndAdvisors() {
|
||||||
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(this.testInterceptor);
|
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(this.testInterceptor);
|
||||||
advisor.addInterface(Serializable.class);
|
advisor.addInterface(Serializable.class);
|
||||||
|
|
@ -491,12 +490,8 @@ public class AutoProxyCreatorTests {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ITestBean getObject() {
|
public ITestBean getObject() {
|
||||||
return (ITestBean) Proxy.newProxyInstance(CustomProxyFactoryBean.class.getClassLoader(), new Class<?>[]{ITestBean.class}, new InvocationHandler() {
|
return (ITestBean) Proxy.newProxyInstance(CustomProxyFactoryBean.class.getClassLoader(), new Class<?>[]{ITestBean.class},
|
||||||
@Override
|
(proxy, method, args) -> ReflectionUtils.invokeMethod(method, tb, args));
|
||||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
|
||||||
return ReflectionUtils.invokeMethod(method, tb, args);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -158,8 +158,8 @@ class CommonsPool2TargetSourceTests {
|
||||||
pooledInstances[9] = targetSource.getTarget();
|
pooledInstances[9] = targetSource.getTarget();
|
||||||
|
|
||||||
// release all objects
|
// release all objects
|
||||||
for (int i = 0; i < pooledInstances.length; i++) {
|
for (Object element : pooledInstances) {
|
||||||
targetSource.releaseTarget(pooledInstances[i]);
|
targetSource.releaseTarget(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,21 +33,24 @@ public class LifecycleContextBean extends LifecycleBean implements ApplicationCo
|
||||||
@Override
|
@Override
|
||||||
public void setBeanFactory(BeanFactory beanFactory) {
|
public void setBeanFactory(BeanFactory beanFactory) {
|
||||||
super.setBeanFactory(beanFactory);
|
super.setBeanFactory(beanFactory);
|
||||||
if (this.owningContext != null)
|
if (this.owningContext != null) {
|
||||||
throw new RuntimeException("Factory called setBeanFactory after setApplicationContext");
|
throw new RuntimeException("Factory called setBeanFactory after setApplicationContext");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
super.afterPropertiesSet();
|
super.afterPropertiesSet();
|
||||||
if (this.owningContext == null)
|
if (this.owningContext == null) {
|
||||||
throw new RuntimeException("Factory didn't call setApplicationContext before afterPropertiesSet on lifecycle bean");
|
throw new RuntimeException("Factory didn't call setApplicationContext before afterPropertiesSet on lifecycle bean");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
if (this.owningFactory == null)
|
if (this.owningFactory == null) {
|
||||||
throw new RuntimeException("Factory called setApplicationContext before setBeanFactory");
|
throw new RuntimeException("Factory called setApplicationContext before setBeanFactory");
|
||||||
|
}
|
||||||
|
|
||||||
this.owningContext = applicationContext;
|
this.owningContext = applicationContext;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -544,19 +544,24 @@ class TestBean {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
if (obj == null)
|
}
|
||||||
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
}
|
||||||
|
if (getClass() != obj.getClass()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
TestBean other = (TestBean) obj;
|
TestBean other = (TestBean) obj;
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
if (other.name != null)
|
if (other.name != null) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (!name.equals(other.name))
|
else if (!name.equals(other.name)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -214,12 +214,7 @@ public class CommonAnnotationBeanPostProcessorTests {
|
||||||
bf.registerBeanDefinition("testBean4", tbd);
|
bf.registerBeanDefinition("testBean4", tbd);
|
||||||
|
|
||||||
bf.registerResolvableDependency(BeanFactory.class, bf);
|
bf.registerResolvableDependency(BeanFactory.class, bf);
|
||||||
bf.registerResolvableDependency(INestedTestBean.class, new ObjectFactory<Object>() {
|
bf.registerResolvableDependency(INestedTestBean.class, (ObjectFactory<Object>) () -> new NestedTestBean());
|
||||||
@Override
|
|
||||||
public Object getObject() throws BeansException {
|
|
||||||
return new NestedTestBean();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer();
|
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer();
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,8 @@ package org.springframework.context.annotation;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
|
||||||
import org.springframework.beans.testfixture.beans.TestBean;
|
import org.springframework.beans.testfixture.beans.TestBean;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
@ -72,11 +70,8 @@ public class ConfigurationClassAndBFPPTests {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public BeanFactoryPostProcessor bfpp() {
|
public BeanFactoryPostProcessor bfpp() {
|
||||||
return new BeanFactoryPostProcessor() {
|
return beanFactory -> {
|
||||||
@Override
|
// no-op
|
||||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
|
||||||
// no-op
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -88,11 +83,8 @@ public class ConfigurationClassAndBFPPTests {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public static final BeanFactoryPostProcessor bfpp() {
|
public static final BeanFactoryPostProcessor bfpp() {
|
||||||
return new BeanFactoryPostProcessor() {
|
return beanFactory -> {
|
||||||
@Override
|
// no-op
|
||||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
|
||||||
// no-op
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -291,7 +291,9 @@ public class ConfigurationClassWithConditionTests {
|
||||||
static class ImportsNotCreated {
|
static class ImportsNotCreated {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
if (true) throw new RuntimeException();
|
if (true) {
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -299,14 +301,18 @@ public class ConfigurationClassWithConditionTests {
|
||||||
static class ConfigurationNotCreated {
|
static class ConfigurationNotCreated {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
if (true) throw new RuntimeException();
|
if (true) {
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class RegistrarNotCreated implements ImportBeanDefinitionRegistrar {
|
static class RegistrarNotCreated implements ImportBeanDefinitionRegistrar {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
if (true) throw new RuntimeException();
|
if (true) {
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -318,7 +324,9 @@ public class ConfigurationClassWithConditionTests {
|
||||||
static class ImportSelectorNotCreated implements ImportSelector {
|
static class ImportSelectorNotCreated implements ImportSelector {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
if (true) throw new RuntimeException();
|
if (true) {
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -136,10 +136,7 @@ public class ConfigurationClassAspectIntegrationTests {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
Runnable fromInnerClass() {
|
Runnable fromInnerClass() {
|
||||||
return new Runnable() {
|
return () -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@ import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
|
||||||
import org.springframework.beans.factory.config.DependencyDescriptor;
|
import org.springframework.beans.factory.config.DependencyDescriptor;
|
||||||
import org.springframework.beans.factory.config.ListFactoryBean;
|
import org.springframework.beans.factory.config.ListFactoryBean;
|
||||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||||
|
|
@ -558,12 +557,9 @@ public class ConfigurationClassProcessingTests {
|
||||||
|
|
||||||
// @Bean
|
// @Bean
|
||||||
public BeanFactoryPostProcessor beanFactoryPostProcessor() {
|
public BeanFactoryPostProcessor beanFactoryPostProcessor() {
|
||||||
return new BeanFactoryPostProcessor() {
|
return beanFactory -> {
|
||||||
@Override
|
BeanDefinition bd = beanFactory.getBeanDefinition("beanPostProcessor");
|
||||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
|
bd.getPropertyValues().addPropertyValue("nameSuffix", "-processed-" + myProp);
|
||||||
BeanDefinition bd = beanFactory.getBeanDefinition("beanPostProcessor");
|
|
||||||
bd.getPropertyValues().addPropertyValue("nameSuffix", "-processed-" + myProp);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 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.
|
||||||
|
|
@ -20,7 +20,6 @@ import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
@ -141,12 +140,9 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||||
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
|
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
|
||||||
|
|
||||||
SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
|
SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
|
||||||
smc.setTaskExecutor(new Executor() {
|
smc.setTaskExecutor(command -> {
|
||||||
@Override
|
command.run();
|
||||||
public void execute(Runnable command) {
|
command.run();
|
||||||
command.run();
|
|
||||||
command.run();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
smc.addApplicationListener(listener);
|
smc.addApplicationListener(listener);
|
||||||
|
|
||||||
|
|
@ -429,12 +425,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||||
public void anonymousClassAsListener() {
|
public void anonymousClassAsListener() {
|
||||||
final Set<MyEvent> seenEvents = new HashSet<>();
|
final Set<MyEvent> seenEvents = new HashSet<>();
|
||||||
StaticApplicationContext context = new StaticApplicationContext();
|
StaticApplicationContext context = new StaticApplicationContext();
|
||||||
context.addApplicationListener(new ApplicationListener<MyEvent>() {
|
context.addApplicationListener((MyEvent event) -> seenEvents.add(event));
|
||||||
@Override
|
|
||||||
public void onApplicationEvent(MyEvent event) {
|
|
||||||
seenEvents.add(event);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
context.refresh();
|
context.refresh();
|
||||||
|
|
||||||
MyEvent event1 = new MyEvent(context);
|
MyEvent event1 = new MyEvent(context);
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ class PayloadApplicationEventTests {
|
||||||
void testProgrammaticPayloadListener() {
|
void testProgrammaticPayloadListener() {
|
||||||
List<String> events = new ArrayList<>();
|
List<String> events = new ArrayList<>();
|
||||||
ApplicationListener<PayloadApplicationEvent<String>> listener = ApplicationListener.forPayload(events::add);
|
ApplicationListener<PayloadApplicationEvent<String>> listener = ApplicationListener.forPayload(events::add);
|
||||||
ApplicationListener<PayloadApplicationEvent<Integer>> mismatch = ApplicationListener.forPayload(payload -> payload.intValue());
|
ApplicationListener<PayloadApplicationEvent<Integer>> mismatch = ApplicationListener.forPayload(Integer::intValue);
|
||||||
|
|
||||||
ConfigurableApplicationContext ac = new GenericApplicationContext();
|
ConfigurableApplicationContext ac = new GenericApplicationContext();
|
||||||
ac.addApplicationListener(listener);
|
ac.addApplicationListener(listener);
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,12 @@ public abstract class AbstractIdentifiable implements Identifiable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
AbstractIdentifiable that = (AbstractIdentifiable) o;
|
AbstractIdentifiable that = (AbstractIdentifiable) o;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,12 @@ public class GenericEventPojo<T> implements ResolvableTypeProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
GenericEventPojo<?> that = (GenericEventPojo<?>) o;
|
GenericEventPojo<?> that = (GenericEventPojo<?>) o;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,12 @@ public abstract class IdentifiableApplicationEvent extends ApplicationEvent impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
IdentifiableApplicationEvent that = (IdentifiableApplicationEvent) o;
|
IdentifiableApplicationEvent that = (IdentifiableApplicationEvent) o;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -99,8 +99,7 @@ public class ConversionServiceFactoryBeanTests {
|
||||||
Set<Object> converters = new HashSet<>();
|
Set<Object> converters = new HashSet<>();
|
||||||
converters.add("bogus");
|
converters.add("bogus");
|
||||||
factory.setConverters(converters);
|
factory.setConverters(converters);
|
||||||
assertThatIllegalArgumentException().isThrownBy(
|
assertThatIllegalArgumentException().isThrownBy(factory::afterPropertiesSet);
|
||||||
factory::afterPropertiesSet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ import org.springframework.core.convert.support.DefaultConversionService;
|
||||||
import org.springframework.format.annotation.NumberFormat;
|
import org.springframework.format.annotation.NumberFormat;
|
||||||
import org.springframework.format.annotation.NumberFormat.Style;
|
import org.springframework.format.annotation.NumberFormat.Style;
|
||||||
import org.springframework.format.support.FormattingConversionService;
|
import org.springframework.format.support.FormattingConversionService;
|
||||||
import org.springframework.util.StringValueResolver;
|
|
||||||
import org.springframework.validation.DataBinder;
|
import org.springframework.validation.DataBinder;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
@ -49,15 +48,12 @@ public class NumberFormattingTests {
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
DefaultConversionService.addDefaultConverters(conversionService);
|
DefaultConversionService.addDefaultConverters(conversionService);
|
||||||
conversionService.setEmbeddedValueResolver(new StringValueResolver() {
|
conversionService.setEmbeddedValueResolver(strVal -> {
|
||||||
@Override
|
if ("${pattern}".equals(strVal)) {
|
||||||
public String resolveStringValue(String strVal) {
|
return "#,##.00";
|
||||||
if ("${pattern}".equals(strVal)) {
|
}
|
||||||
return "#,##.00";
|
else {
|
||||||
}
|
return strVal;
|
||||||
else {
|
|
||||||
return strVal;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
conversionService.addFormatterForFieldType(Number.class, new NumberStyleFormatter());
|
conversionService.addFormatterForFieldType(Number.class, new NumberStyleFormatter());
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -189,24 +189,14 @@ public class FormattingConversionServiceFactoryBeanTests {
|
||||||
public Printer<?> getPrinter(SpecialInt annotation, Class<?> fieldType) {
|
public Printer<?> getPrinter(SpecialInt annotation, Class<?> fieldType) {
|
||||||
assertThat(annotation.value()).isEqualTo("aliased");
|
assertThat(annotation.value()).isEqualTo("aliased");
|
||||||
assertThat(annotation.alias()).isEqualTo("aliased");
|
assertThat(annotation.alias()).isEqualTo("aliased");
|
||||||
return new Printer<Integer>() {
|
return (object, locale) -> ":" + object.toString();
|
||||||
@Override
|
|
||||||
public String print(Integer object, Locale locale) {
|
|
||||||
return ":" + object.toString();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Parser<?> getParser(SpecialInt annotation, Class<?> fieldType) {
|
public Parser<?> getParser(SpecialInt annotation, Class<?> fieldType) {
|
||||||
assertThat(annotation.value()).isEqualTo("aliased");
|
assertThat(annotation.value()).isEqualTo("aliased");
|
||||||
assertThat(annotation.alias()).isEqualTo("aliased");
|
assertThat(annotation.alias()).isEqualTo("aliased");
|
||||||
return new Parser<Integer>() {
|
return (text, locale) -> Integer.parseInt(text, 1, text.length(), 10);
|
||||||
@Override
|
|
||||||
public Integer parse(String text, Locale locale) throws ParseException {
|
|
||||||
return Integer.parseInt(text, 1, text.length(), 10);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.jmx.AbstractMBeanServerTests;
|
import org.springframework.jmx.AbstractMBeanServerTests;
|
||||||
import org.springframework.jmx.JmxTestBean;
|
import org.springframework.jmx.JmxTestBean;
|
||||||
import org.springframework.jmx.export.naming.ObjectNamingStrategy;
|
|
||||||
import org.springframework.jmx.support.ObjectNameManager;
|
import org.springframework.jmx.support.ObjectNameManager;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
@ -74,12 +73,7 @@ class MBeanExporterOperationsTests extends AbstractMBeanServerTests {
|
||||||
|
|
||||||
MBeanExporter exporter = new MBeanExporter();
|
MBeanExporter exporter = new MBeanExporter();
|
||||||
exporter.setServer(getServer());
|
exporter.setServer(getServer());
|
||||||
exporter.setNamingStrategy(new ObjectNamingStrategy() {
|
exporter.setNamingStrategy((managedBean, beanKey) -> objectNameTemplate);
|
||||||
@Override
|
|
||||||
public ObjectName getObjectName(Object managedBean, String beanKey) {
|
|
||||||
return objectNameTemplate;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
JmxTestBean bean1 = new JmxTestBean();
|
JmxTestBean bean1 = new JmxTestBean();
|
||||||
JmxTestBean bean2 = new JmxTestBean();
|
JmxTestBean bean2 = new JmxTestBean();
|
||||||
|
|
@ -101,12 +95,7 @@ class MBeanExporterOperationsTests extends AbstractMBeanServerTests {
|
||||||
MBeanExporter exporter = new MBeanExporter();
|
MBeanExporter exporter = new MBeanExporter();
|
||||||
exporter.setServer(getServer());
|
exporter.setServer(getServer());
|
||||||
exporter.setEnsureUniqueRuntimeObjectNames(false);
|
exporter.setEnsureUniqueRuntimeObjectNames(false);
|
||||||
exporter.setNamingStrategy(new ObjectNamingStrategy() {
|
exporter.setNamingStrategy((managedBean, beanKey) -> objectNameTemplate);
|
||||||
@Override
|
|
||||||
public ObjectName getObjectName(Object managedBean, String beanKey) {
|
|
||||||
return objectNameTemplate;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
JmxTestBean bean1 = new JmxTestBean();
|
JmxTestBean bean1 = new JmxTestBean();
|
||||||
JmxTestBean bean2 = new JmxTestBean();
|
JmxTestBean bean2 = new JmxTestBean();
|
||||||
|
|
|
||||||
|
|
@ -90,11 +90,8 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||||
@Test
|
@Test
|
||||||
void testRegisterNotificationListenerForNonExistentMBean() throws Exception {
|
void testRegisterNotificationListenerForNonExistentMBean() throws Exception {
|
||||||
Map<String, NotificationListener> listeners = new HashMap<>();
|
Map<String, NotificationListener> listeners = new HashMap<>();
|
||||||
NotificationListener dummyListener = new NotificationListener() {
|
NotificationListener dummyListener = (notification, handback) -> {
|
||||||
@Override
|
throw new UnsupportedOperationException();
|
||||||
public void handleNotification(Notification notification, Object handback) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
// the MBean with the supplied object name does not exist...
|
// the MBean with the supplied object name does not exist...
|
||||||
listeners.put("spring:type=Test", dummyListener);
|
listeners.put("spring:type=Test", dummyListener);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 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.
|
||||||
|
|
@ -23,7 +23,6 @@ import javax.management.Attribute;
|
||||||
import javax.management.AttributeChangeNotification;
|
import javax.management.AttributeChangeNotification;
|
||||||
import javax.management.MalformedObjectNameException;
|
import javax.management.MalformedObjectNameException;
|
||||||
import javax.management.Notification;
|
import javax.management.Notification;
|
||||||
import javax.management.NotificationFilter;
|
|
||||||
import javax.management.NotificationListener;
|
import javax.management.NotificationListener;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
|
||||||
|
|
@ -117,7 +116,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
|
||||||
MBeanExporter exporter = new MBeanExporter();
|
MBeanExporter exporter = new MBeanExporter();
|
||||||
exporter.setServer(server);
|
exporter.setServer(server);
|
||||||
exporter.setBeans(beans);
|
exporter.setBeans(beans);
|
||||||
exporter.setNotificationListeners(new NotificationListenerBean[] { listenerBean });
|
exporter.setNotificationListeners(listenerBean);
|
||||||
start(exporter);
|
start(exporter);
|
||||||
|
|
||||||
// update the attribute
|
// update the attribute
|
||||||
|
|
@ -145,7 +144,7 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
|
||||||
MBeanExporter exporter = new MBeanExporter();
|
MBeanExporter exporter = new MBeanExporter();
|
||||||
exporter.setServer(server);
|
exporter.setServer(server);
|
||||||
exporter.setBeans(beans);
|
exporter.setBeans(beans);
|
||||||
exporter.setNotificationListeners(new NotificationListenerBean[] { listenerBean });
|
exporter.setNotificationListeners(listenerBean);
|
||||||
start(exporter);
|
start(exporter);
|
||||||
|
|
||||||
// update the attribute
|
// update the attribute
|
||||||
|
|
@ -168,23 +167,20 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
|
||||||
|
|
||||||
NotificationListenerBean listenerBean = new NotificationListenerBean();
|
NotificationListenerBean listenerBean = new NotificationListenerBean();
|
||||||
listenerBean.setNotificationListener(listener);
|
listenerBean.setNotificationListener(listener);
|
||||||
listenerBean.setNotificationFilter(new NotificationFilter() {
|
listenerBean.setNotificationFilter(notification -> {
|
||||||
@Override
|
if (notification instanceof AttributeChangeNotification) {
|
||||||
public boolean isNotificationEnabled(Notification notification) {
|
AttributeChangeNotification changeNotification = (AttributeChangeNotification) notification;
|
||||||
if (notification instanceof AttributeChangeNotification) {
|
return "Name".equals(changeNotification.getAttributeName());
|
||||||
AttributeChangeNotification changeNotification = (AttributeChangeNotification) notification;
|
}
|
||||||
return "Name".equals(changeNotification.getAttributeName());
|
else {
|
||||||
}
|
return false;
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
MBeanExporter exporter = new MBeanExporter();
|
MBeanExporter exporter = new MBeanExporter();
|
||||||
exporter.setServer(server);
|
exporter.setServer(server);
|
||||||
exporter.setBeans(beans);
|
exporter.setBeans(beans);
|
||||||
exporter.setNotificationListeners(new NotificationListenerBean[] { listenerBean });
|
exporter.setNotificationListeners(listenerBean);
|
||||||
start(exporter);
|
start(exporter);
|
||||||
|
|
||||||
// update the attributes
|
// update the attributes
|
||||||
|
|
|
||||||
|
|
@ -83,9 +83,9 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
|
||||||
MBeanAttributeInfo[] inf = info.getAttributes();
|
MBeanAttributeInfo[] inf = info.getAttributes();
|
||||||
assertThat(inf).as("Invalid number of Attributes returned").hasSize(getExpectedAttributeCount());
|
assertThat(inf).as("Invalid number of Attributes returned").hasSize(getExpectedAttributeCount());
|
||||||
|
|
||||||
for (int x = 0; x < inf.length; x++) {
|
for (MBeanAttributeInfo element : inf) {
|
||||||
assertThat(inf[x]).as("MBeanAttributeInfo should not be null").isNotNull();
|
assertThat(element).as("MBeanAttributeInfo should not be null").isNotNull();
|
||||||
assertThat(inf[x].getDescription()).as("Description for MBeanAttributeInfo should not be null").isNotNull();
|
assertThat(element.getDescription()).as("Description for MBeanAttributeInfo should not be null").isNotNull();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,9 +95,9 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
|
||||||
MBeanOperationInfo[] inf = info.getOperations();
|
MBeanOperationInfo[] inf = info.getOperations();
|
||||||
assertThat(inf).as("Invalid number of Operations returned").hasSize(getExpectedOperationCount());
|
assertThat(inf).as("Invalid number of Operations returned").hasSize(getExpectedOperationCount());
|
||||||
|
|
||||||
for (int x = 0; x < inf.length; x++) {
|
for (MBeanOperationInfo element : inf) {
|
||||||
assertThat(inf[x]).as("MBeanOperationInfo should not be null").isNotNull();
|
assertThat(element).as("MBeanOperationInfo should not be null").isNotNull();
|
||||||
assertThat(inf[x].getDescription()).as("Description for MBeanOperationInfo should not be null").isNotNull();
|
assertThat(element.getDescription()).as("Description for MBeanOperationInfo should not be null").isNotNull();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInterceptor;
|
import org.aopalliance.intercept.MethodInterceptor;
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
|
||||||
import org.awaitility.Awaitility;
|
import org.awaitility.Awaitility;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
@ -613,16 +612,13 @@ public class AsyncExecutionTests {
|
||||||
|
|
||||||
public DynamicAsyncInterfaceBean() {
|
public DynamicAsyncInterfaceBean() {
|
||||||
ProxyFactory pf = new ProxyFactory(new HashMap<>());
|
ProxyFactory pf = new ProxyFactory(new HashMap<>());
|
||||||
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() {
|
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor((MethodInterceptor) invocation -> {
|
||||||
@Override
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName);
|
||||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
assertThat(condition).isTrue();
|
||||||
boolean condition = !Thread.currentThread().getName().equals(originalThreadName);
|
if (Future.class.equals(invocation.getMethod().getReturnType())) {
|
||||||
assertThat(condition).isTrue();
|
return new AsyncResult<>(invocation.getArguments()[0].toString());
|
||||||
if (Future.class.equals(invocation.getMethod().getReturnType())) {
|
|
||||||
return new AsyncResult<>(invocation.getArguments()[0].toString());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
advisor.addInterface(AsyncInterface.class);
|
advisor.addInterface(AsyncInterface.class);
|
||||||
pf.addAdvisor(advisor);
|
pf.addAdvisor(advisor);
|
||||||
|
|
@ -686,16 +682,13 @@ public class AsyncExecutionTests {
|
||||||
|
|
||||||
public DynamicAsyncMethodsInterfaceBean() {
|
public DynamicAsyncMethodsInterfaceBean() {
|
||||||
ProxyFactory pf = new ProxyFactory(new HashMap<>());
|
ProxyFactory pf = new ProxyFactory(new HashMap<>());
|
||||||
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() {
|
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor((MethodInterceptor) invocation -> {
|
||||||
@Override
|
boolean condition = !Thread.currentThread().getName().equals(originalThreadName);
|
||||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
assertThat(condition).isTrue();
|
||||||
boolean condition = !Thread.currentThread().getName().equals(originalThreadName);
|
if (Future.class.equals(invocation.getMethod().getReturnType())) {
|
||||||
assertThat(condition).isTrue();
|
return new AsyncResult<>(invocation.getArguments()[0].toString());
|
||||||
if (Future.class.equals(invocation.getMethod().getReturnType())) {
|
|
||||||
return new AsyncResult<>(invocation.getArguments()[0].toString());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
advisor.addInterface(AsyncMethodsInterface.class);
|
advisor.addInterface(AsyncMethodsInterface.class);
|
||||||
pf.addAdvisor(advisor);
|
pf.addAdvisor(advisor);
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.scheduling.config;
|
package org.springframework.scheduling.config;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.FutureTask;
|
import java.util.concurrent.FutureTask;
|
||||||
|
|
||||||
|
|
@ -59,12 +58,7 @@ public class ExecutorBeanDefinitionParserTests {
|
||||||
assertThat(getKeepAliveSeconds(executor)).isEqualTo(60);
|
assertThat(getKeepAliveSeconds(executor)).isEqualTo(60);
|
||||||
assertThat(getAllowCoreThreadTimeOut(executor)).isFalse();
|
assertThat(getAllowCoreThreadTimeOut(executor)).isFalse();
|
||||||
|
|
||||||
FutureTask<String> task = new FutureTask<>(new Callable<String>() {
|
FutureTask<String> task = new FutureTask<>(() -> "foo");
|
||||||
@Override
|
|
||||||
public String call() throws Exception {
|
|
||||||
return "foo";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
executor.execute(task);
|
executor.execute(task);
|
||||||
assertThat(task.get()).isEqualTo("foo");
|
assertThat(task.get()).isEqualTo("foo");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import org.codehaus.groovy.control.BytecodeProcessor;
|
||||||
*/
|
*/
|
||||||
public class MyBytecodeProcessor implements BytecodeProcessor {
|
public class MyBytecodeProcessor implements BytecodeProcessor {
|
||||||
|
|
||||||
public final Set<String> processed = new HashSet<String>();
|
public final Set<String> processed = new HashSet<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] processBytecode(String name, byte[] original) {
|
public byte[] processBytecode(String name, byte[] original) {
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -17,8 +17,6 @@
|
||||||
package org.springframework.ui;
|
package org.springframework.ui;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.InvocationHandler;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
@ -281,12 +279,7 @@ public class ModelMapTests {
|
||||||
Object proxy = Proxy.newProxyInstance(
|
Object proxy = Proxy.newProxyInstance(
|
||||||
getClass().getClassLoader(),
|
getClass().getClassLoader(),
|
||||||
new Class<?>[] {Map.class},
|
new Class<?>[] {Map.class},
|
||||||
new InvocationHandler() {
|
(proxy1, method, args) -> "proxy");
|
||||||
@Override
|
|
||||||
public Object invoke(Object proxy, Method method, Object[] args) {
|
|
||||||
return "proxy";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
map.addAttribute(proxy);
|
map.addAttribute(proxy);
|
||||||
assertThat(map.get("map")).isSameAs(proxy);
|
assertThat(map.get("map")).isSameAs(proxy);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,9 @@ public class LockMixin extends DelegatingIntroductionInterceptor implements Lock
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||||
if (locked() && invocation.getMethod().getName().indexOf("set") == 0)
|
if (locked() && invocation.getMethod().getName().indexOf("set") == 0) {
|
||||||
throw new LockedException();
|
throw new LockedException();
|
||||||
|
}
|
||||||
return super.invoke(invocation);
|
return super.invoke(invocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ package org.springframework.context.testfixture;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -75,8 +74,7 @@ public class SimpleMapScope implements Scope, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
for (Iterator<Runnable> it = this.callbacks.iterator(); it.hasNext();) {
|
for (Runnable runnable : this.callbacks) {
|
||||||
Runnable runnable = it.next();
|
|
||||||
runnable.run();
|
runnable.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1699,7 +1699,7 @@ class MergedAnnotationsTests {
|
||||||
assertThat(componentScan).isNotNull();
|
assertThat(componentScan).isNotNull();
|
||||||
assertThat(componentScan.value().pattern()).isEqualTo("*Foo");
|
assertThat(componentScan.value().pattern()).isEqualTo("*Foo");
|
||||||
Map<String, Object> map = MergedAnnotation.from(componentScan).asMap(
|
Map<String, Object> map = MergedAnnotation.from(componentScan).asMap(
|
||||||
annotation -> new LinkedHashMap<String, Object>(),
|
annotation -> new LinkedHashMap<>(),
|
||||||
Adapt.ANNOTATION_TO_MAP);
|
Adapt.ANNOTATION_TO_MAP);
|
||||||
Map<String, Object> filterMap = (Map<String, Object>) map.get("value");
|
Map<String, Object> filterMap = (Map<String, Object>) map.get("value");
|
||||||
assertThat(filterMap.get("pattern")).isEqualTo("*Foo");
|
assertThat(filterMap.get("pattern")).isEqualTo("*Foo");
|
||||||
|
|
@ -1719,7 +1719,7 @@ class MergedAnnotationsTests {
|
||||||
ComponentScan.class);
|
ComponentScan.class);
|
||||||
assertThat(componentScan).isNotNull();
|
assertThat(componentScan).isNotNull();
|
||||||
Map<String, Object> map = MergedAnnotation.from(componentScan).asMap(
|
Map<String, Object> map = MergedAnnotation.from(componentScan).asMap(
|
||||||
annotation -> new LinkedHashMap<String, Object>(),
|
annotation -> new LinkedHashMap<>(),
|
||||||
Adapt.ANNOTATION_TO_MAP);
|
Adapt.ANNOTATION_TO_MAP);
|
||||||
Map<String, Object>[] filters = (Map[]) map.get("excludeFilters");
|
Map<String, Object>[] filters = (Map[]) map.get("excludeFilters");
|
||||||
List<String> patterns = Arrays.stream(filters).map(
|
List<String> patterns = Arrays.stream(filters).map(
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ class ConvertingComparatorTests {
|
||||||
assertThat(o2).isInstanceOf(Integer.class);
|
assertThat(o2).isInstanceOf(Integer.class);
|
||||||
this.called = true;
|
this.called = true;
|
||||||
return super.compare(o1, o2);
|
return super.compare(o1, o2);
|
||||||
};
|
}
|
||||||
|
|
||||||
public void assertCalled() {
|
public void assertCalled() {
|
||||||
assertThat(this.called).isTrue();
|
assertThat(this.called).isTrue();
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ class AutoPopulatingListTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withElementFactoryAndUserSuppliedBackingList() throws Exception {
|
void withElementFactoryAndUserSuppliedBackingList() throws Exception {
|
||||||
doTestWithElementFactory(new AutoPopulatingList<Object>(new ArrayList<>(), new MockElementFactory()));
|
doTestWithElementFactory(new AutoPopulatingList<>(new ArrayList<>(), new MockElementFactory()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTestWithClass(AutoPopulatingList<Object> list) {
|
private void doTestWithClass(AutoPopulatingList<Object> list) {
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
*/
|
*/
|
||||||
class ConcurrentReferenceHashMapTests {
|
class ConcurrentReferenceHashMapTests {
|
||||||
|
|
||||||
private static final Comparator<? super String> NULL_SAFE_STRING_SORT = new NullSafeComparator<String>(
|
private static final Comparator<? super String> NULL_SAFE_STRING_SORT = new NullSafeComparator<>(
|
||||||
new ComparableComparator<String>(), true);
|
new ComparableComparator<String>(), true);
|
||||||
|
|
||||||
private TestWeakConcurrentCache<Integer, String> map = new TestWeakConcurrentCache<>();
|
private TestWeakConcurrentCache<Integer, String> map = new TestWeakConcurrentCache<>();
|
||||||
|
|
|
||||||
|
|
@ -391,8 +391,8 @@ class ReflectionUtilsTests {
|
||||||
|
|
||||||
int add(int... args) {
|
int add(int... args) {
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int arg : args) {
|
||||||
sum += args[i];
|
sum += arg;
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -608,14 +608,8 @@ class StringUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTestCommaDelimitedListToStringArrayLegalMatch(String[] components) {
|
private void doTestCommaDelimitedListToStringArrayLegalMatch(String[] components) {
|
||||||
StringBuilder sb = new StringBuilder();
|
String sb = String.join(String.valueOf(','), components);
|
||||||
for (int i = 0; i < components.length; i++) {
|
String[] sa = StringUtils.commaDelimitedListToStringArray(sb);
|
||||||
if (i != 0) {
|
|
||||||
sb.append(',');
|
|
||||||
}
|
|
||||||
sb.append(components[i]);
|
|
||||||
}
|
|
||||||
String[] sa = StringUtils.commaDelimitedListToStringArray(sb.toString());
|
|
||||||
assertThat(sa != null).as("String array isn't null with legal match").isTrue();
|
assertThat(sa != null).as("String array isn't null with legal match").isTrue();
|
||||||
assertThat(sa.length).as("String array length is correct with legal match").isEqualTo(components.length);
|
assertThat(sa.length).as("String array length is correct with legal match").isEqualTo(components.length);
|
||||||
assertThat(Arrays.equals(sa, components)).as("Output equals input").isTrue();
|
assertThat(Arrays.equals(sa, components)).as("Output equals input").isTrue();
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ public abstract class AbstractRowMapperTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected enum MockType {ONE, TWO, THREE};
|
protected enum MockType {ONE, TWO, THREE}
|
||||||
|
|
||||||
|
|
||||||
protected static class Mock {
|
protected static class Mock {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.ResultSetMetaData;
|
import java.sql.ResultSetMetaData;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -160,12 +159,7 @@ public class JdbcTemplateQueryTests {
|
||||||
String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3";
|
String sql = "SELECT AGE FROM CUSTMR WHERE ID = 3";
|
||||||
given(this.resultSet.next()).willReturn(true, false);
|
given(this.resultSet.next()).willReturn(true, false);
|
||||||
given(this.resultSet.getInt(1)).willReturn(22);
|
given(this.resultSet.getInt(1)).willReturn(22);
|
||||||
Object o = this.template.queryForObject(sql, new RowMapper<Integer>() {
|
Object o = this.template.queryForObject(sql, (RowMapper<Integer>) (rs, rowNum) -> rs.getInt(1));
|
||||||
@Override
|
|
||||||
public Integer mapRow(ResultSet rs, int rowNum) throws SQLException {
|
|
||||||
return rs.getInt(1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
assertThat(o instanceof Integer).as("Correct result type").isTrue();
|
assertThat(o instanceof Integer).as("Correct result type").isTrue();
|
||||||
verify(this.resultSet).close();
|
verify(this.resultSet).close();
|
||||||
verify(this.statement).close();
|
verify(this.statement).close();
|
||||||
|
|
|
||||||
|
|
@ -152,12 +152,12 @@ public class JdbcTemplateTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStringsWithStaticSql() throws Exception {
|
public void testStringsWithStaticSql() throws Exception {
|
||||||
doTestStrings(null, null, null, null, (template, sql, rch) -> template.query(sql, rch));
|
doTestStrings(null, null, null, null, JdbcTemplate::query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStringsWithStaticSqlAndFetchSizeAndMaxRows() throws Exception {
|
public void testStringsWithStaticSqlAndFetchSizeAndMaxRows() throws Exception {
|
||||||
doTestStrings(10, 20, 30, null, (template, sql, rch) -> template.query(sql, rch));
|
doTestStrings(10, 20, 30, null, JdbcTemplate::query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -268,28 +268,22 @@ public class JdbcTemplateTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectionCallback() throws Exception {
|
public void testConnectionCallback() throws Exception {
|
||||||
String result = this.template.execute(new ConnectionCallback<String>() {
|
String result = this.template.execute((ConnectionCallback<String>) con -> {
|
||||||
@Override
|
assertThat(con instanceof ConnectionProxy).isTrue();
|
||||||
public String doInConnection(Connection con) {
|
assertThat(((ConnectionProxy) con).getTargetConnection()).isSameAs(JdbcTemplateTests.this.connection);
|
||||||
assertThat(con instanceof ConnectionProxy).isTrue();
|
return "test";
|
||||||
assertThat(((ConnectionProxy) con).getTargetConnection()).isSameAs(JdbcTemplateTests.this.connection);
|
|
||||||
return "test";
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
assertThat(result).isEqualTo("test");
|
assertThat(result).isEqualTo("test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectionCallbackWithStatementSettings() throws Exception {
|
public void testConnectionCallbackWithStatementSettings() throws Exception {
|
||||||
String result = this.template.execute(new ConnectionCallback<String>() {
|
String result = this.template.execute((ConnectionCallback<String>) con -> {
|
||||||
@Override
|
PreparedStatement ps = con.prepareStatement("some SQL");
|
||||||
public String doInConnection(Connection con) throws SQLException {
|
ps.setFetchSize(10);
|
||||||
PreparedStatement ps = con.prepareStatement("some SQL");
|
ps.setMaxRows(20);
|
||||||
ps.setFetchSize(10);
|
ps.close();
|
||||||
ps.setMaxRows(20);
|
return "test";
|
||||||
ps.close();
|
|
||||||
return "test";
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assertThat(result).isEqualTo("test");
|
assertThat(result).isEqualTo("test");
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.ResultSetMetaData;
|
import java.sql.ResultSetMetaData;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -176,12 +175,7 @@ public class NamedParameterQueryTests {
|
||||||
MapSqlParameterSource params = new MapSqlParameterSource();
|
MapSqlParameterSource params = new MapSqlParameterSource();
|
||||||
params.addValue("id", 3);
|
params.addValue("id", 3);
|
||||||
Object o = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id",
|
Object o = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id",
|
||||||
params, new RowMapper<Object>() {
|
params, (RowMapper<Object>) (rs, rowNum) -> rs.getInt(1));
|
||||||
@Override
|
|
||||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
|
||||||
return rs.getInt(1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
boolean condition = o instanceof Integer;
|
boolean condition = o instanceof Integer;
|
||||||
assertThat(condition).as("Correct result type").isTrue();
|
assertThat(condition).as("Correct result type").isTrue();
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -46,9 +46,7 @@ import org.springframework.jdbc.core.SqlParameter;
|
||||||
import org.springframework.jdbc.core.SqlReturnResultSet;
|
import org.springframework.jdbc.core.SqlReturnResultSet;
|
||||||
import org.springframework.jdbc.core.support.AbstractSqlTypeValue;
|
import org.springframework.jdbc.core.support.AbstractSqlTypeValue;
|
||||||
import org.springframework.jdbc.datasource.ConnectionHolder;
|
import org.springframework.jdbc.datasource.ConnectionHolder;
|
||||||
import org.springframework.jdbc.support.SQLExceptionTranslator;
|
|
||||||
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
|
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
|
||||||
import org.springframework.lang.Nullable;
|
|
||||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
@ -148,8 +146,7 @@ public class StoredProcedureTests {
|
||||||
given(callableStatement.execute()).willReturn(false);
|
given(callableStatement.execute()).willReturn(false);
|
||||||
given(callableStatement.getUpdateCount()).willReturn(-1);
|
given(callableStatement.getUpdateCount()).willReturn(-1);
|
||||||
given(callableStatement.getObject(3)).willReturn(4);
|
given(callableStatement.getObject(3)).willReturn(4);
|
||||||
given(connection.prepareCall("{call " + AddInvoice.SQL + "(?, ?, ?)}")
|
given(connection.prepareCall("{call " + AddInvoice.SQL + "(?, ?, ?)}")).willReturn(callableStatement);
|
||||||
).willReturn(callableStatement);
|
|
||||||
TransactionSynchronizationManager.bindResource(dataSource, new ConnectionHolder(connection));
|
TransactionSynchronizationManager.bindResource(dataSource, new ConnectionHolder(connection));
|
||||||
try {
|
try {
|
||||||
testAddInvoice(1106, 3);
|
testAddInvoice(1106, 3);
|
||||||
|
|
@ -174,8 +171,7 @@ public class StoredProcedureTests {
|
||||||
given(callableStatement.execute()).willReturn(false);
|
given(callableStatement.execute()).willReturn(false);
|
||||||
given(callableStatement.getUpdateCount()).willReturn(-1);
|
given(callableStatement.getUpdateCount()).willReturn(-1);
|
||||||
given(callableStatement.getObject(2)).willReturn(5);
|
given(callableStatement.getObject(2)).willReturn(5);
|
||||||
given(connection.prepareCall("{call " + StoredProcedureConfiguredViaJdbcTemplate.SQL + "(?, ?)}")
|
given(connection.prepareCall("{call " + StoredProcedureConfiguredViaJdbcTemplate.SQL + "(?, ?)}")).willReturn(callableStatement);
|
||||||
).willReturn(callableStatement);
|
|
||||||
|
|
||||||
class TestJdbcTemplate extends JdbcTemplate {
|
class TestJdbcTemplate extends JdbcTemplate {
|
||||||
|
|
||||||
|
|
@ -210,8 +206,7 @@ public class StoredProcedureTests {
|
||||||
given(callableStatement.execute()).willReturn(false);
|
given(callableStatement.execute()).willReturn(false);
|
||||||
given(callableStatement.getUpdateCount()).willReturn(-1);
|
given(callableStatement.getUpdateCount()).willReturn(-1);
|
||||||
given(callableStatement.getObject(2)).willReturn(4);
|
given(callableStatement.getObject(2)).willReturn(4);
|
||||||
given(connection.prepareCall("{call " + StoredProcedureConfiguredViaJdbcTemplate.SQL + "(?, ?)}")
|
given(connection.prepareCall("{call " + StoredProcedureConfiguredViaJdbcTemplate.SQL + "(?, ?)}")).willReturn(callableStatement);
|
||||||
).willReturn(callableStatement);
|
|
||||||
JdbcTemplate t = new JdbcTemplate();
|
JdbcTemplate t = new JdbcTemplate();
|
||||||
t.setDataSource(dataSource);
|
t.setDataSource(dataSource);
|
||||||
StoredProcedureConfiguredViaJdbcTemplate sp = new StoredProcedureConfiguredViaJdbcTemplate(t);
|
StoredProcedureConfiguredViaJdbcTemplate sp = new StoredProcedureConfiguredViaJdbcTemplate(t);
|
||||||
|
|
@ -234,28 +229,24 @@ public class StoredProcedureTests {
|
||||||
public void testUnnamedParameter() throws Exception {
|
public void testUnnamedParameter() throws Exception {
|
||||||
this.verifyClosedAfter = false;
|
this.verifyClosedAfter = false;
|
||||||
// Shouldn't succeed in creating stored procedure with unnamed parameter
|
// Shouldn't succeed in creating stored procedure with unnamed parameter
|
||||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() ->
|
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||||
new UnnamedParameterStoredProcedure(dataSource));
|
.isThrownBy(() -> new UnnamedParameterStoredProcedure(dataSource));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMissingParameter() throws Exception {
|
public void testMissingParameter() throws Exception {
|
||||||
this.verifyClosedAfter = false;
|
this.verifyClosedAfter = false;
|
||||||
MissingParameterStoredProcedure mp = new MissingParameterStoredProcedure(dataSource);
|
MissingParameterStoredProcedure mp = new MissingParameterStoredProcedure(dataSource);
|
||||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(
|
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(mp::execute);
|
||||||
mp::execute);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStoredProcedureExceptionTranslator() throws Exception {
|
public void testStoredProcedureExceptionTranslator() throws Exception {
|
||||||
SQLException sqlException = new SQLException(
|
SQLException sqlException = new SQLException("Syntax error or access violation exception", "42000");
|
||||||
"Syntax error or access violation exception", "42000");
|
|
||||||
given(callableStatement.execute()).willThrow(sqlException);
|
given(callableStatement.execute()).willThrow(sqlException);
|
||||||
given(connection.prepareCall("{call " + StoredProcedureExceptionTranslator.SQL + "()}")
|
given(connection.prepareCall("{call " + StoredProcedureExceptionTranslator.SQL + "()}")).willReturn(callableStatement);
|
||||||
).willReturn(callableStatement);
|
|
||||||
StoredProcedureExceptionTranslator sproc = new StoredProcedureExceptionTranslator(dataSource);
|
StoredProcedureExceptionTranslator sproc = new StoredProcedureExceptionTranslator(dataSource);
|
||||||
assertThatExceptionOfType(CustomDataException.class).isThrownBy(
|
assertThatExceptionOfType(CustomDataException.class).isThrownBy(sproc::execute);
|
||||||
sproc::execute);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -266,8 +257,7 @@ public class StoredProcedureTests {
|
||||||
given(callableStatement.getUpdateCount()).willReturn(-1);
|
given(callableStatement.getUpdateCount()).willReturn(-1);
|
||||||
given(callableStatement.getResultSet()).willReturn(resultSet);
|
given(callableStatement.getResultSet()).willReturn(resultSet);
|
||||||
given(callableStatement.getUpdateCount()).willReturn(-1);
|
given(callableStatement.getUpdateCount()).willReturn(-1);
|
||||||
given(connection.prepareCall("{call " + StoredProcedureWithResultSet.SQL + "()}")
|
given(connection.prepareCall("{call " + StoredProcedureWithResultSet.SQL + "()}")).willReturn(callableStatement);
|
||||||
).willReturn(callableStatement);
|
|
||||||
StoredProcedureWithResultSet sproc = new StoredProcedureWithResultSet(dataSource);
|
StoredProcedureWithResultSet sproc = new StoredProcedureWithResultSet(dataSource);
|
||||||
sproc.execute();
|
sproc.execute();
|
||||||
assertThat(sproc.getCount()).isEqualTo(2);
|
assertThat(sproc.getCount()).isEqualTo(2);
|
||||||
|
|
@ -285,14 +275,11 @@ public class StoredProcedureTests {
|
||||||
given(callableStatement.getResultSet()).willReturn(resultSet);
|
given(callableStatement.getResultSet()).willReturn(resultSet);
|
||||||
given(callableStatement.getMoreResults()).willReturn(false);
|
given(callableStatement.getMoreResults()).willReturn(false);
|
||||||
given(callableStatement.getUpdateCount()).willReturn(-1);
|
given(callableStatement.getUpdateCount()).willReturn(-1);
|
||||||
given(connection.prepareCall("{call " + StoredProcedureWithResultSetMapped.SQL + "()}")
|
given(connection.prepareCall("{call " + StoredProcedureWithResultSetMapped.SQL + "()}")).willReturn(callableStatement);
|
||||||
).willReturn(callableStatement);
|
|
||||||
StoredProcedureWithResultSetMapped sproc = new StoredProcedureWithResultSetMapped(dataSource);
|
StoredProcedureWithResultSetMapped sproc = new StoredProcedureWithResultSetMapped(dataSource);
|
||||||
Map<String, Object> res = sproc.execute();
|
Map<String, Object> res = sproc.execute();
|
||||||
List<String> rs = (List<String>) res.get("rs");
|
List<String> rs = (List<String>) res.get("rs");
|
||||||
assertThat(rs.size()).isEqualTo(2);
|
assertThat(rs).containsExactly("Foo", "Bar");
|
||||||
assertThat(rs.get(0)).isEqualTo("Foo");
|
|
||||||
assertThat(rs.get(1)).isEqualTo("Bar");
|
|
||||||
verify(resultSet).close();
|
verify(resultSet).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -319,8 +306,7 @@ public class StoredProcedureTests {
|
||||||
given(callableStatement.getResultSet()).willReturn(resultSet1, resultSet2);
|
given(callableStatement.getResultSet()).willReturn(resultSet1, resultSet2);
|
||||||
given(callableStatement.getMoreResults()).willReturn(true, false, false);
|
given(callableStatement.getMoreResults()).willReturn(true, false, false);
|
||||||
given(callableStatement.getUpdateCount()).willReturn(-1, -1, 0, -1);
|
given(callableStatement.getUpdateCount()).willReturn(-1, -1, 0, -1);
|
||||||
given(connection.prepareCall("{call " + StoredProcedureWithResultSetMapped.SQL + "()}")
|
given(connection.prepareCall("{call " + StoredProcedureWithResultSetMapped.SQL + "()}")).willReturn(callableStatement);
|
||||||
).willReturn(callableStatement);
|
|
||||||
|
|
||||||
StoredProcedureWithResultSetMapped sproc = new StoredProcedureWithResultSetMapped(dataSource);
|
StoredProcedureWithResultSetMapped sproc = new StoredProcedureWithResultSetMapped(dataSource);
|
||||||
Map<String, Object> res = sproc.execute();
|
Map<String, Object> res = sproc.execute();
|
||||||
|
|
@ -328,15 +314,12 @@ public class StoredProcedureTests {
|
||||||
assertThat(res.size()).as("incorrect number of returns").isEqualTo(3);
|
assertThat(res.size()).as("incorrect number of returns").isEqualTo(3);
|
||||||
|
|
||||||
List<String> rs1 = (List<String>) res.get("rs");
|
List<String> rs1 = (List<String>) res.get("rs");
|
||||||
assertThat(rs1.size()).isEqualTo(2);
|
assertThat(rs1).containsExactly("Foo", "Bar");
|
||||||
assertThat(rs1.get(0)).isEqualTo("Foo");
|
|
||||||
assertThat(rs1.get(1)).isEqualTo("Bar");
|
|
||||||
|
|
||||||
List<Object> rs2 = (List<Object>) res.get("#result-set-2");
|
List<Object> rs2 = (List<Object>) res.get("#result-set-2");
|
||||||
assertThat(rs2.size()).isEqualTo(1);
|
assertThat(rs2.size()).isEqualTo(1);
|
||||||
Object o2 = rs2.get(0);
|
Object o2 = rs2.get(0);
|
||||||
boolean condition = o2 instanceof Map;
|
assertThat(o2).as("wron type returned for result set 2").isInstanceOf(Map.class);
|
||||||
assertThat(condition).as("wron type returned for result set 2").isTrue();
|
|
||||||
Map<String, String> m2 = (Map<String, String>) o2;
|
Map<String, String> m2 = (Map<String, String>) o2;
|
||||||
assertThat(m2.get("spam")).isEqualTo("Spam");
|
assertThat(m2.get("spam")).isEqualTo("Spam");
|
||||||
assertThat(m2.get("eggs")).isEqualTo("Eggs");
|
assertThat(m2.get("eggs")).isEqualTo("Eggs");
|
||||||
|
|
@ -351,12 +334,10 @@ public class StoredProcedureTests {
|
||||||
public void testStoredProcedureSkippingResultsProcessing() throws Exception {
|
public void testStoredProcedureSkippingResultsProcessing() throws Exception {
|
||||||
given(callableStatement.execute()).willReturn(true);
|
given(callableStatement.execute()).willReturn(true);
|
||||||
given(callableStatement.getUpdateCount()).willReturn(-1);
|
given(callableStatement.getUpdateCount()).willReturn(-1);
|
||||||
given(connection.prepareCall("{call " + StoredProcedureWithResultSetMapped.SQL + "()}")
|
given(connection.prepareCall("{call " + StoredProcedureWithResultSetMapped.SQL + "()}")).willReturn(callableStatement);
|
||||||
).willReturn(callableStatement);
|
|
||||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
jdbcTemplate.setSkipResultsProcessing(true);
|
jdbcTemplate.setSkipResultsProcessing(true);
|
||||||
StoredProcedureWithResultSetMapped sproc = new StoredProcedureWithResultSetMapped(
|
StoredProcedureWithResultSetMapped sproc = new StoredProcedureWithResultSetMapped(jdbcTemplate);
|
||||||
jdbcTemplate);
|
|
||||||
Map<String, Object> res = sproc.execute();
|
Map<String, Object> res = sproc.execute();
|
||||||
assertThat(res.size()).as("incorrect number of returns").isEqualTo(0);
|
assertThat(res.size()).as("incorrect number of returns").isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
@ -372,13 +353,11 @@ public class StoredProcedureTests {
|
||||||
given(callableStatement.getResultSet()).willReturn(resultSet);
|
given(callableStatement.getResultSet()).willReturn(resultSet);
|
||||||
given(callableStatement.getMoreResults()).willReturn(true, false);
|
given(callableStatement.getMoreResults()).willReturn(true, false);
|
||||||
given(callableStatement.getUpdateCount()).willReturn(-1, -1);
|
given(callableStatement.getUpdateCount()).willReturn(-1, -1);
|
||||||
given(connection.prepareCall("{call " + StoredProcedureWithResultSetMapped.SQL + "()}")
|
given(connection.prepareCall("{call " + StoredProcedureWithResultSetMapped.SQL + "()}")).willReturn(callableStatement);
|
||||||
).willReturn(callableStatement);
|
|
||||||
|
|
||||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
jdbcTemplate.setSkipUndeclaredResults(true);
|
jdbcTemplate.setSkipUndeclaredResults(true);
|
||||||
StoredProcedureWithResultSetMapped sproc = new StoredProcedureWithResultSetMapped(
|
StoredProcedureWithResultSetMapped sproc = new StoredProcedureWithResultSetMapped(jdbcTemplate);
|
||||||
jdbcTemplate);
|
|
||||||
Map<String, Object> res = sproc.execute();
|
Map<String, Object> res = sproc.execute();
|
||||||
|
|
||||||
assertThat(res.size()).as("incorrect number of returns").isEqualTo(1);
|
assertThat(res.size()).as("incorrect number of returns").isEqualTo(1);
|
||||||
|
|
@ -394,8 +373,7 @@ public class StoredProcedureTests {
|
||||||
given(callableStatement.execute()).willReturn(false);
|
given(callableStatement.execute()).willReturn(false);
|
||||||
given(callableStatement.getUpdateCount()).willReturn(-1);
|
given(callableStatement.getUpdateCount()).willReturn(-1);
|
||||||
given(callableStatement.getObject(2)).willReturn("OK");
|
given(callableStatement.getObject(2)).willReturn("OK");
|
||||||
given(connection.prepareCall("{call " + ParameterMapperStoredProcedure.SQL + "(?, ?)}")
|
given(connection.prepareCall("{call " + ParameterMapperStoredProcedure.SQL + "(?, ?)}")).willReturn(callableStatement);
|
||||||
).willReturn(callableStatement);
|
|
||||||
|
|
||||||
ParameterMapperStoredProcedure pmsp = new ParameterMapperStoredProcedure(dataSource);
|
ParameterMapperStoredProcedure pmsp = new ParameterMapperStoredProcedure(dataSource);
|
||||||
Map<String, Object> out = pmsp.executeTest();
|
Map<String, Object> out = pmsp.executeTest();
|
||||||
|
|
@ -411,8 +389,7 @@ public class StoredProcedureTests {
|
||||||
given(callableStatement.execute()).willReturn(false);
|
given(callableStatement.execute()).willReturn(false);
|
||||||
given(callableStatement.getUpdateCount()).willReturn(-1);
|
given(callableStatement.getUpdateCount()).willReturn(-1);
|
||||||
given(callableStatement.getObject(2)).willReturn("OK");
|
given(callableStatement.getObject(2)).willReturn("OK");
|
||||||
given(connection.prepareCall("{call " + SqlTypeValueStoredProcedure.SQL + "(?, ?)}")
|
given(connection.prepareCall("{call " + SqlTypeValueStoredProcedure.SQL + "(?, ?)}")).willReturn(callableStatement);
|
||||||
).willReturn(callableStatement);
|
|
||||||
|
|
||||||
SqlTypeValueStoredProcedure stvsp = new SqlTypeValueStoredProcedure(dataSource);
|
SqlTypeValueStoredProcedure stvsp = new SqlTypeValueStoredProcedure(dataSource);
|
||||||
Map<String, Object> out = stvsp.executeTest(testVal);
|
Map<String, Object> out = stvsp.executeTest(testVal);
|
||||||
|
|
@ -426,8 +403,7 @@ public class StoredProcedureTests {
|
||||||
given(callableStatement.execute()).willReturn(false);
|
given(callableStatement.execute()).willReturn(false);
|
||||||
given(callableStatement.getUpdateCount()).willReturn(-1);
|
given(callableStatement.getUpdateCount()).willReturn(-1);
|
||||||
given(callableStatement.getObject(1)).willReturn(new BigDecimal("12345.6789"));
|
given(callableStatement.getObject(1)).willReturn(new BigDecimal("12345.6789"));
|
||||||
given(connection.prepareCall("{call " + NumericWithScaleStoredProcedure.SQL + "(?)}")
|
given(connection.prepareCall("{call " + NumericWithScaleStoredProcedure.SQL + "(?)}")).willReturn(callableStatement);
|
||||||
).willReturn(callableStatement);
|
|
||||||
NumericWithScaleStoredProcedure nwssp = new NumericWithScaleStoredProcedure(dataSource);
|
NumericWithScaleStoredProcedure nwssp = new NumericWithScaleStoredProcedure(dataSource);
|
||||||
Map<String, Object> out = nwssp.executeTest();
|
Map<String, Object> out = nwssp.executeTest();
|
||||||
assertThat(out.get("out")).isEqualTo(new BigDecimal("12345.6789"));
|
assertThat(out.get("out")).isEqualTo(new BigDecimal("12345.6789"));
|
||||||
|
|
@ -686,12 +662,7 @@ public class StoredProcedureTests {
|
||||||
public StoredProcedureExceptionTranslator(DataSource ds) {
|
public StoredProcedureExceptionTranslator(DataSource ds) {
|
||||||
setDataSource(ds);
|
setDataSource(ds);
|
||||||
setSql(SQL);
|
setSql(SQL);
|
||||||
getJdbcTemplate().setExceptionTranslator(new SQLExceptionTranslator() {
|
getJdbcTemplate().setExceptionTranslator((task, sql, ex) -> new CustomDataException(sql, ex));
|
||||||
@Override
|
|
||||||
public DataAccessException translate(String task, @Nullable String sql, SQLException ex) {
|
|
||||||
return new CustomDataException(sql, ex);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
compile();
|
compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 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.
|
||||||
|
|
@ -87,7 +87,7 @@ public class SQLErrorCodeSQLExceptionTranslatorTests {
|
||||||
|
|
||||||
SQLException dupKeyEx = new SQLException("", "", 10);
|
SQLException dupKeyEx = new SQLException("", "", 10);
|
||||||
DataAccessException dksex = sext.translate("task", "SQL", dupKeyEx);
|
DataAccessException dksex = sext.translate("task", "SQL", dupKeyEx);
|
||||||
assertThat(DataIntegrityViolationException.class.isInstance(dksex)).as("Not instance of DataIntegrityViolationException").isTrue();
|
assertThat(dksex).isInstanceOf(DataIntegrityViolationException.class);
|
||||||
|
|
||||||
// Test fallback. We assume that no database will ever return this error code,
|
// Test fallback. We assume that no database will ever return this error code,
|
||||||
// but 07xxx will be bad grammar picked up by the fallback SQLState translator
|
// but 07xxx will be bad grammar picked up by the fallback SQLState translator
|
||||||
|
|
|
||||||
|
|
@ -200,12 +200,9 @@ class JmsTemplateTests {
|
||||||
JmsTemplate template = createTemplate();
|
JmsTemplate template = createTemplate();
|
||||||
template.setConnectionFactory(this.connectionFactory);
|
template.setConnectionFactory(this.connectionFactory);
|
||||||
|
|
||||||
template.execute(new SessionCallback<Void>() {
|
template.execute((SessionCallback<Void>) session -> {
|
||||||
@Override
|
session.getTransacted();
|
||||||
public Void doInJms(Session session) throws JMSException {
|
return null;
|
||||||
session.getTransacted();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
verify(this.session).close();
|
verify(this.session).close();
|
||||||
|
|
@ -220,19 +217,13 @@ class JmsTemplateTests {
|
||||||
|
|
||||||
TransactionSynchronizationManager.initSynchronization();
|
TransactionSynchronizationManager.initSynchronization();
|
||||||
try {
|
try {
|
||||||
template.execute(new SessionCallback<Void>() {
|
template.execute((SessionCallback<Void>) session -> {
|
||||||
@Override
|
session.getTransacted();
|
||||||
public Void doInJms(Session session) throws JMSException {
|
return null;
|
||||||
session.getTransacted();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
template.execute(new SessionCallback<Void>() {
|
template.execute((SessionCallback<Void>) session -> {
|
||||||
@Override
|
session.getTransacted();
|
||||||
public Void doInJms(Session session) throws JMSException {
|
return null;
|
||||||
session.getTransacted();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assertThat(ConnectionFactoryUtils.getTransactionalSession(scf, null, false)).isSameAs(this.session);
|
assertThat(ConnectionFactoryUtils.getTransactionalSession(scf, null, false)).isSameAs(this.session);
|
||||||
|
|
@ -374,29 +365,14 @@ class JmsTemplateTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useDefaultDestination) {
|
if (useDefaultDestination) {
|
||||||
template.send(new MessageCreator() {
|
template.send(session -> session.createTextMessage("just testing"));
|
||||||
@Override
|
|
||||||
public Message createMessage(Session session) throws JMSException {
|
|
||||||
return session.createTextMessage("just testing");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (explicitDestination) {
|
if (explicitDestination) {
|
||||||
template.send(this.queue, new MessageCreator() {
|
template.send(this.queue, (MessageCreator) session -> session.createTextMessage("just testing"));
|
||||||
@Override
|
|
||||||
public Message createMessage(Session session) throws JMSException {
|
|
||||||
return session.createTextMessage("just testing");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
template.send(destinationName, new MessageCreator() {
|
template.send(destinationName, (MessageCreator) session -> session.createTextMessage("just testing"));
|
||||||
@Override
|
|
||||||
public Message createMessage(Session session) throws JMSException {
|
|
||||||
return session.createTextMessage("just testing");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ import jakarta.jms.Session;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.context.support.GenericApplicationContext;
|
import org.springframework.context.support.GenericApplicationContext;
|
||||||
import org.springframework.core.task.TaskExecutor;
|
|
||||||
import org.springframework.jms.StubQueue;
|
import org.springframework.jms.StubQueue;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.ErrorHandler;
|
import org.springframework.util.ErrorHandler;
|
||||||
|
|
@ -182,16 +181,13 @@ public class SimpleMessageListenerContainerTests {
|
||||||
|
|
||||||
this.container.setConnectionFactory(connectionFactory);
|
this.container.setConnectionFactory(connectionFactory);
|
||||||
this.container.setDestinationName(DESTINATION_NAME);
|
this.container.setDestinationName(DESTINATION_NAME);
|
||||||
this.container.setMessageListener(new SessionAwareMessageListener<Message>() {
|
this.container.setMessageListener((SessionAwareMessageListener<Message>) (Message message, @Nullable Session sess) -> {
|
||||||
@Override
|
try {
|
||||||
public void onMessage(Message message, @Nullable Session sess) {
|
// Check correct Session passed into SessionAwareMessageListener.
|
||||||
try {
|
assertThat(session).isSameAs(sess);
|
||||||
// Check correct Session passed into SessionAwareMessageListener.
|
}
|
||||||
assertThat(session).isSameAs(sess);
|
catch (Throwable ex) {
|
||||||
}
|
failure.add("MessageListener execution failed: " + ex);
|
||||||
catch (Throwable ex) {
|
|
||||||
failure.add("MessageListener execution failed: " + ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -231,14 +227,11 @@ public class SimpleMessageListenerContainerTests {
|
||||||
this.container.setConnectionFactory(connectionFactory);
|
this.container.setConnectionFactory(connectionFactory);
|
||||||
this.container.setDestinationName(DESTINATION_NAME);
|
this.container.setDestinationName(DESTINATION_NAME);
|
||||||
this.container.setMessageListener(listener);
|
this.container.setMessageListener(listener);
|
||||||
this.container.setTaskExecutor(new TaskExecutor() {
|
this.container.setTaskExecutor(task -> {
|
||||||
@Override
|
listener.executorInvoked = true;
|
||||||
public void execute(Runnable task) {
|
assertThat(listener.listenerInvoked).isFalse();
|
||||||
listener.executorInvoked = true;
|
task.run();
|
||||||
assertThat(listener.listenerInvoked).isFalse();
|
assertThat(listener.listenerInvoked).isTrue();
|
||||||
task.run();
|
|
||||||
assertThat(listener.listenerInvoked).isTrue();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
this.container.afterPropertiesSet();
|
this.container.afterPropertiesSet();
|
||||||
this.container.start();
|
this.container.start();
|
||||||
|
|
@ -278,11 +271,8 @@ public class SimpleMessageListenerContainerTests {
|
||||||
|
|
||||||
this.container.setConnectionFactory(connectionFactory);
|
this.container.setConnectionFactory(connectionFactory);
|
||||||
this.container.setDestinationName(DESTINATION_NAME);
|
this.container.setDestinationName(DESTINATION_NAME);
|
||||||
this.container.setMessageListener(new SessionAwareMessageListener<Message>() {
|
this.container.setMessageListener((SessionAwareMessageListener<Message>) (Message message, @Nullable Session session1) -> {
|
||||||
@Override
|
throw theException;
|
||||||
public void onMessage(Message message, @Nullable Session session) throws JMSException {
|
|
||||||
throw theException;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ExceptionListener exceptionListener = mock(ExceptionListener.class);
|
ExceptionListener exceptionListener = mock(ExceptionListener.class);
|
||||||
|
|
@ -328,11 +318,8 @@ public class SimpleMessageListenerContainerTests {
|
||||||
|
|
||||||
this.container.setConnectionFactory(connectionFactory);
|
this.container.setConnectionFactory(connectionFactory);
|
||||||
this.container.setDestinationName(DESTINATION_NAME);
|
this.container.setDestinationName(DESTINATION_NAME);
|
||||||
this.container.setMessageListener(new SessionAwareMessageListener<Message>() {
|
this.container.setMessageListener((SessionAwareMessageListener<Message>) (Message message, @Nullable Session session1) -> {
|
||||||
@Override
|
throw theException;
|
||||||
public void onMessage(Message message, @Nullable Session session) throws JMSException {
|
|
||||||
throw theException;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ErrorHandler errorHandler = mock(ErrorHandler.class);
|
ErrorHandler errorHandler = mock(ErrorHandler.class);
|
||||||
|
|
@ -374,11 +361,8 @@ public class SimpleMessageListenerContainerTests {
|
||||||
|
|
||||||
this.container.setConnectionFactory(connectionFactory);
|
this.container.setConnectionFactory(connectionFactory);
|
||||||
this.container.setDestinationName(DESTINATION_NAME);
|
this.container.setDestinationName(DESTINATION_NAME);
|
||||||
this.container.setMessageListener(new MessageListener() {
|
this.container.setMessageListener((MessageListener) message -> {
|
||||||
@Override
|
throw new UnsupportedOperationException();
|
||||||
public void onMessage(Message message) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
this.container.afterPropertiesSet();
|
this.container.afterPropertiesSet();
|
||||||
this.container.start();
|
this.container.start();
|
||||||
|
|
@ -418,11 +402,8 @@ public class SimpleMessageListenerContainerTests {
|
||||||
|
|
||||||
this.container.setConnectionFactory(connectionFactory);
|
this.container.setConnectionFactory(connectionFactory);
|
||||||
this.container.setDestinationName(DESTINATION_NAME);
|
this.container.setDestinationName(DESTINATION_NAME);
|
||||||
this.container.setMessageListener(new MessageListener() {
|
this.container.setMessageListener((MessageListener) message -> {
|
||||||
@Override
|
throw new UnsupportedOperationException();
|
||||||
public void onMessage(Message message) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
this.container.afterPropertiesSet();
|
this.container.afterPropertiesSet();
|
||||||
this.container.start();
|
this.container.start();
|
||||||
|
|
|
||||||
|
|
@ -431,8 +431,8 @@ public class MessagingMessageListenerAdapterTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Summary {};
|
interface Summary {}
|
||||||
interface Full extends Summary {};
|
interface Full extends Summary {}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static class SampleResponse {
|
private static class SampleResponse {
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,6 @@ import jakarta.jms.ObjectMessage;
|
||||||
import jakarta.jms.Session;
|
import jakarta.jms.Session;
|
||||||
import jakarta.jms.TextMessage;
|
import jakarta.jms.TextMessage;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
|
||||||
import org.mockito.stubbing.Answer;
|
|
||||||
|
|
||||||
import org.springframework.jms.support.converter.MessageConversionException;
|
import org.springframework.jms.support.converter.MessageConversionException;
|
||||||
import org.springframework.jms.support.converter.SimpleMessageConverter;
|
import org.springframework.jms.support.converter.SimpleMessageConverter;
|
||||||
|
|
@ -76,12 +74,7 @@ public class SimpleMessageConverterTests {
|
||||||
|
|
||||||
given(session.createBytesMessage()).willReturn(message);
|
given(session.createBytesMessage()).willReturn(message);
|
||||||
given(message.getBodyLength()).willReturn((long) content.length);
|
given(message.getBodyLength()).willReturn((long) content.length);
|
||||||
given(message.readBytes(any(byte[].class))).willAnswer(new Answer<Integer>() {
|
given(message.readBytes(any(byte[].class))).willAnswer(invocation -> byteArrayInputStream.read((byte[]) invocation.getArguments()[0]));
|
||||||
@Override
|
|
||||||
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
|
||||||
return byteArrayInputStream.read((byte[]) invocation.getArguments()[0]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
SimpleMessageConverter converter = new SimpleMessageConverter();
|
SimpleMessageConverter converter = new SimpleMessageConverter();
|
||||||
Message msg = converter.toMessage(content, session);
|
Message msg = converter.toMessage(content, session);
|
||||||
|
|
|
||||||
|
|
@ -299,9 +299,9 @@ class MappingJackson2MessageConverterTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private interface Summary {};
|
private interface Summary {}
|
||||||
|
|
||||||
private interface Full extends Summary {};
|
private interface Full extends Summary {}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
|
|
||||||
|
|
@ -319,9 +319,9 @@ public class MappingJackson2MessageConverterTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public interface MyJacksonView1 {};
|
public interface MyJacksonView1 {}
|
||||||
|
|
||||||
public interface MyJacksonView2 {};
|
public interface MyJacksonView2 {}
|
||||||
|
|
||||||
|
|
||||||
public static class JacksonViewBean {
|
public static class JacksonViewBean {
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ import org.springframework.messaging.MessageChannel;
|
||||||
import org.springframework.messaging.MessageDeliveryException;
|
import org.springframework.messaging.MessageDeliveryException;
|
||||||
import org.springframework.messaging.MessageHandler;
|
import org.springframework.messaging.MessageHandler;
|
||||||
import org.springframework.messaging.MessageHeaders;
|
import org.springframework.messaging.MessageHeaders;
|
||||||
import org.springframework.messaging.MessagingException;
|
|
||||||
import org.springframework.messaging.StubMessageChannel;
|
import org.springframework.messaging.StubMessageChannel;
|
||||||
import org.springframework.messaging.SubscribableChannel;
|
import org.springframework.messaging.SubscribableChannel;
|
||||||
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
||||||
|
|
@ -112,12 +111,9 @@ public class GenericMessagingTemplateTests {
|
||||||
@Test
|
@Test
|
||||||
public void sendAndReceive() {
|
public void sendAndReceive() {
|
||||||
SubscribableChannel channel = new ExecutorSubscribableChannel(this.executor);
|
SubscribableChannel channel = new ExecutorSubscribableChannel(this.executor);
|
||||||
channel.subscribe(new MessageHandler() {
|
channel.subscribe(message -> {
|
||||||
@Override
|
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
|
||||||
public void handleMessage(Message<?> message) throws MessagingException {
|
replyChannel.send(new GenericMessage<>("response"));
|
||||||
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
|
|
||||||
replyChannel.send(new GenericMessage<>("response"));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
String actual = this.template.convertSendAndReceive(channel, "request", String.class);
|
String actual = this.template.convertSendAndReceive(channel, "request", String.class);
|
||||||
|
|
@ -126,7 +122,7 @@ public class GenericMessagingTemplateTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sendAndReceiveTimeout() throws InterruptedException {
|
public void sendAndReceiveTimeout() throws InterruptedException {
|
||||||
final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
|
final AtomicReference<Throwable> failure = new AtomicReference<>();
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|
||||||
this.template.setReceiveTimeout(1);
|
this.template.setReceiveTimeout(1);
|
||||||
|
|
@ -152,7 +148,7 @@ public class GenericMessagingTemplateTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sendAndReceiveVariableTimeout() throws InterruptedException {
|
public void sendAndReceiveVariableTimeout() throws InterruptedException {
|
||||||
final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
|
final AtomicReference<Throwable> failure = new AtomicReference<>();
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|
||||||
this.template.setSendTimeout(20_000);
|
this.template.setSendTimeout(20_000);
|
||||||
|
|
@ -182,7 +178,7 @@ public class GenericMessagingTemplateTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sendAndReceiveVariableTimeoutCustomHeaders() throws InterruptedException {
|
public void sendAndReceiveVariableTimeoutCustomHeaders() throws InterruptedException {
|
||||||
final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
|
final AtomicReference<Throwable> failure = new AtomicReference<>();
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|
||||||
this.template.setSendTimeout(20_000);
|
this.template.setSendTimeout(20_000);
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ public class MessageMappingMessageHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Message<?> message(String destination, String... content) {
|
private Message<?> message(String destination, String... content) {
|
||||||
Flux<DataBuffer> payload = Flux.fromIterable(Arrays.asList(content)).map(parts -> toDataBuffer(parts));
|
Flux<DataBuffer> payload = Flux.fromIterable(Arrays.asList(content)).map(this::toDataBuffer);
|
||||||
MessageHeaderAccessor headers = new MessageHeaderAccessor();
|
MessageHeaderAccessor headers = new MessageHeaderAccessor();
|
||||||
headers.setLeaveMutable(true);
|
headers.setLeaveMutable(true);
|
||||||
headers.setHeader(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER,
|
headers.setHeader(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER,
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.support.StaticListableBeanFactory;
|
import org.springframework.beans.factory.support.StaticListableBeanFactory;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.core.convert.converter.Converter;
|
|
||||||
import org.springframework.core.convert.support.GenericConversionService;
|
import org.springframework.core.convert.support.GenericConversionService;
|
||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.converter.ByteArrayMessageConverter;
|
import org.springframework.messaging.converter.ByteArrayMessageConverter;
|
||||||
|
|
@ -59,12 +58,7 @@ public class DefaultMessageHandlerMethodFactoryTests {
|
||||||
public void customConversion() throws Exception {
|
public void customConversion() throws Exception {
|
||||||
DefaultMessageHandlerMethodFactory instance = createInstance();
|
DefaultMessageHandlerMethodFactory instance = createInstance();
|
||||||
GenericConversionService conversionService = new GenericConversionService();
|
GenericConversionService conversionService = new GenericConversionService();
|
||||||
conversionService.addConverter(SampleBean.class, String.class, new Converter<SampleBean, String>() {
|
conversionService.addConverter(SampleBean.class, String.class, source -> "foo bar");
|
||||||
@Override
|
|
||||||
public String convert(SampleBean source) {
|
|
||||||
return "foo bar";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
instance.setConversionService(conversionService);
|
instance.setConversionService(conversionService);
|
||||||
instance.afterPropertiesSet();
|
instance.afterPropertiesSet();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -131,8 +131,7 @@ public class SimpAttributesContextHolderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void currentAttributesNone() {
|
public void currentAttributesNone() {
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException().isThrownBy(SimpAttributesContextHolder::currentAttributes)
|
||||||
SimpAttributesContextHolder.currentAttributes())
|
|
||||||
.withMessageStartingWith("No thread-bound SimpAttributes found");
|
.withMessageStartingWith("No thread-bound SimpAttributes found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -224,8 +224,8 @@ public class SubscriptionMethodReturnValueHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private interface MyJacksonView1 {};
|
private interface MyJacksonView1 {}
|
||||||
private interface MyJacksonView2 {};
|
private interface MyJacksonView2 {}
|
||||||
|
|
||||||
private static class JacksonViewBean {
|
private static class JacksonViewBean {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ package org.springframework.messaging.simp.stomp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
@ -286,12 +285,7 @@ class StompBrokerRelayMessageHandlerTests {
|
||||||
|
|
||||||
|
|
||||||
private static ListenableFutureTask<Void> getVoidFuture() {
|
private static ListenableFutureTask<Void> getVoidFuture() {
|
||||||
ListenableFutureTask<Void> futureTask = new ListenableFutureTask<>(new Callable<Void>() {
|
ListenableFutureTask<Void> futureTask = new ListenableFutureTask<>(() -> null);
|
||||||
@Override
|
|
||||||
public Void call() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
futureTask.run();
|
futureTask.run();
|
||||||
return futureTask;
|
return futureTask;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ import org.springframework.transaction.InvalidIsolationLevelException;
|
||||||
import org.springframework.transaction.TransactionDefinition;
|
import org.springframework.transaction.TransactionDefinition;
|
||||||
import org.springframework.transaction.TransactionStatus;
|
import org.springframework.transaction.TransactionStatus;
|
||||||
import org.springframework.transaction.TransactionSystemException;
|
import org.springframework.transaction.TransactionSystemException;
|
||||||
import org.springframework.transaction.support.TransactionCallback;
|
|
||||||
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
|
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
|
||||||
import org.springframework.transaction.support.TransactionSynchronization;
|
import org.springframework.transaction.support.TransactionSynchronization;
|
||||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
|
|
@ -99,13 +98,10 @@ public class JpaTransactionManagerTests {
|
||||||
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||||
assertThat(condition2).isTrue();
|
assertThat(condition2).isTrue();
|
||||||
|
|
||||||
Object result = tt.execute(new TransactionCallback() {
|
Object result = tt.execute(status -> {
|
||||||
@Override
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
return l;
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
assertThat(result).isSameAs(l);
|
assertThat(result).isSameAs(l);
|
||||||
|
|
||||||
|
|
@ -134,13 +130,10 @@ public class JpaTransactionManagerTests {
|
||||||
assertThat(condition2).isTrue();
|
assertThat(condition2).isTrue();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Object result = tt.execute(new TransactionCallback() {
|
Object result = tt.execute(status -> {
|
||||||
@Override
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
return l;
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
assertThat(result).isSameAs(l);
|
assertThat(result).isSameAs(l);
|
||||||
}
|
}
|
||||||
|
|
@ -173,13 +166,10 @@ public class JpaTransactionManagerTests {
|
||||||
assertThat(condition2).isTrue();
|
assertThat(condition2).isTrue();
|
||||||
|
|
||||||
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() ->
|
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() ->
|
||||||
tt.execute(new TransactionCallback() {
|
tt.execute(status -> {
|
||||||
@Override
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory);
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
throw new RuntimeException("some exception");
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory);
|
|
||||||
throw new RuntimeException("some exception");
|
|
||||||
}
|
|
||||||
})).withMessage("some exception");
|
})).withMessage("some exception");
|
||||||
|
|
||||||
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
||||||
|
|
@ -204,13 +194,10 @@ public class JpaTransactionManagerTests {
|
||||||
assertThat(condition2).isTrue();
|
assertThat(condition2).isTrue();
|
||||||
|
|
||||||
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() ->
|
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() ->
|
||||||
tt.execute(new TransactionCallback() {
|
tt.execute(status -> {
|
||||||
@Override
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory);
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
throw new RuntimeException("some exception");
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory);
|
|
||||||
throw new RuntimeException("some exception");
|
|
||||||
}
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
||||||
|
|
@ -234,16 +221,13 @@ public class JpaTransactionManagerTests {
|
||||||
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||||
assertThat(condition2).isTrue();
|
assertThat(condition2).isTrue();
|
||||||
|
|
||||||
tt.execute(new TransactionCallback() {
|
tt.execute(status -> {
|
||||||
@Override
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
|
||||||
|
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
||||||
status.setRollbackOnly();
|
status.setRollbackOnly();
|
||||||
|
|
||||||
return l;
|
return l;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
||||||
|
|
@ -268,19 +252,13 @@ public class JpaTransactionManagerTests {
|
||||||
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||||
assertThat(condition2).isTrue();
|
assertThat(condition2).isTrue();
|
||||||
|
|
||||||
tt.execute(new TransactionCallback() {
|
tt.execute(status -> {
|
||||||
@Override
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
|
||||||
|
|
||||||
return tt.execute(new TransactionCallback() {
|
return tt.execute(status1 -> {
|
||||||
@Override
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
return l;
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
});
|
||||||
return l;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
||||||
|
|
@ -307,18 +285,12 @@ public class JpaTransactionManagerTests {
|
||||||
assertThat(condition2).isTrue();
|
assertThat(condition2).isTrue();
|
||||||
|
|
||||||
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() ->
|
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() ->
|
||||||
tt.execute(new TransactionCallback() {
|
tt.execute(status -> {
|
||||||
@Override
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
return tt.execute(status1 -> {
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory);
|
||||||
return tt.execute(new TransactionCallback() {
|
throw new RuntimeException("some exception");
|
||||||
@Override
|
});
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory);
|
|
||||||
throw new RuntimeException("some exception");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
||||||
|
|
@ -347,20 +319,14 @@ public class JpaTransactionManagerTests {
|
||||||
assertThat(condition2).isTrue();
|
assertThat(condition2).isTrue();
|
||||||
|
|
||||||
assertThatExceptionOfType(TransactionSystemException.class).isThrownBy(() ->
|
assertThatExceptionOfType(TransactionSystemException.class).isThrownBy(() ->
|
||||||
tt.execute(new TransactionCallback() {
|
tt.execute(status -> {
|
||||||
@Override
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
|
||||||
|
|
||||||
return tt.execute(new TransactionCallback() {
|
return tt.execute(status1 -> {
|
||||||
@Override
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
status1.setRollbackOnly();
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
return null;
|
||||||
status.setRollbackOnly();
|
});
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
.withCauseInstanceOf(RollbackException.class);
|
.withCauseInstanceOf(RollbackException.class);
|
||||||
|
|
||||||
|
|
@ -390,18 +356,12 @@ public class JpaTransactionManagerTests {
|
||||||
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||||
assertThat(condition2).isTrue();
|
assertThat(condition2).isTrue();
|
||||||
|
|
||||||
Object result = tt.execute(new TransactionCallback() {
|
Object result = tt.execute(status -> {
|
||||||
@Override
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
return tt.execute(status1 -> {
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
||||||
return tt.execute(new TransactionCallback() {
|
return l;
|
||||||
@Override
|
});
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
assertThat(result).isSameAs(l);
|
assertThat(result).isSameAs(l);
|
||||||
|
|
||||||
|
|
@ -432,20 +392,14 @@ public class JpaTransactionManagerTests {
|
||||||
TransactionSynchronizationManager.bindResource(factory, new EntityManagerHolder(manager));
|
TransactionSynchronizationManager.bindResource(factory, new EntityManagerHolder(manager));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Object result = tt.execute(new TransactionCallback() {
|
Object result = tt.execute(status -> {
|
||||||
@Override
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory);
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory);
|
|
||||||
|
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
return tt.execute(new TransactionCallback() {
|
return tt.execute(status1 -> {
|
||||||
@Override
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
return l;
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
});
|
||||||
return l;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
assertThat(result).isSameAs(l);
|
assertThat(result).isSameAs(l);
|
||||||
}
|
}
|
||||||
|
|
@ -478,20 +432,14 @@ public class JpaTransactionManagerTests {
|
||||||
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||||
assertThat(condition2).isTrue();
|
assertThat(condition2).isTrue();
|
||||||
|
|
||||||
Object result = tt.execute(new TransactionCallback() {
|
Object result = tt.execute(status -> {
|
||||||
@Override
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isFalse();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
TransactionTemplate tt2 = new TransactionTemplate(tm);
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isFalse();
|
tt2.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||||
TransactionTemplate tt2 = new TransactionTemplate(tm);
|
return tt2.execute(status1 -> {
|
||||||
tt2.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
||||||
return tt2.execute(new TransactionCallback() {
|
return l;
|
||||||
@Override
|
});
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
assertThat(result).isSameAs(l);
|
assertThat(result).isSameAs(l);
|
||||||
|
|
||||||
|
|
@ -521,22 +469,16 @@ public class JpaTransactionManagerTests {
|
||||||
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||||
assertThat(condition2).isTrue();
|
assertThat(condition2).isTrue();
|
||||||
|
|
||||||
Object result = tt.execute(new TransactionCallback() {
|
Object result = tt.execute(status -> {
|
||||||
@Override
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory);
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory);
|
|
||||||
|
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
TransactionTemplate tt2 = new TransactionTemplate(tm);
|
TransactionTemplate tt2 = new TransactionTemplate(tm);
|
||||||
tt2.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
tt2.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||||
return tt2.execute(new TransactionCallback() {
|
return tt2.execute(status1 -> {
|
||||||
@Override
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
return l;
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
});
|
||||||
return l;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
assertThat(result).isSameAs(l);
|
assertThat(result).isSameAs(l);
|
||||||
|
|
||||||
|
|
@ -567,24 +509,18 @@ public class JpaTransactionManagerTests {
|
||||||
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||||
assertThat(condition2).isTrue();
|
assertThat(condition2).isTrue();
|
||||||
|
|
||||||
tt.execute(new TransactionCallback() {
|
tt.execute(status -> {
|
||||||
@Override
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
@Override
|
||||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
public void afterCompletion(int status) {
|
||||||
@Override
|
tt.execute(status1 -> {
|
||||||
public void afterCompletion(int status) {
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
||||||
tt.execute(new TransactionCallback() {
|
return null;
|
||||||
@Override
|
});
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
}
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
||||||
|
|
@ -615,17 +551,14 @@ public class JpaTransactionManagerTests {
|
||||||
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||||
assertThat(condition2).isTrue();
|
assertThat(condition2).isTrue();
|
||||||
|
|
||||||
Object result = tt.execute(new TransactionCallback() {
|
Object result = tt.execute(status -> {
|
||||||
@Override
|
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
assertThat(condition1).isTrue();
|
||||||
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
|
||||||
assertThat(condition1).isTrue();
|
boolean condition = !status.isNewTransaction();
|
||||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
|
assertThat(condition).isTrue();
|
||||||
boolean condition = !status.isNewTransaction();
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
||||||
assertThat(condition).isTrue();
|
return l;
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
assertThat(result).isSameAs(l);
|
assertThat(result).isSameAs(l);
|
||||||
|
|
||||||
|
|
@ -649,18 +582,15 @@ public class JpaTransactionManagerTests {
|
||||||
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
boolean condition2 = !TransactionSynchronizationManager.isSynchronizationActive();
|
||||||
assertThat(condition2).isTrue();
|
assertThat(condition2).isTrue();
|
||||||
|
|
||||||
tt.execute(new TransactionCallback() {
|
tt.execute(status -> {
|
||||||
@Override
|
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
assertThat(condition1).isTrue();
|
||||||
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
|
||||||
assertThat(condition1).isTrue();
|
boolean condition = !status.isNewTransaction();
|
||||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
|
assertThat(condition).isTrue();
|
||||||
boolean condition = !status.isNewTransaction();
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
||||||
assertThat(condition).isTrue();
|
status.setRollbackOnly();
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
return null;
|
||||||
status.setRollbackOnly();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
boolean condition1 = !TransactionSynchronizationManager.hasResource(factory);
|
||||||
|
|
@ -686,14 +616,11 @@ public class JpaTransactionManagerTests {
|
||||||
TransactionSynchronizationManager.bindResource(factory, new EntityManagerHolder(manager));
|
TransactionSynchronizationManager.bindResource(factory, new EntityManagerHolder(manager));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Object result = tt.execute(new TransactionCallback() {
|
Object result = tt.execute(status -> {
|
||||||
@Override
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory);
|
||||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
|
return l;
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory);
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
assertThat(result).isSameAs(l);
|
assertThat(result).isSameAs(l);
|
||||||
|
|
||||||
|
|
@ -721,15 +648,12 @@ public class JpaTransactionManagerTests {
|
||||||
TransactionSynchronizationManager.bindResource(factory, new EntityManagerHolder(manager));
|
TransactionSynchronizationManager.bindResource(factory, new EntityManagerHolder(manager));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
tt.execute(new TransactionCallback() {
|
tt.execute(status -> {
|
||||||
@Override
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory);
|
||||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
|
status.setRollbackOnly();
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory);
|
return null;
|
||||||
status.setRollbackOnly();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
|
|
@ -759,16 +683,13 @@ public class JpaTransactionManagerTests {
|
||||||
TransactionSynchronizationManager.bindResource(factory, new EntityManagerHolder(manager));
|
TransactionSynchronizationManager.bindResource(factory, new EntityManagerHolder(manager));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Object result = tt.execute(new TransactionCallback() {
|
Object result = tt.execute(status -> {
|
||||||
@Override
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
boolean condition = !status.isNewTransaction();
|
||||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
|
assertThat(condition).isTrue();
|
||||||
boolean condition = !status.isNewTransaction();
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
||||||
assertThat(condition).isTrue();
|
return l;
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
assertThat(result).isSameAs(l);
|
assertThat(result).isSameAs(l);
|
||||||
|
|
||||||
|
|
@ -794,17 +715,14 @@ public class JpaTransactionManagerTests {
|
||||||
TransactionSynchronizationManager.bindResource(factory, new EntityManagerHolder(manager));
|
TransactionSynchronizationManager.bindResource(factory, new EntityManagerHolder(manager));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
tt.execute(new TransactionCallback() {
|
tt.execute(status -> {
|
||||||
@Override
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
public Object doInTransaction(TransactionStatus status) {
|
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
boolean condition = !status.isNewTransaction();
|
||||||
assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isTrue();
|
assertThat(condition).isTrue();
|
||||||
boolean condition = !status.isNewTransaction();
|
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
||||||
assertThat(condition).isTrue();
|
status.setRollbackOnly();
|
||||||
EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush();
|
return null;
|
||||||
status.setRollbackOnly();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
assertThat(TransactionSynchronizationManager.hasResource(factory)).isTrue();
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -72,13 +72,7 @@ public class InterceptingClientHttpRequestFactoryTests {
|
||||||
@Test
|
@Test
|
||||||
public void noExecution() throws Exception {
|
public void noExecution() throws Exception {
|
||||||
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
|
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
|
||||||
interceptors.add(new ClientHttpRequestInterceptor() {
|
interceptors.add((request, body, execution) -> responseMock);
|
||||||
@Override
|
|
||||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
|
|
||||||
throws IOException {
|
|
||||||
return responseMock;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
interceptors.add(new NoOpInterceptor());
|
interceptors.add(new NoOpInterceptor());
|
||||||
requestFactory = new InterceptingClientHttpRequestFactory(requestFactoryMock, interceptors);
|
requestFactory = new InterceptingClientHttpRequestFactory(requestFactoryMock, interceptors);
|
||||||
|
|
@ -97,15 +91,11 @@ public class InterceptingClientHttpRequestFactoryTests {
|
||||||
final String headerValue = "Bar";
|
final String headerValue = "Bar";
|
||||||
final String otherValue = "Baz";
|
final String otherValue = "Baz";
|
||||||
|
|
||||||
ClientHttpRequestInterceptor interceptor = new ClientHttpRequestInterceptor() {
|
ClientHttpRequestInterceptor interceptor = (request, body, execution) -> {
|
||||||
@Override
|
|
||||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
|
|
||||||
throws IOException {
|
|
||||||
HttpRequestWrapper wrapper = new HttpRequestWrapper(request);
|
HttpRequestWrapper wrapper = new HttpRequestWrapper(request);
|
||||||
wrapper.getHeaders().add(headerName, otherValue);
|
wrapper.getHeaders().add(headerName, otherValue);
|
||||||
return execution.execute(wrapper, body);
|
return execution.execute(wrapper, body);
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
requestMock = new RequestMock() {
|
requestMock = new RequestMock() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -119,8 +109,7 @@ public class InterceptingClientHttpRequestFactoryTests {
|
||||||
};
|
};
|
||||||
requestMock.getHeaders().add(headerName, headerValue);
|
requestMock.getHeaders().add(headerName, headerValue);
|
||||||
|
|
||||||
requestFactory =
|
requestFactory = new InterceptingClientHttpRequestFactory(requestFactoryMock, Collections.singletonList(interceptor));
|
||||||
new InterceptingClientHttpRequestFactory(requestFactoryMock, Collections.singletonList(interceptor));
|
|
||||||
|
|
||||||
ClientHttpRequest request = requestFactory.createRequest(new URI("https://example.com"), HttpMethod.GET);
|
ClientHttpRequest request = requestFactory.createRequest(new URI("https://example.com"), HttpMethod.GET);
|
||||||
request.execute();
|
request.execute();
|
||||||
|
|
@ -130,19 +119,13 @@ public class InterceptingClientHttpRequestFactoryTests {
|
||||||
public void changeURI() throws Exception {
|
public void changeURI() throws Exception {
|
||||||
final URI changedUri = new URI("https://example.com/2");
|
final URI changedUri = new URI("https://example.com/2");
|
||||||
|
|
||||||
ClientHttpRequestInterceptor interceptor = new ClientHttpRequestInterceptor() {
|
ClientHttpRequestInterceptor interceptor = (request, body, execution) -> execution.execute(new HttpRequestWrapper(request) {
|
||||||
@Override
|
@Override
|
||||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
|
public URI getURI() {
|
||||||
throws IOException {
|
return changedUri;
|
||||||
return execution.execute(new HttpRequestWrapper(request) {
|
|
||||||
@Override
|
|
||||||
public URI getURI() {
|
|
||||||
return changedUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
}, body);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
}, body);
|
||||||
|
|
||||||
requestFactoryMock = new RequestFactoryMock() {
|
requestFactoryMock = new RequestFactoryMock() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -152,8 +135,7 @@ public class InterceptingClientHttpRequestFactoryTests {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
requestFactory =
|
requestFactory = new InterceptingClientHttpRequestFactory(requestFactoryMock, Collections.singletonList(interceptor));
|
||||||
new InterceptingClientHttpRequestFactory(requestFactoryMock, Collections.singletonList(interceptor));
|
|
||||||
|
|
||||||
ClientHttpRequest request = requestFactory.createRequest(new URI("https://example.com"), HttpMethod.GET);
|
ClientHttpRequest request = requestFactory.createRequest(new URI("https://example.com"), HttpMethod.GET);
|
||||||
request.execute();
|
request.execute();
|
||||||
|
|
@ -163,19 +145,13 @@ public class InterceptingClientHttpRequestFactoryTests {
|
||||||
public void changeMethod() throws Exception {
|
public void changeMethod() throws Exception {
|
||||||
final HttpMethod changedMethod = HttpMethod.POST;
|
final HttpMethod changedMethod = HttpMethod.POST;
|
||||||
|
|
||||||
ClientHttpRequestInterceptor interceptor = new ClientHttpRequestInterceptor() {
|
ClientHttpRequestInterceptor interceptor = (request, body, execution) -> execution.execute(new HttpRequestWrapper(request) {
|
||||||
@Override
|
@Override
|
||||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
|
public HttpMethod getMethod() {
|
||||||
throws IOException {
|
return changedMethod;
|
||||||
return execution.execute(new HttpRequestWrapper(request) {
|
|
||||||
@Override
|
|
||||||
public HttpMethod getMethod() {
|
|
||||||
return changedMethod;
|
|
||||||
}
|
|
||||||
|
|
||||||
}, body);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
}, body);
|
||||||
|
|
||||||
requestFactoryMock = new RequestFactoryMock() {
|
requestFactoryMock = new RequestFactoryMock() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -185,8 +161,7 @@ public class InterceptingClientHttpRequestFactoryTests {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
requestFactory =
|
requestFactory = new InterceptingClientHttpRequestFactory(requestFactoryMock, Collections.singletonList(interceptor));
|
||||||
new InterceptingClientHttpRequestFactory(requestFactoryMock, Collections.singletonList(interceptor));
|
|
||||||
|
|
||||||
ClientHttpRequest request = requestFactory.createRequest(new URI("https://example.com"), HttpMethod.GET);
|
ClientHttpRequest request = requestFactory.createRequest(new URI("https://example.com"), HttpMethod.GET);
|
||||||
request.execute();
|
request.execute();
|
||||||
|
|
@ -196,16 +171,9 @@ public class InterceptingClientHttpRequestFactoryTests {
|
||||||
public void changeBody() throws Exception {
|
public void changeBody() throws Exception {
|
||||||
final byte[] changedBody = "Foo".getBytes();
|
final byte[] changedBody = "Foo".getBytes();
|
||||||
|
|
||||||
ClientHttpRequestInterceptor interceptor = new ClientHttpRequestInterceptor() {
|
ClientHttpRequestInterceptor interceptor = (request, body, execution) -> execution.execute(request, changedBody);
|
||||||
@Override
|
|
||||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
|
|
||||||
throws IOException {
|
|
||||||
return execution.execute(request, changedBody);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
requestFactory =
|
requestFactory = new InterceptingClientHttpRequestFactory(requestFactoryMock, Collections.singletonList(interceptor));
|
||||||
new InterceptingClientHttpRequestFactory(requestFactoryMock, Collections.singletonList(interceptor));
|
|
||||||
|
|
||||||
ClientHttpRequest request = requestFactory.createRequest(new URI("https://example.com"), HttpMethod.GET);
|
ClientHttpRequest request = requestFactory.createRequest(new URI("https://example.com"), HttpMethod.GET);
|
||||||
request.execute();
|
request.execute();
|
||||||
|
|
|
||||||
|
|
@ -271,9 +271,9 @@ public class MappingJackson2XmlHttpMessageConverterTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private interface MyJacksonView1 {};
|
private interface MyJacksonView1 {}
|
||||||
|
|
||||||
private interface MyJacksonView2 {};
|
private interface MyJacksonView2 {}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
|
|
||||||
|
|
@ -249,13 +249,13 @@ public class ServletRequestDataBinderTests {
|
||||||
m.put("forname", "Tony");
|
m.put("forname", "Tony");
|
||||||
m.put("surname", "Blair");
|
m.put("surname", "Blair");
|
||||||
m.put("age", "50");
|
m.put("age", "50");
|
||||||
for (int i = 0; i < ps.length; i++) {
|
for (PropertyValue element : ps) {
|
||||||
Object val = m.get(ps[i].getName());
|
Object val = m.get(element.getName());
|
||||||
assertThat(val != null).as("Can't have unexpected value").isTrue();
|
assertThat(val != null).as("Can't have unexpected value").isTrue();
|
||||||
boolean condition = val instanceof String;
|
boolean condition = val instanceof String;
|
||||||
assertThat(condition).as("Val i string").isTrue();
|
assertThat(condition).as("Val i string").isTrue();
|
||||||
assertThat(val.equals(ps[i].getValue())).as("val matches expected").isTrue();
|
assertThat(val.equals(element.getValue())).as("val matches expected").isTrue();
|
||||||
m.remove(ps[i].getName());
|
m.remove(element.getName());
|
||||||
}
|
}
|
||||||
assertThat(m.size() == 0).as("Map size is 0").isTrue();
|
assertThat(m.size() == 0).as("Map size is 0").isTrue();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.web.context.request.async;
|
package org.springframework.web.context.request.async;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.web.context.request.async.DeferredResult.DeferredResultHandler;
|
import org.springframework.web.context.request.async.DeferredResult.DeferredResultHandler;
|
||||||
|
|
@ -127,12 +125,7 @@ public class DeferredResultTests {
|
||||||
DeferredResult<String> result = new DeferredResult<>(null, "error result");
|
DeferredResult<String> result = new DeferredResult<>(null, "error result");
|
||||||
result.setResultHandler(handler);
|
result.setResultHandler(handler);
|
||||||
Exception e = new Exception();
|
Exception e = new Exception();
|
||||||
result.onError(new Consumer<Throwable>() {
|
result.onError(t -> sb.append("error event"));
|
||||||
@Override
|
|
||||||
public void accept(Throwable t) {
|
|
||||||
sb.append("error event");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
result.getInterceptor().handleError(null, null, e);
|
result.getInterceptor().handleError(null, null, e);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.web.context.request.async;
|
package org.springframework.web.context.request.async;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
import jakarta.servlet.AsyncEvent;
|
import jakarta.servlet.AsyncEvent;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
|
@ -95,12 +94,7 @@ public class WebAsyncManagerErrorTests {
|
||||||
|
|
||||||
StubCallable callable = new StubCallable();
|
StubCallable callable = new StubCallable();
|
||||||
WebAsyncTask<Object> webAsyncTask = new WebAsyncTask<>(callable);
|
WebAsyncTask<Object> webAsyncTask = new WebAsyncTask<>(callable);
|
||||||
webAsyncTask.onError(new Callable<Object>() {
|
webAsyncTask.onError(() -> 7);
|
||||||
@Override
|
|
||||||
public Object call() throws Exception {
|
|
||||||
return 7;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.asyncManager.startCallableProcessing(webAsyncTask);
|
this.asyncManager.startCallableProcessing(webAsyncTask);
|
||||||
|
|
||||||
|
|
@ -201,12 +195,7 @@ public class WebAsyncManagerErrorTests {
|
||||||
public void startDeferredResultProcessingErrorAndResumeThroughCallback() throws Exception {
|
public void startDeferredResultProcessingErrorAndResumeThroughCallback() throws Exception {
|
||||||
|
|
||||||
final DeferredResult<Throwable> deferredResult = new DeferredResult<>();
|
final DeferredResult<Throwable> deferredResult = new DeferredResult<>();
|
||||||
deferredResult.onError(new Consumer<Throwable>() {
|
deferredResult.onError(t -> deferredResult.setResult(t));
|
||||||
@Override
|
|
||||||
public void accept(Throwable t) {
|
|
||||||
deferredResult.setResult(t);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.asyncManager.startDeferredResultProcessing(deferredResult);
|
this.asyncManager.startDeferredResultProcessing(deferredResult);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,12 +96,7 @@ public class WebAsyncManagerTimeoutTests {
|
||||||
|
|
||||||
StubCallable callable = new StubCallable();
|
StubCallable callable = new StubCallable();
|
||||||
WebAsyncTask<Object> webAsyncTask = new WebAsyncTask<>(callable);
|
WebAsyncTask<Object> webAsyncTask = new WebAsyncTask<>(callable);
|
||||||
webAsyncTask.onTimeout(new Callable<Object>() {
|
webAsyncTask.onTimeout(() -> 7);
|
||||||
@Override
|
|
||||||
public Object call() throws Exception {
|
|
||||||
return 7;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.asyncManager.startCallableProcessing(webAsyncTask);
|
this.asyncManager.startCallableProcessing(webAsyncTask);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -20,8 +20,6 @@ import java.io.IOException;
|
||||||
|
|
||||||
import jakarta.servlet.FilterChain;
|
import jakarta.servlet.FilterChain;
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
import jakarta.servlet.ServletRequest;
|
|
||||||
import jakarta.servlet.ServletResponse;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
@ -67,14 +65,9 @@ public class HiddenHttpMethodFilterTests {
|
||||||
}
|
}
|
||||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
|
||||||
FilterChain filterChain = new FilterChain() {
|
FilterChain filterChain = (filterRequest, filterResponse) ->
|
||||||
|
assertThat(((HttpServletRequest) filterRequest).getMethod())
|
||||||
@Override
|
.as("Invalid method").isEqualTo(expectedMethod);
|
||||||
public void doFilter(ServletRequest filterRequest,
|
|
||||||
ServletResponse filterResponse) throws IOException, ServletException {
|
|
||||||
assertThat(((HttpServletRequest) filterRequest).getMethod()).as("Invalid method").isEqualTo(expectedMethod);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.filter.doFilter(request, response, filterChain);
|
this.filter.doFilter(request, response, filterChain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -54,27 +54,24 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
public class ModelFactoryOrderingTests {
|
class ModelFactoryOrderingTests {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(ModelFactoryOrderingTests.class);
|
private static final Log logger = LogFactory.getLog(ModelFactoryOrderingTests.class);
|
||||||
|
|
||||||
private NativeWebRequest webRequest;
|
private final NativeWebRequest webRequest = new ServletWebRequest(new MockHttpServletRequest(), new MockHttpServletResponse());
|
||||||
|
|
||||||
private ModelAndViewContainer mavContainer;
|
private final ModelAndViewContainer mavContainer = new ModelAndViewContainer();
|
||||||
|
|
||||||
private SessionAttributeStore sessionAttributeStore;
|
private final SessionAttributeStore sessionAttributeStore = new DefaultSessionAttributeStore();
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
this.sessionAttributeStore = new DefaultSessionAttributeStore();
|
|
||||||
this.webRequest = new ServletWebRequest(new MockHttpServletRequest(), new MockHttpServletResponse());
|
|
||||||
this.mavContainer = new ModelAndViewContainer();
|
|
||||||
this.mavContainer.addAttribute("methods", new ArrayList<String>());
|
this.mavContainer.addAttribute("methods", new ArrayList<String>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void straightLineDependency() throws Exception {
|
void straightLineDependency() throws Exception {
|
||||||
runTest(new StraightLineDependencyController());
|
runTest(new StraightLineDependencyController());
|
||||||
assertInvokedBefore("getA", "getB1", "getB2", "getC1", "getC2", "getC3", "getC4");
|
assertInvokedBefore("getA", "getB1", "getB2", "getC1", "getC2", "getC3", "getC4");
|
||||||
assertInvokedBefore("getB1", "getB2", "getC1", "getC2", "getC3", "getC4");
|
assertInvokedBefore("getB1", "getB2", "getC1", "getC2", "getC3", "getC4");
|
||||||
|
|
@ -85,7 +82,7 @@ public class ModelFactoryOrderingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void treeDependency() throws Exception {
|
void treeDependency() throws Exception {
|
||||||
runTest(new TreeDependencyController());
|
runTest(new TreeDependencyController());
|
||||||
assertInvokedBefore("getA", "getB1", "getB2", "getC1", "getC2", "getC3", "getC4");
|
assertInvokedBefore("getA", "getB1", "getB2", "getC1", "getC2", "getC3", "getC4");
|
||||||
assertInvokedBefore("getB1", "getC1", "getC2");
|
assertInvokedBefore("getB1", "getC1", "getC2");
|
||||||
|
|
@ -93,7 +90,7 @@ public class ModelFactoryOrderingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void InvertedTreeDependency() throws Exception {
|
void InvertedTreeDependency() throws Exception {
|
||||||
runTest(new InvertedTreeDependencyController());
|
runTest(new InvertedTreeDependencyController());
|
||||||
assertInvokedBefore("getC1", "getA", "getB1");
|
assertInvokedBefore("getC1", "getA", "getB1");
|
||||||
assertInvokedBefore("getC2", "getA", "getB1");
|
assertInvokedBefore("getC2", "getA", "getB1");
|
||||||
|
|
@ -104,7 +101,7 @@ public class ModelFactoryOrderingTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unresolvedDependency() throws Exception {
|
void unresolvedDependency() throws Exception {
|
||||||
runTest(new UnresolvedDependencyController());
|
runTest(new UnresolvedDependencyController());
|
||||||
assertInvokedBefore("getA", "getC1", "getC2", "getC3", "getC4");
|
assertInvokedBefore("getA", "getC1", "getC2", "getC3", "getC4");
|
||||||
|
|
||||||
|
|
@ -133,19 +130,16 @@ public class ModelFactoryOrderingTests {
|
||||||
ModelFactory factory = new ModelFactory(modelMethods, dataBinderFactory, sessionHandler);
|
ModelFactory factory = new ModelFactory(modelMethods, dataBinderFactory, sessionHandler);
|
||||||
factory.initModel(this.webRequest, this.mavContainer, new HandlerMethod(controller, "handle"));
|
factory.initModel(this.webRequest, this.mavContainer, new HandlerMethod(controller, "handle"));
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
StringBuilder sb = new StringBuilder();
|
logger.debug(String.join(" >> ", getInvokedMethods()));
|
||||||
for (String name : getInvokedMethods()) {
|
|
||||||
sb.append(" >> ").append(name);
|
|
||||||
}
|
|
||||||
logger.debug(sb);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertInvokedBefore(String beforeMethod, String... afterMethods) {
|
private void assertInvokedBefore(String beforeMethod, String... afterMethods) {
|
||||||
List<String> actual = getInvokedMethods();
|
List<String> actual = getInvokedMethods();
|
||||||
for (String afterMethod : afterMethods) {
|
for (String afterMethod : afterMethods) {
|
||||||
assertThat(actual.indexOf(beforeMethod) < actual.indexOf(afterMethod)).as(beforeMethod + " should be before " + afterMethod + ". Actual order: " +
|
assertThat(actual.indexOf(beforeMethod) < actual.indexOf(afterMethod))
|
||||||
actual.toString()).isTrue();
|
.as(beforeMethod + " should be before " + afterMethod + ". Actual order: " + actual.toString())
|
||||||
|
.isTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -321,13 +315,8 @@ public class ModelFactoryOrderingTests {
|
||||||
private static class C4 { }
|
private static class C4 { }
|
||||||
|
|
||||||
|
|
||||||
private static final ReflectionUtils.MethodFilter METHOD_FILTER = new ReflectionUtils.MethodFilter() {
|
private static final ReflectionUtils.MethodFilter METHOD_FILTER = method ->
|
||||||
|
((AnnotationUtils.findAnnotation(method, RequestMapping.class) == null) &&
|
||||||
@Override
|
(AnnotationUtils.findAnnotation(method, ModelAttribute.class) != null));
|
||||||
public boolean matches(Method method) {
|
|
||||||
return ((AnnotationUtils.findAnnotation(method, RequestMapping.class) == null) &&
|
|
||||||
(AnnotationUtils.findAnnotation(method, ModelAttribute.class) != null));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ public class BodyExtractorsTests {
|
||||||
return hints;
|
return hints;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.hints = new HashMap<String, Object>();
|
this.hints = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
import org.springframework.web.server.WebFilter;
|
import org.springframework.web.server.WebFilter;
|
||||||
import org.springframework.web.server.WebFilterChain;
|
|
||||||
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest;
|
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest;
|
||||||
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse;
|
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse;
|
||||||
import org.springframework.web.testfixture.server.MockServerWebExchange;
|
import org.springframework.web.testfixture.server.MockServerWebExchange;
|
||||||
|
|
@ -295,12 +294,9 @@ public class RouterFunctionsTests {
|
||||||
public void toHttpHandlerWebFilter() {
|
public void toHttpHandlerWebFilter() {
|
||||||
AtomicBoolean filterInvoked = new AtomicBoolean();
|
AtomicBoolean filterInvoked = new AtomicBoolean();
|
||||||
|
|
||||||
WebFilter webFilter = new WebFilter() {
|
WebFilter webFilter = (exchange, chain) -> {
|
||||||
@Override
|
filterInvoked.set(true);
|
||||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
return chain.filter(exchange);
|
||||||
filterInvoked.set(true);
|
|
||||||
return chain.filter(exchange);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.accepted().build();
|
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.accepted().build();
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ public class ResourceUrlProviderTests {
|
||||||
|
|
||||||
|
|
||||||
private Condition<PathPattern> pathPatternStringOf(String expected) {
|
private Condition<PathPattern> pathPatternStringOf(String expected) {
|
||||||
return new Condition<PathPattern>(
|
return new Condition<>(
|
||||||
actual -> actual != null && actual.getPatternString().equals(expected),
|
actual -> actual != null && actual.getPatternString().equals(expected),
|
||||||
"Pattern %s", expected);
|
"Pattern %s", expected);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,21 +33,24 @@ public class LifecycleContextBean extends LifecycleBean implements ApplicationCo
|
||||||
@Override
|
@Override
|
||||||
public void setBeanFactory(BeanFactory beanFactory) {
|
public void setBeanFactory(BeanFactory beanFactory) {
|
||||||
super.setBeanFactory(beanFactory);
|
super.setBeanFactory(beanFactory);
|
||||||
if (this.owningContext != null)
|
if (this.owningContext != null) {
|
||||||
throw new RuntimeException("Factory called setBeanFactory after setApplicationContext");
|
throw new RuntimeException("Factory called setBeanFactory after setApplicationContext");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
super.afterPropertiesSet();
|
super.afterPropertiesSet();
|
||||||
if (this.owningContext == null)
|
if (this.owningContext == null) {
|
||||||
throw new RuntimeException("Factory didn't call setApplicationContext before afterPropertiesSet on lifecycle bean");
|
throw new RuntimeException("Factory didn't call setApplicationContext before afterPropertiesSet on lifecycle bean");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
if (this.owningFactory == null)
|
if (this.owningFactory == null) {
|
||||||
throw new RuntimeException("Factory called setApplicationContext before setBeanFactory");
|
throw new RuntimeException("Factory called setApplicationContext before setBeanFactory");
|
||||||
|
}
|
||||||
|
|
||||||
this.owningContext = applicationContext;
|
this.owningContext = applicationContext;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 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.
|
||||||
|
|
@ -24,9 +24,7 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
|
||||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
|
||||||
import org.springframework.beans.testfixture.beans.TestBean;
|
import org.springframework.beans.testfixture.beans.TestBean;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.NoSuchMessageException;
|
import org.springframework.context.NoSuchMessageException;
|
||||||
|
|
@ -55,24 +53,15 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes
|
||||||
MockServletContext sc = new MockServletContext("");
|
MockServletContext sc = new MockServletContext("");
|
||||||
root.setServletContext(sc);
|
root.setServletContext(sc);
|
||||||
root.setConfigLocations("/org/springframework/web/context/WEB-INF/applicationContext.xml");
|
root.setConfigLocations("/org/springframework/web/context/WEB-INF/applicationContext.xml");
|
||||||
root.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() {
|
root.addBeanFactoryPostProcessor(beanFactory -> beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
|
||||||
@Override
|
@Override
|
||||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
|
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
|
||||||
beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
|
if (bean instanceof TestBean) {
|
||||||
@Override
|
((TestBean) bean).getFriends().add("myFriend");
|
||||||
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
|
}
|
||||||
if (bean instanceof TestBean) {
|
return bean;
|
||||||
((TestBean) bean).getFriends().add("myFriend");
|
|
||||||
}
|
|
||||||
return bean;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
|
|
||||||
return bean;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
root.refresh();
|
root.refresh();
|
||||||
XmlWebApplicationContext wac = new XmlWebApplicationContext();
|
XmlWebApplicationContext wac = new XmlWebApplicationContext();
|
||||||
wac.getEnvironment().addActiveProfile("wacProfile1");
|
wac.getEnvironment().addActiveProfile("wacProfile1");
|
||||||
|
|
@ -108,7 +97,7 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes
|
||||||
@Test
|
@Test
|
||||||
@Override
|
@Override
|
||||||
public void count() {
|
public void count() {
|
||||||
assertThat(this.applicationContext.getBeanDefinitionCount() == 14).as("should have 14 beans, not "+ this.applicationContext.getBeanDefinitionCount()).isTrue();
|
assertThat(this.applicationContext.getBeanDefinitionCount()).as("should have 14 beans").isEqualTo(14);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -20,8 +20,6 @@ import java.io.IOException;
|
||||||
|
|
||||||
import jakarta.servlet.Servlet;
|
import jakarta.servlet.Servlet;
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.web.HttpRequestHandler;
|
import org.springframework.web.HttpRequestHandler;
|
||||||
|
|
@ -45,24 +43,21 @@ public class HttpRequestHandlerTests {
|
||||||
@Test
|
@Test
|
||||||
public void testHttpRequestHandlerServletPassThrough() throws Exception {
|
public void testHttpRequestHandlerServletPassThrough() throws Exception {
|
||||||
MockServletContext servletContext = new MockServletContext();
|
MockServletContext servletContext = new MockServletContext();
|
||||||
final MockHttpServletRequest request = new MockHttpServletRequest();
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
final MockHttpServletResponse response = new MockHttpServletResponse();
|
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||||
|
|
||||||
StaticWebApplicationContext wac = new StaticWebApplicationContext();
|
StaticWebApplicationContext wac = new StaticWebApplicationContext();
|
||||||
wac.getBeanFactory().registerSingleton("myHandler", new HttpRequestHandler() {
|
wac.getBeanFactory().registerSingleton("myHandler", (HttpRequestHandler) (req, res) -> {
|
||||||
@Override
|
assertThat(req).isSameAs(request);
|
||||||
public void handleRequest(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
|
assertThat(res).isSameAs(response);
|
||||||
assertThat(req).isSameAs(request);
|
String exception = request.getParameter("exception");
|
||||||
assertThat(res).isSameAs(response);
|
if ("ServletException".equals(exception)) {
|
||||||
String exception = request.getParameter("exception");
|
throw new ServletException("test");
|
||||||
if ("ServletException".equals(exception)) {
|
|
||||||
throw new ServletException("test");
|
|
||||||
}
|
|
||||||
if ("IOException".equals(exception)) {
|
|
||||||
throw new IOException("test");
|
|
||||||
}
|
|
||||||
res.getWriter().write("myResponse");
|
|
||||||
}
|
}
|
||||||
|
if ("IOException".equals(exception)) {
|
||||||
|
throw new IOException("test");
|
||||||
|
}
|
||||||
|
res.getWriter().write("myResponse");
|
||||||
});
|
});
|
||||||
wac.setServletContext(servletContext);
|
wac.setServletContext(servletContext);
|
||||||
wac.refresh();
|
wac.refresh();
|
||||||
|
|
@ -75,13 +70,13 @@ public class HttpRequestHandlerTests {
|
||||||
assertThat(response.getContentAsString()).isEqualTo("myResponse");
|
assertThat(response.getContentAsString()).isEqualTo("myResponse");
|
||||||
|
|
||||||
request.setParameter("exception", "ServletException");
|
request.setParameter("exception", "ServletException");
|
||||||
assertThatExceptionOfType(ServletException.class).isThrownBy(() ->
|
assertThatExceptionOfType(ServletException.class)
|
||||||
servlet.service(request, response))
|
.isThrownBy(() -> servlet.service(request, response))
|
||||||
.withMessage("test");
|
.withMessage("test");
|
||||||
|
|
||||||
request.setParameter("exception", "IOException");
|
request.setParameter("exception", "IOException");
|
||||||
assertThatIOException().isThrownBy(() ->
|
assertThatIOException()
|
||||||
servlet.service(request, response))
|
.isThrownBy(() -> servlet.service(request, response))
|
||||||
.withMessage("test");
|
.withMessage("test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
import org.springframework.beans.testfixture.beans.TestBean;
|
import org.springframework.beans.testfixture.beans.TestBean;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.convert.converter.Converter;
|
|
||||||
import org.springframework.core.io.FileSystemResourceLoader;
|
import org.springframework.core.io.FileSystemResourceLoader;
|
||||||
import org.springframework.format.FormatterRegistry;
|
import org.springframework.format.FormatterRegistry;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
@ -360,12 +359,7 @@ public class WebMvcConfigurationSupportExtensionTests {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addFormatters(FormatterRegistry registry) {
|
public void addFormatters(FormatterRegistry registry) {
|
||||||
registry.addConverter(new Converter<TestBean, String>() {
|
registry.addConverter(TestBean.class, String.class, testBean -> "converted");
|
||||||
@Override
|
|
||||||
public String convert(TestBean source) {
|
|
||||||
return "converted";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
@ -48,13 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class DefaultEntityResponseBuilderTests {
|
public class DefaultEntityResponseBuilderTests {
|
||||||
|
|
||||||
static final ServerResponse.Context EMPTY_CONTEXT = new ServerResponse.Context() {
|
static final ServerResponse.Context EMPTY_CONTEXT = () -> Collections.emptyList();
|
||||||
@Override
|
|
||||||
public List<HttpMessageConverter<?>> messageConverters() {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fromObject() {
|
public void fromObject() {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import jakarta.servlet.http.Cookie;
|
import jakarta.servlet.http.Cookie;
|
||||||
|
|
@ -28,7 +27,6 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
@ -42,13 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class DefaultRenderingResponseTests {
|
public class DefaultRenderingResponseTests {
|
||||||
|
|
||||||
static final ServerResponse.Context EMPTY_CONTEXT = new ServerResponse.Context() {
|
static final ServerResponse.Context EMPTY_CONTEXT = () -> Collections.emptyList();
|
||||||
@Override
|
|
||||||
public List<HttpMessageConverter<?>> messageConverters() {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void create() throws Exception {
|
public void create() throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -317,12 +317,7 @@ class DefaultServerRequestTests {
|
||||||
@Test
|
@Test
|
||||||
void principal() {
|
void principal() {
|
||||||
MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("GET", "/", true);
|
MockHttpServletRequest servletRequest = PathPatternsTestUtils.initRequest("GET", "/", true);
|
||||||
Principal principal = new Principal() {
|
Principal principal = () -> "foo";
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "foo";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
servletRequest.setUserPrincipal(principal);
|
servletRequest.setUserPrincipal(principal);
|
||||||
|
|
||||||
DefaultServerRequest request = new DefaultServerRequest(servletRequest,
|
DefaultServerRequest request = new DefaultServerRequest(servletRequest,
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@ import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
|
||||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
|
|
@ -54,14 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class DefaultServerResponseBuilderTests {
|
public class DefaultServerResponseBuilderTests {
|
||||||
|
|
||||||
static final ServerResponse.Context EMPTY_CONTEXT = new ServerResponse.Context() {
|
static final ServerResponse.Context EMPTY_CONTEXT = () -> Collections.emptyList();
|
||||||
@Override
|
|
||||||
public List<HttpMessageConverter<?>> messageConverters() {
|
|
||||||
return Collections.emptyList();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void status() {
|
public void status() {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import java.io.StringReader;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
@ -948,12 +947,7 @@ public class SelectTagTests extends AbstractFormTagTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map getCountryToLocaleMap() {
|
private Map getCountryToLocaleMap() {
|
||||||
Map map = new TreeMap(new Comparator() {
|
Map map = new TreeMap((o1, o2) -> ((Country)o1).getName().compareTo(((Country)o2).getName()));
|
||||||
@Override
|
|
||||||
public int compare(Object o1, Object o2) {
|
|
||||||
return ((Country)o1).getName().compareTo(((Country)o2).getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
map.put(Country.COUNTRY_AT, LOCALE_AT);
|
map.put(Country.COUNTRY_AT, LOCALE_AT);
|
||||||
map.put(Country.COUNTRY_NL, LOCALE_NL);
|
map.put(Country.COUNTRY_NL, LOCALE_NL);
|
||||||
map.put(Country.COUNTRY_US, Locale.US);
|
map.put(Country.COUNTRY_US, Locale.US);
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||||
import org.springframework.messaging.simp.SimpMessageType;
|
import org.springframework.messaging.simp.SimpMessageType;
|
||||||
import org.springframework.messaging.simp.user.SimpSubscription;
|
import org.springframework.messaging.simp.user.SimpSubscription;
|
||||||
import org.springframework.messaging.simp.user.SimpSubscriptionMatcher;
|
|
||||||
import org.springframework.messaging.simp.user.SimpUser;
|
import org.springframework.messaging.simp.user.SimpUser;
|
||||||
import org.springframework.messaging.support.MessageBuilder;
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
import org.springframework.web.socket.CloseStatus;
|
import org.springframework.web.socket.CloseStatus;
|
||||||
|
|
@ -143,12 +142,7 @@ public class DefaultSimpUserRegistryTests {
|
||||||
subscribeEvent = new SessionSubscribeEvent(this, message, user);
|
subscribeEvent = new SessionSubscribeEvent(this, message, user);
|
||||||
registry.onApplicationEvent(subscribeEvent);
|
registry.onApplicationEvent(subscribeEvent);
|
||||||
|
|
||||||
Set<SimpSubscription> matches = registry.findSubscriptions(new SimpSubscriptionMatcher() {
|
Set<SimpSubscription> matches = registry.findSubscriptions(subscription -> subscription.getDestination().equals("/match"));
|
||||||
@Override
|
|
||||||
public boolean match(SimpSubscription subscription) {
|
|
||||||
return subscription.getDestination().equals("/match");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
assertThat(matches.size()).isEqualTo(2);
|
assertThat(matches.size()).isEqualTo(2);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue