提交 3fa4d638 编写于 作者: S Sam Brannen

Polish tests in integration-tests

上级 998f6af2
...@@ -16,23 +16,20 @@ ...@@ -16,23 +16,20 @@
package org.springframework.aop.config; package org.springframework.aop.config;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
import org.springframework.context.ApplicationContext; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpSession; import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
import org.springframework.tests.sample.beans.ITestBean; import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean; import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.ClassUtils;
import org.springframework.util.SerializationTestUtils; import org.springframework.util.SerializationTestUtils;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.support.XmlWebApplicationContext;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
...@@ -44,51 +41,50 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -44,51 +41,50 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Chris Beams * @author Chris Beams
* @see org.springframework.aop.config.AopNamespaceHandlerTests * @see org.springframework.aop.config.AopNamespaceHandlerTests
*/ */
public class AopNamespaceHandlerScopeIntegrationTests { @SpringJUnitWebConfig
class AopNamespaceHandlerScopeIntegrationTests {
private static final String CONTEXT = format("classpath:%s-context.xml", @Autowired
ClassUtils.convertClassNameToResourcePath(AopNamespaceHandlerScopeIntegrationTests.class.getName())); ITestBean singletonScoped;
private ApplicationContext context; @Autowired
ITestBean requestScoped;
@Autowired
ITestBean sessionScoped;
@BeforeEach @Autowired
public void setUp() { ITestBean sessionScopedAlias;
XmlWebApplicationContext wac = new XmlWebApplicationContext();
wac.setConfigLocations(CONTEXT); @Autowired
wac.refresh(); ITestBean testBean;
this.context = wac;
}
@Test @Test
public void testSingletonScoping() throws Exception { void testSingletonScoping() throws Exception {
ITestBean scoped = (ITestBean) this.context.getBean("singletonScoped"); assertThat(AopUtils.isAopProxy(singletonScoped)).as("Should be AOP proxy").isTrue();
assertThat(AopUtils.isAopProxy(scoped)).as("Should be AOP proxy").isTrue(); boolean condition = singletonScoped instanceof TestBean;
boolean condition = scoped instanceof TestBean;
assertThat(condition).as("Should be target class proxy").isTrue(); assertThat(condition).as("Should be target class proxy").isTrue();
String rob = "Rob Harrop"; String rob = "Rob Harrop";
String bram = "Bram Smeets"; String bram = "Bram Smeets";
assertThat(scoped.getName()).isEqualTo(rob); assertThat(singletonScoped.getName()).isEqualTo(rob);
scoped.setName(bram); singletonScoped.setName(bram);
assertThat(scoped.getName()).isEqualTo(bram); assertThat(singletonScoped.getName()).isEqualTo(bram);
ITestBean deserialized = (ITestBean) SerializationTestUtils.serializeAndDeserialize(scoped); ITestBean deserialized = (ITestBean) SerializationTestUtils.serializeAndDeserialize(singletonScoped);
assertThat(deserialized.getName()).isEqualTo(bram); assertThat(deserialized.getName()).isEqualTo(bram);
} }
@Test @Test
public void testRequestScoping() throws Exception { void testRequestScoping() throws Exception {
MockHttpServletRequest oldRequest = new MockHttpServletRequest(); MockHttpServletRequest oldRequest = new MockHttpServletRequest();
MockHttpServletRequest newRequest = new MockHttpServletRequest(); MockHttpServletRequest newRequest = new MockHttpServletRequest();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(oldRequest)); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(oldRequest));
ITestBean scoped = (ITestBean) this.context.getBean("requestScoped"); assertThat(AopUtils.isAopProxy(requestScoped)).as("Should be AOP proxy").isTrue();
assertThat(AopUtils.isAopProxy(scoped)).as("Should be AOP proxy").isTrue(); boolean condition = requestScoped instanceof TestBean;
boolean condition = scoped instanceof TestBean;
assertThat(condition).as("Should be target class proxy").isTrue(); assertThat(condition).as("Should be target class proxy").isTrue();
ITestBean testBean = (ITestBean) this.context.getBean("testBean");
assertThat(AopUtils.isAopProxy(testBean)).as("Should be AOP proxy").isTrue(); assertThat(AopUtils.isAopProxy(testBean)).as("Should be AOP proxy").isTrue();
boolean condition1 = testBean instanceof TestBean; boolean condition1 = testBean instanceof TestBean;
assertThat(condition1).as("Regular bean should be JDK proxy").isFalse(); assertThat(condition1).as("Regular bean should be JDK proxy").isFalse();
...@@ -96,18 +92,18 @@ public class AopNamespaceHandlerScopeIntegrationTests { ...@@ -96,18 +92,18 @@ public class AopNamespaceHandlerScopeIntegrationTests {
String rob = "Rob Harrop"; String rob = "Rob Harrop";
String bram = "Bram Smeets"; String bram = "Bram Smeets";
assertThat(scoped.getName()).isEqualTo(rob); assertThat(requestScoped.getName()).isEqualTo(rob);
scoped.setName(bram); requestScoped.setName(bram);
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(newRequest)); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(newRequest));
assertThat(scoped.getName()).isEqualTo(rob); assertThat(requestScoped.getName()).isEqualTo(rob);
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(oldRequest)); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(oldRequest));
assertThat(scoped.getName()).isEqualTo(bram); assertThat(requestScoped.getName()).isEqualTo(bram);
assertThat(((Advised) scoped).getAdvisors().length > 0).as("Should have advisors").isTrue(); assertThat(((Advised) requestScoped).getAdvisors().length > 0).as("Should have advisors").isTrue();
} }
@Test @Test
public void testSessionScoping() throws Exception { void testSessionScoping() throws Exception {
MockHttpSession oldSession = new MockHttpSession(); MockHttpSession oldSession = new MockHttpSession();
MockHttpSession newSession = new MockHttpSession(); MockHttpSession newSession = new MockHttpSession();
...@@ -115,15 +111,12 @@ public class AopNamespaceHandlerScopeIntegrationTests { ...@@ -115,15 +111,12 @@ public class AopNamespaceHandlerScopeIntegrationTests {
request.setSession(oldSession); request.setSession(oldSession);
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
ITestBean scoped = (ITestBean) this.context.getBean("sessionScoped"); assertThat(AopUtils.isAopProxy(sessionScoped)).as("Should be AOP proxy").isTrue();
assertThat(AopUtils.isAopProxy(scoped)).as("Should be AOP proxy").isTrue(); boolean condition1 = sessionScoped instanceof TestBean;
boolean condition1 = scoped instanceof TestBean;
assertThat(condition1).as("Should not be target class proxy").isFalse(); assertThat(condition1).as("Should not be target class proxy").isFalse();
ITestBean scopedAlias = (ITestBean) this.context.getBean("sessionScopedAlias"); assertThat(sessionScopedAlias).isSameAs(sessionScoped);
assertThat(scopedAlias).isSameAs(scoped);
ITestBean testBean = (ITestBean) this.context.getBean("testBean");
assertThat(AopUtils.isAopProxy(testBean)).as("Should be AOP proxy").isTrue(); assertThat(AopUtils.isAopProxy(testBean)).as("Should be AOP proxy").isTrue();
boolean condition = testBean instanceof TestBean; boolean condition = testBean instanceof TestBean;
assertThat(condition).as("Regular bean should be JDK proxy").isFalse(); assertThat(condition).as("Regular bean should be JDK proxy").isFalse();
...@@ -131,14 +124,14 @@ public class AopNamespaceHandlerScopeIntegrationTests { ...@@ -131,14 +124,14 @@ public class AopNamespaceHandlerScopeIntegrationTests {
String rob = "Rob Harrop"; String rob = "Rob Harrop";
String bram = "Bram Smeets"; String bram = "Bram Smeets";
assertThat(scoped.getName()).isEqualTo(rob); assertThat(sessionScoped.getName()).isEqualTo(rob);
scoped.setName(bram); sessionScoped.setName(bram);
request.setSession(newSession); request.setSession(newSession);
assertThat(scoped.getName()).isEqualTo(rob); assertThat(sessionScoped.getName()).isEqualTo(rob);
request.setSession(oldSession); request.setSession(oldSession);
assertThat(scoped.getName()).isEqualTo(bram); assertThat(sessionScoped.getName()).isEqualTo(bram);
assertThat(((Advised) scoped).getAdvisors().length > 0).as("Should have advisors").isTrue(); assertThat(((Advised) sessionScoped).getAdvisors().length > 0).as("Should have advisors").isTrue();
} }
} }
...@@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rod Johnson * @author Rod Johnson
* @author Chris Beams * @author Chris Beams
*/ */
public class AdvisorAutoProxyCreatorIntegrationTests { class AdvisorAutoProxyCreatorIntegrationTests {
private static final Class<?> CLASS = AdvisorAutoProxyCreatorIntegrationTests.class; private static final Class<?> CLASS = AdvisorAutoProxyCreatorIntegrationTests.class;
private static final String CLASSNAME = CLASS.getSimpleName(); private static final String CLASSNAME = CLASS.getSimpleName();
...@@ -66,7 +66,7 @@ public class AdvisorAutoProxyCreatorIntegrationTests { ...@@ -66,7 +66,7 @@ public class AdvisorAutoProxyCreatorIntegrationTests {
} }
@Test @Test
public void testDefaultExclusionPrefix() throws Exception { void testDefaultExclusionPrefix() throws Exception {
DefaultAdvisorAutoProxyCreator aapc = (DefaultAdvisorAutoProxyCreator) getBeanFactory().getBean(ADVISOR_APC_BEAN_NAME); DefaultAdvisorAutoProxyCreator aapc = (DefaultAdvisorAutoProxyCreator) getBeanFactory().getBean(ADVISOR_APC_BEAN_NAME);
assertThat(aapc.getAdvisorBeanNamePrefix()).isEqualTo((ADVISOR_APC_BEAN_NAME + DefaultAdvisorAutoProxyCreator.SEPARATOR)); assertThat(aapc.getAdvisorBeanNamePrefix()).isEqualTo((ADVISOR_APC_BEAN_NAME + DefaultAdvisorAutoProxyCreator.SEPARATOR));
assertThat(aapc.isUsePrefix()).isFalse(); assertThat(aapc.isUsePrefix()).isFalse();
...@@ -76,21 +76,21 @@ public class AdvisorAutoProxyCreatorIntegrationTests { ...@@ -76,21 +76,21 @@ public class AdvisorAutoProxyCreatorIntegrationTests {
* If no pointcuts match (no attrs) there should be proxying. * If no pointcuts match (no attrs) there should be proxying.
*/ */
@Test @Test
public void testNoProxy() throws Exception { void testNoProxy() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();
Object o = bf.getBean("noSetters"); Object o = bf.getBean("noSetters");
assertThat(AopUtils.isAopProxy(o)).isFalse(); assertThat(AopUtils.isAopProxy(o)).isFalse();
} }
@Test @Test
public void testTxIsProxied() throws Exception { void testTxIsProxied() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();
ITestBean test = (ITestBean) bf.getBean("test"); ITestBean test = (ITestBean) bf.getBean("test");
assertThat(AopUtils.isAopProxy(test)).isTrue(); assertThat(AopUtils.isAopProxy(test)).isTrue();
} }
@Test @Test
public void testRegexpApplied() throws Exception { void testRegexpApplied() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();
ITestBean test = (ITestBean) bf.getBean("test"); ITestBean test = (ITestBean) bf.getBean("test");
MethodCounter counter = (MethodCounter) bf.getBean("countingAdvice"); MethodCounter counter = (MethodCounter) bf.getBean("countingAdvice");
...@@ -100,7 +100,7 @@ public class AdvisorAutoProxyCreatorIntegrationTests { ...@@ -100,7 +100,7 @@ public class AdvisorAutoProxyCreatorIntegrationTests {
} }
@Test @Test
public void testTransactionAttributeOnMethod() throws Exception { void testTransactionAttributeOnMethod() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();
ITestBean test = (ITestBean) bf.getBean("test"); ITestBean test = (ITestBean) bf.getBean("test");
...@@ -122,7 +122,7 @@ public class AdvisorAutoProxyCreatorIntegrationTests { ...@@ -122,7 +122,7 @@ public class AdvisorAutoProxyCreatorIntegrationTests {
* Should not roll back on servlet exception. * Should not roll back on servlet exception.
*/ */
@Test @Test
public void testRollbackRulesOnMethodCauseRollback() throws Exception { void testRollbackRulesOnMethodCauseRollback() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();
Rollback rb = (Rollback) bf.getBean("rollback"); Rollback rb = (Rollback) bf.getBean("rollback");
...@@ -148,7 +148,7 @@ public class AdvisorAutoProxyCreatorIntegrationTests { ...@@ -148,7 +148,7 @@ public class AdvisorAutoProxyCreatorIntegrationTests {
} }
@Test @Test
public void testRollbackRulesOnMethodPreventRollback() throws Exception { void testRollbackRulesOnMethodPreventRollback() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();
Rollback rb = (Rollback) bf.getBean("rollback"); Rollback rb = (Rollback) bf.getBean("rollback");
...@@ -166,7 +166,7 @@ public class AdvisorAutoProxyCreatorIntegrationTests { ...@@ -166,7 +166,7 @@ public class AdvisorAutoProxyCreatorIntegrationTests {
} }
@Test @Test
public void testProgrammaticRollback() throws Exception { void testProgrammaticRollback() throws Exception {
BeanFactory bf = getBeanFactory(); BeanFactory bf = getBeanFactory();
Object bean = bf.getBean(TXMANAGER_BEAN_NAME); Object bean = bf.getBean(TXMANAGER_BEAN_NAME);
......
...@@ -43,10 +43,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; ...@@ -43,10 +43,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @since 3.1 * @since 3.1
*/ */
@SuppressWarnings("resource") @SuppressWarnings("resource")
public class EnableCachingIntegrationTests { class EnableCachingIntegrationTests {
@Test @Test
public void repositoryIsClassBasedCacheProxy() { void repositoryIsClassBasedCacheProxy() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class, ProxyTargetClassCachingConfig.class); ctx.register(Config.class, ProxyTargetClassCachingConfig.class);
ctx.refresh(); ctx.refresh();
...@@ -56,7 +56,7 @@ public class EnableCachingIntegrationTests { ...@@ -56,7 +56,7 @@ public class EnableCachingIntegrationTests {
} }
@Test @Test
public void repositoryUsesAspectJAdviceMode() { void repositoryUsesAspectJAdviceMode() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class, AspectJCacheConfig.class); ctx.register(Config.class, AspectJCacheConfig.class);
// this test is a bit fragile, but gets the job done, proving that an // this test is a bit fragile, but gets the job done, proving that an
......
...@@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
*/ */
public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests { class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
private static final String DEFAULT_NAME = "default"; private static final String DEFAULT_NAME = "default";
...@@ -64,7 +64,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests { ...@@ -64,7 +64,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
@BeforeEach @BeforeEach
public void setUp() { void setUp() {
this.oldRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest()); this.oldRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest());
this.newRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest()); this.newRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest());
...@@ -78,13 +78,13 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests { ...@@ -78,13 +78,13 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
} }
@AfterEach @AfterEach
public void tearDown() throws Exception { void tearDown() throws Exception {
RequestContextHolder.setRequestAttributes(null); RequestContextHolder.setRequestAttributes(null);
} }
@Test @Test
public void testPrototype() { void testPrototype() {
ApplicationContext context = createContext(ScopedProxyMode.NO); ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("prototype"); ScopedTestBean bean = (ScopedTestBean) context.getBean("prototype");
assertThat(bean).isNotNull(); assertThat(bean).isNotNull();
...@@ -93,7 +93,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests { ...@@ -93,7 +93,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
} }
@Test @Test
public void testSingletonScopeWithNoProxy() { void testSingletonScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes); RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.NO); ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton"); ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
...@@ -116,7 +116,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests { ...@@ -116,7 +116,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
} }
@Test @Test
public void testSingletonScopeIgnoresProxyInterfaces() { void testSingletonScopeIgnoresProxyInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes); RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES); ApplicationContext context = createContext(ScopedProxyMode.INTERFACES);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton"); ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
...@@ -137,7 +137,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests { ...@@ -137,7 +137,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
} }
@Test @Test
public void testSingletonScopeIgnoresProxyTargetClass() { void testSingletonScopeIgnoresProxyTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes); RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS); ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton"); ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
...@@ -158,7 +158,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests { ...@@ -158,7 +158,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
} }
@Test @Test
public void testRequestScopeWithNoProxy() { void testRequestScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes); RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.NO); ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("request"); ScopedTestBean bean = (ScopedTestBean) context.getBean("request");
...@@ -179,7 +179,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests { ...@@ -179,7 +179,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
} }
@Test @Test
public void testRequestScopeWithProxiedInterfaces() { void testRequestScopeWithProxiedInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes); RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES); ApplicationContext context = createContext(ScopedProxyMode.INTERFACES);
IScopedTestBean bean = (IScopedTestBean) context.getBean("request"); IScopedTestBean bean = (IScopedTestBean) context.getBean("request");
...@@ -201,7 +201,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests { ...@@ -201,7 +201,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
} }
@Test @Test
public void testRequestScopeWithProxiedTargetClass() { void testRequestScopeWithProxiedTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes); RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS); ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS);
IScopedTestBean bean = (IScopedTestBean) context.getBean("request"); IScopedTestBean bean = (IScopedTestBean) context.getBean("request");
...@@ -223,7 +223,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests { ...@@ -223,7 +223,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
} }
@Test @Test
public void testSessionScopeWithNoProxy() { void testSessionScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession); RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(ScopedProxyMode.NO); ApplicationContext context = createContext(ScopedProxyMode.NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("session"); ScopedTestBean bean = (ScopedTestBean) context.getBean("session");
...@@ -244,7 +244,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests { ...@@ -244,7 +244,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
} }
@Test @Test
public void testSessionScopeWithProxiedInterfaces() { void testSessionScopeWithProxiedInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession); RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(ScopedProxyMode.INTERFACES); ApplicationContext context = createContext(ScopedProxyMode.INTERFACES);
IScopedTestBean bean = (IScopedTestBean) context.getBean("session"); IScopedTestBean bean = (IScopedTestBean) context.getBean("session");
...@@ -272,7 +272,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests { ...@@ -272,7 +272,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
} }
@Test @Test
public void testSessionScopeWithProxiedTargetClass() { void testSessionScopeWithProxiedTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession); RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS); ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS);
IScopedTestBean bean = (IScopedTestBean) context.getBean("session"); IScopedTestBean bean = (IScopedTestBean) context.getBean("session");
...@@ -341,7 +341,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests { ...@@ -341,7 +341,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
} }
public static interface IScopedTestBean { public interface IScopedTestBean {
String getName(); String getName();
...@@ -372,7 +372,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests { ...@@ -372,7 +372,7 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
} }
public static interface AnotherScopeTestInterface { public interface AnotherScopeTestInterface {
} }
...@@ -391,14 +391,14 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests { ...@@ -391,14 +391,14 @@ public class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests {
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE}) @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@javax.inject.Scope @javax.inject.Scope
public static @interface RequestScoped { public @interface RequestScoped {
} }
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE}) @Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@javax.inject.Scope @javax.inject.Scope
public static @interface SessionScoped { public @interface SessionScoped {
} }
} }
...@@ -45,7 +45,7 @@ import static org.springframework.context.annotation.ScopedProxyMode.TARGET_CLAS ...@@ -45,7 +45,7 @@ import static org.springframework.context.annotation.ScopedProxyMode.TARGET_CLAS
* @author Chris Beams * @author Chris Beams
* @author Sam Brannen * @author Sam Brannen
*/ */
public class ClassPathBeanDefinitionScannerScopeIntegrationTests { class ClassPathBeanDefinitionScannerScopeIntegrationTests {
private static final String DEFAULT_NAME = "default"; private static final String DEFAULT_NAME = "default";
private static final String MODIFIED_NAME = "modified"; private static final String MODIFIED_NAME = "modified";
...@@ -58,7 +58,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests { ...@@ -58,7 +58,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
@BeforeEach @BeforeEach
public void setUp() { void setUp() {
MockHttpServletRequest oldRequestWithSession = new MockHttpServletRequest(); MockHttpServletRequest oldRequestWithSession = new MockHttpServletRequest();
oldRequestWithSession.setSession(new MockHttpSession()); oldRequestWithSession.setSession(new MockHttpSession());
this.oldRequestAttributesWithSession = new ServletRequestAttributes(oldRequestWithSession); this.oldRequestAttributesWithSession = new ServletRequestAttributes(oldRequestWithSession);
...@@ -69,13 +69,13 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests { ...@@ -69,13 +69,13 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
} }
@AfterEach @AfterEach
public void tearDown() throws Exception { void tearDown() throws Exception {
RequestContextHolder.resetRequestAttributes(); RequestContextHolder.resetRequestAttributes();
} }
@Test @Test
public void singletonScopeWithNoProxy() { void singletonScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes); RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(NO); ApplicationContext context = createContext(NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton"); ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
...@@ -96,7 +96,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests { ...@@ -96,7 +96,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
} }
@Test @Test
public void singletonScopeIgnoresProxyInterfaces() { void singletonScopeIgnoresProxyInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes); RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(INTERFACES); ApplicationContext context = createContext(INTERFACES);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton"); ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
...@@ -117,7 +117,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests { ...@@ -117,7 +117,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
} }
@Test @Test
public void singletonScopeIgnoresProxyTargetClass() { void singletonScopeIgnoresProxyTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes); RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(TARGET_CLASS); ApplicationContext context = createContext(TARGET_CLASS);
ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton"); ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
...@@ -138,7 +138,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests { ...@@ -138,7 +138,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
} }
@Test @Test
public void requestScopeWithNoProxy() { void requestScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes); RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(NO); ApplicationContext context = createContext(NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("request"); ScopedTestBean bean = (ScopedTestBean) context.getBean("request");
...@@ -159,7 +159,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests { ...@@ -159,7 +159,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
} }
@Test @Test
public void requestScopeWithProxiedInterfaces() { void requestScopeWithProxiedInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes); RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(INTERFACES); ApplicationContext context = createContext(INTERFACES);
IScopedTestBean bean = (IScopedTestBean) context.getBean("request"); IScopedTestBean bean = (IScopedTestBean) context.getBean("request");
...@@ -181,7 +181,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests { ...@@ -181,7 +181,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
} }
@Test @Test
public void requestScopeWithProxiedTargetClass() { void requestScopeWithProxiedTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributes); RequestContextHolder.setRequestAttributes(oldRequestAttributes);
ApplicationContext context = createContext(TARGET_CLASS); ApplicationContext context = createContext(TARGET_CLASS);
IScopedTestBean bean = (IScopedTestBean) context.getBean("request"); IScopedTestBean bean = (IScopedTestBean) context.getBean("request");
...@@ -203,7 +203,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests { ...@@ -203,7 +203,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
} }
@Test @Test
public void sessionScopeWithNoProxy() { void sessionScopeWithNoProxy() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession); RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(NO); ApplicationContext context = createContext(NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("session"); ScopedTestBean bean = (ScopedTestBean) context.getBean("session");
...@@ -224,7 +224,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests { ...@@ -224,7 +224,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
} }
@Test @Test
public void sessionScopeWithProxiedInterfaces() { void sessionScopeWithProxiedInterfaces() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession); RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(INTERFACES); ApplicationContext context = createContext(INTERFACES);
IScopedTestBean bean = (IScopedTestBean) context.getBean("session"); IScopedTestBean bean = (IScopedTestBean) context.getBean("session");
...@@ -252,7 +252,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests { ...@@ -252,7 +252,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
} }
@Test @Test
public void sessionScopeWithProxiedTargetClass() { void sessionScopeWithProxiedTargetClass() {
RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession); RequestContextHolder.setRequestAttributes(oldRequestAttributesWithSession);
ApplicationContext context = createContext(TARGET_CLASS); ApplicationContext context = createContext(TARGET_CLASS);
IScopedTestBean bean = (IScopedTestBean) context.getBean("session"); IScopedTestBean bean = (IScopedTestBean) context.getBean("session");
...@@ -298,7 +298,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests { ...@@ -298,7 +298,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
} }
static interface IScopedTestBean { interface IScopedTestBean {
String getName(); String getName();
...@@ -323,7 +323,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests { ...@@ -323,7 +323,7 @@ public class ClassPathBeanDefinitionScannerScopeIntegrationTests {
} }
static interface AnotherScopeTestInterface { interface AnotherScopeTestInterface {
} }
......
...@@ -100,14 +100,14 @@ public class EnvironmentSystemIntegrationTests { ...@@ -100,14 +100,14 @@ public class EnvironmentSystemIntegrationTests {
private final ConfigurableEnvironment prodWebEnv = new StandardServletEnvironment(); private final ConfigurableEnvironment prodWebEnv = new StandardServletEnvironment();
@BeforeEach @BeforeEach
public void setUp() { void setUp() {
prodEnv.setActiveProfiles(PROD_ENV_NAME); prodEnv.setActiveProfiles(PROD_ENV_NAME);
devEnv.setActiveProfiles(DEV_ENV_NAME); devEnv.setActiveProfiles(DEV_ENV_NAME);
prodWebEnv.setActiveProfiles(PROD_ENV_NAME); prodWebEnv.setActiveProfiles(PROD_ENV_NAME);
} }
@Test @Test
public void genericApplicationContext_standardEnv() { void genericApplicationContext_standardEnv() {
ConfigurableApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean()); ConfigurableApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
ctx.refresh(); ctx.refresh();
...@@ -117,7 +117,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -117,7 +117,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void genericApplicationContext_customEnv() { void genericApplicationContext_customEnv() {
GenericApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean()); GenericApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
ctx.setEnvironment(prodEnv); ctx.setEnvironment(prodEnv);
ctx.refresh(); ctx.refresh();
...@@ -128,7 +128,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -128,7 +128,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void xmlBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() { void xmlBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() {
GenericApplicationContext ctx = new GenericApplicationContext(); GenericApplicationContext ctx = new GenericApplicationContext();
ctx.setEnvironment(prodEnv); ctx.setEnvironment(prodEnv);
new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(XML_PATH); new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(XML_PATH);
...@@ -138,7 +138,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -138,7 +138,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void annotatedBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() { void annotatedBeanDefinitionReader_inheritsEnvironmentFromEnvironmentCapableBDR() {
GenericApplicationContext ctx = new GenericApplicationContext(); GenericApplicationContext ctx = new GenericApplicationContext();
ctx.setEnvironment(prodEnv); ctx.setEnvironment(prodEnv);
new AnnotatedBeanDefinitionReader(ctx).register(Config.class); new AnnotatedBeanDefinitionReader(ctx).register(Config.class);
...@@ -148,7 +148,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -148,7 +148,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedConfigClasses() { void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedConfigClasses() {
// it's actually ConfigurationClassPostProcessor's Environment that gets the job done here. // it's actually ConfigurationClassPostProcessor's Environment that gets the job done here.
GenericApplicationContext ctx = new GenericApplicationContext(); GenericApplicationContext ctx = new GenericApplicationContext();
ctx.setEnvironment(prodEnv); ctx.setEnvironment(prodEnv);
...@@ -160,7 +160,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -160,7 +160,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedComponents() { void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedComponents() {
GenericApplicationContext ctx = new GenericApplicationContext(); GenericApplicationContext ctx = new GenericApplicationContext();
ctx.setEnvironment(prodEnv); ctx.setEnvironment(prodEnv);
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
...@@ -172,7 +172,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -172,7 +172,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void genericXmlApplicationContext() { void genericXmlApplicationContext() {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
assertHasStandardEnvironment(ctx); assertHasStandardEnvironment(ctx);
ctx.setEnvironment(prodEnv); ctx.setEnvironment(prodEnv);
...@@ -187,7 +187,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -187,7 +187,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void classPathXmlApplicationContext() { void classPathXmlApplicationContext() {
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(XML_PATH); ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(XML_PATH);
ctx.setEnvironment(prodEnv); ctx.setEnvironment(prodEnv);
ctx.refresh(); ctx.refresh();
...@@ -200,7 +200,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -200,7 +200,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void fileSystemXmlApplicationContext() throws IOException { void fileSystemXmlApplicationContext() throws IOException {
ClassPathResource xml = new ClassPathResource(XML_PATH); ClassPathResource xml = new ClassPathResource(XML_PATH);
File tmpFile = File.createTempFile("test", "xml"); File tmpFile = File.createTempFile("test", "xml");
FileCopyUtils.copy(xml.getFile(), tmpFile); FileCopyUtils.copy(xml.getFile(), tmpFile);
...@@ -218,7 +218,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -218,7 +218,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void annotationConfigApplicationContext_withPojos() { void annotationConfigApplicationContext_withPojos() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
assertHasStandardEnvironment(ctx); assertHasStandardEnvironment(ctx);
...@@ -231,7 +231,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -231,7 +231,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void annotationConfigApplicationContext_withProdEnvAndProdConfigClass() { void annotationConfigApplicationContext_withProdEnvAndProdConfigClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
assertHasStandardEnvironment(ctx); assertHasStandardEnvironment(ctx);
...@@ -244,7 +244,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -244,7 +244,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void annotationConfigApplicationContext_withProdEnvAndDevConfigClass() { void annotationConfigApplicationContext_withProdEnvAndDevConfigClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
assertHasStandardEnvironment(ctx); assertHasStandardEnvironment(ctx);
...@@ -258,7 +258,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -258,7 +258,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void annotationConfigApplicationContext_withDevEnvAndDevConfigClass() { void annotationConfigApplicationContext_withDevEnvAndDevConfigClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
assertHasStandardEnvironment(ctx); assertHasStandardEnvironment(ctx);
...@@ -272,7 +272,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -272,7 +272,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void annotationConfigApplicationContext_withImportedConfigClasses() { void annotationConfigApplicationContext_withImportedConfigClasses() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
assertHasStandardEnvironment(ctx); assertHasStandardEnvironment(ctx);
...@@ -288,7 +288,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -288,7 +288,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void mostSpecificDerivedClassDrivesEnvironment_withDerivedDevEnvAndDerivedDevConfigClass() { void mostSpecificDerivedClassDrivesEnvironment_withDerivedDevEnvAndDerivedDevConfigClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
StandardEnvironment derivedDevEnv = new StandardEnvironment(); StandardEnvironment derivedDevEnv = new StandardEnvironment();
derivedDevEnv.setActiveProfiles(DERIVED_DEV_ENV_NAME); derivedDevEnv.setActiveProfiles(DERIVED_DEV_ENV_NAME);
...@@ -302,7 +302,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -302,7 +302,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void mostSpecificDerivedClassDrivesEnvironment_withDevEnvAndDerivedDevConfigClass() { void mostSpecificDerivedClassDrivesEnvironment_withDevEnvAndDerivedDevConfigClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.setEnvironment(devEnv); ctx.setEnvironment(devEnv);
ctx.register(DerivedDevConfig.class); ctx.register(DerivedDevConfig.class);
...@@ -314,22 +314,22 @@ public class EnvironmentSystemIntegrationTests { ...@@ -314,22 +314,22 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void annotationConfigApplicationContext_withProfileExpressionMatchOr() { void annotationConfigApplicationContext_withProfileExpressionMatchOr() {
testProfileExpression(true, "p3"); testProfileExpression(true, "p3");
} }
@Test @Test
public void annotationConfigApplicationContext_withProfileExpressionMatchAnd() { void annotationConfigApplicationContext_withProfileExpressionMatchAnd() {
testProfileExpression(true, "p1", "p2"); testProfileExpression(true, "p1", "p2");
} }
@Test @Test
public void annotationConfigApplicationContext_withProfileExpressionNoMatchAnd() { void annotationConfigApplicationContext_withProfileExpressionNoMatchAnd() {
testProfileExpression(false, "p1"); testProfileExpression(false, "p1");
} }
@Test @Test
public void annotationConfigApplicationContext_withProfileExpressionNoMatchNone() { void annotationConfigApplicationContext_withProfileExpressionNoMatchNone() {
testProfileExpression(false, "p4"); testProfileExpression(false, "p4");
} }
...@@ -344,7 +344,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -344,7 +344,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void webApplicationContext() { void webApplicationContext() {
GenericWebApplicationContext ctx = new GenericWebApplicationContext(newBeanFactoryWithEnvironmentAwareBean()); GenericWebApplicationContext ctx = new GenericWebApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
assertHasStandardServletEnvironment(ctx); assertHasStandardServletEnvironment(ctx);
ctx.setEnvironment(prodWebEnv); ctx.setEnvironment(prodWebEnv);
...@@ -356,7 +356,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -356,7 +356,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void xmlWebApplicationContext() { void xmlWebApplicationContext() {
AbstractRefreshableWebApplicationContext ctx = new XmlWebApplicationContext(); AbstractRefreshableWebApplicationContext ctx = new XmlWebApplicationContext();
ctx.setConfigLocation("classpath:" + XML_PATH); ctx.setConfigLocation("classpath:" + XML_PATH);
ctx.setEnvironment(prodWebEnv); ctx.setEnvironment(prodWebEnv);
...@@ -370,7 +370,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -370,7 +370,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void staticApplicationContext() { void staticApplicationContext() {
StaticApplicationContext ctx = new StaticApplicationContext(); StaticApplicationContext ctx = new StaticApplicationContext();
assertHasStandardEnvironment(ctx); assertHasStandardEnvironment(ctx);
...@@ -386,7 +386,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -386,7 +386,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void staticWebApplicationContext() { void staticWebApplicationContext() {
StaticWebApplicationContext ctx = new StaticWebApplicationContext(); StaticWebApplicationContext ctx = new StaticWebApplicationContext();
assertHasStandardServletEnvironment(ctx); assertHasStandardServletEnvironment(ctx);
...@@ -402,7 +402,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -402,7 +402,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void annotationConfigWebApplicationContext() { void annotationConfigWebApplicationContext() {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.setEnvironment(prodWebEnv); ctx.setEnvironment(prodWebEnv);
ctx.setConfigLocation(EnvironmentAwareBean.class.getName()); ctx.setConfigLocation(EnvironmentAwareBean.class.getName());
...@@ -414,7 +414,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -414,7 +414,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void registerServletParamPropertySources_AbstractRefreshableWebApplicationContext() { void registerServletParamPropertySources_AbstractRefreshableWebApplicationContext() {
MockServletContext servletContext = new MockServletContext(); MockServletContext servletContext = new MockServletContext();
servletContext.addInitParameter("pCommon", "pCommonContextValue"); servletContext.addInitParameter("pCommon", "pCommonContextValue");
servletContext.addInitParameter("pContext1", "pContext1Value"); servletContext.addInitParameter("pContext1", "pContext1Value");
...@@ -459,7 +459,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -459,7 +459,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void registerServletParamPropertySources_GenericWebApplicationContext() { void registerServletParamPropertySources_GenericWebApplicationContext() {
MockServletContext servletContext = new MockServletContext(); MockServletContext servletContext = new MockServletContext();
servletContext.addInitParameter("pCommon", "pCommonContextValue"); servletContext.addInitParameter("pCommon", "pCommonContextValue");
servletContext.addInitParameter("pContext1", "pContext1Value"); servletContext.addInitParameter("pContext1", "pContext1Value");
...@@ -493,7 +493,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -493,7 +493,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void registerServletParamPropertySources_StaticWebApplicationContext() { void registerServletParamPropertySources_StaticWebApplicationContext() {
MockServletContext servletContext = new MockServletContext(); MockServletContext servletContext = new MockServletContext();
servletContext.addInitParameter("pCommon", "pCommonContextValue"); servletContext.addInitParameter("pCommon", "pCommonContextValue");
servletContext.addInitParameter("pContext1", "pContext1Value"); servletContext.addInitParameter("pContext1", "pContext1Value");
...@@ -536,7 +536,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -536,7 +536,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void resourceAdapterApplicationContext() { void resourceAdapterApplicationContext() {
ResourceAdapterApplicationContext ctx = new ResourceAdapterApplicationContext(new SimpleBootstrapContext(new SimpleTaskWorkManager())); ResourceAdapterApplicationContext ctx = new ResourceAdapterApplicationContext(new SimpleBootstrapContext(new SimpleTaskWorkManager()));
assertHasStandardEnvironment(ctx); assertHasStandardEnvironment(ctx);
...@@ -552,7 +552,7 @@ public class EnvironmentSystemIntegrationTests { ...@@ -552,7 +552,7 @@ public class EnvironmentSystemIntegrationTests {
} }
@Test @Test
public void abstractApplicationContextValidatesRequiredPropertiesOnRefresh() { void abstractApplicationContextValidatesRequiredPropertiesOnRefresh() {
{ {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(); ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.refresh(); ctx.refresh();
......
...@@ -22,11 +22,11 @@ import org.springframework.context.support.GenericApplicationContext; ...@@ -22,11 +22,11 @@ import org.springframework.context.support.GenericApplicationContext;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition; import static org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition;
public class PropertyPlaceholderConfigurerEnvironmentIntegrationTests { class PropertyPlaceholderConfigurerEnvironmentIntegrationTests {
@Test @Test
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void test() { void test() {
GenericApplicationContext ctx = new GenericApplicationContext(); GenericApplicationContext ctx = new GenericApplicationContext();
ctx.registerBeanDefinition("ppc", ctx.registerBeanDefinition("ppc",
rootBeanDefinition(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.class) rootBeanDefinition(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.class)
......
...@@ -18,29 +18,26 @@ package org.springframework.expression.spel.support; ...@@ -18,29 +18,26 @@ package org.springframework.expression.spel.support;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.TypeDescriptor;
import org.springframework.expression.MethodExecutor; import org.springframework.expression.MethodExecutor;
public class Spr7538Tests { class Spr7538Tests {
@Disabled @Test @Test
public void repro() throws Exception { void repro() throws Exception {
AlwaysTrueReleaseStrategy target = new AlwaysTrueReleaseStrategy(); AlwaysTrueReleaseStrategy target = new AlwaysTrueReleaseStrategy();
BeanFactoryTypeConverter converter = new BeanFactoryTypeConverter(); BeanFactoryTypeConverter converter = new BeanFactoryTypeConverter();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
context.setTypeConverter(converter); context.setTypeConverter(converter);
List<Foo> arguments = new ArrayList<>(); List<Foo> arguments = Collections.emptyList();
// !!!! With the below line commented you'll get NPE. Uncomment and everything is OK!
//arguments.add(new Foo());
List<TypeDescriptor> paramDescriptors = new ArrayList<>(); List<TypeDescriptor> paramDescriptors = new ArrayList<>();
Method method = AlwaysTrueReleaseStrategy.class.getMethod("checkCompleteness", List.class); Method method = AlwaysTrueReleaseStrategy.class.getMethod("checkCompleteness", List.class);
...@@ -56,11 +53,11 @@ public class Spr7538Tests { ...@@ -56,11 +53,11 @@ public class Spr7538Tests {
System.out.println("Result: " + result); System.out.println("Result: " + result);
} }
public static class AlwaysTrueReleaseStrategy { static class AlwaysTrueReleaseStrategy {
public boolean checkCompleteness(List<Foo> messages) { public boolean checkCompleteness(List<Foo> messages) {
return true; return true;
} }
} }
public static class Foo{} static class Foo{}
} }
...@@ -54,66 +54,57 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; ...@@ -54,66 +54,57 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @since 3.1 * @since 3.1
*/ */
@SuppressWarnings("resource") @SuppressWarnings("resource")
public class EnableTransactionManagementIntegrationTests { class EnableTransactionManagementIntegrationTests {
@Test @Test
public void repositoryIsNotTxProxy() { void repositoryIsNotTxProxy() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
ctx.register(Config.class);
ctx.refresh();
assertThat(isTxProxy(ctx.getBean(FooRepository.class))).isFalse(); assertThat(isTxProxy(ctx.getBean(FooRepository.class))).isFalse();
} }
@Test @Test
public void repositoryIsTxProxy_withDefaultTxManagerName() { void repositoryIsTxProxy_withDefaultTxManagerName() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class, DefaultTxManagerNameConfig.class);
ctx.register(Config.class, DefaultTxManagerNameConfig.class);
ctx.refresh();
assertTxProxying(ctx); assertTxProxying(ctx);
} }
@Test @Test
public void repositoryIsTxProxy_withCustomTxManagerName() { void repositoryIsTxProxy_withCustomTxManagerName() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class, CustomTxManagerNameConfig.class);
ctx.register(Config.class, CustomTxManagerNameConfig.class);
ctx.refresh();
assertTxProxying(ctx); assertTxProxying(ctx);
} }
@Test @Test
public void repositoryIsTxProxy_withNonConventionalTxManagerName_fallsBackToByTypeLookup() { void repositoryIsTxProxy_withNonConventionalTxManagerName_fallsBackToByTypeLookup() {
assertTxProxying(new AnnotationConfigApplicationContext(Config.class, NonConventionalTxManagerNameConfig.class)); assertTxProxying(new AnnotationConfigApplicationContext(Config.class, NonConventionalTxManagerNameConfig.class));
} }
@Test @Test
public void repositoryIsClassBasedTxProxy() { void repositoryIsClassBasedTxProxy() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class, ProxyTargetClassTxConfig.class);
ctx.register(Config.class, ProxyTargetClassTxConfig.class);
ctx.refresh();
assertTxProxying(ctx); assertTxProxying(ctx);
assertThat(AopUtils.isCglibProxy(ctx.getBean(FooRepository.class))).isTrue(); assertThat(AopUtils.isCglibProxy(ctx.getBean(FooRepository.class))).isTrue();
} }
@Test @Test
public void repositoryUsesAspectJAdviceMode() { void repositoryUsesAspectJAdviceMode() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class, AspectJTxConfig.class); ctx.register(Config.class, AspectJTxConfig.class);
// this test is a bit fragile, but gets the job done, proving that an // this test is a bit fragile, but gets the job done, proving that an
// attempt was made to look up the AJ aspect. It's due to classpath issues // attempt was made to look up the AJ aspect. It's due to classpath issues
// in .integration-tests that it's not found. // in .integration-tests that it's not found.
assertThatExceptionOfType(Exception.class).isThrownBy( assertThatExceptionOfType(Exception.class)
ctx::refresh) .isThrownBy(ctx::refresh)
.withMessageContaining("AspectJJtaTransactionManagementConfiguration"); .withMessageContaining("AspectJJtaTransactionManagementConfiguration");
} }
@Test @Test
public void implicitTxManager() { void implicitTxManager() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImplicitTxManagerConfig.class);
ctx.register(ImplicitTxManagerConfig.class);
ctx.refresh();
FooRepository fooRepository = ctx.getBean(FooRepository.class); FooRepository fooRepository = ctx.getBean(FooRepository.class);
fooRepository.findAll(); fooRepository.findAll();
...@@ -125,10 +116,8 @@ public class EnableTransactionManagementIntegrationTests { ...@@ -125,10 +116,8 @@ public class EnableTransactionManagementIntegrationTests {
} }
@Test @Test
public void explicitTxManager() { void explicitTxManager() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ExplicitTxManagerConfig.class);
ctx.register(ExplicitTxManagerConfig.class);
ctx.refresh();
FooRepository fooRepository = ctx.getBean(FooRepository.class); FooRepository fooRepository = ctx.getBean(FooRepository.class);
fooRepository.findAll(); fooRepository.findAll();
...@@ -145,10 +134,8 @@ public class EnableTransactionManagementIntegrationTests { ...@@ -145,10 +134,8 @@ public class EnableTransactionManagementIntegrationTests {
} }
@Test @Test
public void apcEscalation() { void apcEscalation() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); new AnnotationConfigApplicationContext(EnableTxAndCachingConfig.class);
ctx.register(EnableTxAndCachingConfig.class);
ctx.refresh();
} }
......
...@@ -35,10 +35,10 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -35,10 +35,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Chris Beams * @author Chris Beams
*/ */
@SuppressWarnings("resource") @SuppressWarnings("resource")
public class ProxyAnnotationDiscoveryTests { class ProxyAnnotationDiscoveryTests {
@Test @Test
public void annotatedServiceWithoutInterface_PTC_true() { void annotatedServiceWithoutInterface_PTC_true() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(PTCTrue.class, AnnotatedServiceWithoutInterface.class); ctx.register(PTCTrue.class, AnnotatedServiceWithoutInterface.class);
ctx.refresh(); ctx.refresh();
...@@ -48,7 +48,7 @@ public class ProxyAnnotationDiscoveryTests { ...@@ -48,7 +48,7 @@ public class ProxyAnnotationDiscoveryTests {
} }
@Test @Test
public void annotatedServiceWithoutInterface_PTC_false() { void annotatedServiceWithoutInterface_PTC_false() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(PTCFalse.class, AnnotatedServiceWithoutInterface.class); ctx.register(PTCFalse.class, AnnotatedServiceWithoutInterface.class);
ctx.refresh(); ctx.refresh();
...@@ -58,7 +58,7 @@ public class ProxyAnnotationDiscoveryTests { ...@@ -58,7 +58,7 @@ public class ProxyAnnotationDiscoveryTests {
} }
@Test @Test
public void nonAnnotatedService_PTC_true() { void nonAnnotatedService_PTC_true() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(PTCTrue.class, AnnotatedServiceImpl.class); ctx.register(PTCTrue.class, AnnotatedServiceImpl.class);
ctx.refresh(); ctx.refresh();
...@@ -68,7 +68,7 @@ public class ProxyAnnotationDiscoveryTests { ...@@ -68,7 +68,7 @@ public class ProxyAnnotationDiscoveryTests {
} }
@Test @Test
public void nonAnnotatedService_PTC_false() { void nonAnnotatedService_PTC_false() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(PTCFalse.class, AnnotatedServiceImpl.class); ctx.register(PTCFalse.class, AnnotatedServiceImpl.class);
ctx.refresh(); ctx.refresh();
...@@ -78,7 +78,7 @@ public class ProxyAnnotationDiscoveryTests { ...@@ -78,7 +78,7 @@ public class ProxyAnnotationDiscoveryTests {
} }
@Test @Test
public void annotatedService_PTC_true() { void annotatedService_PTC_true() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(PTCTrue.class, NonAnnotatedServiceImpl.class); ctx.register(PTCTrue.class, NonAnnotatedServiceImpl.class);
ctx.refresh(); ctx.refresh();
...@@ -88,7 +88,7 @@ public class ProxyAnnotationDiscoveryTests { ...@@ -88,7 +88,7 @@ public class ProxyAnnotationDiscoveryTests {
} }
@Test @Test
public void annotatedService_PTC_false() { void annotatedService_PTC_false() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(PTCFalse.class, NonAnnotatedServiceImpl.class); ctx.register(PTCFalse.class, NonAnnotatedServiceImpl.class);
ctx.refresh(); ctx.refresh();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册