Use Gradle test fixture support for spring-beans and spring-context

See gh-23550
This commit is contained in:
Sam Brannen
2019-12-28 17:13:39 +01:00
parent 5718bf424b
commit 61d4ee594d
585 changed files with 2270 additions and 1618 deletions

View File

@@ -22,9 +22,9 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.aspectj.AdviceBindingTestAspect.AdviceBindingCollaborator;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

View File

@@ -22,9 +22,9 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.aspectj.AfterReturningAdviceBindingTestAspect.AfterReturningAdviceBindingCollaborator;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

View File

@@ -20,8 +20,8 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.aop.aspectj.AfterThrowingAdviceBindingTestAspect.AfterThrowingAdviceBindingCollaborator;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.mock;

View File

@@ -23,10 +23,10 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.aspectj.AroundAdviceBindingTestAspect.AroundAdviceBindingCollaborator;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

View File

@@ -24,10 +24,10 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.ITestBean;
/**
* @author Adrian Colyer

View File

@@ -21,8 +21,8 @@ import org.aopalliance.intercept.MethodInvocation;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -22,9 +22,9 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory;
import org.springframework.aop.framework.Advised;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -25,9 +25,9 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.Advised;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.ITestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -22,9 +22,9 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.aspectj.AdviceBindingTestAspect.AdviceBindingCollaborator;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

View File

@@ -21,8 +21,8 @@ import org.junit.jupiter.api.Test;
import test.mixin.Lockable;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.aspectj;
import org.aspectj.lang.ProceedingJoinPoint;
@@ -20,8 +21,8 @@ import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.junit.jupiter.api.Test;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.TestBean;
/**
* Tests to check if the first implicit join point argument is correctly processed.
@@ -33,14 +34,15 @@ import org.springframework.tests.sample.beans.TestBean;
public class ImplicitJPArgumentMatchingAtAspectJTests {
@Test
@SuppressWarnings("resource")
public void testAspect() {
// nothing to really test; it is enough if we don't get error while creating app context
// nothing to really test; it is enough if we don't get error while creating the app context
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
}
@Aspect
static class CounterAtAspectJAspect {
@Around(value="execution(* org.springframework.tests.sample.beans.TestBean.*(..)) and this(bean) and args(argument)",
@Around(value="execution(* org.springframework.beans.test.fixtures.beans.TestBean.*(..)) and this(bean) and args(argument)",
argNames="bean,argument")
public void increment(ProceedingJoinPoint pjp, TestBean bean, Object argument) throws Throwable {
pjp.proceed();

View File

@@ -20,8 +20,8 @@ import org.aspectj.lang.ProceedingJoinPoint;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -18,9 +18,9 @@ package org.springframework.aop.aspectj.autoproxy;
import org.junit.jupiter.api.Test;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -43,6 +43,10 @@ import org.springframework.beans.factory.config.MethodInvokingFactoryBean;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.test.fixtures.beans.INestedTestBean;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.NestedTestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
@@ -54,10 +58,6 @@ import org.springframework.core.test.fixtures.Assume;
import org.springframework.core.test.fixtures.EnabledForTestGroups;
import org.springframework.core.test.fixtures.TestGroup;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.INestedTestBean;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.NestedTestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.StopWatch;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -23,8 +23,8 @@ import org.aspectj.lang.annotation.Aspect;
import org.junit.jupiter.api.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import static org.assertj.core.api.Assertions.assertThat;
@@ -64,7 +64,7 @@ class ExceptionHandlingAspect {
public IOException lastException;
@AfterThrowing(pointcut = "within(org.springframework.tests.sample.beans.ITestBean+)", throwing = "ex")
@AfterThrowing(pointcut = "within(org.springframework.beans.test.fixtures.beans.ITestBean+)", throwing = "ex")
public void handleIOException(IOException ex) {
handled++;
lastException = ex;

View File

@@ -32,8 +32,8 @@ import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.StaticMethodMatcherPointcut;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.util.StopWatch;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -25,9 +25,9 @@ import org.aspectj.lang.annotation.Pointcut;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.test.fixtures.beans.Employee;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.Employee;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -23,11 +23,11 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.aop.advice.CountingBeforeAdvice;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -57,6 +57,11 @@ import org.springframework.aop.support.Pointcuts;
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
import org.springframework.aop.target.HotSwappableTargetSource;
import org.springframework.aop.target.SingletonTargetSource;
import org.springframework.beans.test.fixtures.beans.IOther;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.Person;
import org.springframework.beans.test.fixtures.beans.SerializablePerson;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.core.test.fixtures.EnabledForTestGroups;
import org.springframework.core.test.fixtures.TestGroup;
import org.springframework.core.test.fixtures.TimeStamped;
@@ -69,11 +74,6 @@ import org.springframework.tests.aop.advice.MyThrowsHandler;
import org.springframework.tests.aop.interceptor.NopInterceptor;
import org.springframework.tests.aop.interceptor.SerializableNopInterceptor;
import org.springframework.tests.aop.interceptor.TimestampIntroductionInterceptor;
import org.springframework.tests.sample.beans.IOther;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.Person;
import org.springframework.tests.sample.beans.SerializablePerson;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.StopWatch;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -28,13 +28,13 @@ import org.springframework.aop.MethodMatcher;
import org.springframework.aop.Pointcut;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.aop.advice.CountingBeforeAdvice;
import org.springframework.tests.aop.interceptor.NopInterceptor;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

View File

@@ -24,9 +24,9 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
import org.springframework.aop.support.AopUtils;
import org.springframework.tests.sample.beans.IOther;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.beans.test.fixtures.beans.IOther;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

View File

@@ -45,8 +45,12 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.Person;
import org.springframework.beans.test.fixtures.beans.SideEffectBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.ApplicationListener;
import org.springframework.context.TestListener;
import org.springframework.context.test.fixtures.beans.TestApplicationListener;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.test.fixtures.TimeStamped;
import org.springframework.core.test.fixtures.io.SerializationTestUtils;
@@ -55,10 +59,6 @@ import org.springframework.tests.aop.advice.CountingBeforeAdvice;
import org.springframework.tests.aop.advice.MyThrowsHandler;
import org.springframework.tests.aop.interceptor.NopInterceptor;
import org.springframework.tests.aop.interceptor.TimestampIntroductionInterceptor;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.Person;
import org.springframework.tests.sample.beans.SideEffectBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -93,7 +93,7 @@ public class ProxyFactoryBeanTests {
@BeforeEach
public void setUp() throws Exception {
DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
parent.registerBeanDefinition("target2", new RootBeanDefinition(TestListener.class));
parent.registerBeanDefinition("target2", new RootBeanDefinition(TestApplicationListener.class));
this.factory = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.factory).loadBeanDefinitions(
new ClassPathResource(CONTEXT, getClass()));

View File

@@ -28,8 +28,8 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.Advisor;
import org.springframework.aop.BeforeAdvice;
import org.springframework.aop.framework.Advised;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

View File

@@ -31,11 +31,11 @@ import org.springframework.aop.target.LazyInitTargetSource;
import org.springframework.aop.target.PrototypeTargetSource;
import org.springframework.aop.target.ThreadLocalTargetSource;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.test.fixtures.beans.CountingTestBean;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.aop.advice.CountingBeforeAdvice;
import org.springframework.tests.aop.interceptor.NopInterceptor;
import org.springframework.tests.sample.beans.CountingTestBean;
import org.springframework.tests.sample.beans.ITestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -37,16 +37,16 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.IndexedTestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.beans.test.fixtures.beans.factory.DummyFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.MessageSource;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.context.support.StaticMessageSource;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.IndexedTestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.tests.sample.beans.factory.DummyFactory;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -21,9 +21,9 @@ import java.lang.reflect.Method;
import org.junit.jupiter.api.Test;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

View File

@@ -25,12 +25,12 @@ import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.test.fixtures.TimeStamped;
import org.springframework.tests.aop.advice.CountingBeforeAdvice;
import org.springframework.tests.aop.interceptor.NopInterceptor;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

View File

@@ -25,12 +25,12 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.test.fixtures.SimpleMapScope;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.test.fixtures.io.SerializationTestUtils;
import org.springframework.tests.context.SimpleMapScope;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -25,12 +25,12 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.test.fixtures.beans.Person;
import org.springframework.beans.test.fixtures.beans.SerializablePerson;
import org.springframework.beans.test.fixtures.beans.SideEffectBean;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.test.fixtures.io.SerializationTestUtils;
import org.springframework.tests.sample.beans.Person;
import org.springframework.tests.sample.beans.SerializablePerson;
import org.springframework.tests.sample.beans.SideEffectBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

View File

@@ -20,9 +20,9 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.aop.interceptor.DebugInterceptor;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -18,9 +18,9 @@ package org.springframework.beans.factory.xml;
import org.junit.jupiter.api.Test;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -33,10 +33,10 @@ import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.MethodReplacer;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.IndexedTestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.tests.sample.beans.factory.DummyFactory;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.IndexedTestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.beans.test.fixtures.beans.factory.DummyFactory;
/**
* Types used by {@link XmlBeanFactoryTests} and its attendant XML config files.

View File

@@ -51,18 +51,18 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.MethodReplacer;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.test.fixtures.beans.DependenciesBean;
import org.springframework.beans.test.fixtures.beans.DerivedTestBean;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.IndexedTestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.beans.test.fixtures.beans.factory.DummyFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.UrlResource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.test.fixtures.io.SerializationTestUtils;
import org.springframework.tests.sample.beans.DependenciesBean;
import org.springframework.tests.sample.beans.DerivedTestBean;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.IndexedTestBean;
import org.springframework.tests.sample.beans.ResourceTestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.tests.sample.beans.factory.DummyFactory;
import org.springframework.util.ClassUtils;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.StopWatch;

View File

@@ -51,13 +51,13 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.beans.factory.xml.PluggableSchemaResolver;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.ApplicationListener;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.tests.aop.interceptor.NopInterceptor;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -1,213 +0,0 @@
/*
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cache;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Stephane Nicoll
*/
public abstract class AbstractCacheTests<T extends Cache> {
protected final static String CACHE_NAME = "testCache";
protected abstract T getCache();
protected abstract Object getNativeCache();
@Test
public void testCacheName() throws Exception {
assertThat(getCache().getName()).isEqualTo(CACHE_NAME);
}
@Test
public void testNativeCache() throws Exception {
assertThat(getCache().getNativeCache()).isSameAs(getNativeCache());
}
@Test
public void testCachePut() throws Exception {
T cache = getCache();
String key = createRandomKey();
Object value = "george";
assertThat((Object) cache.get(key)).isNull();
assertThat(cache.get(key, String.class)).isNull();
assertThat(cache.get(key, Object.class)).isNull();
cache.put(key, value);
assertThat(cache.get(key).get()).isEqualTo(value);
assertThat(cache.get(key, String.class)).isEqualTo(value);
assertThat(cache.get(key, Object.class)).isEqualTo(value);
assertThat(cache.get(key, (Class<?>) null)).isEqualTo(value);
cache.put(key, null);
assertThat(cache.get(key)).isNotNull();
assertThat(cache.get(key).get()).isNull();
assertThat(cache.get(key, String.class)).isNull();
assertThat(cache.get(key, Object.class)).isNull();
}
@Test
public void testCachePutIfAbsent() throws Exception {
T cache = getCache();
String key = createRandomKey();
Object value = "initialValue";
assertThat(cache.get(key)).isNull();
assertThat(cache.putIfAbsent(key, value)).isNull();
assertThat(cache.get(key).get()).isEqualTo(value);
assertThat(cache.putIfAbsent(key, "anotherValue").get()).isEqualTo("initialValue");
// not changed
assertThat(cache.get(key).get()).isEqualTo(value);
}
@Test
public void testCacheRemove() throws Exception {
T cache = getCache();
String key = createRandomKey();
Object value = "george";
assertThat((Object) cache.get(key)).isNull();
cache.put(key, value);
}
@Test
public void testCacheClear() throws Exception {
T cache = getCache();
assertThat((Object) cache.get("enescu")).isNull();
cache.put("enescu", "george");
assertThat((Object) cache.get("vlaicu")).isNull();
cache.put("vlaicu", "aurel");
cache.clear();
assertThat((Object) cache.get("vlaicu")).isNull();
assertThat((Object) cache.get("enescu")).isNull();
}
@Test
public void testCacheGetCallable() {
doTestCacheGetCallable("test");
}
@Test
public void testCacheGetCallableWithNull() {
doTestCacheGetCallable(null);
}
private void doTestCacheGetCallable(Object returnValue) {
T cache = getCache();
String key = createRandomKey();
assertThat((Object) cache.get(key)).isNull();
Object value = cache.get(key, () -> returnValue);
assertThat(value).isEqualTo(returnValue);
assertThat(cache.get(key).get()).isEqualTo(value);
}
@Test
public void testCacheGetCallableNotInvokedWithHit() {
doTestCacheGetCallableNotInvokedWithHit("existing");
}
@Test
public void testCacheGetCallableNotInvokedWithHitNull() {
doTestCacheGetCallableNotInvokedWithHit(null);
}
private void doTestCacheGetCallableNotInvokedWithHit(Object initialValue) {
T cache = getCache();
String key = createRandomKey();
cache.put(key, initialValue);
Object value = cache.get(key, () -> {
throw new IllegalStateException("Should not have been invoked");
});
assertThat(value).isEqualTo(initialValue);
}
@Test
public void testCacheGetCallableFail() {
T cache = getCache();
String key = createRandomKey();
assertThat((Object) cache.get(key)).isNull();
try {
cache.get(key, () -> {
throw new UnsupportedOperationException("Expected exception");
});
}
catch (Cache.ValueRetrievalException ex) {
assertThat(ex.getCause()).isNotNull();
assertThat(ex.getCause().getClass()).isEqualTo(UnsupportedOperationException.class);
}
}
/**
* Test that a call to get with a Callable concurrently properly synchronize the
* invocations.
*/
@Test
public void testCacheGetSynchronized() throws InterruptedException {
T cache = getCache();
final AtomicInteger counter = new AtomicInteger();
final List<Object> results = new CopyOnWriteArrayList<>();
final CountDownLatch latch = new CountDownLatch(10);
String key = createRandomKey();
Runnable run = () -> {
try {
Integer value = cache.get(key, () -> {
Thread.sleep(50); // make sure the thread will overlap
return counter.incrementAndGet();
});
results.add(value);
}
finally {
latch.countDown();
}
};
for (int i = 0; i < 10; i++) {
new Thread(run).start();
}
latch.await();
assertThat(results.size()).isEqualTo(10);
results.forEach(r -> assertThat(r).isEqualTo(1)); // Only one method got invoked
}
protected String createRandomKey() {
return UUID.randomUUID().toString();
}
}

