Sync with 3.1.x
* 3.1.x: (61 commits) Compensate for changes in JDK 7 Introspector Avoid 'type mismatch' errors in ExtendedBeanInfo Polish ExtendedBeanInfo and tests Infer AnnotationAttributes method return types Minor fix in MVC reference doc chapter Hibernate 4.1 etc TypeDescriptor equals implementation accepts annotations in any order "setBasenames" uses varargs now (for programmatic setup; SPR-9106) @ActiveProfiles mechanism works with @ImportResource as well (SPR-8992 polishing clarified Resource's "getFilename" method to consistently return null substituteNamedParameters detects and unwraps SqlParameterValue object Replace spaces with tabs Consider security in ClassUtils#getMostSpecificMethod Adding null check for username being null. Improvements for registering custom SQL exception translators in app c SPR-7680 Adding QueryTimeoutException to the DataAccessException hiera Minor polish in WebMvcConfigurationSupport Detect overridden boolean getters in ExtendedBeanInfo Polish ExtendedBeanInfoTests ...
This commit is contained in:
@@ -42,7 +42,7 @@ public abstract class AbstractCircularImportDetectionTests {
|
||||
public void simpleCircularImportIsDetected() throws Exception {
|
||||
boolean threw = false;
|
||||
try {
|
||||
newParser().parse(loadAsConfigurationSource(A.class), null);
|
||||
newParser().parse(loadAsConfigurationSource(A.class), "A");
|
||||
} catch (BeanDefinitionParsingException ex) {
|
||||
assertTrue("Wrong message. Got: " + ex.getMessage(),
|
||||
ex.getMessage().contains(
|
||||
@@ -59,7 +59,7 @@ public abstract class AbstractCircularImportDetectionTests {
|
||||
public void complexCircularImportIsDetected() throws Exception {
|
||||
boolean threw = false;
|
||||
try {
|
||||
newParser().parse(loadAsConfigurationSource(X.class), null);
|
||||
newParser().parse(loadAsConfigurationSource(X.class), "X");
|
||||
}
|
||||
catch (BeanDefinitionParsingException ex) {
|
||||
assertTrue("Wrong message. Got: " + ex.getMessage(),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* 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.
|
||||
@@ -19,18 +19,19 @@ package org.springframework.context.annotation;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.springframework.context.annotation.MetadataUtils.attributesFor;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor;
|
||||
|
||||
@@ -55,8 +56,8 @@ public class ImportAwareTests {
|
||||
AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
|
||||
assertThat("import metadata was not injected", importMetadata, notNullValue());
|
||||
assertThat(importMetadata.getClassName(), is(ImportingConfig.class.getName()));
|
||||
Map<String, Object> importAttribs = importMetadata.getAnnotationAttributes(Import.class.getName());
|
||||
Class<?>[] importedClasses = (Class<?>[])importAttribs.get("value");
|
||||
AnnotationAttributes importAttribs = attributesFor(importMetadata, Import.class);
|
||||
Class<?>[] importedClasses = importAttribs.getClassArray("value");
|
||||
assertThat(importedClasses[0].getName(), is(ImportedConfig.class.getName()));
|
||||
}
|
||||
|
||||
@@ -72,8 +73,8 @@ public class ImportAwareTests {
|
||||
AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
|
||||
assertThat("import metadata was not injected", importMetadata, notNullValue());
|
||||
assertThat(importMetadata.getClassName(), is(IndirectlyImportingConfig.class.getName()));
|
||||
Map<String, Object> enableAttribs = importMetadata.getAnnotationAttributes(EnableImportedConfig.class.getName());
|
||||
String foo = (String)enableAttribs.get("foo");
|
||||
AnnotationAttributes enableAttribs = attributesFor(importMetadata, EnableImportedConfig.class);
|
||||
String foo = enableAttribs.getString("foo");
|
||||
assertThat(foo, is("xyz"));
|
||||
}
|
||||
|
||||
@@ -129,7 +130,6 @@ public class ImportAwareTests {
|
||||
}
|
||||
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
System.out.println("ImportAwareTests.BPP.setBeanFactory()");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import test.beans.TestBean;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ConfigurationClassPostProcessor;
|
||||
@@ -53,13 +54,6 @@ public class ImportTests {
|
||||
assertThat(beanFactory.getBeanDefinitionCount(), equalTo(expectedCount));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessImports() {
|
||||
int configClasses = 2;
|
||||
int beansInClasses = 2;
|
||||
assertBeanDefinitionCount((configClasses + beansInClasses), ConfigurationWithImportAnnotation.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessImportsWithAsm() {
|
||||
int configClasses = 2;
|
||||
@@ -315,4 +309,36 @@ public class ImportTests {
|
||||
static class ConfigAnnotated { }
|
||||
|
||||
static class NonConfigAnnotated { }
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Test that values supplied to @Configuration(value="...") are propagated as the
|
||||
* bean name for the configuration class even in the case of inclusion via @Import
|
||||
* or in the case of automatic registration via nesting
|
||||
*/
|
||||
@Test
|
||||
public void reproSpr9023() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(B.class);
|
||||
ctx.refresh();
|
||||
System.out.println(ctx.getBeanFactory());
|
||||
assertThat(ctx.getBeanNamesForType(B.class)[0], is("config-b"));
|
||||
assertThat(ctx.getBeanNamesForType(A.class)[0], is("config-a"));
|
||||
}
|
||||
|
||||
@Configuration("config-a")
|
||||
static class A { }
|
||||
|
||||
@Configuration("config-b")
|
||||
@Import(A.class)
|
||||
static class B { }
|
||||
|
||||
@Test
|
||||
public void testProcessImports() {
|
||||
int configClasses = 2;
|
||||
int beansInClasses = 2;
|
||||
assertBeanDefinitionCount((configClasses + beansInClasses), ConfigurationWithImportAnnotation.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* http://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.annotation.configuration.spr9031;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.configuration.spr9031.scanpackage.Spr9031Component;
|
||||
|
||||
/**
|
||||
* Unit tests cornering bug SPR-9031.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public class Spr9031Tests {
|
||||
|
||||
/**
|
||||
* Use of @Import to register LowLevelConfig results in ASM-based annotation
|
||||
* processing.
|
||||
*/
|
||||
@Test
|
||||
public void withAsmAnnotationProcessing() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(HighLevelConfig.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBean(LowLevelConfig.class).scanned, not(nullValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Direct registration of LowLevelConfig results in reflection-based annotation
|
||||
* processing.
|
||||
*/
|
||||
@Test
|
||||
public void withoutAsmAnnotationProcessing() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
ctx.register(LowLevelConfig.class);
|
||||
ctx.refresh();
|
||||
assertThat(ctx.getBean(LowLevelConfig.class).scanned, not(nullValue()));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import(LowLevelConfig.class)
|
||||
static class HighLevelConfig {}
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(
|
||||
basePackages = "org.springframework.context.annotation.configuration.spr9031.scanpackage",
|
||||
includeFilters = { @Filter(MarkerAnnotation.class) })
|
||||
static class LowLevelConfig {
|
||||
// fails to wire when LowLevelConfig is processed with ASM because nested @Filter
|
||||
// annotation is not parsed
|
||||
@Autowired Spr9031Component scanned;
|
||||
}
|
||||
|
||||
public @interface MarkerAnnotation {}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* http://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.annotation.configuration.spr9031.scanpackage;
|
||||
|
||||
import org.springframework.context.annotation.configuration.spr9031.Spr9031Tests.MarkerAnnotation;
|
||||
|
||||
@MarkerAnnotation
|
||||
public class Spr9031Component {
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* 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.
|
||||
@@ -110,11 +110,22 @@ public class ValidatorFactoryTests {
|
||||
assertEquals(2, result.getErrorCount());
|
||||
FieldError fieldError = result.getFieldError("name");
|
||||
assertEquals("name", fieldError.getField());
|
||||
System.out.println(Arrays.asList(fieldError.getCodes()));
|
||||
List<String> errorCodes = Arrays.asList(fieldError.getCodes());
|
||||
assertEquals(4, errorCodes.size());
|
||||
assertTrue(errorCodes.contains("NotNull.person.name"));
|
||||
assertTrue(errorCodes.contains("NotNull.name"));
|
||||
assertTrue(errorCodes.contains("NotNull.java.lang.String"));
|
||||
assertTrue(errorCodes.contains("NotNull"));
|
||||
System.out.println(fieldError.getDefaultMessage());
|
||||
fieldError = result.getFieldError("address.street");
|
||||
assertEquals("address.street", fieldError.getField());
|
||||
System.out.println(Arrays.asList(fieldError.getCodes()));
|
||||
errorCodes = Arrays.asList(fieldError.getCodes());
|
||||
assertEquals(5, errorCodes.size());
|
||||
assertTrue(errorCodes.contains("NotNull.person.address.street"));
|
||||
assertTrue(errorCodes.contains("NotNull.address.street"));
|
||||
assertTrue(errorCodes.contains("NotNull.street"));
|
||||
assertTrue(errorCodes.contains("NotNull.java.lang.String"));
|
||||
assertTrue(errorCodes.contains("NotNull"));
|
||||
System.out.println(fieldError.getDefaultMessage());
|
||||
}
|
||||
|
||||
@@ -129,7 +140,10 @@ public class ValidatorFactoryTests {
|
||||
validator.validate(person, result);
|
||||
assertEquals(1, result.getErrorCount());
|
||||
ObjectError globalError = result.getGlobalError();
|
||||
System.out.println(Arrays.asList(globalError.getCodes()));
|
||||
List<String> errorCodes = Arrays.asList(globalError.getCodes());
|
||||
assertEquals(2, errorCodes.size());
|
||||
assertTrue(errorCodes.contains("NameAddressValid.person"));
|
||||
assertTrue(errorCodes.contains("NameAddressValid"));
|
||||
System.out.println(globalError.getDefaultMessage());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user