View File

@@ -1,45 +0,0 @@
/*
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cache;
import org.junit.jupiter.api.Test;
import org.springframework.cache.support.AbstractValueAdaptingCache;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* @author Stephane Nicoll
*/
public abstract class AbstractValueAdaptingCacheTests<T extends AbstractValueAdaptingCache>
extends AbstractCacheTests<T> {
protected final static String CACHE_NAME_NO_NULL = "testCacheNoNull";
protected abstract T getCache(boolean allowNull);
@Test
public void testCachePutNullValueAllowNullFalse() {
T cache = getCache(false);
String key = createRandomKey();
assertThatIllegalArgumentException().isThrownBy(() ->
cache.put(key, null))
.withMessageContaining(CACHE_NAME_NO_NULL)
.withMessageContaining("is configured to not allow null values but null was provided");
}
}

View File

@@ -24,6 +24,7 @@ import java.util.Optional;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
@@ -39,7 +40,6 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;

View File

@@ -1,70 +0,0 @@
/*
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cache;
import java.util.ArrayList;
import java.util.List;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.cache.support.SimpleCacheManager;
import static org.assertj.core.api.Assertions.assertThat;
/**
* General cache-related test utilities.
*
* @author Stephane Nicoll
*/
public class CacheTestUtils {
/**
* Create a {@link SimpleCacheManager} with the specified cache(s).
* @param cacheNames the names of the caches to create
*/
public static CacheManager createSimpleCacheManager(String... cacheNames) {
SimpleCacheManager result = new SimpleCacheManager();
List<Cache> caches = new ArrayList<>();
for (String cacheName : cacheNames) {
caches.add(new ConcurrentMapCache(cacheName));
}
result.setCaches(caches);
result.afterPropertiesSet();
return result;
}
/**
* Assert the following key is not held within the specified cache(s).
*/
public static void assertCacheMiss(Object key, Cache... caches) {
for (Cache cache : caches) {
assertThat(cache.get(key)).as("No entry in " + cache + " should have been found with key " + key).isNull();
}
}
/**
* Assert the following key has a matching value within the specified cache(s).
*/
public static void assertCacheHit(Object key, Object value, Cache... caches) {
for (Cache cache : caches) {
Cache.ValueWrapper wrapper = cache.get(key);
assertThat(wrapper).as("An entry in " + cache + " should have been found with key " + key).isNotNull();
assertThat(wrapper.get()).as("Wrong value in " + cache + " for entry with key " + key).isEqualTo(value);
}
}
}

View File

@@ -25,7 +25,7 @@ import java.util.concurrent.ConcurrentMap;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.cache.AbstractValueAdaptingCacheTests;
import org.springframework.context.test.fixtures.cache.AbstractValueAdaptingCacheTests;
import org.springframework.core.serializer.support.SerializationDelegate;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -1,874 +0,0 @@
/*
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cache.config;
import java.util.Collection;
import java.util.UUID;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.context.ConfigurableApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIOException;
/**
* Abstract cache annotation tests (containing several reusable methods).
*
* @author Costin Leau
* @author Chris Beams
* @author Phillip Webb
* @author Stephane Nicoll
*/
public abstract class AbstractCacheAnnotationTests {
protected ConfigurableApplicationContext ctx;
protected CacheableService<?> cs;
protected CacheableService<?> ccs;
protected CacheManager cm;
/**
* @return a refreshed application context
*/
protected abstract ConfigurableApplicationContext getApplicationContext();
@BeforeEach
public void setup() {
this.ctx = getApplicationContext();
this.cs = ctx.getBean("service", CacheableService.class);
this.ccs = ctx.getBean("classService", CacheableService.class);
this.cm = ctx.getBean("cacheManager", CacheManager.class);
Collection<String> cn = this.cm.getCacheNames();
assertThat(cn.contains("testCache")).isTrue();
assertThat(cn.contains("secondary")).isTrue();
assertThat(cn.contains("primary")).isTrue();
}
@AfterEach
public void close() {
if (this.ctx != null) {
this.ctx.close();
}
}
protected void testCacheable(CacheableService<?> service) {
Object o1 = new Object();
Object r1 = service.cache(o1);
Object r2 = service.cache(o1);
Object r3 = service.cache(o1);
assertThat(r2).isSameAs(r1);
assertThat(r3).isSameAs(r1);
}
protected void testCacheableNull(CacheableService<?> service) {
Object o1 = new Object();
assertThat(this.cm.getCache("testCache").get(o1)).isNull();
Object r1 = service.cacheNull(o1);
Object r2 = service.cacheNull(o1);
Object r3 = service.cacheNull(o1);
assertThat(r2).isSameAs(r1);
assertThat(r3).isSameAs(r1);
assertThat(this.cm.getCache("testCache").get(o1).get()).isEqualTo(r3);
assertThat(r3).as("Cached value should be null").isNull();
}
protected void testCacheableSync(CacheableService<?> service) {
Object o1 = new Object();
Object r1 = service.cacheSync(o1);
Object r2 = service.cacheSync(o1);
Object r3 = service.cacheSync(o1);
assertThat(r2).isSameAs(r1);
assertThat(r3).isSameAs(r1);
}
protected void testCacheableSyncNull(CacheableService<?> service) {
Object o1 = new Object();
assertThat(this.cm.getCache("testCache").get(o1)).isNull();
Object r1 = service.cacheSyncNull(o1);
Object r2 = service.cacheSyncNull(o1);
Object r3 = service.cacheSyncNull(o1);
assertThat(r2).isSameAs(r1);
assertThat(r3).isSameAs(r1);
assertThat(this.cm.getCache("testCache").get(o1).get()).isEqualTo(r3);
assertThat(r3).as("Cached value should be null").isNull();
}
protected void testEvict(CacheableService<?> service, boolean successExpected) {
Cache cache = this.cm.getCache("testCache");
Object o1 = new Object();
cache.putIfAbsent(o1, -1L);
Object r1 = service.cache(o1);
service.evict(o1, null);
if (successExpected) {
assertThat(cache.get(o1)).isNull();
}
else {
assertThat(cache.get(o1)).isNotNull();
}
Object r2 = service.cache(o1);
if (successExpected) {
assertThat(r2).isNotSameAs(r1);
}
else {
assertThat(r2).isSameAs(r1);
}
}
protected void testEvictEarly(CacheableService<?> service) {
Cache cache = this.cm.getCache("testCache");
Object o1 = new Object();
cache.putIfAbsent(o1, -1L);
Object r1 = service.cache(o1);
try {
service.evictEarly(o1);
}
catch (RuntimeException ex) {
// expected
}
assertThat(cache.get(o1)).isNull();
Object r2 = service.cache(o1);
assertThat(r2).isNotSameAs(r1);
}
protected void testEvictException(CacheableService<?> service) {
Object o1 = new Object();
Object r1 = service.cache(o1);
try {
service.evictWithException(o1);
}
catch (RuntimeException ex) {
// expected
}
// exception occurred, eviction skipped, data should still be in the cache
Object r2 = service.cache(o1);
assertThat(r2).isSameAs(r1);
}
protected void testEvictWithKey(CacheableService<?> service) {
Object o1 = new Object();
Object r1 = service.cache(o1);
service.evict(o1, null);
Object r2 = service.cache(o1);
assertThat(r2).isNotSameAs(r1);
}
protected void testEvictWithKeyEarly(CacheableService<?> service) {
Object o1 = new Object();
Object r1 = service.cache(o1);
try {
service.evictEarly(o1);
}
catch (Exception ex) {
// expected
}
Object r2 = service.cache(o1);
assertThat(r2).isNotSameAs(r1);
}
protected void testEvictAll(CacheableService<?> service, boolean successExpected) {
Cache cache = this.cm.getCache("testCache");
Object o1 = new Object();
Object o2 = new Object();
cache.putIfAbsent(o1, -1L);
cache.putIfAbsent(o2, -2L);
Object r1 = service.cache(o1);
Object r2 = service.cache(o2);
assertThat(r2).isNotSameAs(r1);
service.evictAll(new Object());
if (successExpected) {
assertThat(cache.get(o1)).isNull();
assertThat(cache.get(o2)).isNull();
}
else {
assertThat(cache.get(o1)).isNotNull();
assertThat(cache.get(o2)).isNotNull();
}
Object r3 = service.cache(o1);
Object r4 = service.cache(o2);
if (successExpected) {
assertThat(r3).isNotSameAs(r1);
assertThat(r4).isNotSameAs(r2);
}
else {
assertThat(r3).isSameAs(r1);
assertThat(r4).isSameAs(r2);
}
}
protected void testEvictAllEarly(CacheableService<?> service) {
Cache cache = this.cm.getCache("testCache");
Object o1 = new Object();
Object o2 = new Object();
cache.putIfAbsent(o1, -1L);
cache.putIfAbsent(o2, -2L);
Object r1 = service.cache(o1);
Object r2 = service.cache(o2);
assertThat(r2).isNotSameAs(r1);
try {
service.evictAllEarly(new Object());
}
catch (Exception ex) {
// expected
}
assertThat(cache.get(o1)).isNull();
assertThat(cache.get(o2)).isNull();
Object r3 = service.cache(o1);
Object r4 = service.cache(o2);
assertThat(r3).isNotSameAs(r1);
assertThat(r4).isNotSameAs(r2);
}
protected void testConditionalExpression(CacheableService<?> service) {
Object r1 = service.conditional(4);
Object r2 = service.conditional(4);
assertThat(r2).isNotSameAs(r1);
Object r3 = service.conditional(3);
Object r4 = service.conditional(3);
assertThat(r4).isSameAs(r3);
}
protected void testConditionalExpressionSync(CacheableService<?> service) {
Object r1 = service.conditionalSync(4);
Object r2 = service.conditionalSync(4);
assertThat(r2).isNotSameAs(r1);
Object r3 = service.conditionalSync(3);
Object r4 = service.conditionalSync(3);
assertThat(r4).isSameAs(r3);
}
protected void testUnlessExpression(CacheableService<?> service) {
Cache cache = this.cm.getCache("testCache");
cache.clear();
service.unless(10);
service.unless(11);
assertThat(cache.get(10).get()).isEqualTo(10L);
assertThat(cache.get(11)).isNull();
}
protected void testKeyExpression(CacheableService<?> service) {
Object r1 = service.key(5, 1);
Object r2 = service.key(5, 2);
assertThat(r2).isSameAs(r1);
Object r3 = service.key(1, 5);
Object r4 = service.key(2, 5);
assertThat(r4).isNotSameAs(r3);
}
protected void testVarArgsKey(CacheableService<?> service) {
Object r1 = service.varArgsKey(1, 2, 3);
Object r2 = service.varArgsKey(1, 2, 3);
assertThat(r2).isSameAs(r1);
Object r3 = service.varArgsKey(1, 2, 3);
Object r4 = service.varArgsKey(1, 2);
assertThat(r4).isNotSameAs(r3);
}
protected void testNullValue(CacheableService<?> service) {
Object key = new Object();
assertThat(service.nullValue(key)).isNull();
int nr = service.nullInvocations().intValue();
assertThat(service.nullValue(key)).isNull();
assertThat(service.nullInvocations().intValue()).isEqualTo(nr);
assertThat(service.nullValue(new Object())).isNull();
assertThat(service.nullInvocations().intValue()).isEqualTo(nr + 1);
}
protected void testMethodName(CacheableService<?> service, String keyName) {
Object key = new Object();
Object r1 = service.name(key);
assertThat(service.name(key)).isSameAs(r1);
Cache cache = this.cm.getCache("testCache");
// assert the method name is used
assertThat(cache.get(keyName)).isNotNull();
}
protected void testRootVars(CacheableService<?> service) {
Object key = new Object();
Object r1 = service.rootVars(key);
assertThat(service.rootVars(key)).isSameAs(r1);
Cache cache = this.cm.getCache("testCache");
// assert the method name is used
String expectedKey = "rootVarsrootVars" + AopProxyUtils.ultimateTargetClass(service) + service;
assertThat(cache.get(expectedKey)).isNotNull();
}
protected void testCheckedThrowable(CacheableService<?> service) {
String arg = UUID.randomUUID().toString();
assertThatIOException().isThrownBy(() ->
service.throwChecked(arg))
.withMessage(arg);
}
protected void testUncheckedThrowable(CacheableService<?> service) {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
service.throwUnchecked(1L))
.withMessage("1");
}
protected void testCheckedThrowableSync(CacheableService<?> service) {
String arg = UUID.randomUUID().toString();
assertThatIOException().isThrownBy(() ->
service.throwCheckedSync(arg))
.withMessage(arg);
}
protected void testUncheckedThrowableSync(CacheableService<?> service) {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
service.throwUncheckedSync(1L))
.withMessage("1");
}
protected void testNullArg(CacheableService<?> service) {
Object r1 = service.cache(null);
assertThat(service.cache(null)).isSameAs(r1);
}
protected void testCacheUpdate(CacheableService<?> service) {
Object o = new Object();
Cache cache = this.cm.getCache("testCache");
assertThat(cache.get(o)).isNull();
Object r1 = service.update(o);
assertThat(cache.get(o).get()).isSameAs(r1);
o = new Object();
assertThat(cache.get(o)).isNull();
Object r2 = service.update(o);
assertThat(cache.get(o).get()).isSameAs(r2);
}
protected void testConditionalCacheUpdate(CacheableService<?> service) {
Integer one = 1;
Integer three = 3;
Cache cache = this.cm.getCache("testCache");
assertThat((int) Integer.valueOf(service.conditionalUpdate(one).toString())).isEqualTo((int) one);
assertThat(cache.get(one)).isNull();
assertThat((int) Integer.valueOf(service.conditionalUpdate(three).toString())).isEqualTo((int) three);
assertThat((int) Integer.valueOf(cache.get(three).get().toString())).isEqualTo((int) three);
}
protected void testMultiCache(CacheableService<?> service) {
Object o1 = new Object();
Object o2 = new Object();
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
assertThat(primary.get(o1)).isNull();
assertThat(secondary.get(o1)).isNull();
Object r1 = service.multiCache(o1);
assertThat(primary.get(o1).get()).isSameAs(r1);
assertThat(secondary.get(o1).get()).isSameAs(r1);
Object r2 = service.multiCache(o1);
Object r3 = service.multiCache(o1);
assertThat(r2).isSameAs(r1);
assertThat(r3).isSameAs(r1);
assertThat(primary.get(o2)).isNull();
assertThat(secondary.get(o2)).isNull();
Object r4 = service.multiCache(o2);
assertThat(primary.get(o2).get()).isSameAs(r4);
assertThat(secondary.get(o2).get()).isSameAs(r4);
}
protected void testMultiEvict(CacheableService<?> service) {
Object o1 = new Object();
Object o2 = o1.toString() + "A";
Object r1 = service.multiCache(o1);
Object r2 = service.multiCache(o1);
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
primary.put(o2, o2);
assertThat(r2).isSameAs(r1);
assertThat(primary.get(o1).get()).isSameAs(r1);
assertThat(secondary.get(o1).get()).isSameAs(r1);
service.multiEvict(o1);
assertThat(primary.get(o1)).isNull();
assertThat(secondary.get(o1)).isNull();
assertThat(primary.get(o2)).isNull();
Object r3 = service.multiCache(o1);
Object r4 = service.multiCache(o1);
assertThat(r3).isNotSameAs(r1);
assertThat(r4).isSameAs(r3);
assertThat(primary.get(o1).get()).isSameAs(r3);
assertThat(secondary.get(o1).get()).isSameAs(r4);
}
protected void testMultiPut(CacheableService<?> service) {
Object o = 1;
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
assertThat(primary.get(o)).isNull();
assertThat(secondary.get(o)).isNull();
Object r1 = service.multiUpdate(o);
assertThat(primary.get(o).get()).isSameAs(r1);
assertThat(secondary.get(o).get()).isSameAs(r1);
o = 2;
assertThat(primary.get(o)).isNull();
assertThat(secondary.get(o)).isNull();
Object r2 = service.multiUpdate(o);
assertThat(primary.get(o).get()).isSameAs(r2);
assertThat(secondary.get(o).get()).isSameAs(r2);
}
protected void testPutRefersToResult(CacheableService<?> service) {
Long id = Long.MIN_VALUE;
TestEntity entity = new TestEntity();
Cache primary = this.cm.getCache("primary");
assertThat(primary.get(id)).isNull();
assertThat(entity.getId()).isNull();
service.putRefersToResult(entity);
assertThat(primary.get(id).get()).isSameAs(entity);
}
protected void testMultiCacheAndEvict(CacheableService<?> service) {
String methodName = "multiCacheAndEvict";
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
Object key = 1;
secondary.put(key, key);
assertThat(secondary.get(methodName)).isNull();
assertThat(secondary.get(key).get()).isSameAs(key);
Object r1 = service.multiCacheAndEvict(key);
assertThat(service.multiCacheAndEvict(key)).isSameAs(r1);
// assert the method name is used
assertThat(primary.get(methodName).get()).isSameAs(r1);
assertThat(secondary.get(methodName)).isNull();
assertThat(secondary.get(key)).isNull();
}
protected void testMultiConditionalCacheAndEvict(CacheableService<?> service) {
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
Object key = 1;
secondary.put(key, key);
assertThat(primary.get(key)).isNull();
assertThat(secondary.get(key).get()).isSameAs(key);
Object r1 = service.multiConditionalCacheAndEvict(key);
Object r3 = service.multiConditionalCacheAndEvict(key);
assertThat(!r1.equals(r3)).isTrue();
assertThat(primary.get(key)).isNull();
Object key2 = 3;
Object r2 = service.multiConditionalCacheAndEvict(key2);
assertThat(service.multiConditionalCacheAndEvict(key2)).isSameAs(r2);
// assert the method name is used
assertThat(primary.get(key2).get()).isSameAs(r2);
assertThat(secondary.get(key2)).isNull();
}
@Test
public void testCacheable() {
testCacheable(this.cs);
}
@Test
public void testCacheableNull() {
testCacheableNull(this.cs);
}
@Test
public void testCacheableSync() {
testCacheableSync(this.cs);
}
@Test
public void testCacheableSyncNull() {
testCacheableSyncNull(this.cs);
}
@Test
public void testEvict() {
testEvict(this.cs, true);
}
@Test
public void testEvictEarly() {
testEvictEarly(this.cs);
}
@Test
public void testEvictWithException() {
testEvictException(this.cs);
}
@Test
public void testEvictAll() {
testEvictAll(this.cs, true);
}
@Test
public void testEvictAllEarly() {
testEvictAllEarly(this.cs);
}
@Test
public void testEvictWithKey() {
testEvictWithKey(this.cs);
}
@Test
public void testEvictWithKeyEarly() {
testEvictWithKeyEarly(this.cs);
}
@Test
public void testConditionalExpression() {
testConditionalExpression(this.cs);
}
@Test
public void testConditionalExpressionSync() {
testConditionalExpressionSync(this.cs);
}
@Test
public void testUnlessExpression() {
testUnlessExpression(this.cs);
}
@Test
public void testClassCacheUnlessExpression() {
testUnlessExpression(this.cs);
}
@Test
public void testKeyExpression() {
testKeyExpression(this.cs);
}
@Test
public void testVarArgsKey() {
testVarArgsKey(this.cs);
}
@Test
public void testClassCacheCacheable() {
testCacheable(this.ccs);
}
@Test
public void testClassCacheEvict() {
testEvict(this.ccs, true);
}
@Test
public void testClassEvictEarly() {
testEvictEarly(this.ccs);
}
@Test
public void testClassEvictAll() {
testEvictAll(this.ccs, true);
}
@Test
public void testClassEvictWithException() {
testEvictException(this.ccs);
}
@Test
public void testClassCacheEvictWithWKey() {
testEvictWithKey(this.ccs);
}
@Test
public void testClassEvictWithKeyEarly() {
testEvictWithKeyEarly(this.ccs);
}
@Test
public void testNullValue() {
testNullValue(this.cs);
}
@Test
public void testClassNullValue() {
Object key = new Object();
assertThat(this.ccs.nullValue(key)).isNull();
int nr = this.ccs.nullInvocations().intValue();
assertThat(this.ccs.nullValue(key)).isNull();
assertThat(this.ccs.nullInvocations().intValue()).isEqualTo(nr);
assertThat(this.ccs.nullValue(new Object())).isNull();
// the check method is also cached
assertThat(this.ccs.nullInvocations().intValue()).isEqualTo(nr);
assertThat(AnnotatedClassCacheableService.nullInvocations.intValue()).isEqualTo(nr + 1);
}
@Test
public void testMethodName() {
testMethodName(this.cs, "name");
}
@Test
public void testClassMethodName() {
testMethodName(this.ccs, "nametestCache");
}
@Test
public void testRootVars() {
testRootVars(this.cs);
}
@Test
public void testClassRootVars() {
testRootVars(this.ccs);
}
@Test
public void testCustomKeyGenerator() {
Object param = new Object();
Object r1 = this.cs.customKeyGenerator(param);
assertThat(this.cs.customKeyGenerator(param)).isSameAs(r1);
Cache cache = this.cm.getCache("testCache");
// Checks that the custom keyGenerator was used
Object expectedKey = SomeCustomKeyGenerator.generateKey("customKeyGenerator", param);
assertThat(cache.get(expectedKey)).isNotNull();
}
@Test
public void testUnknownCustomKeyGenerator() {
Object param = new Object();
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
this.cs.unknownCustomKeyGenerator(param));
}
@Test
public void testCustomCacheManager() {
CacheManager customCm = this.ctx.getBean("customCacheManager", CacheManager.class);
Object key = new Object();
Object r1 = this.cs.customCacheManager(key);
assertThat(this.cs.customCacheManager(key)).isSameAs(r1);
Cache cache = customCm.getCache("testCache");
assertThat(cache.get(key)).isNotNull();
}
@Test
public void testUnknownCustomCacheManager() {
Object param = new Object();
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
this.cs.unknownCustomCacheManager(param));
}
@Test
public void testNullArg() {
testNullArg(this.cs);
}
@Test
public void testClassNullArg() {
testNullArg(this.ccs);
}
@Test
public void testCheckedException() {
testCheckedThrowable(this.cs);
}
@Test
public void testClassCheckedException() {
testCheckedThrowable(this.ccs);
}
@Test
public void testCheckedExceptionSync() {
testCheckedThrowableSync(this.cs);
}
@Test
public void testClassCheckedExceptionSync() {
testCheckedThrowableSync(this.ccs);
}
@Test
public void testUncheckedException() {
testUncheckedThrowable(this.cs);
}
@Test
public void testClassUncheckedException() {
testUncheckedThrowable(this.ccs);
}
@Test
public void testUncheckedExceptionSync() {
testUncheckedThrowableSync(this.cs);
}
@Test
public void testClassUncheckedExceptionSync() {
testUncheckedThrowableSync(this.ccs);
}
@Test
public void testUpdate() {
testCacheUpdate(this.cs);
}
@Test
public void testClassUpdate() {
testCacheUpdate(this.ccs);
}
@Test
public void testConditionalUpdate() {
testConditionalCacheUpdate(this.cs);
}
@Test
public void testClassConditionalUpdate() {
testConditionalCacheUpdate(this.ccs);
}
@Test
public void testMultiCache() {
testMultiCache(this.cs);
}
@Test
public void testClassMultiCache() {
testMultiCache(this.ccs);
}
@Test
public void testMultiEvict() {
testMultiEvict(this.cs);
}
@Test
public void testClassMultiEvict() {
testMultiEvict(this.ccs);
}
@Test
public void testMultiPut() {
testMultiPut(this.cs);
}
@Test
public void testClassMultiPut() {
testMultiPut(this.ccs);
}
@Test
public void testPutRefersToResult() {
testPutRefersToResult(this.cs);
}
@Test
public void testClassPutRefersToResult() {
testPutRefersToResult(this.ccs);
}
@Test
public void testMultiCacheAndEvict() {
testMultiCacheAndEvict(this.cs);
}
@Test
public void testClassMultiCacheAndEvict() {
testMultiCacheAndEvict(this.ccs);
}
@Test
public void testMultiConditionalCacheAndEvict() {
testMultiConditionalCacheAndEvict(this.cs);
}
@Test
public void testClassMultiConditionalCacheAndEvict() {
testMultiConditionalCacheAndEvict(this.ccs);
}
}

View File

@@ -1,238 +0,0 @@
/*
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cache.config;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
/**
* @author Costin Leau
* @author Phillip Webb
* @author Stephane Nicoll
*/
@Cacheable("testCache")
public class AnnotatedClassCacheableService implements CacheableService<Object> {
private final AtomicLong counter = new AtomicLong();
public static final AtomicLong nullInvocations = new AtomicLong();
@Override
public Object cache(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
public Object cacheNull(Object arg1) {
return null;
}
@Override
@Cacheable(cacheNames = "testCache", sync = true)
public Object cacheSync(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", sync = true)
public Object cacheSyncNull(Object arg1) {
return null;
}
@Override
public Object conditional(int field) {
return null;
}
@Override
public Object conditionalSync(int field) {
return null;
}
@Override
@Cacheable(cacheNames = "testCache", unless = "#result > 10")
public Object unless(int arg) {
return arg;
}
@Override
@CacheEvict(cacheNames = "testCache", key = "#p0")
public void evict(Object arg1, Object arg2) {
}
@Override
@CacheEvict("testCache")
public void evictWithException(Object arg1) {
throw new RuntimeException("exception thrown - evict should NOT occur");
}
@Override
@CacheEvict(cacheNames = "testCache", beforeInvocation = true)
public void evictEarly(Object arg1) {
throw new RuntimeException("exception thrown - evict should still occur");
}
@Override
@CacheEvict(cacheNames = "testCache", allEntries = true)
public void evictAll(Object arg1) {
}
@Override
@CacheEvict(cacheNames = "testCache", allEntries = true, beforeInvocation = true)
public void evictAllEarly(Object arg1) {
throw new RuntimeException("exception thrown - evict should still occur");
}
@Override
@Cacheable(cacheNames = "testCache", key = "#p0")
public Object key(Object arg1, Object arg2) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable("testCache")
public Object varArgsKey(Object... args) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", key = "#root.methodName + #root.caches[0].name")
public Object name(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", key = "#root.methodName + #root.method.name + #root.targetClass + #root.target")
public Object rootVars(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", keyGenerator = "customKyeGenerator")
public Object customKeyGenerator(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", keyGenerator = "unknownBeanName")
public Object unknownCustomKeyGenerator(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", cacheManager = "customCacheManager")
public Object customCacheManager(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", cacheManager = "unknownBeanName")
public Object unknownCustomCacheManager(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@CachePut("testCache")
public Object update(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@CachePut(cacheNames = "testCache", condition = "#arg.equals(3)")
public Object conditionalUpdate(Object arg) {
return arg;
}
@Override
public Object nullValue(Object arg1) {
nullInvocations.incrementAndGet();
return null;
}
@Override
public Number nullInvocations() {
return nullInvocations.get();
}
@Override
public Long throwChecked(Object arg1) throws Exception {
throw new IOException(arg1.toString());
}
@Override
public Long throwUnchecked(Object arg1) {
throw new UnsupportedOperationException(arg1.toString());
}
@Override
@Cacheable(cacheNames = "testCache", sync = true)
public Object throwCheckedSync(Object arg1) throws Exception {
throw new IOException(arg1.toString());
}
@Override
@Cacheable(cacheNames = "testCache", sync = true)
public Object throwUncheckedSync(Object arg1) {
throw new UnsupportedOperationException(arg1.toString());
}
// multi annotations
@Override
@Caching(cacheable = { @Cacheable("primary"), @Cacheable("secondary") })
public Object multiCache(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Caching(evict = { @CacheEvict("primary"), @CacheEvict(cacheNames = "secondary", key = "#a0"), @CacheEvict(cacheNames = "primary", key = "#p0 + 'A'") })
public Object multiEvict(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Caching(cacheable = { @Cacheable(cacheNames = "primary", key = "#root.methodName") }, evict = { @CacheEvict("secondary") })
public Object multiCacheAndEvict(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Caching(cacheable = { @Cacheable(cacheNames = "primary", condition = "#a0 == 3") }, evict = { @CacheEvict("secondary") })
public Object multiConditionalCacheAndEvict(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Caching(put = { @CachePut("primary"), @CachePut("secondary") })
public Object multiUpdate(Object arg1) {
return arg1;
}
@Override
@CachePut(cacheNames = "primary", key = "#result.id")
public TestEntity putRefersToResult(TestEntity arg1) {
arg1.setId(Long.MIN_VALUE);
return arg1;
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cache.config;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.context.test.fixtures.cache.AbstractCacheAnnotationTests;
/**
* @author Costin Leau

View File

@@ -22,6 +22,7 @@ import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.cache.interceptor.CacheInterceptor;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.context.test.fixtures.cache.AbstractCacheAnnotationTests;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.cache.interceptor.CacheInterceptor;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.context.test.fixtures.cache.AbstractCacheAnnotationTests;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -1,96 +0,0 @@
/*
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cache.config;
/**
* Basic service interface for caching tests.
*
* @author Costin Leau
* @author Phillip Webb
* @author Stephane Nicoll
*/
public interface CacheableService<T> {
T cache(Object arg1);
T cacheNull(Object arg1);
T cacheSync(Object arg1);
T cacheSyncNull(Object arg1);
void evict(Object arg1, Object arg2);
void evictWithException(Object arg1);
void evictEarly(Object arg1);
void evictAll(Object arg1);
void evictAllEarly(Object arg1);
T conditional(int field);
T conditionalSync(int field);
T unless(int arg);
T key(Object arg1, Object arg2);
T varArgsKey(Object... args);
T name(Object arg1);
T nullValue(Object arg1);
T update(Object arg1);
T conditionalUpdate(Object arg2);
Number nullInvocations();
T rootVars(Object arg1);
T customKeyGenerator(Object arg1);
T unknownCustomKeyGenerator(Object arg1);
T customCacheManager(Object arg1);
T unknownCustomCacheManager(Object arg1);
T throwChecked(Object arg1) throws Exception;
T throwUnchecked(Object arg1);
T throwCheckedSync(Object arg1) throws Exception;
T throwUncheckedSync(Object arg1);
T multiCache(Object arg1);
T multiEvict(Object arg1);
T multiCacheAndEvict(Object arg1);
T multiConditionalCacheAndEvict(Object arg1);
T multiUpdate(Object arg1);
TestEntity putRefersToResult(TestEntity arg1);
}

View File

@@ -24,7 +24,6 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.cache.CacheManager;
import org.springframework.cache.CacheTestUtils;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.CacheInterceptor;
import org.springframework.cache.interceptor.CacheOperationInvoker;
@@ -33,6 +32,9 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.test.fixtures.cache.CacheTestUtils;
import org.springframework.context.test.fixtures.cache.beans.CacheableService;
import org.springframework.context.test.fixtures.cache.beans.DefaultCacheableService;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

View File

@@ -1,246 +0,0 @@
/*
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cache.config;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
/**
* Simple cacheable service.
*
* @author Costin Leau
* @author Phillip Webb
* @author Stephane Nicoll
*/
public class DefaultCacheableService implements CacheableService<Long> {
private final AtomicLong counter = new AtomicLong();
private final AtomicLong nullInvocations = new AtomicLong();
@Override
@Cacheable("testCache")
public Long cache(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable("testCache")
public Long cacheNull(Object arg1) {
return null;
}
@Override
@Cacheable(cacheNames = "testCache", sync = true)
public Long cacheSync(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", sync = true)
public Long cacheSyncNull(Object arg1) {
return null;
}
@Override
@CacheEvict(cacheNames = "testCache", key = "#p0")
public void evict(Object arg1, Object arg2) {
}
@Override
@CacheEvict("testCache")
public void evictWithException(Object arg1) {
throw new RuntimeException("exception thrown - evict should NOT occur");
}
@Override
@CacheEvict(cacheNames = "testCache", beforeInvocation = true)
public void evictEarly(Object arg1) {
throw new RuntimeException("exception thrown - evict should still occur");
}
@Override
@CacheEvict(cacheNames = "testCache", allEntries = true)
public void evictAll(Object arg1) {
}
@Override
@CacheEvict(cacheNames = "testCache", allEntries = true, beforeInvocation = true)
public void evictAllEarly(Object arg1) {
throw new RuntimeException("exception thrown - evict should still occur");
}
@Override
@Cacheable(cacheNames = "testCache", condition = "#p0 == 3")
public Long conditional(int classField) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", sync = true, condition = "#p0 == 3")
public Long conditionalSync(int classField) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", unless = "#result > 10")
public Long unless(int arg) {
return (long) arg;
}
@Override
@Cacheable(cacheNames = "testCache", key = "#p0")
public Long key(Object arg1, Object arg2) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache")
public Long varArgsKey(Object... args) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", key = "#root.methodName")
public Long name(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", key = "#root.methodName + #root.method.name + #root.targetClass + #root.target")
public Long rootVars(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", keyGenerator = "customKeyGenerator")
public Long customKeyGenerator(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", keyGenerator = "unknownBeanName")
public Long unknownCustomKeyGenerator(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", cacheManager = "customCacheManager")
public Long customCacheManager(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", cacheManager = "unknownBeanName")
public Long unknownCustomCacheManager(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@CachePut("testCache")
public Long update(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@CachePut(cacheNames = "testCache", condition = "#arg.equals(3)")
public Long conditionalUpdate(Object arg) {
return Long.valueOf(arg.toString());
}
@Override
@Cacheable("testCache")
public Long nullValue(Object arg1) {
this.nullInvocations.incrementAndGet();
return null;
}
@Override
public Number nullInvocations() {
return this.nullInvocations.get();
}
@Override
@Cacheable("testCache")
public Long throwChecked(Object arg1) throws Exception {
throw new IOException(arg1.toString());
}
@Override
@Cacheable("testCache")
public Long throwUnchecked(Object arg1) {
throw new UnsupportedOperationException(arg1.toString());
}
@Override
@Cacheable(cacheNames = "testCache", sync = true)
public Long throwCheckedSync(Object arg1) throws Exception {
throw new IOException(arg1.toString());
}
@Override
@Cacheable(cacheNames = "testCache", sync = true)
public Long throwUncheckedSync(Object arg1) {
throw new UnsupportedOperationException(arg1.toString());
}
// multi annotations
@Override
@Caching(cacheable = { @Cacheable("primary"), @Cacheable("secondary") })
public Long multiCache(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Caching(evict = { @CacheEvict("primary"), @CacheEvict(cacheNames = "secondary", key = "#p0"), @CacheEvict(cacheNames = "primary", key = "#p0 + 'A'") })
public Long multiEvict(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Caching(cacheable = { @Cacheable(cacheNames = "primary", key = "#root.methodName") }, evict = { @CacheEvict("secondary") })
public Long multiCacheAndEvict(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Caching(cacheable = { @Cacheable(cacheNames = "primary", condition = "#p0 == 3") }, evict = { @CacheEvict("secondary") })
public Long multiConditionalCacheAndEvict(Object arg1) {
return this.counter.getAndIncrement();
}
@Override
@Caching(put = { @CachePut("primary"), @CachePut("secondary") })
public Long multiUpdate(Object arg1) {
return Long.valueOf(arg1.toString());
}
@Override
@CachePut(cacheNames = "primary", key = "#result.id")
public TestEntity putRefersToResult(TestEntity arg1) {
arg1.setId(Long.MIN_VALUE);
return arg1;
}
}

View File

@@ -24,7 +24,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.CacheTestUtils;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.CachingConfigurerSupport;
@@ -34,12 +33,13 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.test.fixtures.cache.CacheTestUtils;
import org.springframework.core.env.Environment;
import org.springframework.mock.env.MockEnvironment;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cache.CacheTestUtils.assertCacheHit;
import static org.springframework.cache.CacheTestUtils.assertCacheMiss;
import static org.springframework.context.test.fixtures.cache.CacheTestUtils.assertCacheHit;
import static org.springframework.context.test.fixtures.cache.CacheTestUtils.assertCacheMiss;
/**
* Tests that represent real use cases with advanced configuration.

View File

@@ -20,7 +20,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.cache.CacheManager;
import org.springframework.cache.CacheTestUtils;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.CacheErrorHandler;
@@ -35,6 +34,13 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.test.fixtures.cache.AbstractCacheAnnotationTests;
import org.springframework.context.test.fixtures.cache.CacheTestUtils;
import org.springframework.context.test.fixtures.cache.SomeCustomKeyGenerator;
import org.springframework.context.test.fixtures.cache.SomeKeyGenerator;
import org.springframework.context.test.fixtures.cache.beans.AnnotatedClassCacheableService;
import org.springframework.context.test.fixtures.cache.beans.CacheableService;
import org.springframework.context.test.fixtures.cache.beans.DefaultCacheableService;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cache.config;
import java.lang.reflect.Method;
import org.springframework.cache.interceptor.KeyGenerator;
/**
* A custom {@link KeyGenerator} that exposes the algorithm used to compute the key
* for convenience in tests scenario.
*
* @author Stephane Nicoll
*/
public class SomeCustomKeyGenerator implements KeyGenerator {
@Override
public Object generate(Object target, Method method, Object... params) {
return generateKey(method.getName(), params);
}
/**
* @see #generate(Object, java.lang.reflect.Method, Object...)
*/
static Object generateKey(String methodName, Object... params) {
final StringBuilder sb = new StringBuilder(methodName);
for (Object param : params) {
sb.append(param);
}
return sb.toString();
}
}

View File

@@ -1,22 +0,0 @@
/*
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cache.config;
import org.springframework.cache.interceptor.SimpleKeyGenerator;
public class SomeKeyGenerator extends SimpleKeyGenerator {
}

View File

@@ -1,56 +0,0 @@
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cache.config;
import org.springframework.util.ObjectUtils;
/**
* Simple test entity for use with caching tests.
*
* @author Michael Plod
*/
public class TestEntity {
private Long id;
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(this.id);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null) {
return false;
}
if (obj instanceof TestEntity) {
return ObjectUtils.nullSafeEquals(this.id, ((TestEntity) obj).id);
}
return false;
}
}

View File

@@ -27,7 +27,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.CacheTestUtils;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.CachingConfigurerSupport;
@@ -36,14 +35,15 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.test.fixtures.cache.CacheTestUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.springframework.cache.CacheTestUtils.assertCacheHit;
import static org.springframework.cache.CacheTestUtils.assertCacheMiss;
import static org.springframework.context.test.fixtures.cache.CacheTestUtils.assertCacheHit;
import static org.springframework.context.test.fixtures.cache.CacheTestUtils.assertCacheMiss;
/**
* Provides various {@link CacheResolver} customisations scenario

View File

@@ -23,7 +23,6 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.cache.CacheManager;
import org.springframework.cache.CacheTestUtils;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
@@ -33,6 +32,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.test.fixtures.cache.CacheTestUtils;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;

View File

@@ -1,49 +0,0 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.context;
import java.util.Locale;
public class ACATester implements ApplicationContextAware {
private ApplicationContext ac;
@Override
public void setApplicationContext(ApplicationContext ctx) throws ApplicationContextException {
// check reinitialization
if (this.ac != null) {
throw new IllegalStateException("Already initialized");
}
// check message source availability
if (ctx != null) {
try {
ctx.getMessage("code1", null, Locale.getDefault());
}
catch (NoSuchMessageException ex) {
// expected
}
}
this.ac = ctx;
}
public ApplicationContext getApplicationContext() {
return ac;
}
}

View File

@@ -1,196 +0,0 @@
/*
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.context;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Locale;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.AbstractListableBeanFactoryTests;
import org.springframework.tests.sample.beans.LifecycleBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* @author Rod Johnson
* @author Juergen Hoeller
* @author Sam Brannen
*/
public abstract class AbstractApplicationContextTests extends AbstractListableBeanFactoryTests {
/** Must be supplied as XML */
public static final String TEST_NAMESPACE = "testNamespace";
protected ConfigurableApplicationContext applicationContext;
/** Subclass must register this */
protected TestListener listener = new TestListener();
protected TestListener parentListener = new TestListener();
@BeforeEach
public void setUp() throws Exception {
this.applicationContext = createContext();
}
@Override
protected BeanFactory getBeanFactory() {
return applicationContext;
}
protected ApplicationContext getApplicationContext() {
return applicationContext;
}
/**
* Must register a TestListener.
* Must register standard beans.
* Parent must register rod with name Roderick
* and father with name Albert.
*/
protected abstract ConfigurableApplicationContext createContext() throws Exception;
@Test
public void contextAwareSingletonWasCalledBack() throws Exception {
ACATester aca = (ACATester) applicationContext.getBean("aca");
assertThat(aca.getApplicationContext() == applicationContext).as("has had context set").isTrue();
Object aca2 = applicationContext.getBean("aca");
assertThat(aca == aca2).as("Same instance").isTrue();
assertThat(applicationContext.isSingleton("aca")).as("Says is singleton").isTrue();
}
@Test
public void contextAwarePrototypeWasCalledBack() throws Exception {
ACATester aca = (ACATester) applicationContext.getBean("aca-prototype");
assertThat(aca.getApplicationContext() == applicationContext).as("has had context set").isTrue();
Object aca2 = applicationContext.getBean("aca-prototype");
assertThat(aca != aca2).as("NOT Same instance").isTrue();
boolean condition = !applicationContext.isSingleton("aca-prototype");
assertThat(condition).as("Says is prototype").isTrue();
}
@Test
public void parentNonNull() {
assertThat(applicationContext.getParent() != null).as("parent isn't null").isTrue();
}
@Test
public void grandparentNull() {
assertThat(applicationContext.getParent().getParent() == null).as("grandparent is null").isTrue();
}
@Test
public void overrideWorked() throws Exception {
TestBean rod = (TestBean) applicationContext.getParent().getBean("rod");
assertThat(rod.getName().equals("Roderick")).as("Parent's name differs").isTrue();
}
@Test
public void grandparentDefinitionFound() throws Exception {
TestBean dad = (TestBean) applicationContext.getBean("father");
assertThat(dad.getName().equals("Albert")).as("Dad has correct name").isTrue();
}
@Test
public void grandparentTypedDefinitionFound() throws Exception {
TestBean dad = applicationContext.getBean("father", TestBean.class);
assertThat(dad.getName().equals("Albert")).as("Dad has correct name").isTrue();
}
@Test
public void closeTriggersDestroy() {
LifecycleBean lb = (LifecycleBean) applicationContext.getBean("lifecycle");
boolean condition = !lb.isDestroyed();
assertThat(condition).as("Not destroyed").isTrue();
applicationContext.close();
if (applicationContext.getParent() != null) {
((ConfigurableApplicationContext) applicationContext.getParent()).close();
}
assertThat(lb.isDestroyed()).as("Destroyed").isTrue();
applicationContext.close();
if (applicationContext.getParent() != null) {
((ConfigurableApplicationContext) applicationContext.getParent()).close();
}
assertThat(lb.isDestroyed()).as("Destroyed").isTrue();
}
@Test
public void messageSource() throws NoSuchMessageException {
assertThat(applicationContext.getMessage("code1", null, Locale.getDefault())).isEqualTo("message1");
assertThat(applicationContext.getMessage("code2", null, Locale.getDefault())).isEqualTo("message2");
assertThatExceptionOfType(NoSuchMessageException.class).isThrownBy(() ->
applicationContext.getMessage("code0", null, Locale.getDefault()));
}
@Test
public void events() throws Exception {
doTestEvents(this.listener, this.parentListener, new MyEvent(this));
}
@Test
public void eventsWithNoSource() throws Exception {
// See SPR-10945 Serialized events result in a null source
MyEvent event = new MyEvent(this);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(event);
oos.close();
event = (MyEvent) new ObjectInputStream(new ByteArrayInputStream(
bos.toByteArray())).readObject();
doTestEvents(this.listener, this.parentListener, event);
}
protected void doTestEvents(TestListener listener, TestListener parentListener,
MyEvent event) {
listener.zeroCounter();
parentListener.zeroCounter();
assertThat(listener.getEventCount() == 0).as("0 events before publication").isTrue();
assertThat(parentListener.getEventCount() == 0).as("0 parent events before publication").isTrue();
this.applicationContext.publishEvent(event);
assertThat(listener.getEventCount() == 1).as("1 events after publication, not " + listener.getEventCount()).isTrue();
assertThat(parentListener.getEventCount() == 1).as("1 parent events after publication").isTrue();
}
@Test
public void beanAutomaticallyHearsEvents() throws Exception {
//String[] listenerNames = ((ListableBeanFactory) applicationContext).getBeanDefinitionNames(ApplicationListener.class);
//assertTrue("listeners include beanThatListens", Arrays.asList(listenerNames).contains("beanThatListens"));
BeanThatListens b = (BeanThatListens) applicationContext.getBean("beanThatListens");
b.zero();
assertThat(b.getEventCount() == 0).as("0 events before publication").isTrue();
this.applicationContext.publishEvent(new MyEvent(this));
assertThat(b.getEventCount() == 1).as("1 events after publication, not " + b.getEventCount()).isTrue();
}
@SuppressWarnings("serial")
public static class MyEvent extends ApplicationEvent {
public MyEvent(Object source) {
super(source);
}
}
}

View File

@@ -1,37 +0,0 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.context;
/**
* @author Juergen Hoeller
*/
public class BeanThatBroadcasts implements ApplicationContextAware {
public ApplicationContext applicationContext;
public int receivedCount;
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
if (applicationContext.getDisplayName().contains("listener")) {
applicationContext.getBean("listener");
}
}
}

View File

@@ -1,62 +0,0 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.context;
import java.util.Map;
/**
* A stub {@link ApplicationListener}.
*
* @author Thomas Risberg
* @author Juergen Hoeller
*/
public class BeanThatListens implements ApplicationListener<ApplicationEvent> {
private BeanThatBroadcasts beanThatBroadcasts;
private int eventCount;
public BeanThatListens() {
}
public BeanThatListens(BeanThatBroadcasts beanThatBroadcasts) {
this.beanThatBroadcasts = beanThatBroadcasts;
Map<?, BeanThatListens> beans = beanThatBroadcasts.applicationContext.getBeansOfType(BeanThatListens.class);
if (!beans.isEmpty()) {
throw new IllegalStateException("Shouldn't have found any BeanThatListens instances");
}
}
@Override
public void onApplicationEvent(ApplicationEvent event) {
eventCount++;
if (beanThatBroadcasts != null) {
beanThatBroadcasts.receivedCount++;
}
}
public int getEventCount() {
return eventCount;
}
public void zero() {
eventCount = 0;
}
}

View File

@@ -18,7 +18,7 @@ package org.springframework.context;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.tests.sample.beans.LifecycleBean;
import org.springframework.beans.test.fixtures.beans.LifecycleBean;
/**
* Simple bean to test ApplicationContext lifecycle methods for beans

View File

@@ -1,42 +0,0 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.context;
/**
* Listener that maintains a global count of events.
*
* @author Rod Johnson
* @since January 21, 2001
*/
public class TestListener implements ApplicationListener<ApplicationEvent> {
private int eventCount;
public int getEventCount() {
return eventCount;
}
public void zeroCounter() {
eventCount = 0;
}
@Override
public void onApplicationEvent(ApplicationEvent e) {
++eventCount;
}
}

View File

@@ -19,7 +19,7 @@ package org.springframework.context.annotation;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -33,11 +33,11 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.test.fixtures.Assume;
import org.springframework.core.test.fixtures.EnabledForTestGroups;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.core.test.fixtures.TestGroup.PERFORMANCE;

View File

@@ -31,13 +31,13 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.support.StaticListableBeanFactory;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation2.NamedStubDao2;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.stereotype.Component;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

View File

@@ -23,12 +23,12 @@ import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.annotation4.DependencyBean;
import org.springframework.context.annotation4.FactoryMethodComponent;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.tests.context.SimpleMapScope;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.context.test.fixtures.SimpleMapScope;
import org.springframework.util.ClassUtils;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -42,7 +42,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.index.CandidateComponentsTestClassLoader;
import org.springframework.context.test.fixtures.index.CandidateComponentsTestClassLoader;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.ClassPathResource;

View File

@@ -36,14 +36,14 @@ import org.springframework.beans.factory.config.DestructionAwareBeanPostProcesso
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.test.fixtures.beans.INestedTestBean;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.NestedTestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.test.fixtures.jndi.ExpectedLookupTemplate;
import org.springframework.core.test.fixtures.io.SerializationTestUtils;
import org.springframework.jndi.support.SimpleJndiBeanFactory;
import org.springframework.tests.mock.jndi.ExpectedLookupTemplate;
import org.springframework.tests.sample.beans.INestedTestBean;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.NestedTestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -51,6 +51,7 @@ import org.springframework.context.annotation.ComponentScanParserTests.KustomAnn
import org.springframework.context.annotation.componentscan.simple.ClassWithNestedComponents;
import org.springframework.context.annotation.componentscan.simple.SimpleComponent;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.test.fixtures.SimpleMapScope;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
@@ -59,7 +60,6 @@ import org.springframework.core.test.fixtures.io.SerializationTestUtils;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.tests.context.SimpleMapScope;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition;

View File

@@ -23,8 +23,8 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.test.fixtures.SimpleMapScope;
import org.springframework.core.test.fixtures.io.SerializationTestUtils;
import org.springframework.tests.context.SimpleMapScope;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

View File

@@ -22,7 +22,7 @@ import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -21,7 +21,7 @@ import javax.annotation.PostConstruct;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -53,6 +53,8 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProce
import org.springframework.beans.factory.support.ChildBeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.componentscan.simple.SimpleComponent;
import org.springframework.core.ResolvableType;
@@ -61,8 +63,6 @@ import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.DescriptiveResource;
import org.springframework.stereotype.Component;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;

View File

@@ -23,7 +23,7 @@ import org.springframework.core.convert.converter.Converter;
/**
* @author Juergen Hoeller
*/
public class FooServiceDependentConverter implements Converter<String, org.springframework.tests.sample.beans.TestBean> {
public class FooServiceDependentConverter implements Converter<String, org.springframework.beans.test.fixtures.beans.TestBean> {
@SuppressWarnings("unused")
private FooService fooService;
@@ -33,8 +33,8 @@ public class FooServiceDependentConverter implements Converter<String, org.sprin
}
@Override
public org.springframework.tests.sample.beans.TestBean convert(String source) {
return new org.springframework.tests.sample.beans.TestBean(source);
public org.springframework.beans.test.fixtures.beans.TestBean convert(String source) {
return new org.springframework.beans.test.fixtures.beans.TestBean(source);
}
}

View File

@@ -28,7 +28,7 @@ import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostP
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

View File

@@ -23,8 +23,8 @@ package org.springframework.context.annotation;
class MyTestBean {
@Bean
public org.springframework.tests.sample.beans.TestBean myTestBean() {
return new org.springframework.tests.sample.beans.TestBean();
public org.springframework.beans.test.fixtures.beans.TestBean myTestBean() {
return new org.springframework.beans.test.fixtures.beans.TestBean();
}
}

View File

@@ -18,8 +18,8 @@ package org.springframework.context.annotation;
import org.junit.jupiter.api.Test;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.stereotype.Component;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -30,6 +30,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.core.annotation.AliasFor;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
@@ -37,7 +38,6 @@ import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.core.io.support.PropertySourceFactory;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

View File

@@ -16,10 +16,10 @@
package org.springframework.context.annotation.componentscan.level1;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.tests.sample.beans.TestBean;
@Configuration
@ComponentScan("org.springframework.context.annotation.componentscan.level2")

View File

@@ -16,10 +16,10 @@
package org.springframework.context.annotation.componentscan.level2;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.tests.sample.beans.TestBean;
@Configuration
@ComponentScan("org.springframework.context.annotation.componentscan.level3")

View File

@@ -33,6 +33,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.test.fixtures.beans.Colour;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -42,8 +44,6 @@ import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.annotation.AliasFor;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.tests.sample.beans.Colour;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -25,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.test.fixtures.beans.NestedTestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -32,8 +34,6 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
import org.springframework.tests.sample.beans.NestedTestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -33,7 +34,6 @@ import org.springframework.context.annotation.ConfigurationClassPostProcessor;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
@@ -97,7 +97,7 @@ public class ConfigurationClassAspectIntegrationTests {
return new TestBean("name");
}
@Before("execution(* org.springframework.tests.sample.beans.TestBean.absquatulate(..)) && target(testBean)")
@Before("execution(* org.springframework.beans.test.fixtures.beans.TestBean.absquatulate(..)) && target(testBean)")
public void touchBean(TestBean testBean) {
testBean.setName("advisedName");
}
@@ -122,7 +122,7 @@ public class ConfigurationClassAspectIntegrationTests {
@Aspect
static class NameChangingAspect {
@Before("execution(* org.springframework.tests.sample.beans.TestBean.absquatulate(..)) && target(testBean)")
@Before("execution(* org.springframework.beans.test.fixtures.beans.TestBean.absquatulate(..)) && target(testBean)")
public void touchBean(TestBean testBean) {
testBean.setName("advisedName");
}

View File

@@ -46,6 +46,9 @@ import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.NestedTestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.AnnotationConfigUtils;
@@ -56,9 +59,6 @@ import org.springframework.context.annotation.Scope;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.NestedTestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

View File

@@ -19,12 +19,12 @@ package org.springframework.context.annotation.configuration;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -21,10 +21,10 @@ import java.lang.annotation.RetentionPolicy;
import org.junit.jupiter.api.Test;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -23,11 +23,11 @@ import java.lang.annotation.Target;
import org.junit.jupiter.api.Test;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -26,13 +26,13 @@ import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
@@ -147,7 +147,7 @@ public class ImportResourceTests {
@Aspect
static class AnAspect {
@Before("execution(* org.springframework.tests.sample.beans.TestBean.*(..))")
@Before("execution(* org.springframework.beans.test.fixtures.beans.TestBean.*(..))")
public void advice() { }
}

View File

@@ -20,14 +20,14 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ConfigurationClassPostProcessor;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Import;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -19,12 +19,12 @@ package org.springframework.context.annotation.configuration;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.ClassUtils;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -31,14 +31,14 @@ import org.springframework.aop.scope.ScopedObject;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -18,12 +18,12 @@ package org.springframework.context.annotation4;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.BeanAge;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
import org.springframework.tests.sample.beans.TestBean;
/**
* Class used to test the functionality of factory method bean definitions

View File

@@ -16,8 +16,8 @@
package org.springframework.context.annotation4;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.annotation.Bean;
import org.springframework.tests.sample.beans.TestBean;
/**
* Class to test that @FactoryMethods are detected only when inside a class with an @Component

View File

@@ -16,9 +16,9 @@
package org.springframework.context.annotation6;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.tests.sample.beans.TestBean;
@Configuration
public class ConfigForScanning {

View File

@@ -31,22 +31,22 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.BeanThatBroadcasts;
import org.springframework.context.BeanThatListens;
import org.springframework.context.PayloadApplicationEvent;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.context.support.StaticMessageSource;
import org.springframework.context.test.fixtures.beans.BeanThatBroadcasts;
import org.springframework.context.test.fixtures.beans.BeanThatListens;
import org.springframework.core.Ordered;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.support.TaskUtils;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -22,13 +22,13 @@ import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.test.fixtures.beans.ITestBean;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.TestListener;
import org.springframework.context.event.test.TestEvent;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.context.test.fixtures.beans.TestApplicationListener;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -85,7 +85,7 @@ public class EventPublicationInterceptorTests {
@Test
public void testExpectedBehavior() {
TestBean target = new TestBean();
final TestListener listener = new TestListener();
final TestApplicationListener listener = new TestApplicationListener();
class TestContext extends StaticApplicationContext {
@Override
@@ -114,7 +114,7 @@ public class EventPublicationInterceptorTests {
// two events: ContextRefreshedEvent and TestEvent
assertThat(listener.getEventCount() == 2).as("Interceptor must have published 2 events").isTrue();
TestListener otherListener = (TestListener) ctx.getBean("&otherListener");
TestApplicationListener otherListener = (TestApplicationListener) ctx.getBean("&otherListener");
assertThat(otherListener.getEventCount() == 2).as("Interceptor must have published 2 events").isTrue();
}
@@ -128,7 +128,7 @@ public class EventPublicationInterceptorTests {
}
public static class FactoryBeanTestListener extends TestListener implements FactoryBean<Object> {
public static class FactoryBeanTestListener extends TestApplicationListener implements FactoryBean<Object> {
@Override
public Object getObject() {

View File

@@ -43,6 +43,7 @@ import org.springframework.beans.factory.support.AutowireCandidateQualifier;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.AnnotationConfigUtils;
import org.springframework.context.support.GenericApplicationContext;
@@ -54,7 +55,6 @@ import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.test.fixtures.Assume;
import org.springframework.core.test.fixtures.EnabledForTestGroups;
import org.springframework.core.test.fixtures.io.SerializationTestUtils;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.StopWatch;

View File

@@ -19,10 +19,10 @@ package org.springframework.context.expression;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.test.fixtures.env.MockPropertySource;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition;

View File

@@ -21,6 +21,7 @@ import java.util.Set;
import org.junit.jupiter.api.Test;
import org.springframework.context.test.fixtures.index.CandidateComponentsTestClassLoader;
import org.springframework.core.io.ClassPathResource;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -1,96 +0,0 @@
/*
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.context.index;
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.core.io.Resource;
/**
* A test {@link ClassLoader} that can be used in testing context to control the
* {@code spring.components} resource that should be loaded. Can also simulate a failure
* by throwing a configurable {@link IOException}.
*
* @author Stephane Nicoll
*/
public class CandidateComponentsTestClassLoader extends ClassLoader {
/**
* Create a test {@link ClassLoader} that disable the use of the index, even
* if resources are present at the standard location.
* @param classLoader the classloader to use for all other operations
* @return a test {@link ClassLoader} that has no index
* @see CandidateComponentsIndexLoader#COMPONENTS_RESOURCE_LOCATION
*/
public static ClassLoader disableIndex(ClassLoader classLoader) {
return new CandidateComponentsTestClassLoader(classLoader,
Collections.enumeration(Collections.emptyList()));
}
/**
* Create a test {@link ClassLoader} that creates an index with the
* specified {@link Resource} instances
* @param classLoader the classloader to use for all other operations
* @return a test {@link ClassLoader} with an index built based on the
* specified resources.
*/
public static ClassLoader index(ClassLoader classLoader, Resource... resources) {
return new CandidateComponentsTestClassLoader(classLoader,
Collections.enumeration(Stream.of(resources).map(r -> {
try {
return r.getURL();
}
catch (Exception ex) {
throw new IllegalArgumentException("Invalid resource " + r, ex);
}
}).collect(Collectors.toList())));
}
private final Enumeration<URL> resourceUrls;
private final IOException cause;
public CandidateComponentsTestClassLoader(ClassLoader classLoader, Enumeration<URL> resourceUrls) {
super(classLoader);
this.resourceUrls = resourceUrls;
this.cause = null;
}
public CandidateComponentsTestClassLoader(ClassLoader parent, IOException cause) {
super(parent);
this.resourceUrls = null;
this.cause = cause;
}
@Override
public Enumeration<URL> getResources(String name) throws IOException {
if (CandidateComponentsIndexLoader.COMPONENTS_RESOURCE_LOCATION.equals(name)) {
if (this.resourceUrls != null) {
return this.resourceUrls;
}
throw this.cause;
}
return super.getResources(name);
}
}

View File

@@ -27,13 +27,13 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.test.fixtures.beans.TestBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.Ordered;
import org.springframework.core.PriorityOrdered;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.Assert;
import static org.assertj.core.api.Assertions.assertThat;

Some files were not shown because too many files have changed in this diff Show More