Merge branch '3.2.x' into cleanup-3.2.x

This commit is contained in:
Chris Beams 2013-01-03 19:02:05 +01:00
commit 1c31f6af8e
186 changed files with 1915 additions and 1289 deletions

5
.gitignore vendored
View File

@ -13,12 +13,15 @@ jmx.log
derby.log derby.log
spring-test/test-output/ spring-test/test-output/
.gradle .gradle
build
.classpath .classpath
.project .project
argfile* argfile*
pom.xml pom.xml
/build
buildSrc/build
/spring-*/build
# IDEA artifacts and output dirs # IDEA artifacts and output dirs
*.iml *.iml
*.ipr *.ipr

View File

@ -23,7 +23,7 @@ truly trivial, e.g. typo fixes, removing compiler warnings, etc.
If you're considering anything more than correcting a typo or fixing a minor If you're considering anything more than correcting a typo or fixing a minor
bug, please discuss it on the [spring-framework-contrib][] mailing list before bug, please discuss it on the [spring-framework-contrib][] mailing list before
submitting a pull request. We're happy to provide guidance but please spend an submitting a pull request. We're happy to provide guidance, but please spend an
hour or two researching the subject on your own including searching the mailing hour or two researching the subject on your own including searching the mailing
list for prior discussions. list for prior discussions.
@ -31,26 +31,26 @@ list for prior discussions.
If you have not previously done so, please fill out and submit the If you have not previously done so, please fill out and submit the
[SpringSource CLA form][]. You'll receive a token when this process is complete. [SpringSource CLA form][]. You'll receive a token when this process is complete.
Keep track of this, you may be asked for it later! Keep track of this; you may be asked for it later!
Note that emailing/postal mailing a signed copy is _not_ necessary. Submission Note that emailing/postal mailing a signed copy is _not_ necessary. Submission
of the web form is all that is required. of the web form is all that is required.
When you've completed the web form, simply add the following in a comment on Once you've completed the web form, simply add the following in a comment on
your pull request: your pull request:
I have signed and agree to the terms of the SpringSource Individual I have signed and agree to the terms of the SpringSource Individual
Contributor License Agreement. Contributor License Agreement.
You do not need to include your token/id. Please add the statement above to all You do not need to include your token/id. Please add the statement above to all
future pull requests as well, simply so the Spring Framework team knows future pull requests as well, simply so that the Spring Framework team knows
immediately that this process is complete. immediately that this process is complete.
## Create your branch from `3.2.x` ## Create your branch from `3.2.x`
If your pull request addresses a bug or improvement, please create your branch If your pull request addresses a bug or improvement, please create your branch
Spring Framework's `3.2.x` branch. `master` is reserved for work on new features from Spring Framework's `3.2.x` branch. `master` is reserved for work on new features
for the next major version of the framework. Rest assured that if your pull for the next major version of the framework. Rest assured that if your pull
request is accepted and merged into `3.2.x`, these changes will also eventually request is accepted and merged into `3.2.x`, these changes will also eventually
be merged into `master`. be merged into `master`.
@ -72,7 +72,7 @@ Please carefully follow the whitespace and formatting conventions already
present in the framework. present in the framework.
1. Tabs, not spaces 1. Tabs, not spaces
1. Unix (LF), not dos (CRLF) line endings 1. Unix (LF), not DOS (CRLF) line endings
1. Eliminate all trailing whitespace 1. Eliminate all trailing whitespace
1. Wrap Javadoc at 90 characters 1. Wrap Javadoc at 90 characters
1. Aim to wrap code at 90 characters, but favor readability over wrapping 1. Aim to wrap code at 90 characters, but favor readability over wrapping
@ -228,11 +228,11 @@ Most importantly, please format your commit messages in the following way
1. Use imperative statements in the subject line, e.g. "Fix broken Javadoc link" 1. Use imperative statements in the subject line, e.g. "Fix broken Javadoc link"
1. Begin the subject line sentence with a capitalized verb, e.g. "Add, Prune, 1. Begin the subject line sentence with a capitalized verb, e.g. "Add, Prune,
Fix, Introduce, Avoid, etc" Fix, Introduce, Avoid, etc."
1. Do not end the subject line with a period 1. Do not end the subject line with a period
1. Keep the subject line to 50 characters or less if possible 1. Keep the subject line to 50 characters or less if possible
1. Wrap lines in the body at 72 characters or less 1. Wrap lines in the body at 72 characters or less
1. Mention associated jira issue(s) at the end of the commit comment, prefixed 1. Mention associated JIRA issue(s) at the end of the commit comment, prefixed
with "Issue: " as above with "Issue: " as above
1. In the body of the commit message, explain how things worked before this 1. In the body of the commit message, explain how things worked before this
commit, what has changed, and how things work now commit, what has changed, and how things work now

View File

@ -28,6 +28,7 @@ configure(allprojects) {
apply plugin: "java" apply plugin: "java"
apply plugin: "propdeps-eclipse" apply plugin: "propdeps-eclipse"
apply plugin: "propdeps-idea" apply plugin: "propdeps-idea"
apply plugin: "test-source-set-dependencies"
apply from: "${gradleScriptDir}/ide.gradle" apply from: "${gradleScriptDir}/ide.gradle"
group = "org.springframework" group = "org.springframework"
@ -110,7 +111,7 @@ configure(allprojects.findAll{it.name in ["spring", "spring-jms", "spring-orm",
} }
} }
configure(subprojects - project(":spring-build-junit")) { subproject -> configure(subprojects - project(":spring-build-src")) { subproject ->
apply plugin: "merge" apply plugin: "merge"
apply from: "${gradleScriptDir}/publish-maven.gradle" apply from: "${gradleScriptDir}/publish-maven.gradle"
@ -159,35 +160,26 @@ configure(subprojects - project(":spring-build-junit")) { subproject ->
} }
} }
configure(allprojects - project(":spring-build-junit")) { configure(allprojects) {
dependencies { dependencies {
testCompile(project(":spring-build-junit")) testCompile("junit:junit:${junitVersion}")
testCompile("org.hamcrest:hamcrest-all:1.3")
} }
eclipse.classpath.file.whenMerged { classpath ->
classpath.entries.find{it.path == "/spring-build-junit"}.exported = false
}
test.systemProperties.put("testGroups", properties.get("testGroups")) test.systemProperties.put("testGroups", properties.get("testGroups"))
} }
project("spring-build-junit") { project("spring-build-src") {
description = "Build-time JUnit dependencies and utilities" description = "Exposes gradle buildSrc for IDE support"
apply plugin: "groovy"
// NOTE: This is an internal project and is not published.
dependencies { dependencies {
compile("commons-logging:commons-logging:1.1.1") compile gradleApi()
compile("junit:junit:${junitVersion}") groovy localGroovy()
compile("org.hamcrest:hamcrest-all:1.3")
compile("org.easymock:easymock:${easymockVersion}")
} }
// Don't actually generate any artifacts
configurations.archives.artifacts.clear() configurations.archives.artifacts.clear()
} }
project("spring-core") { project("spring-core") {
description = "Spring Core" description = "Spring Core"
@ -258,7 +250,7 @@ project("spring-core") {
optional("org.aspectj:aspectjweaver:${aspectjVersion}") optional("org.aspectj:aspectjweaver:${aspectjVersion}")
optional("net.sf.jopt-simple:jopt-simple:3.0") optional("net.sf.jopt-simple:jopt-simple:3.0")
optional("log4j:log4j:1.2.17") optional("log4j:log4j:1.2.17")
testCompile("xmlunit:xmlunit:1.2") testCompile("xmlunit:xmlunit:1.3")
testCompile("org.codehaus.woodstox:wstx-asl:3.2.7") testCompile("org.codehaus.woodstox:wstx-asl:3.2.7")
} }
@ -395,7 +387,7 @@ project("spring-oxm") {
optional("org.apache.xmlbeans:xmlbeans:2.4.0") optional("org.apache.xmlbeans:xmlbeans:2.4.0")
optional("org.codehaus.castor:castor-xml:1.3.2") optional("org.codehaus.castor:castor-xml:1.3.2")
testCompile("org.codehaus.jettison:jettison:1.0.1") testCompile("org.codehaus.jettison:jettison:1.0.1")
testCompile("xmlunit:xmlunit:1.2") testCompile("xmlunit:xmlunit:1.3")
testCompile("xmlpull:xmlpull:1.1.3.4a") testCompile("xmlpull:xmlpull:1.1.3.4a")
testCompile(files(genCastor.classesDir).builtBy(genCastor)) testCompile(files(genCastor.classesDir).builtBy(genCastor))
testCompile(files(genJaxb.classesDir).builtBy(genJaxb)) testCompile(files(genJaxb.classesDir).builtBy(genJaxb))
@ -500,7 +492,7 @@ project("spring-web") {
} }
optional("log4j:log4j:1.2.17") optional("log4j:log4j:1.2.17")
testCompile(project(":spring-context-support")) // for JafMediaTypeFactory testCompile(project(":spring-context-support")) // for JafMediaTypeFactory
testCompile("xmlunit:xmlunit:1.2") testCompile("xmlunit:xmlunit:1.3")
} }
// pick up ContextLoader.properties in src/main // pick up ContextLoader.properties in src/main
@ -536,7 +528,6 @@ project("spring-orm") {
testCompile("org.eclipse.persistence:org.eclipse.persistence.asm:1.0.1") testCompile("org.eclipse.persistence:org.eclipse.persistence.asm:1.0.1")
testCompile("org.eclipse.persistence:org.eclipse.persistence.antlr:1.0.1") testCompile("org.eclipse.persistence:org.eclipse.persistence.antlr:1.0.1")
testCompile("hsqldb:hsqldb:${hsqldbVersion}") testCompile("hsqldb:hsqldb:${hsqldbVersion}")
testCompile(project(":spring-web").sourceSets.test.output)
compile(project(":spring-core")) compile(project(":spring-core"))
compile(project(":spring-beans")) compile(project(":spring-beans"))
optional(project(":spring-aop")) optional(project(":spring-aop"))
@ -592,7 +583,7 @@ project("spring-webmvc") {
testCompile(project(":spring-aop")) testCompile(project(":spring-aop"))
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}") testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
testCompile("rhino:js:1.7R1") testCompile("rhino:js:1.7R1")
testCompile("xmlunit:xmlunit:1.2") testCompile("xmlunit:xmlunit:1.3")
testCompile("dom4j:dom4j:1.6.1") { testCompile("dom4j:dom4j:1.6.1") {
exclude group: "xml-apis", module: "xml-apis" exclude group: "xml-apis", module: "xml-apis"
} }
@ -701,7 +692,7 @@ project("spring-test-mvc") {
provided("javax.servlet:javax.servlet-api:3.0.1") provided("javax.servlet:javax.servlet-api:3.0.1")
optional("org.hamcrest:hamcrest-core:1.3") optional("org.hamcrest:hamcrest-core:1.3")
optional("com.jayway.jsonpath:json-path:0.8.1") optional("com.jayway.jsonpath:json-path:0.8.1")
optional("xmlunit:xmlunit:1.2") optional("xmlunit:xmlunit:1.3")
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}") testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
testCompile("javax.servlet:jstl:1.2") testCompile("javax.servlet:jstl:1.2")
testCompile("org.hibernate:hibernate-validator:4.3.0.Final") testCompile("org.hibernate:hibernate-validator:4.3.0.Final")
@ -786,6 +777,7 @@ configure(rootProject) {
dependencies { // for integration tests dependencies { // for integration tests
testCompile(project(":spring-core")) testCompile(project(":spring-core"))
testCompile(project(":spring-core").sourceSets.test.output)
testCompile(project(":spring-beans")) testCompile(project(":spring-beans"))
testCompile(project(":spring-aop")) testCompile(project(":spring-aop"))
testCompile(project(":spring-expression")) testCompile(project(":spring-expression"))

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.build.gradle.merge package org.springframework.build.gradle
import org.gradle.api.* import org.gradle.api.*
import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.Configuration

View File

@ -0,0 +1,57 @@
/*
* 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
*
* 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.build.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ProjectDependency;
/**
* Gradle plugin that automatically updates testCompile dependencies to include
* the test source sets of project dependencies.
*
* @author Phillip Webb
*/
class TestSourceSetDependenciesPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
project.afterEvaluate {
Set<ProjectDependency> projectDependencies = new LinkedHashSet<>()
collectProjectDependencies(projectDependencies, project)
projectDependencies.each {
project.dependencies.add("testCompile", it.dependencyProject.sourceSets.test.output)
}
}
}
private void collectProjectDependencies(Set<ProjectDependency> projectDependencies,
Project project) {
for(def configurationName in ["compile", "optional", "provided"]) {
Configuration configuration = project.getConfigurations().findByName(configurationName)
if(configuration) {
configuration.dependencies.findAll { it instanceof ProjectDependency }.each {
projectDependencies.add(it)
collectProjectDependencies(projectDependencies, it.dependencyProject)
}
}
}
}
}

View File

@ -1 +1 @@
implementation-class=org.springframework.build.gradle.merge.MergePlugin implementation-class=org.springframework.build.gradle.MergePlugin

View File

@ -0,0 +1 @@
implementation-class=org.springframework.build.gradle.TestSourceSetDependenciesPlugin

View File

@ -22,4 +22,7 @@ include "spring-web"
include "spring-webmvc" include "spring-webmvc"
include "spring-webmvc-portlet" include "spring-webmvc-portlet"
include "spring-webmvc-tiles3" include "spring-webmvc-tiles3"
include "spring-build-junit"
// Exposes gradle buildSrc for IDE support
include "buildSrc"
rootProject.children.find{ it.name == "buildSrc" }.name = "spring-build-src"

View File

@ -16,13 +16,15 @@
package org.springframework.aop.config; package org.springframework.aop.config;
import static org.junit.Assert.*; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static test.util.TestResourceUtils.qualifiedResource; import static test.util.TestResourceUtils.qualifiedResource;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
/** /**
* @author Mark Fisher * @author Mark Fisher
@ -33,7 +35,9 @@ public final class AopNamespaceHandlerPointcutErrorTests {
@Test @Test
public void testDuplicatePointcutConfig() { public void testDuplicatePointcutConfig() {
try { try {
new XmlBeanFactory(qualifiedResource(getClass(), "pointcutDuplication.xml")); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
qualifiedResource(getClass(), "pointcutDuplication.xml"));
fail("parsing should have caused a BeanDefinitionStoreException"); fail("parsing should have caused a BeanDefinitionStoreException");
} }
catch (BeanDefinitionStoreException ex) { catch (BeanDefinitionStoreException ex) {
@ -44,7 +48,9 @@ public final class AopNamespaceHandlerPointcutErrorTests {
@Test @Test
public void testMissingPointcutConfig() { public void testMissingPointcutConfig() {
try { try {
new XmlBeanFactory(qualifiedResource(getClass(), "pointcutMissing.xml")); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
qualifiedResource(getClass(), "pointcutMissing.xml"));
fail("parsing should have caused a BeanDefinitionStoreException"); fail("parsing should have caused a BeanDefinitionStoreException");
} }
catch (BeanDefinitionStoreException ex) { catch (BeanDefinitionStoreException ex) {

View File

@ -22,7 +22,8 @@ import static test.util.TestResourceUtils.qualifiedResource;
import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
/** /**
@ -37,12 +38,13 @@ public final class PrototypeTargetTests {
@Test @Test
public void testPrototypeProxyWithPrototypeTarget() { public void testPrototypeProxyWithPrototypeTarget() {
TestBeanImpl.constructionCount = 0; TestBeanImpl.constructionCount = 0;
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
TestBean tb = (TestBean) xbf.getBean("testBeanPrototype"); TestBean tb = (TestBean) bf.getBean("testBeanPrototype");
tb.doSomething(); tb.doSomething();
} }
TestInterceptor interceptor = (TestInterceptor) xbf.getBean("testInterceptor"); TestInterceptor interceptor = (TestInterceptor) bf.getBean("testInterceptor");
assertEquals(10, TestBeanImpl.constructionCount); assertEquals(10, TestBeanImpl.constructionCount);
assertEquals(10, interceptor.invocationCount); assertEquals(10, interceptor.invocationCount);
} }
@ -50,12 +52,13 @@ public final class PrototypeTargetTests {
@Test @Test
public void testSingletonProxyWithPrototypeTarget() { public void testSingletonProxyWithPrototypeTarget() {
TestBeanImpl.constructionCount = 0; TestBeanImpl.constructionCount = 0;
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
TestBean tb = (TestBean) xbf.getBean("testBeanSingleton"); TestBean tb = (TestBean) bf.getBean("testBeanSingleton");
tb.doSomething(); tb.doSomething();
} }
TestInterceptor interceptor = (TestInterceptor) xbf.getBean("testInterceptor"); TestInterceptor interceptor = (TestInterceptor) bf.getBean("testInterceptor");
assertEquals(1, TestBeanImpl.constructionCount); assertEquals(1, TestBeanImpl.constructionCount);
assertEquals(10, interceptor.invocationCount); assertEquals(10, interceptor.invocationCount);
} }

View File

@ -16,12 +16,14 @@
package org.springframework.aop.interceptor; package org.springframework.aop.interceptor;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static test.util.TestResourceUtils.qualifiedResource; import static test.util.TestResourceUtils.qualifiedResource;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import test.beans.ITestBean; import test.beans.ITestBean;
@ -40,7 +42,8 @@ public final class ExposeInvocationInterceptorTests {
@Test @Test
public void testXmlConfig() { public void testXmlConfig() {
XmlBeanFactory bf = new XmlBeanFactory(CONTEXT); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
ITestBean tb = (ITestBean) bf.getBean("proxy"); ITestBean tb = (ITestBean) bf.getBean("proxy");
String name= "tony"; String name= "tony";
tb.setName(name); tb.setName(name);

View File

@ -20,7 +20,8 @@ import static org.junit.Assert.assertSame;
import static test.util.TestResourceUtils.qualifiedResource; import static test.util.TestResourceUtils.qualifiedResource;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
/** /**
@ -36,7 +37,8 @@ public final class ScopedProxyAutowireTests {
@Test @Test
public void testScopedProxyInheritsAutowireCandidateFalse() { public void testScopedProxyInheritsAutowireCandidateFalse() {
XmlBeanFactory bf = new XmlBeanFactory(SCOPED_AUTOWIRE_FALSE_CONTEXT); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(SCOPED_AUTOWIRE_FALSE_CONTEXT);
TestBean autowired = (TestBean) bf.getBean("autowired"); TestBean autowired = (TestBean) bf.getBean("autowired");
TestBean unscoped = (TestBean) bf.getBean("unscoped"); TestBean unscoped = (TestBean) bf.getBean("unscoped");
assertSame(unscoped, autowired.getChild()); assertSame(unscoped, autowired.getChild());
@ -44,7 +46,8 @@ public final class ScopedProxyAutowireTests {
@Test @Test
public void testScopedProxyReplacesAutowireCandidateTrue() { public void testScopedProxyReplacesAutowireCandidateTrue() {
XmlBeanFactory bf = new XmlBeanFactory(SCOPED_AUTOWIRE_TRUE_CONTEXT); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(SCOPED_AUTOWIRE_TRUE_CONTEXT);
TestBean autowired = (TestBean) bf.getBean("autowired"); TestBean autowired = (TestBean) bf.getBean("autowired");
TestBean scoped = (TestBean) bf.getBean("scoped"); TestBean scoped = (TestBean) bf.getBean("scoped");
assertSame(scoped, autowired.getChild()); assertSame(scoped, autowired.getChild());

View File

@ -21,8 +21,8 @@ import static test.util.TestResourceUtils.qualifiedResource;
import org.junit.Test; import org.junit.Test;
import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.Advised;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import test.aop.NopInterceptor; import test.aop.NopInterceptor;
@ -43,7 +43,8 @@ public final class RegexpMethodPointcutAdvisorIntegrationTests {
@Test @Test
public void testSinglePattern() throws Throwable { public void testSinglePattern() throws Throwable {
BeanFactory bf = new XmlBeanFactory(CONTEXT); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
ITestBean advised = (ITestBean) bf.getBean("settersAdvised"); ITestBean advised = (ITestBean) bf.getBean("settersAdvised");
// Interceptor behind regexp advisor // Interceptor behind regexp advisor
NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor"); NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
@ -61,7 +62,8 @@ public final class RegexpMethodPointcutAdvisorIntegrationTests {
@Test @Test
public void testMultiplePatterns() throws Throwable { public void testMultiplePatterns() throws Throwable {
BeanFactory bf = new XmlBeanFactory(CONTEXT); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
// This is a CGLIB proxy, so we can proxy it to the target class // This is a CGLIB proxy, so we can proxy it to the target class
TestBean advised = (TestBean) bf.getBean("settersAndAbsquatulateAdvised"); TestBean advised = (TestBean) bf.getBean("settersAndAbsquatulateAdvised");
// Interceptor behind regexp advisor // Interceptor behind regexp advisor
@ -84,7 +86,8 @@ public final class RegexpMethodPointcutAdvisorIntegrationTests {
@Test @Test
public void testSerialization() throws Throwable { public void testSerialization() throws Throwable {
BeanFactory bf = new XmlBeanFactory(CONTEXT); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CONTEXT);
// This is a CGLIB proxy, so we can proxy it to the target class // This is a CGLIB proxy, so we can proxy it to the target class
Person p = (Person) bf.getBean("serializableSettersAdvised"); Person p = (Person) bf.getBean("serializableSettersAdvised");
// Interceptor behind regexp advisor // Interceptor behind regexp advisor

View File

@ -16,7 +16,9 @@
package org.springframework.aop.target; package org.springframework.aop.target;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static test.util.TestResourceUtils.qualifiedResource; import static test.util.TestResourceUtils.qualifiedResource;
import org.junit.After; import org.junit.After;
@ -25,7 +27,8 @@ import org.junit.Test;
import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import test.aop.SerializableNopInterceptor; import test.aop.SerializableNopInterceptor;
@ -46,11 +49,12 @@ public final class HotSwappableTargetSourceTests {
/** Initial count value set in bean factory XML */ /** Initial count value set in bean factory XML */
private static final int INITIAL_COUNT = 10; private static final int INITIAL_COUNT = 10;
private XmlBeanFactory beanFactory; private DefaultListableBeanFactory beanFactory;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
this.beanFactory = new XmlBeanFactory(CONTEXT); this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(CONTEXT);
} }
/** /**

View File

@ -16,13 +16,16 @@
package org.springframework.aop.target; package org.springframework.aop.target;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static test.util.TestResourceUtils.qualifiedResource; import static test.util.TestResourceUtils.qualifiedResource;
import java.util.Set; import java.util.Set;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import test.beans.ITestBean; import test.beans.ITestBean;
@ -43,7 +46,8 @@ public final class LazyInitTargetSourceTests {
@Test @Test
public void testLazyInitSingletonTargetSource() { public void testLazyInitSingletonTargetSource() {
XmlBeanFactory bf = new XmlBeanFactory(SINGLETON_CONTEXT); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(SINGLETON_CONTEXT);
bf.preInstantiateSingletons(); bf.preInstantiateSingletons();
ITestBean tb = (ITestBean) bf.getBean("proxy"); ITestBean tb = (ITestBean) bf.getBean("proxy");
@ -54,7 +58,8 @@ public final class LazyInitTargetSourceTests {
@Test @Test
public void testCustomLazyInitSingletonTargetSource() { public void testCustomLazyInitSingletonTargetSource() {
XmlBeanFactory bf = new XmlBeanFactory(CUSTOM_TARGET_CONTEXT); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(CUSTOM_TARGET_CONTEXT);
bf.preInstantiateSingletons(); bf.preInstantiateSingletons();
ITestBean tb = (ITestBean) bf.getBean("proxy"); ITestBean tb = (ITestBean) bf.getBean("proxy");
@ -65,7 +70,8 @@ public final class LazyInitTargetSourceTests {
@Test @Test
public void testLazyInitFactoryBeanTargetSource() { public void testLazyInitFactoryBeanTargetSource() {
XmlBeanFactory bf = new XmlBeanFactory(FACTORY_BEAN_CONTEXT); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(FACTORY_BEAN_CONTEXT);
bf.preInstantiateSingletons(); bf.preInstantiateSingletons();
Set<?> set1 = (Set<?>) bf.getBean("proxy1"); Set<?> set1 = (Set<?>) bf.getBean("proxy1");

View File

@ -41,10 +41,12 @@ public final class PrototypeBasedTargetSourceTests {
public void testSerializability() throws Exception { public void testSerializability() throws Exception {
MutablePropertyValues tsPvs = new MutablePropertyValues(); MutablePropertyValues tsPvs = new MutablePropertyValues();
tsPvs.add("targetBeanName", "person"); tsPvs.add("targetBeanName", "person");
RootBeanDefinition tsBd = new RootBeanDefinition(TestTargetSource.class, tsPvs); RootBeanDefinition tsBd = new RootBeanDefinition(TestTargetSource.class);
tsBd.setPropertyValues(tsPvs);
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
RootBeanDefinition bd = new RootBeanDefinition(SerializablePerson.class, pvs); RootBeanDefinition bd = new RootBeanDefinition(SerializablePerson.class);
bd.setPropertyValues(pvs);
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();

View File

@ -22,7 +22,9 @@ import static test.util.TestResourceUtils.qualifiedResource;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import test.beans.SideEffectBean; import test.beans.SideEffectBean;
@ -43,7 +45,8 @@ public final class PrototypeTargetSourceTests {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
this.beanFactory = new XmlBeanFactory(CONTEXT); this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.beanFactory).loadBeanDefinitions(CONTEXT);
} }
/** /**

View File

@ -16,12 +16,15 @@
package org.springframework.aop.target; package org.springframework.aop.target;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static test.util.TestResourceUtils.qualifiedResource; import static test.util.TestResourceUtils.qualifiedResource;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import test.beans.ITestBean; import test.beans.ITestBean;
@ -39,11 +42,12 @@ public class ThreadLocalTargetSourceTests {
/** Initial count value set in bean factory XML */ /** Initial count value set in bean factory XML */
private static final int INITIAL_COUNT = 10; private static final int INITIAL_COUNT = 10;
private XmlBeanFactory beanFactory; private DefaultListableBeanFactory beanFactory;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
this.beanFactory = new XmlBeanFactory(CONTEXT); this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(CONTEXT);
} }
/** /**

View File

@ -19,6 +19,8 @@ package org.springframework.aop.target.dynamic;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.junit.Test; import org.junit.Test;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
/** /**
* @author Rob Harrop * @author Rob Harrop
@ -75,6 +77,8 @@ public final class RefreshableTargetSourceTests {
@Test @Test
public void testRefreshOverTime() throws Exception { public void testRefreshOverTime() throws Exception {
Assume.group(TestGroup.PERFORMANCE);
CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource(true); CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource(true);
ts.setRefreshCheckDelay(100); ts.setRefreshCheckDelay(100);

View File

@ -16,16 +16,18 @@
package org.springframework.mock.staticmock; package org.springframework.mock.staticmock;
import javax.persistence.PersistenceException; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.expectReturn;
import static org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.expectThrow;
import static org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.playback;
import junit.framework.Assert; import javax.persistence.PersistenceException;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
import static org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.*;
/** /**
* Test for static entity mocking framework. * Test for static entity mocking framework.
@ -43,7 +45,7 @@ public class AnnotationDrivenStaticEntityMockingControlTest {
Person.countPeople(); Person.countPeople();
expectReturn(expectedCount); expectReturn(expectedCount);
playback(); playback();
Assert.assertEquals(expectedCount, Person.countPeople()); assertEquals(expectedCount, Person.countPeople());
} }
@Test(expected=PersistenceException.class) @Test(expected=PersistenceException.class)
@ -61,7 +63,7 @@ public class AnnotationDrivenStaticEntityMockingControlTest {
Person.findPerson(id); Person.findPerson(id);
expectReturn(found); expectReturn(found);
playback(); playback();
Assert.assertEquals(found, Person.findPerson(id)); assertEquals(found, Person.findPerson(id));
} }
@ -81,10 +83,10 @@ public class AnnotationDrivenStaticEntityMockingControlTest {
expectReturn(0); expectReturn(0);
playback(); playback();
Assert.assertEquals(found1, Person.findPerson(id1)); assertEquals(found1, Person.findPerson(id1));
Assert.assertEquals(found2, Person.findPerson(id2)); assertEquals(found2, Person.findPerson(id2));
Assert.assertEquals(found1, Person.findPerson(id1)); assertEquals(found1, Person.findPerson(id1));
Assert.assertEquals(0, Person.countPeople()); assertEquals(0, Person.countPeople());
} }
// Note delegation is used when tests are invalid and should fail, as otherwise // Note delegation is used when tests are invalid and should fail, as otherwise
@ -94,7 +96,7 @@ public class AnnotationDrivenStaticEntityMockingControlTest {
public void testArgMethodNoMatchExpectReturn() { public void testArgMethodNoMatchExpectReturn() {
try { try {
new Delegate().testArgMethodNoMatchExpectReturn(); new Delegate().testArgMethodNoMatchExpectReturn();
Assert.fail(); fail();
} catch (IllegalArgumentException expected) { } catch (IllegalArgumentException expected) {
} }
} }
@ -105,7 +107,7 @@ public class AnnotationDrivenStaticEntityMockingControlTest {
} }
private void called(Person found, long id) { private void called(Person found, long id) {
Assert.assertEquals(found, Person.findPerson(id)); assertEquals(found, Person.findPerson(id));
} }
@Test @Test

View File

@ -16,12 +16,12 @@
package org.springframework.mock.staticmock; package org.springframework.mock.staticmock;
import static org.junit.Assert.assertEquals;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import javax.persistence.PersistenceException; import javax.persistence.PersistenceException;
import junit.framework.Assert;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl; import org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl;
@ -40,7 +40,7 @@ public class Delegate {
Person.findPerson(id); Person.findPerson(id);
AnnotationDrivenStaticEntityMockingControl.expectReturn(found); AnnotationDrivenStaticEntityMockingControl.expectReturn(found);
AnnotationDrivenStaticEntityMockingControl.playback(); AnnotationDrivenStaticEntityMockingControl.playback();
Assert.assertEquals(found, Person.findPerson(id + 1)); assertEquals(found, Person.findPerson(id + 1));
} }
@Test @Test
@ -50,7 +50,7 @@ public class Delegate {
Person.findPerson(id); Person.findPerson(id);
AnnotationDrivenStaticEntityMockingControl.expectThrow(new PersistenceException()); AnnotationDrivenStaticEntityMockingControl.expectThrow(new PersistenceException());
AnnotationDrivenStaticEntityMockingControl.playback(); AnnotationDrivenStaticEntityMockingControl.playback();
Assert.assertEquals(found, Person.findPerson(id + 1)); assertEquals(found, Person.findPerson(id + 1));
} }
@Test @Test
@ -62,7 +62,7 @@ public class Delegate {
Person.countPeople(); Person.countPeople();
AnnotationDrivenStaticEntityMockingControl.expectReturn(25); AnnotationDrivenStaticEntityMockingControl.expectReturn(25);
AnnotationDrivenStaticEntityMockingControl.playback(); AnnotationDrivenStaticEntityMockingControl.playback();
Assert.assertEquals(found, Person.findPerson(id)); assertEquals(found, Person.findPerson(id));
} }
@Test @Test

View File

@ -41,8 +41,8 @@ import static org.springframework.beans.PropertyDescriptorUtils.*;
/** /**
* Decorator for a standard {@link BeanInfo} object, e.g. as created by * Decorator for a standard {@link BeanInfo} object, e.g. as created by
* {@link Introspector#getBeanInfo(Class)}, designed to discover and register non-void * {@link Introspector#getBeanInfo(Class)}, designed to discover and register static
* returning setter methods. For example: * and/or non-void returning setter methods. For example:
* <pre>{@code * <pre>{@code
* public class Bean { * public class Bean {
* private Foo foo; * private Foo foo;
@ -102,37 +102,40 @@ class ExtendedBeanInfo implements BeanInfo {
new SimpleNonIndexedPropertyDescriptor(pd)); new SimpleNonIndexedPropertyDescriptor(pd));
} }
for (Method method : findNonVoidWriteMethods(delegate.getMethodDescriptors())) { for (Method method : findCandidateWriteMethods(delegate.getMethodDescriptors())) {
handleNonVoidWriteMethod(method); handleCandidateWriteMethod(method);
} }
} }
private List<Method> findNonVoidWriteMethods(MethodDescriptor[] methodDescriptors) { private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescriptors) {
List<Method> matches = new ArrayList<Method>(); List<Method> matches = new ArrayList<Method>();
for (MethodDescriptor methodDescriptor : methodDescriptors) { for (MethodDescriptor methodDescriptor : methodDescriptors) {
Method method = methodDescriptor.getMethod(); Method method = methodDescriptor.getMethod();
if (isNonVoidWriteMethod(method)) { if (isCandidateWriteMethod(method)) {
matches.add(method); matches.add(method);
} }
} }
return matches; return matches;
} }
public static boolean isNonVoidWriteMethod(Method method) { public static boolean isCandidateWriteMethod(Method method) {
String methodName = method.getName(); String methodName = method.getName();
Class<?>[] parameterTypes = method.getParameterTypes(); Class<?>[] parameterTypes = method.getParameterTypes();
int nParams = parameterTypes.length; int nParams = parameterTypes.length;
if (methodName.length() > 3 && methodName.startsWith("set") && if (methodName.length() > 3 && methodName.startsWith("set") &&
Modifier.isPublic(method.getModifiers()) && Modifier.isPublic(method.getModifiers()) &&
!void.class.isAssignableFrom(method.getReturnType()) && (
!void.class.isAssignableFrom(method.getReturnType()) ||
Modifier.isStatic(method.getModifiers())
) &&
(nParams == 1 || (nParams == 2 && parameterTypes[0].equals(int.class)))) { (nParams == 1 || (nParams == 2 && parameterTypes[0].equals(int.class)))) {
return true; return true;
} }
return false; return false;
} }
private void handleNonVoidWriteMethod(Method method) throws IntrospectionException { private void handleCandidateWriteMethod(Method method) throws IntrospectionException {
int nParams = method.getParameterTypes().length; int nParams = method.getParameterTypes().length;
String propertyName = propertyNameFor(method); String propertyName = propertyNameFor(method);
Class<?> propertyType = method.getParameterTypes()[nParams-1]; Class<?> propertyType = method.getParameterTypes()[nParams-1];

View File

@ -51,7 +51,7 @@ public class ExtendedBeanInfoFactory implements Ordered, BeanInfoFactory {
*/ */
private boolean supports(Class<?> beanClass) { private boolean supports(Class<?> beanClass) {
for (Method method : beanClass.getMethods()) { for (Method method : beanClass.getMethods()) {
if (ExtendedBeanInfo.isNonVoidWriteMethod(method)) { if (ExtendedBeanInfo.isCandidateWriteMethod(method)) {
return true; return true;
} }
} }

View File

@ -234,6 +234,8 @@ public class CustomEditorConfigurer implements BeanFactoryPostProcessor, BeanCla
this.sharedEditor = sharedEditor; this.sharedEditor = sharedEditor;
} }
@Override
@SuppressWarnings("deprecation")
public void registerCustomEditors(PropertyEditorRegistry registry) { public void registerCustomEditors(PropertyEditorRegistry registry) {
if (!(registry instanceof PropertyEditorRegistrySupport)) { if (!(registry instanceof PropertyEditorRegistrySupport)) {
throw new IllegalArgumentException("Cannot registered shared editor " + throw new IllegalArgumentException("Cannot registered shared editor " +

View File

@ -716,6 +716,7 @@ public class BeanDefinitionParserDelegate {
} }
} }
@SuppressWarnings("deprecation")
public int getAutowireMode(String attValue) { public int getAutowireMode(String attValue) {
String att = attValue; String att = attValue;
if (DEFAULT_VALUE.equals(att)) { if (DEFAULT_VALUE.equals(att)) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -77,7 +77,7 @@ public class ResourceEntityResolver extends DelegatingEntityResolver {
try { try {
String decodedSystemId = URLDecoder.decode(systemId); String decodedSystemId = URLDecoder.decode(systemId);
String givenUrl = new URL(decodedSystemId).toString(); String givenUrl = new URL(decodedSystemId).toString();
String systemRootUrl = new File("").toURL().toString(); String systemRootUrl = new File("").toURI().toURL().toString();
// Try relative to resource base if currently in system root. // Try relative to resource base if currently in system root.
if (givenUrl.startsWith(systemRootUrl)) { if (givenUrl.startsWith(systemRootUrl)) {
resourcePath = givenUrl.substring(systemRootUrl.length()); resourcePath = givenUrl.substring(systemRootUrl.length());

View File

@ -15,28 +15,30 @@
*/ */
package com.foo; package com.foo;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import java.util.List; import java.util.List;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
/** /**
* @author Costin Leau * @author Costin Leau
*/ */
public class ComponentBeanDefinitionParserTest { public class ComponentBeanDefinitionParserTest {
private static XmlBeanFactory bf; private static DefaultListableBeanFactory bf;
@BeforeClass @BeforeClass
public static void setUpBeforeClass() throws Exception { public static void setUpBeforeClass() throws Exception {
bf = new XmlBeanFactory(new ClassPathResource( bf = new DefaultListableBeanFactory();
"com/foo/component-config.xml")); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("com/foo/component-config.xml"));
} }
@AfterClass @AfterClass
@ -71,4 +73,4 @@ public class ComponentBeanDefinitionParserTest {
assertThat("Karate-1", equalTo(components.get(0).getName())); assertThat("Karate-1", equalTo(components.get(0).getName()));
assertThat("Sport-1", equalTo(components.get(1).getName())); assertThat("Sport-1", equalTo(components.get(1).getName()));
} }
} }

View File

@ -49,8 +49,8 @@ import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.beans.propertyeditors.StringArrayPropertyEditor; import org.springframework.beans.propertyeditors.StringArrayPropertyEditor;
import org.springframework.beans.propertyeditors.StringTrimmerEditor; import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.beans.support.DerivedFromProtectedBaseBean; import org.springframework.beans.support.DerivedFromProtectedBaseBean;
import org.springframework.build.junit.Assume; import org.springframework.tests.Assume;
import org.springframework.build.junit.TestGroup; import org.springframework.tests.TestGroup;
import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.core.convert.support.DefaultConversionService;
@ -1550,6 +1550,24 @@ public final class BeanWrapperTests {
assertEquals(TestEnum.TEST_VALUE, consumer.getEnumValue()); assertEquals(TestEnum.TEST_VALUE, consumer.getEnumValue());
} }
@Test
public void cornerSpr10115() {
Spr10115Bean foo = new Spr10115Bean();
BeanWrapperImpl bwi = new BeanWrapperImpl();
bwi.setWrappedInstance(foo);
bwi.setPropertyValue("prop1", "val1");
assertEquals("val1", Spr10115Bean.prop1);
}
static class Spr10115Bean {
private static String prop1;
public static void setProp1(String prop1) {
Spr10115Bean.prop1 = prop1;
}
}
private static class Foo { private static class Foo {

View File

@ -946,4 +946,28 @@ public class ExtendedBeanInfoTests {
assertThat(hasIndexedWriteMethodForProperty(bi, "address"), is(true)); assertThat(hasIndexedWriteMethodForProperty(bi, "address"), is(true));
} }
} }
@Test
public void shouldSupportStaticWriteMethod() throws IntrospectionException {
{
BeanInfo bi = Introspector.getBeanInfo(WithStaticWriteMethod.class);
assertThat(hasReadMethodForProperty(bi, "prop1"), is(false));
assertThat(hasWriteMethodForProperty(bi, "prop1"), is(false));
assertThat(hasIndexedReadMethodForProperty(bi, "prop1"), is(false));
assertThat(hasIndexedWriteMethodForProperty(bi, "prop1"), is(false));
}
{
BeanInfo bi = new ExtendedBeanInfo(Introspector.getBeanInfo(WithStaticWriteMethod.class));
assertThat(hasReadMethodForProperty(bi, "prop1"), is(false));
assertThat(hasWriteMethodForProperty(bi, "prop1"), is(true));
assertThat(hasIndexedReadMethodForProperty(bi, "prop1"), is(false));
assertThat(hasIndexedWriteMethodForProperty(bi, "prop1"), is(false));
}
}
static class WithStaticWriteMethod {
@SuppressWarnings("unused")
public static void setProp1(String prop1) {
}
}
} }

View File

@ -16,16 +16,21 @@
package org.springframework.beans.factory; package org.springframework.beans.factory;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static test.util.TestResourceUtils.qualifiedResource;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.StaticListableBeanFactory; import org.springframework.beans.factory.support.StaticListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.cglib.proxy.NoOp; import org.springframework.cglib.proxy.NoOp;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
@ -35,9 +40,6 @@ import test.beans.ITestBean;
import test.beans.IndexedTestBean; import test.beans.IndexedTestBean;
import test.beans.TestBean; import test.beans.TestBean;
import static org.junit.Assert.*;
import static test.util.TestResourceUtils.qualifiedResource;
/** /**
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
@ -60,10 +62,17 @@ public final class BeanFactoryUtilsTests {
public void setUp() { public void setUp() {
// Interesting hierarchical factory to test counts. // Interesting hierarchical factory to test counts.
// Slow to read so we cache it. // Slow to read so we cache it.
XmlBeanFactory grandParent = new XmlBeanFactory(ROOT_CONTEXT);
XmlBeanFactory parent = new XmlBeanFactory(MIDDLE_CONTEXT, grandParent);
XmlBeanFactory child = new XmlBeanFactory(LEAF_CONTEXT, parent); DefaultListableBeanFactory grandParent = new DefaultListableBeanFactory();
this.dependentBeansBF = new XmlBeanFactory(DEPENDENT_BEANS_CONTEXT); new XmlBeanDefinitionReader(grandParent).loadBeanDefinitions(ROOT_CONTEXT);
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(grandParent);
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(MIDDLE_CONTEXT);
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(child).loadBeanDefinitions(LEAF_CONTEXT);
this.dependentBeansBF = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.dependentBeansBF).loadBeanDefinitions(DEPENDENT_BEANS_CONTEXT);
dependentBeansBF.preInstantiateSingletons(); dependentBeansBF.preInstantiateSingletons();
this.listableBeanFactory = child; this.listableBeanFactory = child;
} }

View File

@ -16,7 +16,8 @@
package org.springframework.beans.factory; package org.springframework.beans.factory;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static test.util.TestResourceUtils.qualifiedResource; import static test.util.TestResourceUtils.qualifiedResource;
import java.text.DateFormat; import java.text.DateFormat;
@ -34,7 +35,8 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.PropertyEditorRegistrar; import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry; import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
@ -70,7 +72,8 @@ public final class ConcurrentBeanFactoryTests {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
XmlBeanFactory factory = new XmlBeanFactory(CONTEXT); DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(CONTEXT);
factory.addPropertyEditorRegistrar(new PropertyEditorRegistrar() { factory.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
@Override @Override
public void registerCustomEditors(PropertyEditorRegistry registry) { public void registerCustomEditors(PropertyEditorRegistry registry) {

View File

@ -72,8 +72,8 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.ConstructorDependenciesBean; import org.springframework.beans.factory.xml.ConstructorDependenciesBean;
import org.springframework.beans.factory.xml.DependenciesBean; import org.springframework.beans.factory.xml.DependenciesBean;
import org.springframework.beans.propertyeditors.CustomNumberEditor; import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.build.junit.Assume; import org.springframework.tests.Assume;
import org.springframework.build.junit.TestGroup; import org.springframework.tests.TestGroup;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.core.convert.support.DefaultConversionService;
@ -549,7 +549,9 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("spouse", new RuntimeBeanReference("self")); pvs.add("spouse", new RuntimeBeanReference("self"));
lbf.registerBeanDefinition("self", new RootBeanDefinition(TestBean.class, pvs)); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("self", bd);
TestBean self = (TestBean) lbf.getBean("self"); TestBean self = (TestBean) lbf.getBean("self");
assertEquals(self, self.getSpouse()); assertEquals(self, self.getSpouse());
} }
@ -560,7 +562,9 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("ag", "foobar"); pvs.add("ag", "foobar");
lbf.registerBeanDefinition("tb", new RootBeanDefinition(TestBean.class, pvs)); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("tb", bd);
lbf.getBean("tb"); lbf.getBean("tb");
fail("Should throw exception on invalid property"); fail("Should throw exception on invalid property");
} }
@ -846,7 +850,9 @@ public class DefaultListableBeanFactoryTests {
}); });
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", "1,1"); pvs.add("myFloat", "1,1");
lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, pvs)); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("testBean", bd);
TestBean testBean = (TestBean) lbf.getBean("testBean"); TestBean testBean = (TestBean) lbf.getBean("testBean");
assertTrue(testBean.getMyFloat().floatValue() == 1.1f); assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
} }
@ -870,7 +876,9 @@ public class DefaultListableBeanFactoryTests {
lbf.setConversionService(conversionService); lbf.setConversionService(conversionService);
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", "1,1"); pvs.add("myFloat", "1,1");
lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, pvs)); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("testBean", bd);
TestBean testBean = (TestBean) lbf.getBean("testBean"); TestBean testBean = (TestBean) lbf.getBean("testBean");
assertTrue(testBean.getMyFloat().floatValue() == 1.1f); assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
} }
@ -887,7 +895,9 @@ public class DefaultListableBeanFactoryTests {
}); });
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", new RuntimeBeanReference("myFloat")); pvs.add("myFloat", new RuntimeBeanReference("myFloat"));
lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, pvs)); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("testBean", bd);
lbf.registerSingleton("myFloat", "1,1"); lbf.registerSingleton("myFloat", "1,1");
TestBean testBean = (TestBean) lbf.getBean("testBean"); TestBean testBean = (TestBean) lbf.getBean("testBean");
assertTrue(testBean.getMyFloat().floatValue() == 1.1f); assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
@ -990,7 +1000,8 @@ public class DefaultListableBeanFactoryTests {
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("name", "Tony"); pvs.add("name", "Tony");
pvs.add("age", "48"); pvs.add("age", "48");
RootBeanDefinition bd = new RootBeanDefinition(DependenciesBean.class, pvs); RootBeanDefinition bd = new RootBeanDefinition(DependenciesBean.class);
bd.setPropertyValues(pvs);
bd.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS); bd.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE); bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
lbf.registerBeanDefinition("test", bd); lbf.registerBeanDefinition("test", bd);
@ -1039,7 +1050,8 @@ public class DefaultListableBeanFactoryTests {
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080")); bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090")); bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE); RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
bf.registerBeanDefinition("arrayBean", rbd); bf.registerBeanDefinition("arrayBean", rbd);
ArrayBean ab = (ArrayBean) bf.getBean("arrayBean"); ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");
@ -1051,7 +1063,8 @@ public class DefaultListableBeanFactoryTests {
public void testArrayPropertyWithOptionalAutowiring() throws MalformedURLException { public void testArrayPropertyWithOptionalAutowiring() throws MalformedURLException {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE); RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
bf.registerBeanDefinition("arrayBean", rbd); bf.registerBeanDefinition("arrayBean", rbd);
ArrayBean ab = (ArrayBean) bf.getBean("arrayBean"); ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");
@ -1064,7 +1077,8 @@ public class DefaultListableBeanFactoryTests {
bf.registerSingleton("integer1", new Integer(4)); bf.registerSingleton("integer1", new Integer(4));
bf.registerSingleton("integer2", new Integer(5)); bf.registerSingleton("integer2", new Integer(5));
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR); RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("arrayBean", rbd); bf.registerBeanDefinition("arrayBean", rbd);
ArrayBean ab = (ArrayBean) bf.getBean("arrayBean"); ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");
@ -1076,7 +1090,8 @@ public class DefaultListableBeanFactoryTests {
public void testArrayConstructorWithOptionalAutowiring() { public void testArrayConstructorWithOptionalAutowiring() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR); RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("arrayBean", rbd); bf.registerBeanDefinition("arrayBean", rbd);
ArrayBean ab = (ArrayBean) bf.getBean("arrayBean"); ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");
@ -1091,7 +1106,8 @@ public class DefaultListableBeanFactoryTests {
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080")); bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090")); bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR); RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("arrayBean", rbd); bf.registerBeanDefinition("arrayBean", rbd);
ArrayBean ab = (ArrayBean) bf.getBean("arrayBean"); ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");
@ -1107,7 +1123,8 @@ public class DefaultListableBeanFactoryTests {
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080")); bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090")); bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR); RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("arrayBean", rbd); bf.registerBeanDefinition("arrayBean", rbd);
ArrayBean ab = (ArrayBean) bf.getBean("arrayBean"); ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");
@ -1121,7 +1138,7 @@ public class DefaultListableBeanFactoryTests {
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("rod", bd); lbf.registerBeanDefinition("rod", bd);
assertEquals(1, lbf.getBeanDefinitionCount()); assertEquals(1, lbf.getBeanDefinitionCount());
Object registered = lbf.autowire(NoDependencies.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, false); Object registered = lbf.autowire(NoDependencies.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
assertEquals(1, lbf.getBeanDefinitionCount()); assertEquals(1, lbf.getBeanDefinitionCount());
assertTrue(registered instanceof NoDependencies); assertTrue(registered instanceof NoDependencies);
} }
@ -1131,11 +1148,12 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("name", "Rod"); pvs.add("name", "Rod");
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("rod", bd); lbf.registerBeanDefinition("rod", bd);
assertEquals(1, lbf.getBeanDefinitionCount()); assertEquals(1, lbf.getBeanDefinitionCount());
// Depends on age, name and spouse (TestBean) // Depends on age, name and spouse (TestBean)
Object registered = lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, true); Object registered = lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
assertEquals(1, lbf.getBeanDefinitionCount()); assertEquals(1, lbf.getBeanDefinitionCount());
DependenciesBean kerry = (DependenciesBean) registered; DependenciesBean kerry = (DependenciesBean) registered;
TestBean rod = (TestBean) lbf.getBean("rod"); TestBean rod = (TestBean) lbf.getBean("rod");
@ -1147,10 +1165,11 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("name", "Rod"); pvs.add("name", "Rod");
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("rod", bd); lbf.registerBeanDefinition("rod", bd);
assertEquals(1, lbf.getBeanDefinitionCount()); assertEquals(1, lbf.getBeanDefinitionCount());
Object registered = lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, false); Object registered = lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
assertEquals(1, lbf.getBeanDefinitionCount()); assertEquals(1, lbf.getBeanDefinitionCount());
ConstructorDependency kerry = (ConstructorDependency) registered; ConstructorDependency kerry = (ConstructorDependency) registered;
TestBean rod = (TestBean) lbf.getBean("rod"); TestBean rod = (TestBean) lbf.getBean("rod");
@ -1165,7 +1184,7 @@ public class DefaultListableBeanFactoryTests {
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class); RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("rod2", bd2); lbf.registerBeanDefinition("rod2", bd2);
try { try {
lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, false); lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
fail("Should have thrown UnsatisfiedDependencyException"); fail("Should have thrown UnsatisfiedDependencyException");
} }
catch (UnsatisfiedDependencyException ex) { catch (UnsatisfiedDependencyException ex) {
@ -1180,11 +1199,12 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("name", "Rod")); pvs.addPropertyValue(new PropertyValue("name", "Rod"));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("rod", bd); lbf.registerBeanDefinition("rod", bd);
assertEquals(1, lbf.getBeanDefinitionCount()); assertEquals(1, lbf.getBeanDefinitionCount());
try { try {
lbf.autowire(UnsatisfiedConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, true); lbf.autowire(UnsatisfiedConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, true);
fail("Should have unsatisfied constructor dependency on SideEffectBean"); fail("Should have unsatisfied constructor dependency on SideEffectBean");
} }
catch (UnsatisfiedDependencyException ex) { catch (UnsatisfiedDependencyException ex) {
@ -1467,7 +1487,9 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "99"); pvs.add("age", "99");
lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class, pvs)); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("test", bd);
TestBean tb = new TestBean(); TestBean tb = new TestBean();
assertEquals(0, tb.getAge()); assertEquals(0, tb.getAge());
lbf.applyBeanPropertyValues(tb, "test"); lbf.applyBeanPropertyValues(tb, "test");
@ -1479,7 +1501,9 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "99"); pvs.add("age", "99");
lbf.registerBeanDefinition("test", new RootBeanDefinition(null, pvs)); RootBeanDefinition bd = new RootBeanDefinition();
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("test", bd);
TestBean tb = new TestBean(); TestBean tb = new TestBean();
assertEquals(0, tb.getAge()); assertEquals(0, tb.getAge());
lbf.applyBeanPropertyValues(tb, "test"); lbf.applyBeanPropertyValues(tb, "test");
@ -1493,7 +1517,9 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "99"); pvs.add("age", "99");
lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class, pvs)); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("test", bd);
TestBean tb = new TestBean(); TestBean tb = new TestBean();
assertEquals(0, tb.getAge()); assertEquals(0, tb.getAge());
lbf.configureBean(tb, "test"); lbf.configureBean(tb, "test");
@ -1509,7 +1535,9 @@ public class DefaultListableBeanFactoryTests {
lbf.registerBeanDefinition("spouse", bd); lbf.registerBeanDefinition("spouse", bd);
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "99"); pvs.add("age", "99");
lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class, RootBeanDefinition.AUTOWIRE_BY_NAME)); RootBeanDefinition tbd = new RootBeanDefinition(TestBean.class);
tbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_NAME);
lbf.registerBeanDefinition("test", tbd);
TestBean tb = new TestBean(); TestBean tb = new TestBean();
lbf.configureBean(tb, "test"); lbf.configureBean(tb, "test");
assertSame(lbf, tb.getBeanFactory()); assertSame(lbf, tb.getBeanFactory());
@ -1523,7 +1551,8 @@ public class DefaultListableBeanFactoryTests {
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("spouse", new RuntimeBeanReference("bean" + (i < 99 ? i + 1 : 0)))); pvs.addPropertyValue(new PropertyValue("spouse", new RuntimeBeanReference("bean" + (i < 99 ? i + 1 : 0))));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("bean" + i, bd); lbf.registerBeanDefinition("bean" + i, bd);
} }
lbf.preInstantiateSingletons(); lbf.preInstantiateSingletons();
@ -1537,7 +1566,9 @@ public class DefaultListableBeanFactoryTests {
@Test @Test
public void testCircularReferenceThroughAutowiring() { public void testCircularReferenceThroughAutowiring() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR)); RootBeanDefinition bd = new RootBeanDefinition(ConstructorDependencyBean.class);
bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
lbf.registerBeanDefinition("test", bd);
try { try {
lbf.preInstantiateSingletons(); lbf.preInstantiateSingletons();
fail("Should have thrown UnsatisfiedDependencyException"); fail("Should have thrown UnsatisfiedDependencyException");
@ -1549,7 +1580,9 @@ public class DefaultListableBeanFactoryTests {
@Test @Test
public void testCircularReferenceThroughFactoryBeanAutowiring() { public void testCircularReferenceThroughFactoryBeanAutowiring() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyFactoryBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR)); RootBeanDefinition bd = new RootBeanDefinition(ConstructorDependencyFactoryBean.class);
bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
lbf.registerBeanDefinition("test", bd);
try { try {
lbf.preInstantiateSingletons(); lbf.preInstantiateSingletons();
fail("Should have thrown UnsatisfiedDependencyException"); fail("Should have thrown UnsatisfiedDependencyException");
@ -1561,7 +1594,9 @@ public class DefaultListableBeanFactoryTests {
@Test @Test
public void testCircularReferenceThroughFactoryBeanTypeCheck() { public void testCircularReferenceThroughFactoryBeanTypeCheck() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyFactoryBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR)); RootBeanDefinition bd = new RootBeanDefinition(ConstructorDependencyFactoryBean.class);
bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
lbf.registerBeanDefinition("test", bd);
try { try {
lbf.getBeansOfType(String.class); lbf.getBeansOfType(String.class);
fail("Should have thrown UnsatisfiedDependencyException"); fail("Should have thrown UnsatisfiedDependencyException");
@ -1573,9 +1608,12 @@ public class DefaultListableBeanFactoryTests {
@Test @Test
public void testAvoidCircularReferenceThroughAutowiring() { public void testAvoidCircularReferenceThroughAutowiring() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyFactoryBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR)); RootBeanDefinition bd = new RootBeanDefinition(ConstructorDependencyFactoryBean.class);
lbf.registerBeanDefinition("string", bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
new RootBeanDefinition(String.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR)); lbf.registerBeanDefinition("test", bd);
RootBeanDefinition bd2 = new RootBeanDefinition(String.class);
bd2.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
lbf.registerBeanDefinition("string", bd2);
lbf.preInstantiateSingletons(); lbf.preInstantiateSingletons();
} }

View File

@ -22,9 +22,10 @@ import static org.junit.Assert.assertThat;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.AbstractFactoryBean; import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
/** /**
@ -37,7 +38,8 @@ public class FactoryBeanLookupTests {
@Before @Before
public void setUp() { public void setUp() {
beanFactory = new XmlBeanFactory( beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory).loadBeanDefinitions(
new ClassPathResource("FactoryBeanLookupTests-context.xml", this.getClass())); new ClassPathResource("FactoryBeanLookupTests-context.xml", this.getClass()));
} }

View File

@ -16,12 +16,15 @@
package org.springframework.beans.factory; package org.springframework.beans.factory;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static test.util.TestResourceUtils.qualifiedResource; import static test.util.TestResourceUtils.qualifiedResource;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -38,14 +41,16 @@ public final class FactoryBeanTests {
@Test @Test
public void testFactoryBeanReturnsNull() throws Exception { public void testFactoryBeanReturnsNull() throws Exception {
XmlBeanFactory factory = new XmlBeanFactory(RETURNS_NULL_CONTEXT); DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(RETURNS_NULL_CONTEXT);
Object result = factory.getBean("factoryBean"); Object result = factory.getBean("factoryBean");
assertNull(result); assertNull(result);
} }
@Test @Test
public void testFactoryBeansWithAutowiring() throws Exception { public void testFactoryBeansWithAutowiring() throws Exception {
XmlBeanFactory factory = new XmlBeanFactory(WITH_AUTOWIRING_CONTEXT); DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT);
BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer"); BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
ppc.postProcessBeanFactory(factory); ppc.postProcessBeanFactory(factory);
@ -62,7 +67,8 @@ public final class FactoryBeanTests {
@Test @Test
public void testFactoryBeansWithIntermediateFactoryBeanAutowiringFailure() throws Exception { public void testFactoryBeansWithIntermediateFactoryBeanAutowiringFailure() throws Exception {
XmlBeanFactory factory = new XmlBeanFactory(WITH_AUTOWIRING_CONTEXT); DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT);
BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer"); BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
ppc.postProcessBeanFactory(factory); ppc.postProcessBeanFactory(factory);

View File

@ -16,6 +16,14 @@
package org.springframework.beans.factory.annotation; package org.springframework.beans.factory.annotation;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.Serializable; import java.io.Serializable;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
@ -25,15 +33,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
import test.beans.ITestBean;
import test.beans.IndexedTestBean;
import test.beans.NestedTestBean;
import test.beans.TestBean;
import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AutowireCandidateQualifier; import org.springframework.beans.factory.support.AutowireCandidateQualifier;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@ -41,7 +45,10 @@ import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.util.SerializationTestUtils; import org.springframework.util.SerializationTestUtils;
import static org.junit.Assert.*; import test.beans.ITestBean;
import test.beans.IndexedTestBean;
import test.beans.NestedTestBean;
import test.beans.TestBean;
/** /**
* Unit tests for {@link AutowiredAnnotationBeanPostProcessor}. * Unit tests for {@link AutowiredAnnotationBeanPostProcessor}.
@ -608,7 +615,9 @@ public final class AutowiredAnnotationBeanPostProcessorTests {
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf); bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp); bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryInjectionBean.class, false)); RootBeanDefinition annotatedBeanDefinition = new RootBeanDefinition(ObjectFactoryInjectionBean.class);
annotatedBeanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bf.registerBeanDefinition("annotatedBean", annotatedBeanDefinition);
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class)); bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
ObjectFactoryInjectionBean bean = (ObjectFactoryInjectionBean) bf.getBean("annotatedBean"); ObjectFactoryInjectionBean bean = (ObjectFactoryInjectionBean) bf.getBean("annotatedBean");

View File

@ -32,6 +32,7 @@ import test.beans.TestBean;
import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AutowireCandidateQualifier; import org.springframework.beans.factory.support.AutowireCandidateQualifier;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@ -406,7 +407,9 @@ public class InjectAnnotationBeanPostProcessorTests {
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf); bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp); bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryQualifierFieldInjectionBean.class, false)); RootBeanDefinition annotatedBeanDefinition = new RootBeanDefinition(ObjectFactoryQualifierFieldInjectionBean.class);
annotatedBeanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bf.registerBeanDefinition("annotatedBean", annotatedBeanDefinition);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "testBean")); bd.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "testBean"));
bf.registerBeanDefinition("testBean", bd); bf.registerBeanDefinition("testBean", bd);
@ -426,7 +429,9 @@ public class InjectAnnotationBeanPostProcessorTests {
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf); bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp); bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryQualifierMethodInjectionBean.class, false)); RootBeanDefinition annotatedBeanDefinition = new RootBeanDefinition(ObjectFactoryQualifierMethodInjectionBean.class);
annotatedBeanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bf.registerBeanDefinition("annotatedBean", annotatedBeanDefinition);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "testBean")); bd.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "testBean"));
bf.registerBeanDefinition("testBean", bd); bf.registerBeanDefinition("testBean", bd);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -27,6 +27,7 @@ import org.junit.Test;
* @author Rick Evans * @author Rick Evans
* @author Chris Beams * @author Chris Beams
*/ */
@SuppressWarnings("deprecation")
public final class CommonsLogFactoryBeanTests { public final class CommonsLogFactoryBeanTests {
@Test @Test

View File

@ -62,10 +62,14 @@ public final class CustomEditorConfigurerTests {
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("date", "2.12.1975"); pvs.add("date", "2.12.1975");
bf.registerBeanDefinition("tb1", new RootBeanDefinition(TestBean.class, pvs)); RootBeanDefinition bd1 = new RootBeanDefinition(TestBean.class);
bd1.setPropertyValues(pvs);
bf.registerBeanDefinition("tb1", bd1);
pvs = new MutablePropertyValues(); pvs = new MutablePropertyValues();
pvs.add("someMap[myKey]", new TypedStringValue("2.12.1975", Date.class)); pvs.add("someMap[myKey]", new TypedStringValue("2.12.1975", Date.class));
bf.registerBeanDefinition("tb2", new RootBeanDefinition(TestBean.class, pvs)); RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
bd2.setPropertyValues(pvs);
bf.registerBeanDefinition("tb2", bd2);
TestBean tb1 = (TestBean) bf.getBean("tb1"); TestBean tb1 = (TestBean) bf.getBean("tb1");
assertEquals(df.parse("2.12.1975"), tb1.getDate()); assertEquals(df.parse("2.12.1975"), tb1.getDate());
@ -85,10 +89,14 @@ public final class CustomEditorConfigurerTests {
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("date", "2.12.1975"); pvs.add("date", "2.12.1975");
bf.registerBeanDefinition("tb1", new RootBeanDefinition(TestBean.class, pvs)); RootBeanDefinition bd1 = new RootBeanDefinition(TestBean.class);
bd1.setPropertyValues(pvs);
bf.registerBeanDefinition("tb1", bd1);
pvs = new MutablePropertyValues(); pvs = new MutablePropertyValues();
pvs.add("someMap[myKey]", new TypedStringValue("2.12.1975", Date.class)); pvs.add("someMap[myKey]", new TypedStringValue("2.12.1975", Date.class));
bf.registerBeanDefinition("tb2", new RootBeanDefinition(TestBean.class, pvs)); RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
bd2.setPropertyValues(pvs);
bf.registerBeanDefinition("tb2", bd2);
TestBean tb1 = (TestBean) bf.getBean("tb1"); TestBean tb1 = (TestBean) bf.getBean("tb1");
assertEquals(df.parse("2.12.1975"), tb1.getDate()); assertEquals(df.parse("2.12.1975"), tb1.getDate());
@ -107,7 +115,9 @@ public final class CustomEditorConfigurerTests {
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("date", "2.12.1975"); pvs.add("date", "2.12.1975");
bf.registerBeanDefinition("tb", new RootBeanDefinition(TestBean.class, pvs)); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
bf.registerBeanDefinition("tb", bd);
TestBean tb = (TestBean) bf.getBean("tb"); TestBean tb = (TestBean) bf.getBean("tb");
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN);
@ -125,7 +135,9 @@ public final class CustomEditorConfigurerTests {
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("date", "2.12.1975"); pvs.add("date", "2.12.1975");
bf.registerBeanDefinition("tb", new RootBeanDefinition(TestBean.class, pvs)); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
bf.registerBeanDefinition("tb", bd);
TestBean tb = (TestBean) bf.getBean("tb"); TestBean tb = (TestBean) bf.getBean("tb");
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN);
@ -143,7 +155,9 @@ public final class CustomEditorConfigurerTests {
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("stringArray", "xxx"); pvs.add("stringArray", "xxx");
bf.registerBeanDefinition("tb", new RootBeanDefinition(TestBean.class, pvs)); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
bf.registerBeanDefinition("tb", bd);
TestBean tb = (TestBean) bf.getBean("tb"); TestBean tb = (TestBean) bf.getBean("tb");
assertTrue(tb.getStringArray() != null && tb.getStringArray().length == 1); assertTrue(tb.getStringArray() != null && tb.getStringArray().length == 1);

View File

@ -38,6 +38,7 @@ public class DeprecatedBeanWarnerTests {
@Test @Test
@SuppressWarnings("deprecation")
public void postProcess() { public void postProcess() {
beanFactory = new DefaultListableBeanFactory(); beanFactory = new DefaultListableBeanFactory();
BeanDefinition def = new RootBeanDefinition(MyDeprecatedBean.class); BeanDefinition def = new RootBeanDefinition(MyDeprecatedBean.class);

View File

@ -16,21 +16,25 @@
package org.springframework.beans.factory.config; package org.springframework.beans.factory.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static test.util.TestResourceUtils.qualifiedResource;
import java.util.Date; import java.util.Date;
import javax.inject.Provider; import javax.inject.Provider;
import org.junit.After; import org.junit.After;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static test.util.TestResourceUtils.*;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.util.SerializationTestUtils; import org.springframework.util.SerializationTestUtils;
@ -45,11 +49,12 @@ public class ObjectFactoryCreatingFactoryBeanTests {
private static final Resource CONTEXT = private static final Resource CONTEXT =
qualifiedResource(ObjectFactoryCreatingFactoryBeanTests.class, "context.xml"); qualifiedResource(ObjectFactoryCreatingFactoryBeanTests.class, "context.xml");
private XmlBeanFactory beanFactory; private DefaultListableBeanFactory beanFactory;
@Before @Before
public void setUp() { public void setUp() {
this.beanFactory = new XmlBeanFactory(CONTEXT); this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(CONTEXT);
this.beanFactory.setSerializationId("test"); this.beanFactory.setSerializationId("test");
} }

View File

@ -16,11 +16,15 @@
package org.springframework.beans.factory.config; package org.springframework.beans.factory.config;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static test.util.TestResourceUtils.qualifiedResource; import static test.util.TestResourceUtils.qualifiedResource;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import test.beans.ITestBean; import test.beans.ITestBean;
@ -39,7 +43,8 @@ public class PropertyPathFactoryBeanTests {
@Test @Test
public void testPropertyPathFactoryBeanWithSingletonResult() { public void testPropertyPathFactoryBeanWithSingletonResult() {
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
assertEquals(new Integer(12), xbf.getBean("propertyPath1")); assertEquals(new Integer(12), xbf.getBean("propertyPath1"));
assertEquals(new Integer(11), xbf.getBean("propertyPath2")); assertEquals(new Integer(11), xbf.getBean("propertyPath2"));
assertEquals(new Integer(10), xbf.getBean("tb.age")); assertEquals(new Integer(10), xbf.getBean("tb.age"));
@ -53,7 +58,8 @@ public class PropertyPathFactoryBeanTests {
@Test @Test
public void testPropertyPathFactoryBeanWithPrototypeResult() { public void testPropertyPathFactoryBeanWithPrototypeResult() {
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
assertNull(xbf.getType("tb.spouse")); assertNull(xbf.getType("tb.spouse"));
assertEquals(TestBean.class, xbf.getType("propertyPath3")); assertEquals(TestBean.class, xbf.getType("propertyPath3"));
Object result1 = xbf.getBean("tb.spouse"); Object result1 = xbf.getBean("tb.spouse");
@ -72,14 +78,16 @@ public class PropertyPathFactoryBeanTests {
@Test @Test
public void testPropertyPathFactoryBeanWithNullResult() { public void testPropertyPathFactoryBeanWithNullResult() {
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
assertNull(xbf.getType("tb.spouse.spouse")); assertNull(xbf.getType("tb.spouse.spouse"));
assertNull(xbf.getBean("tb.spouse.spouse")); assertNull(xbf.getBean("tb.spouse.spouse"));
} }
@Test @Test
public void testPropertyPathFactoryBeanAsInnerBean() { public void testPropertyPathFactoryBeanAsInnerBean() {
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
TestBean spouse = (TestBean) xbf.getBean("otb.spouse"); TestBean spouse = (TestBean) xbf.getBean("otb.spouse");
TestBean tbWithInner = (TestBean) xbf.getBean("tbWithInner"); TestBean tbWithInner = (TestBean) xbf.getBean("tbWithInner");
assertSame(spouse, tbWithInner.getSpouse()); assertSame(spouse, tbWithInner.getSpouse());

View File

@ -371,7 +371,8 @@ public final class PropertyResourceConfigurerTests {
pvs2.add("name", "name${var}${var}${"); pvs2.add("name", "name${var}${var}${");
pvs2.add("spouse", new RuntimeBeanReference("${ref}")); pvs2.add("spouse", new RuntimeBeanReference("${ref}"));
pvs2.add("someMap", singletonMap); pvs2.add("someMap", singletonMap);
RootBeanDefinition parent = new RootBeanDefinition(TestBean.class, pvs1); RootBeanDefinition parent = new RootBeanDefinition(TestBean.class);
parent.setPropertyValues(pvs1);
ChildBeanDefinition bd = new ChildBeanDefinition("${parent}", pvs2); ChildBeanDefinition bd = new ChildBeanDefinition("${parent}", pvs2);
factory.registerBeanDefinition("parent1", parent); factory.registerBeanDefinition("parent1", parent);
factory.registerBeanDefinition("tb1", bd); factory.registerBeanDefinition("tb1", bd);
@ -382,7 +383,8 @@ public final class PropertyResourceConfigurerTests {
pvs.add("name", "name${var}${var}${"); pvs.add("name", "name${var}${var}${");
pvs.add("spouse", new RuntimeBeanReference("${ref}")); pvs.add("spouse", new RuntimeBeanReference("${ref}"));
pvs.add("someMap", singletonMap); pvs.add("someMap", singletonMap);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
factory.registerBeanDefinition("tb1", bd); factory.registerBeanDefinition("tb1", bd);
} }
@ -412,7 +414,9 @@ public final class PropertyResourceConfigurerTests {
someMap.put("key2", "${age}name"); someMap.put("key2", "${age}name");
MutablePropertyValues innerPvs = new MutablePropertyValues(); MutablePropertyValues innerPvs = new MutablePropertyValues();
innerPvs.add("touchy", "${os.name}"); innerPvs.add("touchy", "${os.name}");
someMap.put("key3", new RootBeanDefinition(TestBean.class, innerPvs)); RootBeanDefinition innerBd = new RootBeanDefinition(TestBean.class);
innerBd.setPropertyValues(innerPvs);
someMap.put("key3", innerBd);
MutablePropertyValues innerPvs2 = new MutablePropertyValues(innerPvs); MutablePropertyValues innerPvs2 = new MutablePropertyValues(innerPvs);
someMap.put("${key4}", new BeanDefinitionHolder(new ChildBeanDefinition("tb1", innerPvs2), "child")); someMap.put("${key4}", new BeanDefinitionHolder(new ChildBeanDefinition("tb1", innerPvs2), "child"));
pvs.add("someMap", someMap); pvs.add("someMap", someMap);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,6 +20,8 @@ import java.util.Arrays;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.springframework.beans.factory.config.BeanDefinition;
import test.beans.TestBean; import test.beans.TestBean;
/** /**
@ -31,7 +33,8 @@ public class BeanDefinitionBuilderTests extends TestCase {
public void testBeanClassWithSimpleProperty() { public void testBeanClassWithSimpleProperty() {
String[] dependsOn = new String[] { "A", "B", "C" }; String[] dependsOn = new String[] { "A", "B", "C" };
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class); BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class);
bdb.setSingleton(false).addPropertyReference("age", "15"); bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bdb.addPropertyReference("age", "15");
for (int i = 0; i < dependsOn.length; i++) { for (int i = 0; i < dependsOn.length; i++) {
bdb.addDependsOn(dependsOn[i]); bdb.addDependsOn(dependsOn[i]);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,6 +18,7 @@ package org.springframework.beans.factory.support;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.BeanDefinitionHolder;
import test.beans.TestBean; import test.beans.TestBean;
@ -120,10 +121,11 @@ public class BeanDefinitionTests extends TestCase {
bd.getPropertyValues().add("name", "myName"); bd.getPropertyValues().add("name", "myName");
bd.getPropertyValues().add("age", "99"); bd.getPropertyValues().add("age", "99");
ChildBeanDefinition childBd = new ChildBeanDefinition("bd"); GenericBeanDefinition childBd = new GenericBeanDefinition();
childBd.setParentName("bd");
RootBeanDefinition mergedBd = new RootBeanDefinition(bd); RootBeanDefinition mergedBd = new RootBeanDefinition(bd);
mergedBd.overrideFrom(childBd); mergedBd.overrideFrom((BeanDefinition) childBd);
assertEquals(2, mergedBd.getConstructorArgumentValues().getArgumentCount()); assertEquals(2, mergedBd.getConstructorArgumentValues().getArgumentCount());
assertEquals(2, mergedBd.getPropertyValues().size()); assertEquals(2, mergedBd.getPropertyValues().size());
assertEquals(bd, mergedBd); assertEquals(bd, mergedBd);

View File

@ -16,6 +16,13 @@
package org.springframework.beans.factory.support; package org.springframework.beans.factory.support;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
@ -28,24 +35,21 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.junit.Assert.*;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.UrlResource;
import test.beans.GenericBean; import test.beans.GenericBean;
import test.beans.GenericIntegerBean; import test.beans.GenericIntegerBean;
import test.beans.GenericSetOfIntegerBean; import test.beans.GenericSetOfIntegerBean;
import test.beans.TestBean; import test.beans.TestBean;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.UrlResource;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
@ -94,7 +98,8 @@ public class BeanFactoryGenericsTests {
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080")); bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090")); bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
RootBeanDefinition rbd = new RootBeanDefinition(GenericIntegerBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE); RootBeanDefinition rbd = new RootBeanDefinition(GenericIntegerBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
bf.registerBeanDefinition("genericBean", rbd); bf.registerBeanDefinition("genericBean", rbd);
GenericIntegerBean gb = (GenericIntegerBean) bf.getBean("genericBean"); GenericIntegerBean gb = (GenericIntegerBean) bf.getBean("genericBean");
@ -126,7 +131,8 @@ public class BeanFactoryGenericsTests {
public void testGenericListPropertyWithOptionalAutowiring() throws MalformedURLException { public void testGenericListPropertyWithOptionalAutowiring() throws MalformedURLException {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE); RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
bf.registerBeanDefinition("genericBean", rbd); bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean"); GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
@ -152,7 +158,9 @@ public class BeanFactoryGenericsTests {
@Test @Test
public void testGenericListOfArraysProperty() throws MalformedURLException { public void testGenericListOfArraysProperty() throws MalformedURLException {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("genericBeanTests.xml", getClass())); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
GenericBean<?> gb = (GenericBean<?>) bf.getBean("listOfArrays"); GenericBean<?> gb = (GenericBean<?>) bf.getBean("listOfArrays");
assertEquals(1, gb.getListOfArrays().size()); assertEquals(1, gb.getListOfArrays().size());
@ -186,7 +194,8 @@ public class BeanFactoryGenericsTests {
bf.registerSingleton("integer1", new Integer(4)); bf.registerSingleton("integer1", new Integer(4));
bf.registerSingleton("integer2", new Integer(5)); bf.registerSingleton("integer2", new Integer(5));
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR); RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("genericBean", rbd); bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean"); GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
@ -198,7 +207,8 @@ public class BeanFactoryGenericsTests {
public void testGenericSetConstructorWithOptionalAutowiring() { public void testGenericSetConstructorWithOptionalAutowiring() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR); RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("genericBean", rbd); bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean"); GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
@ -236,7 +246,8 @@ public class BeanFactoryGenericsTests {
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080")); bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090")); bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR); RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("genericBean", rbd); bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean"); GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
@ -252,7 +263,8 @@ public class BeanFactoryGenericsTests {
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080")); bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090")); bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR); RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("genericBean", rbd); bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean"); GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
@ -576,7 +588,9 @@ public class BeanFactoryGenericsTests {
@Test @Test
public void testGenericListBean() throws Exception { public void testGenericListBean() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("genericBeanTests.xml", getClass())); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
List<?> list = (List<?>) bf.getBean("list"); List<?> list = (List<?>) bf.getBean("list");
assertEquals(1, list.size()); assertEquals(1, list.size());
assertEquals(new URL("http://localhost:8080"), list.get(0)); assertEquals(new URL("http://localhost:8080"), list.get(0));
@ -584,7 +598,9 @@ public class BeanFactoryGenericsTests {
@Test @Test
public void testGenericSetBean() throws Exception { public void testGenericSetBean() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("genericBeanTests.xml", getClass())); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
Set<?> set = (Set<?>) bf.getBean("set"); Set<?> set = (Set<?>) bf.getBean("set");
assertEquals(1, set.size()); assertEquals(1, set.size());
assertEquals(new URL("http://localhost:8080"), set.iterator().next()); assertEquals(new URL("http://localhost:8080"), set.iterator().next());
@ -592,7 +608,9 @@ public class BeanFactoryGenericsTests {
@Test @Test
public void testGenericMapBean() throws Exception { public void testGenericMapBean() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("genericBeanTests.xml", getClass())); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
Map<?, ?> map = (Map<?, ?>) bf.getBean("map"); Map<?, ?> map = (Map<?, ?>) bf.getBean("map");
assertEquals(1, map.size()); assertEquals(1, map.size());
assertEquals(new Integer(10), map.keySet().iterator().next()); assertEquals(new Integer(10), map.keySet().iterator().next());
@ -601,7 +619,9 @@ public class BeanFactoryGenericsTests {
@Test @Test
public void testGenericallyTypedIntegerBean() throws Exception { public void testGenericallyTypedIntegerBean() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("genericBeanTests.xml", getClass())); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
GenericIntegerBean gb = (GenericIntegerBean) bf.getBean("integerBean"); GenericIntegerBean gb = (GenericIntegerBean) bf.getBean("integerBean");
assertEquals(new Integer(10), gb.getGenericProperty()); assertEquals(new Integer(10), gb.getGenericProperty());
assertEquals(new Integer(20), gb.getGenericListProperty().get(0)); assertEquals(new Integer(20), gb.getGenericListProperty().get(0));
@ -610,7 +630,9 @@ public class BeanFactoryGenericsTests {
@Test @Test
public void testGenericallyTypedSetOfIntegerBean() throws Exception { public void testGenericallyTypedSetOfIntegerBean() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("genericBeanTests.xml", getClass())); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
GenericSetOfIntegerBean gb = (GenericSetOfIntegerBean) bf.getBean("setOfIntegerBean"); GenericSetOfIntegerBean gb = (GenericSetOfIntegerBean) bf.getBean("setOfIntegerBean");
assertEquals(new Integer(10), gb.getGenericProperty().iterator().next()); assertEquals(new Integer(10), gb.getGenericProperty().iterator().next());
assertEquals(new Integer(20), gb.getGenericListProperty().get(0).iterator().next()); assertEquals(new Integer(20), gb.getGenericListProperty().get(0).iterator().next());
@ -619,7 +641,9 @@ public class BeanFactoryGenericsTests {
@Test @Test
public void testSetBean() throws Exception { public void testSetBean() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("genericBeanTests.xml", getClass())); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
UrlSet us = (UrlSet) bf.getBean("setBean"); UrlSet us = (UrlSet) bf.getBean("setBean");
assertEquals(1, us.size()); assertEquals(1, us.size());
assertEquals(new URL("http://www.springframework.org"), us.iterator().next()); assertEquals(new URL("http://www.springframework.org"), us.iterator().next());

View File

@ -16,11 +16,11 @@
package org.springframework.beans.factory.support.security; package org.springframework.beans.factory.support.security;
import static junit.framework.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static junit.framework.Assert.assertNull; import static org.junit.Assert.assertNull;
import static junit.framework.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static junit.framework.Assert.fail; import static org.junit.Assert.fail;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URL; import java.net.URL;
@ -56,7 +56,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.SecurityContextProvider; import org.springframework.beans.factory.support.SecurityContextProvider;
import org.springframework.beans.factory.support.security.support.ConstructorBean; import org.springframework.beans.factory.support.security.support.ConstructorBean;
import org.springframework.beans.factory.support.security.support.CustomCallbackBean; import org.springframework.beans.factory.support.security.support.CustomCallbackBean;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
@ -72,7 +72,7 @@ import org.springframework.core.io.Resource;
*/ */
public class CallbacksSecurityTests { public class CallbacksSecurityTests {
private XmlBeanFactory beanFactory; private DefaultListableBeanFactory beanFactory;
private SecurityContextProvider provider; private SecurityContextProvider provider;
private static class NonPrivilegedBean { private static class NonPrivilegedBean {
@ -312,7 +312,8 @@ public class CallbacksSecurityTests {
DefaultResourceLoader drl = new DefaultResourceLoader(); DefaultResourceLoader drl = new DefaultResourceLoader();
Resource config = drl Resource config = drl
.getResource("/org/springframework/beans/factory/support/security/callbacks.xml"); .getResource("/org/springframework/beans/factory/support/security/callbacks.xml");
beanFactory = new XmlBeanFactory(config); beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(config);
beanFactory.setSecurityContextProvider(provider); beanFactory.setSecurityContextProvider(provider);
} }

View File

@ -20,7 +20,6 @@ import java.beans.PropertyEditorSupport;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.Assert;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyBatchUpdateException; import org.springframework.beans.PropertyBatchUpdateException;
@ -88,7 +87,7 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
*/ */
public void testLifecycleCallbacks() { public void testLifecycleCallbacks() {
LifecycleBean lb = (LifecycleBean) getBeanFactory().getBean("lifecycle"); LifecycleBean lb = (LifecycleBean) getBeanFactory().getBean("lifecycle");
Assert.assertEquals("lifecycle", lb.getBeanName()); assertEquals("lifecycle", lb.getBeanName());
// The dummy business method will throw an exception if the // The dummy business method will throw an exception if the
// necessary callbacks weren't invoked in the right order. // necessary callbacks weren't invoked in the right order.
lb.businessMethod(); lb.businessMethod();
@ -365,4 +364,4 @@ class MustBeInitialized implements InitializingBean {
throw new RuntimeException("Factory didn't call afterPropertiesSet() on MustBeInitialized object"); throw new RuntimeException("Factory didn't call afterPropertiesSet() on MustBeInitialized object");
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,8 +20,6 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.ListableBeanFactory;
import junit.framework.Assert;
import test.beans.TestBean; import test.beans.TestBean;
/** /**
@ -48,24 +46,24 @@ public abstract class AbstractListableBeanFactoryTests extends AbstractBeanFacto
protected final void assertCount(int count) { protected final void assertCount(int count) {
String[] defnames = getListableBeanFactory().getBeanDefinitionNames(); String[] defnames = getListableBeanFactory().getBeanDefinitionNames();
Assert.assertTrue("We should have " + count + " beans, not " + defnames.length, defnames.length == count); assertTrue("We should have " + count + " beans, not " + defnames.length, defnames.length == count);
} }
public void assertTestBeanCount(int count) { public void assertTestBeanCount(int count) {
String[] defNames = getListableBeanFactory().getBeanNamesForType(TestBean.class, true, false); String[] defNames = getListableBeanFactory().getBeanNamesForType(TestBean.class, true, false);
Assert.assertTrue("We should have " + count + " beans for class org.springframework.beans.TestBean, not " + assertTrue("We should have " + count + " beans for class org.springframework.beans.TestBean, not " +
defNames.length, defNames.length == count); defNames.length, defNames.length == count);
int countIncludingFactoryBeans = count + 2; int countIncludingFactoryBeans = count + 2;
String[] names = getListableBeanFactory().getBeanNamesForType(TestBean.class, true, true); String[] names = getListableBeanFactory().getBeanNamesForType(TestBean.class, true, true);
Assert.assertTrue("We should have " + countIncludingFactoryBeans + assertTrue("We should have " + countIncludingFactoryBeans +
" beans for class org.springframework.beans.TestBean, not " + names.length, " beans for class org.springframework.beans.TestBean, not " + names.length,
names.length == countIncludingFactoryBeans); names.length == countIncludingFactoryBeans);
} }
public void testGetDefinitionsForNoSuchClass() { public void testGetDefinitionsForNoSuchClass() {
String[] defnames = getListableBeanFactory().getBeanNamesForType(String.class); String[] defnames = getListableBeanFactory().getBeanNamesForType(String.class);
Assert.assertTrue("No string definitions", defnames.length == 0); assertTrue("No string definitions", defnames.length == 0);
} }
/** /**
@ -73,18 +71,18 @@ public abstract class AbstractListableBeanFactoryTests extends AbstractBeanFacto
* what type factories may return, and it may even change over time.) * what type factories may return, and it may even change over time.)
*/ */
public void testGetCountForFactoryClass() { public void testGetCountForFactoryClass() {
Assert.assertTrue("Should have 2 factories, not " + assertTrue("Should have 2 factories, not " +
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length, getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length,
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2); getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2);
Assert.assertTrue("Should have 2 factories, not " + assertTrue("Should have 2 factories, not " +
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length, getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length,
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2); getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2);
} }
public void testContainsBeanDefinition() { public void testContainsBeanDefinition() {
Assert.assertTrue(getListableBeanFactory().containsBeanDefinition("rod")); assertTrue(getListableBeanFactory().containsBeanDefinition("rod"));
Assert.assertTrue(getListableBeanFactory().containsBeanDefinition("roderick")); assertTrue(getListableBeanFactory().containsBeanDefinition("roderick"));
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,9 +16,7 @@
package org.springframework.beans.factory.xml; package org.springframework.beans.factory.xml;
import junit.framework.Assert;
import junit.framework.TestCase; import junit.framework.TestCase;
import test.beans.TestBean;
import org.springframework.beans.factory.config.PropertiesFactoryBean; import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.config.RuntimeBeanReference;
@ -26,6 +24,8 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import test.beans.TestBean;
/** /**
* @author Rob Harrop * @author Rob Harrop
* @author Juergen Hoeller * @author Juergen Hoeller
@ -34,43 +34,45 @@ public class AutowireWithExclusionTests extends TestCase {
public void testByTypeAutowireWithAutoSelfExclusion() throws Exception { public void testByTypeAutowireWithAutoSelfExclusion() throws Exception {
CountingFactory.reset(); CountingFactory.reset();
XmlBeanFactory beanFactory = getBeanFactory("autowire-with-exclusion.xml"); DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-exclusion.xml");
beanFactory.preInstantiateSingletons(); beanFactory.preInstantiateSingletons();
TestBean rob = (TestBean) beanFactory.getBean("rob"); TestBean rob = (TestBean) beanFactory.getBean("rob");
TestBean sally = (TestBean) beanFactory.getBean("sally"); TestBean sally = (TestBean) beanFactory.getBean("sally");
assertEquals(sally, rob.getSpouse()); assertEquals(sally, rob.getSpouse());
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount()); assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
} }
public void testByTypeAutowireWithExclusion() throws Exception { public void testByTypeAutowireWithExclusion() throws Exception {
CountingFactory.reset(); CountingFactory.reset();
XmlBeanFactory beanFactory = getBeanFactory("autowire-with-exclusion.xml"); DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-exclusion.xml");
beanFactory.preInstantiateSingletons(); beanFactory.preInstantiateSingletons();
TestBean rob = (TestBean) beanFactory.getBean("rob"); TestBean rob = (TestBean) beanFactory.getBean("rob");
assertEquals("props1", rob.getSomeProperties().getProperty("name")); assertEquals("props1", rob.getSomeProperties().getProperty("name"));
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount()); assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
} }
public void testByTypeAutowireWithExclusionInParentFactory() throws Exception { public void testByTypeAutowireWithExclusionInParentFactory() throws Exception {
CountingFactory.reset(); CountingFactory.reset();
XmlBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml"); DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
parent.preInstantiateSingletons(); parent.preInstantiateSingletons();
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE); RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally")); robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
child.registerBeanDefinition("rob2", robDef); child.registerBeanDefinition("rob2", robDef);
TestBean rob = (TestBean) child.getBean("rob2"); TestBean rob = (TestBean) child.getBean("rob2");
assertEquals("props1", rob.getSomeProperties().getProperty("name")); assertEquals("props1", rob.getSomeProperties().getProperty("name"));
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount()); assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
} }
public void testByTypeAutowireWithPrimaryInParentFactory() throws Exception { public void testByTypeAutowireWithPrimaryInParentFactory() throws Exception {
CountingFactory.reset(); CountingFactory.reset();
XmlBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml"); DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
parent.getBeanDefinition("props1").setPrimary(true); parent.getBeanDefinition("props1").setPrimary(true);
parent.preInstantiateSingletons(); parent.preInstantiateSingletons();
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE); RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally")); robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
child.registerBeanDefinition("rob2", robDef); child.registerBeanDefinition("rob2", robDef);
RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class); RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
@ -78,15 +80,16 @@ public class AutowireWithExclusionTests extends TestCase {
child.registerBeanDefinition("props3", propsDef); child.registerBeanDefinition("props3", propsDef);
TestBean rob = (TestBean) child.getBean("rob2"); TestBean rob = (TestBean) child.getBean("rob2");
assertEquals("props1", rob.getSomeProperties().getProperty("name")); assertEquals("props1", rob.getSomeProperties().getProperty("name"));
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount()); assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
} }
public void testByTypeAutowireWithPrimaryOverridingParentFactory() throws Exception { public void testByTypeAutowireWithPrimaryOverridingParentFactory() throws Exception {
CountingFactory.reset(); CountingFactory.reset();
XmlBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml"); DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
parent.preInstantiateSingletons(); parent.preInstantiateSingletons();
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE); RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally")); robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
child.registerBeanDefinition("rob2", robDef); child.registerBeanDefinition("rob2", robDef);
RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class); RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
@ -95,16 +98,17 @@ public class AutowireWithExclusionTests extends TestCase {
child.registerBeanDefinition("props3", propsDef); child.registerBeanDefinition("props3", propsDef);
TestBean rob = (TestBean) child.getBean("rob2"); TestBean rob = (TestBean) child.getBean("rob2");
assertEquals("props3", rob.getSomeProperties().getProperty("name")); assertEquals("props3", rob.getSomeProperties().getProperty("name"));
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount()); assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
} }
public void testByTypeAutowireWithPrimaryInParentAndChild() throws Exception { public void testByTypeAutowireWithPrimaryInParentAndChild() throws Exception {
CountingFactory.reset(); CountingFactory.reset();
XmlBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml"); DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
parent.getBeanDefinition("props1").setPrimary(true); parent.getBeanDefinition("props1").setPrimary(true);
parent.preInstantiateSingletons(); parent.preInstantiateSingletons();
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent); DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE); RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally")); robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
child.registerBeanDefinition("rob2", robDef); child.registerBeanDefinition("rob2", robDef);
RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class); RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
@ -113,29 +117,29 @@ public class AutowireWithExclusionTests extends TestCase {
child.registerBeanDefinition("props3", propsDef); child.registerBeanDefinition("props3", propsDef);
TestBean rob = (TestBean) child.getBean("rob2"); TestBean rob = (TestBean) child.getBean("rob2");
assertEquals("props3", rob.getSomeProperties().getProperty("name")); assertEquals("props3", rob.getSomeProperties().getProperty("name"));
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount()); assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
} }
public void testByTypeAutowireWithInclusion() throws Exception { public void testByTypeAutowireWithInclusion() throws Exception {
CountingFactory.reset(); CountingFactory.reset();
XmlBeanFactory beanFactory = getBeanFactory("autowire-with-inclusion.xml"); DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-inclusion.xml");
beanFactory.preInstantiateSingletons(); beanFactory.preInstantiateSingletons();
TestBean rob = (TestBean) beanFactory.getBean("rob"); TestBean rob = (TestBean) beanFactory.getBean("rob");
assertEquals("props1", rob.getSomeProperties().getProperty("name")); assertEquals("props1", rob.getSomeProperties().getProperty("name"));
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount()); assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
} }
public void testByTypeAutowireWithSelectiveInclusion() throws Exception { public void testByTypeAutowireWithSelectiveInclusion() throws Exception {
CountingFactory.reset(); CountingFactory.reset();
XmlBeanFactory beanFactory = getBeanFactory("autowire-with-selective-inclusion.xml"); DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-selective-inclusion.xml");
beanFactory.preInstantiateSingletons(); beanFactory.preInstantiateSingletons();
TestBean rob = (TestBean) beanFactory.getBean("rob"); TestBean rob = (TestBean) beanFactory.getBean("rob");
assertEquals("props1", rob.getSomeProperties().getProperty("name")); assertEquals("props1", rob.getSomeProperties().getProperty("name"));
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount()); assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
} }
public void testConstructorAutowireWithAutoSelfExclusion() throws Exception { public void testConstructorAutowireWithAutoSelfExclusion() throws Exception {
XmlBeanFactory beanFactory = getBeanFactory("autowire-constructor-with-exclusion.xml"); DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-constructor-with-exclusion.xml");
TestBean rob = (TestBean) beanFactory.getBean("rob"); TestBean rob = (TestBean) beanFactory.getBean("rob");
TestBean sally = (TestBean) beanFactory.getBean("sally"); TestBean sally = (TestBean) beanFactory.getBean("sally");
assertEquals(sally, rob.getSpouse()); assertEquals(sally, rob.getSpouse());
@ -147,13 +151,16 @@ public class AutowireWithExclusionTests extends TestCase {
} }
public void testConstructorAutowireWithExclusion() throws Exception { public void testConstructorAutowireWithExclusion() throws Exception {
XmlBeanFactory beanFactory = getBeanFactory("autowire-constructor-with-exclusion.xml"); DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-constructor-with-exclusion.xml");
TestBean rob = (TestBean) beanFactory.getBean("rob"); TestBean rob = (TestBean) beanFactory.getBean("rob");
assertEquals("props1", rob.getSomeProperties().getProperty("name")); assertEquals("props1", rob.getSomeProperties().getProperty("name"));
} }
private XmlBeanFactory getBeanFactory(String configPath) { private DefaultListableBeanFactory getBeanFactory(String configPath) {
return new XmlBeanFactory(new ClassPathResource(configPath, getClass())); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource(configPath, getClass()));
return bf;
} }
} }

View File

@ -19,6 +19,7 @@ package org.springframework.beans.factory.xml;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -38,9 +39,9 @@ public class CollectingReaderEventListener implements ReaderEventListener {
private final List defaults = new LinkedList(); private final List defaults = new LinkedList();
private final Map componentDefinitions = CollectionFactory.createLinkedMapIfPossible(8); private final Map componentDefinitions = new LinkedHashMap<>(8);
private final Map aliasMap = CollectionFactory.createLinkedMapIfPossible(8); private final Map aliasMap = new LinkedHashMap<>(8);
private final List imports = new LinkedList(); private final List imports = new LinkedList();
@ -92,4 +93,4 @@ public class CollectingReaderEventListener implements ReaderEventListener {
return Collections.unmodifiableList(this.imports); return Collections.unmodifiableList(this.imports);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,25 +16,30 @@
package org.springframework.beans.factory.xml; package org.springframework.beans.factory.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.*;
import org.junit.Test; import org.junit.Test;
import test.beans.TestBean; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import test.beans.TestBean;
/** /**
* @author Rob Harrop * @author Rob Harrop
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class CollectionsWithDefaultTypesTests { public class CollectionsWithDefaultTypesTests {
private final XmlBeanFactory beanFactory; private final DefaultListableBeanFactory beanFactory;
public CollectionsWithDefaultTypesTests() { public CollectionsWithDefaultTypesTests() {
this.beanFactory = new XmlBeanFactory(new ClassPathResource("collectionsWithDefaultTypes.xml", getClass())); this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
new ClassPathResource("collectionsWithDefaultTypes.xml", getClass()));
} }
@Test @Test

View File

@ -18,6 +18,7 @@ package org.springframework.beans.factory.xml;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
/** /**
@ -25,11 +26,13 @@ import org.springframework.core.io.ClassPathResource;
*/ */
public class DefaultLifecycleMethodsTests extends TestCase { public class DefaultLifecycleMethodsTests extends TestCase {
private XmlBeanFactory beanFactory; private DefaultListableBeanFactory beanFactory;
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
this.beanFactory = new XmlBeanFactory(new ClassPathResource("defaultLifecycleMethods.xml", getClass())); this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(new ClassPathResource(
"defaultLifecycleMethods.xml", getClass()));
} }
public void testLifecycleMethodsInvoked() { public void testLifecycleMethodsInvoked() {
@ -49,7 +52,9 @@ public class DefaultLifecycleMethodsTests extends TestCase {
public void testIgnoreDefaultLifecycleMethods() throws Exception { public void testIgnoreDefaultLifecycleMethods() throws Exception {
try { try {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("ignoreDefaultLifecycleMethods.xml", getClass())); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("ignoreDefaultLifecycleMethods.xml", getClass()));
bf.preInstantiateSingletons(); bf.preInstantiateSingletons();
bf.destroySingletons(); bf.destroySingletons();
} }

View File

@ -20,6 +20,7 @@ import junit.framework.TestCase;
import org.springframework.beans.PropertyValue; import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
/** /**
@ -27,11 +28,13 @@ import org.springframework.core.io.ClassPathResource;
*/ */
public class MetadataAttachmentTests extends TestCase { public class MetadataAttachmentTests extends TestCase {
private XmlBeanFactory beanFactory; private DefaultListableBeanFactory beanFactory;
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
this.beanFactory = new XmlBeanFactory(new ClassPathResource("withMeta.xml", getClass())); this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
new ClassPathResource("withMeta.xml", getClass()));
} }
public void testMetadataAttachment() throws Exception { public void testMetadataAttachment() throws Exception {

View File

@ -21,8 +21,8 @@ import static org.junit.Assert.assertThat;
import org.hamcrest.Description; import org.hamcrest.Description;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Test; import org.junit.Test;
import org.junit.internal.matchers.TypeSafeMatcher;
import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;

View File

@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import test.beans.DummyBean; import test.beans.DummyBean;
@ -32,7 +33,7 @@ public class SimpleConstructorNamespaceHandlerTests {
@Test @Test
public void simpleValue() throws Exception { public void simpleValue() throws Exception {
XmlBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml"); DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
String name = "simple"; String name = "simple";
// beanFactory.getBean("simple1", DummyBean.class); // beanFactory.getBean("simple1", DummyBean.class);
DummyBean nameValue = beanFactory.getBean(name, DummyBean.class); DummyBean nameValue = beanFactory.getBean(name, DummyBean.class);
@ -41,7 +42,7 @@ public class SimpleConstructorNamespaceHandlerTests {
@Test @Test
public void simpleRef() throws Exception { public void simpleRef() throws Exception {
XmlBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml"); DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
String name = "simple-ref"; String name = "simple-ref";
// beanFactory.getBean("name-value1", TestBean.class); // beanFactory.getBean("name-value1", TestBean.class);
DummyBean nameValue = beanFactory.getBean(name, DummyBean.class); DummyBean nameValue = beanFactory.getBean(name, DummyBean.class);
@ -50,7 +51,7 @@ public class SimpleConstructorNamespaceHandlerTests {
@Test @Test
public void nameValue() throws Exception { public void nameValue() throws Exception {
XmlBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml"); DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
String name = "name-value"; String name = "name-value";
// beanFactory.getBean("name-value1", TestBean.class); // beanFactory.getBean("name-value1", TestBean.class);
TestBean nameValue = beanFactory.getBean(name, TestBean.class); TestBean nameValue = beanFactory.getBean(name, TestBean.class);
@ -60,7 +61,7 @@ public class SimpleConstructorNamespaceHandlerTests {
@Test @Test
public void nameRef() throws Exception { public void nameRef() throws Exception {
XmlBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml"); DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
TestBean nameValue = beanFactory.getBean("name-value", TestBean.class); TestBean nameValue = beanFactory.getBean("name-value", TestBean.class);
DummyBean nameRef = beanFactory.getBean("name-ref", DummyBean.class); DummyBean nameRef = beanFactory.getBean("name-ref", DummyBean.class);
@ -70,7 +71,7 @@ public class SimpleConstructorNamespaceHandlerTests {
@Test @Test
public void typeIndexedValue() throws Exception { public void typeIndexedValue() throws Exception {
XmlBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml"); DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
DummyBean typeRef = beanFactory.getBean("indexed-value", DummyBean.class); DummyBean typeRef = beanFactory.getBean("indexed-value", DummyBean.class);
assertEquals("at", typeRef.getName()); assertEquals("at", typeRef.getName());
@ -80,7 +81,7 @@ public class SimpleConstructorNamespaceHandlerTests {
@Test @Test
public void typeIndexedRef() throws Exception { public void typeIndexedRef() throws Exception {
XmlBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml"); DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
DummyBean typeRef = beanFactory.getBean("indexed-ref", DummyBean.class); DummyBean typeRef = beanFactory.getBean("indexed-ref", DummyBean.class);
assertEquals("some-name", typeRef.getName()); assertEquals("some-name", typeRef.getName());
@ -89,20 +90,23 @@ public class SimpleConstructorNamespaceHandlerTests {
@Test(expected = BeanDefinitionStoreException.class) @Test(expected = BeanDefinitionStoreException.class)
public void ambiguousConstructor() throws Exception { public void ambiguousConstructor() throws Exception {
new XmlBeanFactory(new ClassPathResource("simpleConstructorNamespaceHandlerTestsWithErrors.xml", getClass())); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("simpleConstructorNamespaceHandlerTestsWithErrors.xml", getClass()));
} }
@Test @Test
public void constructorWithNameEndingInRef() throws Exception { public void constructorWithNameEndingInRef() throws Exception {
XmlBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml"); DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
DummyBean derivedBean = beanFactory.getBean("beanWithRefConstructorArg", DummyBean.class); DummyBean derivedBean = beanFactory.getBean("beanWithRefConstructorArg", DummyBean.class);
assertEquals(10, derivedBean.getAge()); assertEquals(10, derivedBean.getAge());
assertEquals("silly name", derivedBean.getName()); assertEquals("silly name", derivedBean.getName());
} }
private XmlBeanFactory createFactory(String resourceName) { private DefaultListableBeanFactory createFactory(String resourceName) {
XmlBeanFactory fact = new XmlBeanFactory(new ClassPathResource(resourceName, getClass())); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
//fact.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer()); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
return fact; new ClassPathResource(resourceName, getClass()));
return bf;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,13 +17,15 @@
package org.springframework.beans.factory.xml; package org.springframework.beans.factory.xml;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource;
import test.beans.ITestBean; import test.beans.ITestBean;
import test.beans.TestBean; import test.beans.TestBean;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.core.io.ClassPathResource;
/** /**
* @author Rob Harrop * @author Rob Harrop
* @author Juergen Hoeller * @author Juergen Hoeller
@ -33,8 +35,9 @@ public class SimplePropertyNamespaceHandlerTests {
@Test @Test
public void simpleBeanConfigured() throws Exception { public void simpleBeanConfigured() throws Exception {
XmlBeanFactory beanFactory = DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
new XmlBeanFactory(new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass())); new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
ITestBean rob = (TestBean) beanFactory.getBean("rob"); ITestBean rob = (TestBean) beanFactory.getBean("rob");
ITestBean sally = (TestBean) beanFactory.getBean("sally"); ITestBean sally = (TestBean) beanFactory.getBean("sally");
assertEquals("Rob Harrop", rob.getName()); assertEquals("Rob Harrop", rob.getName());
@ -44,8 +47,9 @@ public class SimplePropertyNamespaceHandlerTests {
@Test @Test
public void innerBeanConfigured() throws Exception { public void innerBeanConfigured() throws Exception {
XmlBeanFactory beanFactory = DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
new XmlBeanFactory(new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass())); new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
TestBean sally = (TestBean) beanFactory.getBean("sally2"); TestBean sally = (TestBean) beanFactory.getBean("sally2");
ITestBean rob = sally.getSpouse(); ITestBean rob = sally.getSpouse();
assertEquals("Rob Harrop", rob.getName()); assertEquals("Rob Harrop", rob.getName());
@ -55,13 +59,16 @@ public class SimplePropertyNamespaceHandlerTests {
@Test(expected = BeanDefinitionStoreException.class) @Test(expected = BeanDefinitionStoreException.class)
public void withPropertyDefinedTwice() throws Exception { public void withPropertyDefinedTwice() throws Exception {
new XmlBeanFactory(new ClassPathResource("simplePropertyNamespaceHandlerTestsWithErrors.xml", getClass())); DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
new ClassPathResource("simplePropertyNamespaceHandlerTestsWithErrors.xml", getClass()));
} }
@Test @Test
public void propertyWithNameEndingInRef() throws Exception { public void propertyWithNameEndingInRef() throws Exception {
XmlBeanFactory beanFactory = DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
new XmlBeanFactory(new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass())); new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
ITestBean sally = (TestBean) beanFactory.getBean("derivedSally"); ITestBean sally = (TestBean) beanFactory.getBean("derivedSally");
assertEquals("r", sally.getSpouse().getName()); assertEquals("r", sally.getSpouse().getName());
} }

View File

@ -16,7 +16,14 @@
package org.springframework.beans.factory.xml; package org.springframework.beans.factory.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
@ -27,21 +34,19 @@ import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.IdentityHashMap;
import java.util.HashSet;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
import test.beans.TestBean;
import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.config.ListFactoryBean; import org.springframework.beans.factory.config.ListFactoryBean;
import org.springframework.beans.factory.config.MapFactoryBean; import org.springframework.beans.factory.config.MapFactoryBean;
import org.springframework.beans.factory.config.SetFactoryBean; import org.springframework.beans.factory.config.SetFactoryBean;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import test.beans.TestBean;
/** /**
* Tests for collections in XML bean definitions. * Tests for collections in XML bean definitions.
* *
@ -51,10 +56,12 @@ import org.springframework.core.io.ClassPathResource;
*/ */
public class XmlBeanCollectionTests { public class XmlBeanCollectionTests {
private final XmlBeanFactory beanFactory; private final DefaultListableBeanFactory beanFactory;
public XmlBeanCollectionTests() { public XmlBeanCollectionTests() {
this.beanFactory = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass())); this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
new ClassPathResource("collections.xml", getClass()));
} }
@Test @Test

View File

@ -21,8 +21,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import junit.framework.Assert;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
@ -44,21 +42,25 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
private DefaultListableBeanFactory parent; private DefaultListableBeanFactory parent;
private XmlBeanFactory factory; private DefaultListableBeanFactory factory;
@Override @Override
protected void setUp() { protected void setUp() {
parent = new DefaultListableBeanFactory(); parent = new DefaultListableBeanFactory();
Map m = new HashMap(); Map m = new HashMap();
m.put("name", "Albert"); m.put("name", "Albert");
parent.registerBeanDefinition("father", RootBeanDefinition bd1 = new RootBeanDefinition(TestBean.class);
new RootBeanDefinition(TestBean.class, new MutablePropertyValues(m))); bd1.setPropertyValues(new MutablePropertyValues(m));
parent.registerBeanDefinition("father", bd1);
m = new HashMap(); m = new HashMap();
m.put("name", "Roderick"); m.put("name", "Roderick");
parent.registerBeanDefinition("rod", RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
new RootBeanDefinition(TestBean.class, new MutablePropertyValues(m))); bd2.setPropertyValues(new MutablePropertyValues(m));
parent.registerBeanDefinition("rod", bd2);
this.factory = new XmlBeanFactory(new ClassPathResource("test.xml", getClass()), parent); this.factory = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(this.factory).loadBeanDefinitions(
new ClassPathResource("test.xml", getClass()));
this.factory.addBeanPostProcessor(new BeanPostProcessor() { this.factory.addBeanPostProcessor(new BeanPostProcessor() {
@Override @Override
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException { public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
@ -106,7 +108,7 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
public void testDescriptionButNoProperties() throws Exception { public void testDescriptionButNoProperties() throws Exception {
TestBean validEmpty = (TestBean) getBeanFactory().getBean("validEmptyWithDescription"); TestBean validEmpty = (TestBean) getBeanFactory().getBean("validEmptyWithDescription");
Assert.assertEquals(0, validEmpty.getAge()); assertEquals(0, validEmpty.getAge());
} }
/** /**
@ -117,94 +119,94 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
TestBean tb1 = (TestBean) getBeanFactory().getBean("aliased"); TestBean tb1 = (TestBean) getBeanFactory().getBean("aliased");
TestBean alias1 = (TestBean) getBeanFactory().getBean("myalias"); TestBean alias1 = (TestBean) getBeanFactory().getBean("myalias");
Assert.assertTrue(tb1 == alias1); assertTrue(tb1 == alias1);
List tb1Aliases = Arrays.asList(getBeanFactory().getAliases("aliased")); List tb1Aliases = Arrays.asList(getBeanFactory().getAliases("aliased"));
Assert.assertEquals(2, tb1Aliases.size()); assertEquals(2, tb1Aliases.size());
Assert.assertTrue(tb1Aliases.contains("myalias")); assertTrue(tb1Aliases.contains("myalias"));
Assert.assertTrue(tb1Aliases.contains("youralias")); assertTrue(tb1Aliases.contains("youralias"));
Assert.assertTrue(beanNames.contains("aliased")); assertTrue(beanNames.contains("aliased"));
Assert.assertFalse(beanNames.contains("myalias")); assertFalse(beanNames.contains("myalias"));
Assert.assertFalse(beanNames.contains("youralias")); assertFalse(beanNames.contains("youralias"));
TestBean tb2 = (TestBean) getBeanFactory().getBean("multiAliased"); TestBean tb2 = (TestBean) getBeanFactory().getBean("multiAliased");
TestBean alias2 = (TestBean) getBeanFactory().getBean("alias1"); TestBean alias2 = (TestBean) getBeanFactory().getBean("alias1");
TestBean alias3 = (TestBean) getBeanFactory().getBean("alias2"); TestBean alias3 = (TestBean) getBeanFactory().getBean("alias2");
TestBean alias3a = (TestBean) getBeanFactory().getBean("alias3"); TestBean alias3a = (TestBean) getBeanFactory().getBean("alias3");
TestBean alias3b = (TestBean) getBeanFactory().getBean("alias4"); TestBean alias3b = (TestBean) getBeanFactory().getBean("alias4");
Assert.assertTrue(tb2 == alias2); assertTrue(tb2 == alias2);
Assert.assertTrue(tb2 == alias3); assertTrue(tb2 == alias3);
Assert.assertTrue(tb2 == alias3a); assertTrue(tb2 == alias3a);
Assert.assertTrue(tb2 == alias3b); assertTrue(tb2 == alias3b);
List tb2Aliases = Arrays.asList(getBeanFactory().getAliases("multiAliased")); List tb2Aliases = Arrays.asList(getBeanFactory().getAliases("multiAliased"));
Assert.assertEquals(4, tb2Aliases.size()); assertEquals(4, tb2Aliases.size());
Assert.assertTrue(tb2Aliases.contains("alias1")); assertTrue(tb2Aliases.contains("alias1"));
Assert.assertTrue(tb2Aliases.contains("alias2")); assertTrue(tb2Aliases.contains("alias2"));
Assert.assertTrue(tb2Aliases.contains("alias3")); assertTrue(tb2Aliases.contains("alias3"));
Assert.assertTrue(tb2Aliases.contains("alias4")); assertTrue(tb2Aliases.contains("alias4"));
Assert.assertTrue(beanNames.contains("multiAliased")); assertTrue(beanNames.contains("multiAliased"));
Assert.assertFalse(beanNames.contains("alias1")); assertFalse(beanNames.contains("alias1"));
Assert.assertFalse(beanNames.contains("alias2")); assertFalse(beanNames.contains("alias2"));
Assert.assertFalse(beanNames.contains("alias3")); assertFalse(beanNames.contains("alias3"));
Assert.assertFalse(beanNames.contains("alias4")); assertFalse(beanNames.contains("alias4"));
TestBean tb3 = (TestBean) getBeanFactory().getBean("aliasWithoutId1"); TestBean tb3 = (TestBean) getBeanFactory().getBean("aliasWithoutId1");
TestBean alias4 = (TestBean) getBeanFactory().getBean("aliasWithoutId2"); TestBean alias4 = (TestBean) getBeanFactory().getBean("aliasWithoutId2");
TestBean alias5 = (TestBean) getBeanFactory().getBean("aliasWithoutId3"); TestBean alias5 = (TestBean) getBeanFactory().getBean("aliasWithoutId3");
Assert.assertTrue(tb3 == alias4); assertTrue(tb3 == alias4);
Assert.assertTrue(tb3 == alias5); assertTrue(tb3 == alias5);
List tb3Aliases = Arrays.asList(getBeanFactory().getAliases("aliasWithoutId1")); List tb3Aliases = Arrays.asList(getBeanFactory().getAliases("aliasWithoutId1"));
Assert.assertEquals(2, tb3Aliases.size()); assertEquals(2, tb3Aliases.size());
Assert.assertTrue(tb3Aliases.contains("aliasWithoutId2")); assertTrue(tb3Aliases.contains("aliasWithoutId2"));
Assert.assertTrue(tb3Aliases.contains("aliasWithoutId3")); assertTrue(tb3Aliases.contains("aliasWithoutId3"));
Assert.assertTrue(beanNames.contains("aliasWithoutId1")); assertTrue(beanNames.contains("aliasWithoutId1"));
Assert.assertFalse(beanNames.contains("aliasWithoutId2")); assertFalse(beanNames.contains("aliasWithoutId2"));
Assert.assertFalse(beanNames.contains("aliasWithoutId3")); assertFalse(beanNames.contains("aliasWithoutId3"));
TestBean tb4 = (TestBean) getBeanFactory().getBean(TestBean.class.getName() + "#0"); TestBean tb4 = (TestBean) getBeanFactory().getBean(TestBean.class.getName() + "#0");
Assert.assertEquals(null, tb4.getName()); assertEquals(null, tb4.getName());
Map drs = getListableBeanFactory().getBeansOfType(DummyReferencer.class, false, false); Map drs = getListableBeanFactory().getBeansOfType(DummyReferencer.class, false, false);
Assert.assertEquals(5, drs.size()); assertEquals(5, drs.size());
Assert.assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#0")); assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#0"));
Assert.assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#1")); assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#1"));
Assert.assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#2")); assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#2"));
} }
public void testFactoryNesting() { public void testFactoryNesting() {
ITestBean father = (ITestBean) getBeanFactory().getBean("father"); ITestBean father = (ITestBean) getBeanFactory().getBean("father");
Assert.assertTrue("Bean from root context", father != null); assertTrue("Bean from root context", father != null);
TestBean rod = (TestBean) getBeanFactory().getBean("rod"); TestBean rod = (TestBean) getBeanFactory().getBean("rod");
Assert.assertTrue("Bean from child context", "Rod".equals(rod.getName())); assertTrue("Bean from child context", "Rod".equals(rod.getName()));
Assert.assertTrue("Bean has external reference", rod.getSpouse() == father); assertTrue("Bean has external reference", rod.getSpouse() == father);
rod = (TestBean) parent.getBean("rod"); rod = (TestBean) parent.getBean("rod");
Assert.assertTrue("Bean from root context", "Roderick".equals(rod.getName())); assertTrue("Bean from root context", "Roderick".equals(rod.getName()));
} }
public void testFactoryReferences() { public void testFactoryReferences() {
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory"); DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
DummyReferencer ref = (DummyReferencer) getBeanFactory().getBean("factoryReferencer"); DummyReferencer ref = (DummyReferencer) getBeanFactory().getBean("factoryReferencer");
Assert.assertTrue(ref.getTestBean1() == ref.getTestBean2()); assertTrue(ref.getTestBean1() == ref.getTestBean2());
Assert.assertTrue(ref.getDummyFactory() == factory); assertTrue(ref.getDummyFactory() == factory);
DummyReferencer ref2 = (DummyReferencer) getBeanFactory().getBean("factoryReferencerWithConstructor"); DummyReferencer ref2 = (DummyReferencer) getBeanFactory().getBean("factoryReferencerWithConstructor");
Assert.assertTrue(ref2.getTestBean1() == ref2.getTestBean2()); assertTrue(ref2.getTestBean1() == ref2.getTestBean2());
Assert.assertTrue(ref2.getDummyFactory() == factory); assertTrue(ref2.getDummyFactory() == factory);
} }
public void testPrototypeReferences() { public void testPrototypeReferences() {
// check that not broken by circular reference resolution mechanism // check that not broken by circular reference resolution mechanism
DummyReferencer ref1 = (DummyReferencer) getBeanFactory().getBean("prototypeReferencer"); DummyReferencer ref1 = (DummyReferencer) getBeanFactory().getBean("prototypeReferencer");
Assert.assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref1.getTestBean2()); assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref1.getTestBean2());
DummyReferencer ref2 = (DummyReferencer) getBeanFactory().getBean("prototypeReferencer"); DummyReferencer ref2 = (DummyReferencer) getBeanFactory().getBean("prototypeReferencer");
Assert.assertTrue("Not the same referencer", ref1 != ref2); assertTrue("Not the same referencer", ref1 != ref2);
Assert.assertTrue("Not referencing same bean twice", ref2.getTestBean1() != ref2.getTestBean2()); assertTrue("Not referencing same bean twice", ref2.getTestBean1() != ref2.getTestBean2());
Assert.assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref2.getTestBean1()); assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref2.getTestBean1());
Assert.assertTrue("Not referencing same bean twice", ref1.getTestBean2() != ref2.getTestBean2()); assertTrue("Not referencing same bean twice", ref1.getTestBean2() != ref2.getTestBean2());
Assert.assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref2.getTestBean2()); assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref2.getTestBean2());
} }
public void testBeanPostProcessor() throws Exception { public void testBeanPostProcessor() throws Exception {
@ -212,22 +214,22 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
TestBean kathy = (TestBean) getBeanFactory().getBean("kathy"); TestBean kathy = (TestBean) getBeanFactory().getBean("kathy");
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory"); DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
TestBean factoryCreated = (TestBean) getBeanFactory().getBean("singletonFactory"); TestBean factoryCreated = (TestBean) getBeanFactory().getBean("singletonFactory");
Assert.assertTrue(kerry.isPostProcessed()); assertTrue(kerry.isPostProcessed());
Assert.assertTrue(kathy.isPostProcessed()); assertTrue(kathy.isPostProcessed());
Assert.assertTrue(factory.isPostProcessed()); assertTrue(factory.isPostProcessed());
Assert.assertTrue(factoryCreated.isPostProcessed()); assertTrue(factoryCreated.isPostProcessed());
} }
public void testEmptyValues() { public void testEmptyValues() {
TestBean rod = (TestBean) getBeanFactory().getBean("rod"); TestBean rod = (TestBean) getBeanFactory().getBean("rod");
TestBean kerry = (TestBean) getBeanFactory().getBean("kerry"); TestBean kerry = (TestBean) getBeanFactory().getBean("kerry");
Assert.assertTrue("Touchy is empty", "".equals(rod.getTouchy())); assertTrue("Touchy is empty", "".equals(rod.getTouchy()));
Assert.assertTrue("Touchy is empty", "".equals(kerry.getTouchy())); assertTrue("Touchy is empty", "".equals(kerry.getTouchy()));
} }
public void testCommentsAndCdataInValue() { public void testCommentsAndCdataInValue() {
TestBean bean = (TestBean) getBeanFactory().getBean("commentsInValue"); TestBean bean = (TestBean) getBeanFactory().getBean("commentsInValue");
Assert.assertEquals("Failed to handle comments and CDATA properly", "this is a <!--comment-->", bean.getName()); assertEquals("Failed to handle comments and CDATA properly", "this is a <!--comment-->", bean.getName());
} }
} }

View File

@ -20,8 +20,10 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import javax.activation.FileTypeMap; import javax.activation.FileTypeMap;
import javax.mail.Address; import javax.mail.Address;
import javax.mail.Message; import javax.mail.Message;
@ -59,7 +61,7 @@ public class JavaMailSenderTests extends TestCase {
simpleMessage.setTo("you@mail.org"); simpleMessage.setTo("you@mail.org");
simpleMessage.setCc(new String[] {"he@mail.org", "she@mail.org"}); simpleMessage.setCc(new String[] {"he@mail.org", "she@mail.org"});
simpleMessage.setBcc(new String[] {"us@mail.org", "them@mail.org"}); simpleMessage.setBcc(new String[] {"us@mail.org", "them@mail.org"});
Date sentDate = new Date(2004, 1, 1); Date sentDate = new GregorianCalendar(2004, 1, 1).getTime();
simpleMessage.setSentDate(sentDate); simpleMessage.setSentDate(sentDate);
simpleMessage.setSubject("my subject"); simpleMessage.setSubject("my subject");
simpleMessage.setText("my text"); simpleMessage.setText("my text");
@ -334,7 +336,7 @@ public class JavaMailSenderTests extends TestCase {
MimeMessage mimeMessage = sender.createMimeMessage(); MimeMessage mimeMessage = sender.createMimeMessage();
mimeMessage.setSubject("custom"); mimeMessage.setSubject("custom");
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("you@mail.org")); mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("you@mail.org"));
mimeMessage.setSentDate(new Date(2005, 3, 1)); mimeMessage.setSentDate(new GregorianCalendar(2005, 3, 1).getTime());
sender.send(mimeMessage); sender.send(mimeMessage);
assertEquals("host", sender.transport.getConnectedHost()); assertEquals("host", sender.transport.getConnectedHost());
@ -559,7 +561,7 @@ public class JavaMailSenderTests extends TestCase {
throw new MessagingException("No sentDate specified"); throw new MessagingException("No sentDate specified");
} }
if (message.getSubject() != null && message.getSubject().contains("custom")) { if (message.getSubject() != null && message.getSubject().contains("custom")) {
assertEquals(new Date(2005, 3, 1), message.getSentDate()); assertEquals(new GregorianCalendar(2005, 3, 1).getTime(), message.getSentDate());
} }
this.sentMessages.add(message); this.sentMessages.add(message);
} }

View File

@ -51,17 +51,18 @@ import org.quartz.Trigger;
import org.quartz.TriggerListener; import org.quartz.TriggerListener;
import org.quartz.impl.SchedulerRepository; import org.quartz.impl.SchedulerRepository;
import org.quartz.spi.JobFactory; import org.quartz.spi.JobFactory;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.support.StaticListableBeanFactory; import org.springframework.beans.factory.support.StaticListableBeanFactory;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.StaticApplicationContext; import org.springframework.context.support.StaticApplicationContext;
import org.springframework.core.io.FileSystemResourceLoader; import org.springframework.core.io.FileSystemResourceLoader;
import org.springframework.core.task.TaskExecutor; import org.springframework.core.task.TaskExecutor;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.TestMethodInvokingTask; import org.springframework.scheduling.TestMethodInvokingTask;
/** /**
@ -964,12 +965,14 @@ public class QuartzSupportTests {
// SPR-6038: detect HSQL and stop illegal locks being taken // SPR-6038: detect HSQL and stop illegal locks being taken
@Test @Test
public void testSchedulerWithHsqlDataSource() throws Exception { public void testSchedulerWithHsqlDataSource() throws Exception {
Assume.group(TestGroup.PERFORMANCE);
DummyJob.param = 0; DummyJob.param = 0;
DummyJob.count = 0; DummyJob.count = 0;
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
"/org/springframework/scheduling/quartz/databasePersistence.xml"); "/org/springframework/scheduling/quartz/databasePersistence.xml");
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(ctx.getBean(DataSource.class)); JdbcTemplate jdbcTemplate = new JdbcTemplate(ctx.getBean(DataSource.class));
assertTrue("No triggers were persisted", jdbcTemplate.queryForList("SELECT * FROM qrtz_triggers").size()>0); assertTrue("No triggers were persisted", jdbcTemplate.queryForList("SELECT * FROM qrtz_triggers").size()>0);
Thread.sleep(3000); Thread.sleep(3000);
try { try {

View File

@ -198,7 +198,7 @@ public class JasperReportsUtilsTests extends TestCase {
HSSFRow row = sheet.getRow(3); HSSFRow row = sheet.getRow(3);
HSSFCell cell = row.getCell((short) 1); HSSFCell cell = row.getCell((short) 1);
assertNotNull("Cell should not be null", cell); assertNotNull("Cell should not be null", cell);
assertEquals("Cell content should be Dear Lord!", "Dear Lord!", cell.getStringCellValue()); assertEquals("Cell content should be Dear Lord!", "Dear Lord!", cell.getRichStringCellValue().getString());
} }
private JasperReport getReport() throws Exception { private JasperReport getReport() throws Exception {

View File

@ -56,6 +56,7 @@ import org.springframework.instrument.classloading.websphere.WebSphereLoadTimeWe
* @since 2.5 * @since 2.5
* @see org.springframework.context.ConfigurableApplicationContext#LOAD_TIME_WEAVER_BEAN_NAME * @see org.springframework.context.ConfigurableApplicationContext#LOAD_TIME_WEAVER_BEAN_NAME
*/ */
@SuppressWarnings("deprecation")
public class DefaultContextLoadTimeWeaver implements LoadTimeWeaver, BeanClassLoaderAware, DisposableBean { public class DefaultContextLoadTimeWeaver implements LoadTimeWeaver, BeanClassLoaderAware, DisposableBean {
protected final Log logger = LogFactory.getLog(getClass()); protected final Log logger = LogFactory.getLog(getClass());

View File

@ -99,6 +99,7 @@ class ScriptBeanDefinitionParser extends AbstractBeanDefinitionParser {
* Registers a {@link ScriptFactoryPostProcessor} if needed. * Registers a {@link ScriptFactoryPostProcessor} if needed.
*/ */
@Override @Override
@SuppressWarnings("deprecation")
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
// Resolve the script source. // Resolve the script source.
String value = resolveScriptSource(element, parserContext.getReaderContext()); String value = resolveScriptSource(element, parserContext.getReaderContext());

View File

@ -75,6 +75,7 @@ public abstract class JRubyScriptUtils {
* @return the scripted Java object * @return the scripted Java object
* @throws JumpException in case of JRuby parsing failure * @throws JumpException in case of JRuby parsing failure
*/ */
@SuppressWarnings("deprecation")
public static Object createJRubyObject(String scriptSource, Class[] interfaces, ClassLoader classLoader) { public static Object createJRubyObject(String scriptSource, Class[] interfaces, ClassLoader classLoader) {
Ruby ruby = initializeRuntime(); Ruby ruby = initializeRuntime();

View File

@ -51,8 +51,8 @@ import org.springframework.beans.factory.config.MethodInvokingFactoryBean;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.build.junit.Assume; import org.springframework.tests.Assume;
import org.springframework.build.junit.TestGroup; import org.springframework.tests.TestGroup;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext; import org.springframework.context.support.GenericApplicationContext;

View File

@ -16,8 +16,16 @@
package org.springframework.aop.framework; package org.springframework.aop.framework;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.*; import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
@ -45,10 +53,10 @@ import org.springframework.beans.TestBean;
import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.TestListener; import org.springframework.context.TestListener;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
@ -56,14 +64,13 @@ import org.springframework.util.SerializationTestUtils;
import test.advice.CountingBeforeAdvice; import test.advice.CountingBeforeAdvice;
import test.advice.MyThrowsHandler; import test.advice.MyThrowsHandler;
import test.beans.SideEffectBean;
import test.interceptor.NopInterceptor; import test.interceptor.NopInterceptor;
import test.interceptor.TimestampIntroductionInterceptor; import test.interceptor.TimestampIntroductionInterceptor;
import test.mixin.Lockable; import test.mixin.Lockable;
import test.mixin.LockedException; import test.mixin.LockedException;
import test.util.TimeStamped; import test.util.TimeStamped;
import test.beans.SideEffectBean;
/** /**
* @since 13.03.2003 * @since 13.03.2003
* @author Rod Johnson * @author Rod Johnson
@ -93,7 +100,9 @@ public final class ProxyFactoryBeanTests {
public void setUp() throws Exception { public void setUp() throws Exception {
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
parent.registerBeanDefinition("target2", new RootBeanDefinition(TestListener.class)); parent.registerBeanDefinition("target2", new RootBeanDefinition(TestListener.class));
this.factory = new XmlBeanFactory(new ClassPathResource(CONTEXT, getClass()), parent); this.factory = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.factory).loadBeanDefinitions(
new ClassPathResource(CONTEXT, getClass()));
} }
@Test @Test
@ -133,7 +142,8 @@ public final class ProxyFactoryBeanTests {
private void testDoubleTargetSourceIsRejected(String name) { private void testDoubleTargetSourceIsRejected(String name) {
try { try {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource(DBL_TARGETSOURCE_CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(DBL_TARGETSOURCE_CONTEXT, CLASS));
bf.getBean(name); bf.getBean(name);
fail("Should not allow TargetSource to be specified in interceptorNames as well as targetSource property"); fail("Should not allow TargetSource to be specified in interceptorNames as well as targetSource property");
} }
@ -147,7 +157,8 @@ public final class ProxyFactoryBeanTests {
@Test @Test
public void testTargetSourceNotAtEndOfInterceptorNamesIsRejected() { public void testTargetSourceNotAtEndOfInterceptorNamesIsRejected() {
try { try {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource(NOTLAST_TARGETSOURCE_CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(NOTLAST_TARGETSOURCE_CONTEXT, CLASS));
bf.getBean("targetSourceNotLast"); bf.getBean("targetSourceNotLast");
fail("TargetSource or non-advised object must be last in interceptorNames"); fail("TargetSource or non-advised object must be last in interceptorNames");
} }
@ -160,7 +171,8 @@ public final class ProxyFactoryBeanTests {
@Test @Test
public void testGetObjectTypeWithDirectTarget() { public void testGetObjectTypeWithDirectTarget() {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS));
// We have a counting before advice here // We have a counting before advice here
CountingBeforeAdvice cba = (CountingBeforeAdvice) bf.getBean("countingBeforeAdvice"); CountingBeforeAdvice cba = (CountingBeforeAdvice) bf.getBean("countingBeforeAdvice");
@ -176,7 +188,8 @@ public final class ProxyFactoryBeanTests {
@Test @Test
public void testGetObjectTypeWithTargetViaTargetSource() { public void testGetObjectTypeWithTargetViaTargetSource() {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS));
ITestBean tb = (ITestBean) bf.getBean("viaTargetSource"); ITestBean tb = (ITestBean) bf.getBean("viaTargetSource");
assertTrue(tb.getName().equals("Adam")); assertTrue(tb.getName().equals("Adam"));
ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&viaTargetSource"); ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&viaTargetSource");
@ -185,7 +198,8 @@ public final class ProxyFactoryBeanTests {
@Test @Test
public void testGetObjectTypeWithNoTargetOrTargetSource() { public void testGetObjectTypeWithNoTargetOrTargetSource() {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS));
ITestBean tb = (ITestBean) bf.getBean("noTarget"); ITestBean tb = (ITestBean) bf.getBean("noTarget");
try { try {
@ -246,7 +260,8 @@ public final class ProxyFactoryBeanTests {
// Initial count value set in bean factory XML // Initial count value set in bean factory XML
int INITIAL_COUNT = 10; int INITIAL_COUNT = 10;
BeanFactory bf = new XmlBeanFactory(new ClassPathResource(PROTOTYPE_CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(PROTOTYPE_CONTEXT, CLASS));
// Check it works without AOP // Check it works without AOP
SideEffectBean raw = (SideEffectBean) bf.getBean("prototypeTarget"); SideEffectBean raw = (SideEffectBean) bf.getBean("prototypeTarget");
@ -338,7 +353,8 @@ public final class ProxyFactoryBeanTests {
*/ */
@Test @Test
public void testTargetAsInnerBean() { public void testTargetAsInnerBean() {
ListableBeanFactory bf = new XmlBeanFactory(new ClassPathResource(INNER_BEAN_TARGET_CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(INNER_BEAN_TARGET_CONTEXT, CLASS));
ITestBean itb = (ITestBean) bf.getBean("testBean"); ITestBean itb = (ITestBean) bf.getBean("testBean");
assertEquals("innerBeanTarget", itb.getName()); assertEquals("innerBeanTarget", itb.getName());
assertEquals("Only have proxy and interceptor: no target", 3, bf.getBeanDefinitionCount()); assertEquals("Only have proxy and interceptor: no target", 3, bf.getBeanDefinitionCount());
@ -441,7 +457,8 @@ public final class ProxyFactoryBeanTests {
@Test @Test
public void testCanAddThrowsAdviceWithoutAdvisor() throws Throwable { public void testCanAddThrowsAdviceWithoutAdvisor() throws Throwable {
BeanFactory f = new XmlBeanFactory(new ClassPathResource(THROWS_ADVICE_CONTEXT, CLASS)); DefaultListableBeanFactory f = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(f).loadBeanDefinitions(new ClassPathResource(THROWS_ADVICE_CONTEXT, CLASS));
MyThrowsHandler th = (MyThrowsHandler) f.getBean("throwsAdvice"); MyThrowsHandler th = (MyThrowsHandler) f.getBean("throwsAdvice");
CountingBeforeAdvice cba = (CountingBeforeAdvice) f.getBean("countingBeforeAdvice"); CountingBeforeAdvice cba = (CountingBeforeAdvice) f.getBean("countingBeforeAdvice");
assertEquals(0, cba.getCalls()); assertEquals(0, cba.getCalls());
@ -498,9 +515,10 @@ public final class ProxyFactoryBeanTests {
@Test @Test
public void testEmptyInterceptorNames() { public void testEmptyInterceptorNames() {
XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource(INVALID_CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(INVALID_CONTEXT, CLASS));
try { try {
factory.getBean("emptyInterceptorNames"); bf.getBean("emptyInterceptorNames");
fail("Interceptor names cannot be empty"); fail("Interceptor names cannot be empty");
} }
catch (BeanCreationException ex) { catch (BeanCreationException ex) {
@ -513,9 +531,10 @@ public final class ProxyFactoryBeanTests {
*/ */
@Test @Test
public void testGlobalsWithoutTarget() { public void testGlobalsWithoutTarget() {
XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource(INVALID_CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(INVALID_CONTEXT, CLASS));
try { try {
factory.getBean("globalsWithoutTarget"); bf.getBean("globalsWithoutTarget");
fail("Should require target name"); fail("Should require target name");
} }
catch (BeanCreationException ex) { catch (BeanCreationException ex) {
@ -554,7 +573,8 @@ public final class ProxyFactoryBeanTests {
@Test @Test
public void testSerializableSingletonProxy() throws Exception { public void testSerializableSingletonProxy() throws Exception {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
Person p = (Person) bf.getBean("serializableSingleton"); Person p = (Person) bf.getBean("serializableSingleton");
assertSame("Should be a Singleton", p, bf.getBean("serializableSingleton")); assertSame("Should be a Singleton", p, bf.getBean("serializableSingleton"));
Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p); Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
@ -576,7 +596,8 @@ public final class ProxyFactoryBeanTests {
@Test @Test
public void testSerializablePrototypeProxy() throws Exception { public void testSerializablePrototypeProxy() throws Exception {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
Person p = (Person) bf.getBean("serializablePrototype"); Person p = (Person) bf.getBean("serializablePrototype");
assertNotSame("Should not be a Singleton", p, bf.getBean("serializablePrototype")); assertNotSame("Should not be a Singleton", p, bf.getBean("serializablePrototype"));
Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p); Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
@ -587,7 +608,8 @@ public final class ProxyFactoryBeanTests {
@Test @Test
public void testSerializableSingletonProxyFactoryBean() throws Exception { public void testSerializableSingletonProxyFactoryBean() throws Exception {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
Person p = (Person) bf.getBean("serializableSingleton"); Person p = (Person) bf.getBean("serializableSingleton");
ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&serializableSingleton"); ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&serializableSingleton");
ProxyFactoryBean pfb2 = (ProxyFactoryBean) SerializationTestUtils.serializeAndDeserialize(pfb); ProxyFactoryBean pfb2 = (ProxyFactoryBean) SerializationTestUtils.serializeAndDeserialize(pfb);
@ -599,14 +621,16 @@ public final class ProxyFactoryBeanTests {
@Test @Test
public void testProxyNotSerializableBecauseOfAdvice() throws Exception { public void testProxyNotSerializableBecauseOfAdvice() throws Exception {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
Person p = (Person) bf.getBean("interceptorNotSerializableSingleton"); Person p = (Person) bf.getBean("interceptorNotSerializableSingleton");
assertFalse("Not serializable because an interceptor isn't serializable", SerializationTestUtils.isSerializable(p)); assertFalse("Not serializable because an interceptor isn't serializable", SerializationTestUtils.isSerializable(p));
} }
@Test @Test
public void testPrototypeAdvisor() { public void testPrototypeAdvisor() {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource(CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(CONTEXT, CLASS));
ITestBean bean1 = (ITestBean) bf.getBean("prototypeTestBeanProxy"); ITestBean bean1 = (ITestBean) bf.getBean("prototypeTestBeanProxy");
ITestBean bean2 = (ITestBean) bf.getBean("prototypeTestBeanProxy"); ITestBean bean2 = (ITestBean) bf.getBean("prototypeTestBeanProxy");
@ -637,7 +661,8 @@ public final class ProxyFactoryBeanTests {
@Test @Test
public void testPrototypeInterceptorSingletonTarget() { public void testPrototypeInterceptorSingletonTarget() {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource(CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(CONTEXT, CLASS));
ITestBean bean1 = (ITestBean) bf.getBean("prototypeTestBeanProxySingletonTarget"); ITestBean bean1 = (ITestBean) bf.getBean("prototypeTestBeanProxySingletonTarget");
ITestBean bean2 = (ITestBean) bf.getBean("prototypeTestBeanProxySingletonTarget"); ITestBean bean2 = (ITestBean) bf.getBean("prototypeTestBeanProxySingletonTarget");
@ -671,13 +696,15 @@ public final class ProxyFactoryBeanTests {
*/ */
@Test @Test
public void testInnerBeanTargetUsingAutowiring() { public void testInnerBeanTargetUsingAutowiring() {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource(AUTOWIRING_CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(AUTOWIRING_CONTEXT, CLASS));
bf.getBean("testBean"); bf.getBean("testBean");
} }
@Test @Test
public void testFrozenFactoryBean() { public void testFrozenFactoryBean() {
BeanFactory bf = new XmlBeanFactory(new ClassPathResource(FROZEN_CONTEXT, CLASS)); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(FROZEN_CONTEXT, CLASS));
Advised advised = (Advised)bf.getBean("frozen"); Advised advised = (Advised)bf.getBean("frozen");
assertTrue("The proxy should be frozen", advised.isFrozen()); assertTrue("The proxy should be frozen", advised.isFrozen());

View File

@ -55,7 +55,8 @@ public final class AutoProxyCreatorTests {
proxyCreator.getPropertyValues().add("beanNames", "singletonToBeProxied,innerBean,singletonFactoryToBeProxied"); proxyCreator.getPropertyValues().add("beanNames", "singletonToBeProxied,innerBean,singletonFactoryToBeProxied");
sac.getDefaultListableBeanFactory().registerBeanDefinition("beanNameAutoProxyCreator", proxyCreator); sac.getDefaultListableBeanFactory().registerBeanDefinition("beanNameAutoProxyCreator", proxyCreator);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
RootBeanDefinition innerBean = new RootBeanDefinition(TestBean.class); RootBeanDefinition innerBean = new RootBeanDefinition(TestBean.class);
bd.getPropertyValues().add("spouse", new BeanDefinitionHolder(innerBean, "innerBean")); bd.getPropertyValues().add("spouse", new BeanDefinitionHolder(innerBean, "innerBean"));
sac.getDefaultListableBeanFactory().registerBeanDefinition("singletonToBeProxied", bd); sac.getDefaultListableBeanFactory().registerBeanDefinition("singletonToBeProxied", bd);

View File

@ -16,19 +16,21 @@
package org.springframework.aop.scope; package org.springframework.aop.scope;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.*;
import org.junit.Test; import org.junit.Test;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
import org.springframework.beans.ITestBean; import org.springframework.beans.ITestBean;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import org.springframework.beans.factory.config.SimpleMapScope; import org.springframework.beans.factory.config.SimpleMapScope;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.support.GenericApplicationContext; import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.util.SerializationTestUtils; import org.springframework.util.SerializationTestUtils;
@ -51,14 +53,16 @@ public class ScopedProxyTests {
/* SPR-2108 */ /* SPR-2108 */
@Test @Test
public void testProxyAssignable() throws Exception { public void testProxyAssignable() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(MAP_CONTEXT); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(MAP_CONTEXT);
Object baseMap = bf.getBean("singletonMap"); Object baseMap = bf.getBean("singletonMap");
assertTrue(baseMap instanceof Map); assertTrue(baseMap instanceof Map);
} }
@Test @Test
public void testSimpleProxy() throws Exception { public void testSimpleProxy() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(MAP_CONTEXT); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(MAP_CONTEXT);
Object simpleMap = bf.getBean("simpleMap"); Object simpleMap = bf.getBean("simpleMap");
assertTrue(simpleMap instanceof Map); assertTrue(simpleMap instanceof Map);
assertTrue(simpleMap instanceof HashMap); assertTrue(simpleMap instanceof HashMap);
@ -82,7 +86,8 @@ public class ScopedProxyTests {
@Test @Test
public void testJdkScopedProxy() throws Exception { public void testJdkScopedProxy() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(TESTBEAN_CONTEXT); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(TESTBEAN_CONTEXT);
bf.setSerializationId("X"); bf.setSerializationId("X");
SimpleMapScope scope = new SimpleMapScope(); SimpleMapScope scope = new SimpleMapScope();
bf.registerScope("request", scope); bf.registerScope("request", scope);
@ -111,7 +116,8 @@ public class ScopedProxyTests {
@Test @Test
public void testCglibScopedProxy() throws Exception { public void testCglibScopedProxy() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(LIST_CONTEXT); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(LIST_CONTEXT);
bf.setSerializationId("Y"); bf.setSerializationId("Y");
SimpleMapScope scope = new SimpleMapScope(); SimpleMapScope scope = new SimpleMapScope();
bf.registerScope("request", scope); bf.registerScope("request", scope);

View File

@ -16,7 +16,10 @@
package org.springframework.aop.target; package org.springframework.aop.target;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -27,7 +30,8 @@ import org.junit.Test;
import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.Advised;
import org.springframework.beans.Person; import org.springframework.beans.Person;
import org.springframework.beans.SerializablePerson; import org.springframework.beans.SerializablePerson;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.StaticApplicationContext; import org.springframework.context.support.StaticApplicationContext;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.util.SerializationTestUtils; import org.springframework.util.SerializationTestUtils;
@ -50,11 +54,13 @@ public class CommonsPoolTargetSourceTests {
*/ */
private static final int INITIAL_COUNT = 10; private static final int INITIAL_COUNT = 10;
private XmlBeanFactory beanFactory; private DefaultListableBeanFactory beanFactory;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
this.beanFactory = new XmlBeanFactory(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass())); this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass()));
} }
/** /**

View File

@ -20,7 +20,6 @@ import java.beans.PropertyEditorSupport;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.Assert;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyBatchUpdateException; import org.springframework.beans.PropertyBatchUpdateException;
@ -79,7 +78,7 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
*/ */
public void testLifecycleCallbacks() { public void testLifecycleCallbacks() {
LifecycleBean lb = (LifecycleBean) getBeanFactory().getBean("lifecycle"); LifecycleBean lb = (LifecycleBean) getBeanFactory().getBean("lifecycle");
Assert.assertEquals("lifecycle", lb.getBeanName()); assertEquals("lifecycle", lb.getBeanName());
// The dummy business method will throw an exception if the // The dummy business method will throw an exception if the
// necessary callbacks weren't invoked in the right order. // necessary callbacks weren't invoked in the right order.
lb.businessMethod(); lb.businessMethod();
@ -327,4 +326,4 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,8 +16,6 @@
package org.springframework.beans.factory; package org.springframework.beans.factory;
import junit.framework.Assert;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
/** /**
@ -44,24 +42,24 @@ public abstract class AbstractListableBeanFactoryTests extends AbstractBeanFacto
protected final void assertCount(int count) { protected final void assertCount(int count) {
String[] defnames = getListableBeanFactory().getBeanDefinitionNames(); String[] defnames = getListableBeanFactory().getBeanDefinitionNames();
Assert.assertTrue("We should have " + count + " beans, not " + defnames.length, defnames.length == count); assertTrue("We should have " + count + " beans, not " + defnames.length, defnames.length == count);
} }
public void assertTestBeanCount(int count) { public void assertTestBeanCount(int count) {
String[] defNames = getListableBeanFactory().getBeanNamesForType(TestBean.class, true, false); String[] defNames = getListableBeanFactory().getBeanNamesForType(TestBean.class, true, false);
Assert.assertTrue("We should have " + count + " beans for class org.springframework.beans.TestBean, not " + assertTrue("We should have " + count + " beans for class org.springframework.beans.TestBean, not " +
defNames.length, defNames.length == count); defNames.length, defNames.length == count);
int countIncludingFactoryBeans = count + 2; int countIncludingFactoryBeans = count + 2;
String[] names = getListableBeanFactory().getBeanNamesForType(TestBean.class, true, true); String[] names = getListableBeanFactory().getBeanNamesForType(TestBean.class, true, true);
Assert.assertTrue("We should have " + countIncludingFactoryBeans + assertTrue("We should have " + countIncludingFactoryBeans +
" beans for class org.springframework.beans.TestBean, not " + names.length, " beans for class org.springframework.beans.TestBean, not " + names.length,
names.length == countIncludingFactoryBeans); names.length == countIncludingFactoryBeans);
} }
public void testGetDefinitionsForNoSuchClass() { public void testGetDefinitionsForNoSuchClass() {
String[] defnames = getListableBeanFactory().getBeanNamesForType(String.class); String[] defnames = getListableBeanFactory().getBeanNamesForType(String.class);
Assert.assertTrue("No string definitions", defnames.length == 0); assertTrue("No string definitions", defnames.length == 0);
} }
/** /**
@ -69,18 +67,18 @@ public abstract class AbstractListableBeanFactoryTests extends AbstractBeanFacto
* what type factories may return, and it may even change over time.) * what type factories may return, and it may even change over time.)
*/ */
public void testGetCountForFactoryClass() { public void testGetCountForFactoryClass() {
Assert.assertTrue("Should have 2 factories, not " + assertTrue("Should have 2 factories, not " +
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length, getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length,
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2); getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2);
Assert.assertTrue("Should have 2 factories, not " + assertTrue("Should have 2 factories, not " +
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length, getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length,
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2); getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2);
} }
public void testContainsBeanDefinition() { public void testContainsBeanDefinition() {
Assert.assertTrue(getListableBeanFactory().containsBeanDefinition("rod")); assertTrue(getListableBeanFactory().containsBeanDefinition("rod"));
Assert.assertTrue(getListableBeanFactory().containsBeanDefinition("roderick")); assertTrue(getListableBeanFactory().containsBeanDefinition("roderick"));
} }
} }

View File

@ -19,12 +19,11 @@ package org.springframework.beans.factory.parsing;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.core.CollectionFactory;
/** /**
* @author Rob Harrop * @author Rob Harrop
* @author Juergen Hoeller * @author Juergen Hoeller
@ -33,9 +32,9 @@ public class CollectingReaderEventListener implements ReaderEventListener {
private final List<DefaultsDefinition> defaults = new LinkedList<DefaultsDefinition>(); private final List<DefaultsDefinition> defaults = new LinkedList<DefaultsDefinition>();
private final Map<String, ComponentDefinition> componentDefinitions = CollectionFactory.createLinkedMapIfPossible(8); private final Map<String, ComponentDefinition> componentDefinitions = new LinkedHashMap<>(8);
private final Map<String, List<AliasDefinition>> aliasMap = CollectionFactory.createLinkedMapIfPossible(8); private final Map<String, List<AliasDefinition>> aliasMap = new LinkedHashMap<>(8);
private final List<ImportDefinition> imports = new LinkedList<ImportDefinition>(); private final List<ImportDefinition> imports = new LinkedList<ImportDefinition>();

View File

@ -116,7 +116,6 @@ public final class XmlBeanFactoryTests {
private static final ClassPathResource NO_SUCH_FACTORY_METHOD_CONTEXT = classPathResource("-noSuchFactoryMethod.xml"); private static final ClassPathResource NO_SUCH_FACTORY_METHOD_CONTEXT = classPathResource("-noSuchFactoryMethod.xml");
private static final ClassPathResource RECURSIVE_IMPORT_CONTEXT = classPathResource("-recursiveImport.xml"); private static final ClassPathResource RECURSIVE_IMPORT_CONTEXT = classPathResource("-recursiveImport.xml");
private static final ClassPathResource RESOURCE_CONTEXT = classPathResource("-resource.xml"); private static final ClassPathResource RESOURCE_CONTEXT = classPathResource("-resource.xml");
private static final ClassPathResource RESOURCE_IMPORT_CONTEXT = classPathResource("-resourceImport.xml");
private static final ClassPathResource SATISFIED_ALL_DEP_CONTEXT = classPathResource("-satisfiedAllDepCheck.xml"); private static final ClassPathResource SATISFIED_ALL_DEP_CONTEXT = classPathResource("-satisfiedAllDepCheck.xml");
private static final ClassPathResource SATISFIED_OBJECT_DEP_CONTEXT = classPathResource("-satisfiedObjectDepCheck.xml"); private static final ClassPathResource SATISFIED_OBJECT_DEP_CONTEXT = classPathResource("-satisfiedObjectDepCheck.xml");
private static final ClassPathResource SATISFIED_SIMPLE_DEP_CONTEXT = classPathResource("-satisfiedSimpleDepCheck.xml"); private static final ClassPathResource SATISFIED_SIMPLE_DEP_CONTEXT = classPathResource("-satisfiedSimpleDepCheck.xml");
@ -135,7 +134,8 @@ public final class XmlBeanFactoryTests {
/* SPR-2368 */ /* SPR-2368 */
public @Test void testCollectionsReferredToAsRefLocals() throws Exception { public @Test void testCollectionsReferredToAsRefLocals() throws Exception {
XmlBeanFactory factory = new XmlBeanFactory(COLLECTIONS_XSD_CONTEXT); DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(COLLECTIONS_XSD_CONTEXT);
factory.preInstantiateSingletons(); factory.preInstantiateSingletons();
} }
@ -296,8 +296,10 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testInheritanceFromParentFactoryPrototype() throws Exception { public @Test void testInheritanceFromParentFactoryPrototype() throws Exception {
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT); DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent); new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(child).loadBeanDefinitions(CHILD_CONTEXT);
assertEquals(TestBean.class, child.getType("inheritsFromParentFactory")); assertEquals(TestBean.class, child.getType("inheritsFromParentFactory"));
TestBean inherits = (TestBean) child.getBean("inheritsFromParentFactory"); TestBean inherits = (TestBean) child.getBean("inheritsFromParentFactory");
// Name property value is overridden // Name property value is overridden
@ -309,8 +311,10 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testInheritanceWithDifferentClass() throws Exception { public @Test void testInheritanceWithDifferentClass() throws Exception {
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT); DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent); new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(child).loadBeanDefinitions(CHILD_CONTEXT);
assertEquals(DerivedTestBean.class, child.getType("inheritsWithClass")); assertEquals(DerivedTestBean.class, child.getType("inheritsWithClass"));
DerivedTestBean inherits = (DerivedTestBean) child.getBean("inheritsWithDifferentClass"); DerivedTestBean inherits = (DerivedTestBean) child.getBean("inheritsWithDifferentClass");
// Name property value is overridden // Name property value is overridden
@ -321,8 +325,10 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testInheritanceWithClass() throws Exception { public @Test void testInheritanceWithClass() throws Exception {
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT); DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent); new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(child).loadBeanDefinitions(CHILD_CONTEXT);
assertEquals(DerivedTestBean.class, child.getType("inheritsWithClass")); assertEquals(DerivedTestBean.class, child.getType("inheritsWithClass"));
DerivedTestBean inherits = (DerivedTestBean) child.getBean("inheritsWithClass"); DerivedTestBean inherits = (DerivedTestBean) child.getBean("inheritsWithClass");
// Name property value is overridden // Name property value is overridden
@ -333,8 +339,10 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testPrototypeInheritanceFromParentFactoryPrototype() throws Exception { public @Test void testPrototypeInheritanceFromParentFactoryPrototype() throws Exception {
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT); DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent); new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(child).loadBeanDefinitions(CHILD_CONTEXT);
assertEquals(TestBean.class, child.getType("prototypeInheritsFromParentFactoryPrototype")); assertEquals(TestBean.class, child.getType("prototypeInheritsFromParentFactoryPrototype"));
TestBean inherits = (TestBean) child.getBean("prototypeInheritsFromParentFactoryPrototype"); TestBean inherits = (TestBean) child.getBean("prototypeInheritsFromParentFactoryPrototype");
// Name property value is overridden // Name property value is overridden
@ -350,8 +358,10 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testPrototypeInheritanceFromParentFactorySingleton() throws Exception { public @Test void testPrototypeInheritanceFromParentFactorySingleton() throws Exception {
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT); DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent); new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(child).loadBeanDefinitions(CHILD_CONTEXT);
TestBean inherits = (TestBean) child.getBean("protoypeInheritsFromParentFactorySingleton"); TestBean inherits = (TestBean) child.getBean("protoypeInheritsFromParentFactorySingleton");
// Name property value is overridden // Name property value is overridden
assertTrue(inherits.getName().equals("prototypeOverridesInheritedSingleton")); assertTrue(inherits.getName().equals("prototypeOverridesInheritedSingleton"));
@ -380,7 +390,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testAbstractParentBeans() { public @Test void testAbstractParentBeans() {
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT); DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
parent.preInstantiateSingletons(); parent.preInstantiateSingletons();
assertTrue(parent.isSingleton("inheritedTestBeanWithoutClass")); assertTrue(parent.isSingleton("inheritedTestBeanWithoutClass"));
@ -404,7 +415,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testDependenciesMaterializeThis() throws Exception { public @Test void testDependenciesMaterializeThis() throws Exception {
XmlBeanFactory xbf = new XmlBeanFactory(DEP_MATERIALIZE_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEP_MATERIALIZE_CONTEXT);
assertEquals(2, xbf.getBeansOfType(DummyBo.class, true, false).size()); assertEquals(2, xbf.getBeansOfType(DummyBo.class, true, false).size());
assertEquals(3, xbf.getBeansOfType(DummyBo.class, true, true).size()); assertEquals(3, xbf.getBeansOfType(DummyBo.class, true, true).size());
@ -421,8 +433,10 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testChildOverridesParentBean() throws Exception { public @Test void testChildOverridesParentBean() throws Exception {
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT); DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent); new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(child).loadBeanDefinitions(CHILD_CONTEXT);
TestBean inherits = (TestBean) child.getBean("inheritedTestBean"); TestBean inherits = (TestBean) child.getBean("inheritedTestBean");
// Name property value is overridden // Name property value is overridden
assertTrue(inherits.getName().equals("overrideParentBean")); assertTrue(inherits.getName().equals("overrideParentBean"));
@ -437,8 +451,10 @@ public final class XmlBeanFactoryTests {
* If a singleton does this the factory will fail to load. * If a singleton does this the factory will fail to load.
*/ */
public @Test void testBogusParentageFromParentFactory() throws Exception { public @Test void testBogusParentageFromParentFactory() throws Exception {
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT); DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent); new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(child).loadBeanDefinitions(CHILD_CONTEXT);
try { try {
child.getBean("bogusParent", TestBean.class); child.getBean("bogusParent", TestBean.class);
fail(); fail();
@ -456,8 +472,10 @@ public final class XmlBeanFactoryTests {
* instances even if derived from a prototype * instances even if derived from a prototype
*/ */
public @Test void testSingletonInheritsFromParentFactoryPrototype() throws Exception { public @Test void testSingletonInheritsFromParentFactoryPrototype() throws Exception {
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT); DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent); new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(child).loadBeanDefinitions(CHILD_CONTEXT);
TestBean inherits = (TestBean) child.getBean("singletonInheritsFromParentFactoryPrototype"); TestBean inherits = (TestBean) child.getBean("singletonInheritsFromParentFactoryPrototype");
// Name property value is overriden // Name property value is overriden
assertTrue(inherits.getName().equals("prototype-override")); assertTrue(inherits.getName().equals("prototype-override"));
@ -468,16 +486,20 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testSingletonFromParent() { public @Test void testSingletonFromParent() {
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT); DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
TestBean beanFromParent = (TestBean) parent.getBean("inheritedTestBeanSingleton"); TestBean beanFromParent = (TestBean) parent.getBean("inheritedTestBeanSingleton");
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent); DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(child).loadBeanDefinitions(CHILD_CONTEXT);
TestBean beanFromChild = (TestBean) child.getBean("inheritedTestBeanSingleton"); TestBean beanFromChild = (TestBean) child.getBean("inheritedTestBeanSingleton");
assertTrue("singleton from parent and child is the same", beanFromParent == beanFromChild); assertTrue("singleton from parent and child is the same", beanFromParent == beanFromChild);
} }
public @Test void testNestedPropertyValue() { public @Test void testNestedPropertyValue() {
XmlBeanFactory parent = new XmlBeanFactory(PARENT_CONTEXT); DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
XmlBeanFactory child = new XmlBeanFactory(CHILD_CONTEXT, parent); new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(child).loadBeanDefinitions(CHILD_CONTEXT);
IndexedTestBean bean = (IndexedTestBean) child.getBean("indexedTestBean"); IndexedTestBean bean = (IndexedTestBean) child.getBean("indexedTestBean");
assertEquals("name applied correctly", "myname", bean.getArray()[0].getName()); assertEquals("name applied correctly", "myname", bean.getArray()[0].getName());
} }
@ -571,19 +593,22 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testFactoryReferenceCircle() { public @Test void testFactoryReferenceCircle() {
XmlBeanFactory xbf = new XmlBeanFactory(FACTORY_CIRCLE_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(FACTORY_CIRCLE_CONTEXT);
TestBean tb = (TestBean) xbf.getBean("singletonFactory"); TestBean tb = (TestBean) xbf.getBean("singletonFactory");
DummyFactory db = (DummyFactory) xbf.getBean("&singletonFactory"); DummyFactory db = (DummyFactory) xbf.getBean("&singletonFactory");
assertTrue(tb == db.getOtherTestBean()); assertTrue(tb == db.getOtherTestBean());
} }
public @Test void testFactoryReferenceWithDoublePrefix() { public @Test void testFactoryReferenceWithDoublePrefix() {
XmlBeanFactory xbf = new XmlBeanFactory(FACTORY_CIRCLE_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(FACTORY_CIRCLE_CONTEXT);
assertThat(xbf.getBean("&&singletonFactory"), instanceOf(DummyFactory.class)); assertThat(xbf.getBean("&&singletonFactory"), instanceOf(DummyFactory.class));
} }
public @Test void testComplexFactoryReferenceCircle() { public @Test void testComplexFactoryReferenceCircle() {
XmlBeanFactory xbf = new XmlBeanFactory(COMPLEX_FACTORY_CIRCLE_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(COMPLEX_FACTORY_CIRCLE_CONTEXT);
xbf.getBean("proxy1"); xbf.getBean("proxy1");
// check that unused instances from autowiring got removed // check that unused instances from autowiring got removed
assertEquals(4, xbf.getSingletonCount()); assertEquals(4, xbf.getSingletonCount());
@ -594,7 +619,8 @@ public final class XmlBeanFactoryTests {
public @Test void testNoSuchFactoryBeanMethod() { public @Test void testNoSuchFactoryBeanMethod() {
try { try {
XmlBeanFactory xbf = new XmlBeanFactory(NO_SUCH_FACTORY_METHOD_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(NO_SUCH_FACTORY_METHOD_CONTEXT);
assertNotNull(xbf.getBean("defaultTestBean")); assertNotNull(xbf.getBean("defaultTestBean"));
fail("Should not get invalid bean"); fail("Should not get invalid bean");
} }
@ -604,7 +630,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testInitMethodIsInvoked() throws Exception { public @Test void testInitMethodIsInvoked() throws Exception {
XmlBeanFactory xbf = new XmlBeanFactory(INITIALIZERS_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT);
DoubleInitializer in = (DoubleInitializer) xbf.getBean("init-method1"); DoubleInitializer in = (DoubleInitializer) xbf.getBean("init-method1");
// Initializer should have doubled value // Initializer should have doubled value
assertEquals(14, in.getNum()); assertEquals(14, in.getNum());
@ -614,7 +641,8 @@ public final class XmlBeanFactoryTests {
* Test that if a custom initializer throws an exception, it's handled correctly * Test that if a custom initializer throws an exception, it's handled correctly
*/ */
public @Test void testInitMethodThrowsException() { public @Test void testInitMethodThrowsException() {
XmlBeanFactory xbf = new XmlBeanFactory(INITIALIZERS_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT);
try { try {
xbf.getBean("init-method2"); xbf.getBean("init-method2");
fail(); fail();
@ -627,7 +655,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testNoSuchInitMethod() throws Exception { public @Test void testNoSuchInitMethod() throws Exception {
XmlBeanFactory xbf = new XmlBeanFactory(INITIALIZERS_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT);
try { try {
xbf.getBean("init-method3"); xbf.getBean("init-method3");
fail(); fail();
@ -645,7 +674,8 @@ public final class XmlBeanFactoryTests {
*/ */
public @Test void testInitializingBeanAndInitMethod() throws Exception { public @Test void testInitializingBeanAndInitMethod() throws Exception {
InitAndIB.constructed = false; InitAndIB.constructed = false;
XmlBeanFactory xbf = new XmlBeanFactory(INITIALIZERS_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT);
assertFalse(InitAndIB.constructed); assertFalse(InitAndIB.constructed);
xbf.preInstantiateSingletons(); xbf.preInstantiateSingletons();
assertFalse(InitAndIB.constructed); assertFalse(InitAndIB.constructed);
@ -664,7 +694,8 @@ public final class XmlBeanFactoryTests {
*/ */
public @Test void testInitializingBeanAndSameInitMethod() throws Exception { public @Test void testInitializingBeanAndSameInitMethod() throws Exception {
InitAndIB.constructed = false; InitAndIB.constructed = false;
XmlBeanFactory xbf = new XmlBeanFactory(INITIALIZERS_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT);
assertFalse(InitAndIB.constructed); assertFalse(InitAndIB.constructed);
xbf.preInstantiateSingletons(); xbf.preInstantiateSingletons();
assertFalse(InitAndIB.constructed); assertFalse(InitAndIB.constructed);
@ -680,7 +711,8 @@ public final class XmlBeanFactoryTests {
public @Test void testDefaultLazyInit() throws Exception { public @Test void testDefaultLazyInit() throws Exception {
InitAndIB.constructed = false; InitAndIB.constructed = false;
XmlBeanFactory xbf = new XmlBeanFactory(DEFAULT_LAZY_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEFAULT_LAZY_CONTEXT);
assertFalse(InitAndIB.constructed); assertFalse(InitAndIB.constructed);
xbf.preInstantiateSingletons(); xbf.preInstantiateSingletons();
assertTrue(InitAndIB.constructed); assertTrue(InitAndIB.constructed);
@ -693,8 +725,9 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testNoSuchXmlFile() throws Exception { public @Test void testNoSuchXmlFile() throws Exception {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
try { try {
new XmlBeanFactory(MISSING_CONTEXT); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(MISSING_CONTEXT);
fail("Must not create factory from missing XML"); fail("Must not create factory from missing XML");
} }
catch (BeanDefinitionStoreException expected) { catch (BeanDefinitionStoreException expected) {
@ -702,8 +735,9 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testInvalidXmlFile() throws Exception { public @Test void testInvalidXmlFile() throws Exception {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
try { try {
new XmlBeanFactory(INVALID_CONTEXT); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INVALID_CONTEXT);
fail("Must not create factory from invalid XML"); fail("Must not create factory from invalid XML");
} }
catch (BeanDefinitionStoreException expected) { catch (BeanDefinitionStoreException expected) {
@ -711,8 +745,9 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testUnsatisfiedObjectDependencyCheck() throws Exception { public @Test void testUnsatisfiedObjectDependencyCheck() throws Exception {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
try { try {
XmlBeanFactory xbf = new XmlBeanFactory(UNSATISFIED_OBJECT_DEP_CONTEXT); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(UNSATISFIED_OBJECT_DEP_CONTEXT);
xbf.getBean("a", DependenciesBean.class); xbf.getBean("a", DependenciesBean.class);
fail("Must have thrown an UnsatisfiedDependencyException"); fail("Must have thrown an UnsatisfiedDependencyException");
} }
@ -721,8 +756,9 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testUnsatisfiedSimpleDependencyCheck() throws Exception { public @Test void testUnsatisfiedSimpleDependencyCheck() throws Exception {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
try { try {
XmlBeanFactory xbf = new XmlBeanFactory(UNSATISFIED_SIMPLE_DEP_CONTEXT); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(UNSATISFIED_SIMPLE_DEP_CONTEXT);
xbf.getBean("a", DependenciesBean.class); xbf.getBean("a", DependenciesBean.class);
fail("Must have thrown an UnsatisfiedDependencyException"); fail("Must have thrown an UnsatisfiedDependencyException");
} }
@ -731,21 +767,24 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testSatisfiedObjectDependencyCheck() throws Exception { public @Test void testSatisfiedObjectDependencyCheck() throws Exception {
XmlBeanFactory xbf = new XmlBeanFactory(SATISFIED_OBJECT_DEP_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(SATISFIED_OBJECT_DEP_CONTEXT);
DependenciesBean a = (DependenciesBean) xbf.getBean("a"); DependenciesBean a = (DependenciesBean) xbf.getBean("a");
assertNotNull(a.getSpouse()); assertNotNull(a.getSpouse());
assertEquals(xbf, a.getBeanFactory()); assertEquals(xbf, a.getBeanFactory());
} }
public @Test void testSatisfiedSimpleDependencyCheck() throws Exception { public @Test void testSatisfiedSimpleDependencyCheck() throws Exception {
XmlBeanFactory xbf = new XmlBeanFactory(SATISFIED_SIMPLE_DEP_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(SATISFIED_SIMPLE_DEP_CONTEXT);
DependenciesBean a = (DependenciesBean) xbf.getBean("a"); DependenciesBean a = (DependenciesBean) xbf.getBean("a");
assertEquals(a.getAge(), 33); assertEquals(a.getAge(), 33);
} }
public @Test void testUnsatisfiedAllDependencyCheck() throws Exception { public @Test void testUnsatisfiedAllDependencyCheck() throws Exception {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
try { try {
XmlBeanFactory xbf = new XmlBeanFactory(UNSATISFIED_ALL_DEP_CONTEXT); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(UNSATISFIED_ALL_DEP_CONTEXT);
xbf.getBean("a", DependenciesBean.class); xbf.getBean("a", DependenciesBean.class);
fail("Must have thrown an UnsatisfiedDependencyException"); fail("Must have thrown an UnsatisfiedDependencyException");
} }
@ -754,7 +793,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testSatisfiedAllDependencyCheck() throws Exception { public @Test void testSatisfiedAllDependencyCheck() throws Exception {
XmlBeanFactory xbf = new XmlBeanFactory(SATISFIED_ALL_DEP_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(SATISFIED_ALL_DEP_CONTEXT);
DependenciesBean a = (DependenciesBean) xbf.getBean("a"); DependenciesBean a = (DependenciesBean) xbf.getBean("a");
assertEquals(a.getAge(), 33); assertEquals(a.getAge(), 33);
assertNotNull(a.getName()); assertNotNull(a.getName());
@ -762,23 +802,27 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testAutowire() throws Exception { public @Test void testAutowire() throws Exception {
XmlBeanFactory xbf = new XmlBeanFactory(AUTOWIRE_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(AUTOWIRE_CONTEXT);
TestBean spouse = new TestBean("kerry", 0); TestBean spouse = new TestBean("kerry", 0);
xbf.registerSingleton("spouse", spouse); xbf.registerSingleton("spouse", spouse);
doTestAutowire(xbf); doTestAutowire(xbf);
} }
public @Test void testAutowireWithParent() throws Exception { public @Test void testAutowireWithParent() throws Exception {
XmlBeanFactory xbf = new XmlBeanFactory(AUTOWIRE_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(AUTOWIRE_CONTEXT);
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues(); MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("name", "kerry"); pvs.add("name", "kerry");
lbf.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class, pvs)); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("spouse", bd);
xbf.setParentBeanFactory(lbf); xbf.setParentBeanFactory(lbf);
doTestAutowire(xbf); doTestAutowire(xbf);
} }
private void doTestAutowire(XmlBeanFactory xbf) throws Exception { private void doTestAutowire(DefaultListableBeanFactory xbf) throws Exception {
DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1"); DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1");
TestBean kerry = (TestBean) xbf.getBean("spouse"); TestBean kerry = (TestBean) xbf.getBean("spouse");
// should have been autowired // should have been autowired
@ -827,7 +871,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testAutowireWithDefault() throws Exception { public @Test void testAutowireWithDefault() throws Exception {
XmlBeanFactory xbf = new XmlBeanFactory(DEFAULT_AUTOWIRE_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEFAULT_AUTOWIRE_CONTEXT);
DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1"); DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1");
// should have been autowired // should have been autowired
@ -848,7 +893,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testAutowireByConstructor() throws Exception { public @Test void testAutowireByConstructor() throws Exception {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
ConstructorDependenciesBean rod1 = (ConstructorDependenciesBean) xbf.getBean("rod1"); ConstructorDependenciesBean rod1 = (ConstructorDependenciesBean) xbf.getBean("rod1");
TestBean kerry = (TestBean) xbf.getBean("kerry2"); TestBean kerry = (TestBean) xbf.getBean("kerry2");
// should have been autowired // should have been autowired
@ -884,7 +930,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testAutowireByConstructorWithSimpleValues() throws Exception { public @Test void testAutowireByConstructorWithSimpleValues() throws Exception {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
ConstructorDependenciesBean rod5 = (ConstructorDependenciesBean) xbf.getBean("rod5"); ConstructorDependenciesBean rod5 = (ConstructorDependenciesBean) xbf.getBean("rod5");
TestBean kerry1 = (TestBean) xbf.getBean("kerry1"); TestBean kerry1 = (TestBean) xbf.getBean("kerry1");
@ -912,7 +959,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testRelatedCausesFromConstructorResolution() { public @Test void testRelatedCausesFromConstructorResolution() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
try { try {
xbf.getBean("rod2Accessor"); xbf.getBean("rod2Accessor");
@ -925,7 +973,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testConstructorArgResolution() { public @Test void testConstructorArgResolution() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
TestBean kerry1 = (TestBean) xbf.getBean("kerry1"); TestBean kerry1 = (TestBean) xbf.getBean("kerry1");
TestBean kerry2 = (TestBean) xbf.getBean("kerry2"); TestBean kerry2 = (TestBean) xbf.getBean("kerry2");
@ -972,7 +1021,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testPrototypeWithExplicitArguments() { public @Test void testPrototypeWithExplicitArguments() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
SimpleConstructorArgBean cd1 = (SimpleConstructorArgBean) xbf.getBean("rod18"); SimpleConstructorArgBean cd1 = (SimpleConstructorArgBean) xbf.getBean("rod18");
assertEquals(0, cd1.getAge()); assertEquals(0, cd1.getAge());
SimpleConstructorArgBean cd2 = (SimpleConstructorArgBean) xbf.getBean("rod18", 98); SimpleConstructorArgBean cd2 = (SimpleConstructorArgBean) xbf.getBean("rod18", 98);
@ -986,13 +1036,15 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testConstructorArgWithSingleMatch() { public @Test void testConstructorArgWithSingleMatch() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
File file = (File) xbf.getBean("file"); File file = (File) xbf.getBean("file");
assertEquals(File.separator + "test", file.getPath()); assertEquals(File.separator + "test", file.getPath());
} }
public @Test void testThrowsExceptionOnTooManyArguments() throws Exception { public @Test void testThrowsExceptionOnTooManyArguments() throws Exception {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
try { try {
xbf.getBean("rod7", ConstructorDependenciesBean.class); xbf.getBean("rod7", ConstructorDependenciesBean.class);
fail("Should have thrown BeanCreationException"); fail("Should have thrown BeanCreationException");
@ -1002,7 +1054,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testThrowsExceptionOnAmbiguousResolution() throws Exception { public @Test void testThrowsExceptionOnAmbiguousResolution() throws Exception {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
try { try {
xbf.getBean("rod8", ConstructorDependenciesBean.class); xbf.getBean("rod8", ConstructorDependenciesBean.class);
fail("Must have thrown UnsatisfiedDependencyException"); fail("Must have thrown UnsatisfiedDependencyException");
@ -1058,7 +1111,8 @@ public final class XmlBeanFactoryTests {
PreparingBean2.destroyed = false; PreparingBean2.destroyed = false;
DependingBean.destroyCount = 0; DependingBean.destroyCount = 0;
HoldingBean.destroyCount = 0; HoldingBean.destroyCount = 0;
XmlBeanFactory xbf = new XmlBeanFactory(resource); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(resource);
xbf.preInstantiateSingletons(); xbf.preInstantiateSingletons();
xbf.destroySingletons(); xbf.destroySingletons();
assertTrue(PreparingBean1.prepared); assertTrue(PreparingBean1.prepared);
@ -1078,7 +1132,8 @@ public final class XmlBeanFactoryTests {
* must rather only be picked up when the bean is instantiated. * must rather only be picked up when the bean is instantiated.
*/ */
public @Test void testClassNotFoundWithDefaultBeanClassLoader() { public @Test void testClassNotFoundWithDefaultBeanClassLoader() {
BeanFactory factory = new XmlBeanFactory(CLASS_NOT_FOUND_CONTEXT); DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(CLASS_NOT_FOUND_CONTEXT);
// cool, no errors, so the rubbish class name in the bean def was not resolved // cool, no errors, so the rubbish class name in the bean def was not resolved
try { try {
// let's resolve the bean definition; must blow up // let's resolve the bean definition; must blow up
@ -1100,7 +1155,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testResourceAndInputStream() throws IOException { public @Test void testResourceAndInputStream() throws IOException {
XmlBeanFactory xbf = new XmlBeanFactory(RESOURCE_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(RESOURCE_CONTEXT);
// comes from "resourceImport.xml" // comes from "resourceImport.xml"
ResourceTestBean resource1 = (ResourceTestBean) xbf.getBean("resource1"); ResourceTestBean resource1 = (ResourceTestBean) xbf.getBean("resource1");
// comes from "resource.xml" // comes from "resource.xml"
@ -1122,7 +1178,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testClassPathResourceWithImport() { public @Test void testClassPathResourceWithImport() {
XmlBeanFactory xbf = new XmlBeanFactory(RESOURCE_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(RESOURCE_CONTEXT);
// comes from "resourceImport.xml" // comes from "resourceImport.xml"
xbf.getBean("resource1", ResourceTestBean.class); xbf.getBean("resource1", ResourceTestBean.class);
// comes from "resource.xml" // comes from "resource.xml"
@ -1131,7 +1188,8 @@ public final class XmlBeanFactoryTests {
public @Test void testUrlResourceWithImport() { public @Test void testUrlResourceWithImport() {
URL url = getClass().getResource(RESOURCE_CONTEXT.getPath()); URL url = getClass().getResource(RESOURCE_CONTEXT.getPath());
XmlBeanFactory xbf = new XmlBeanFactory(new UrlResource(url)); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(new UrlResource(url));
// comes from "resourceImport.xml" // comes from "resourceImport.xml"
xbf.getBean("resource1", ResourceTestBean.class); xbf.getBean("resource1", ResourceTestBean.class);
// comes from "resource.xml" // comes from "resource.xml"
@ -1140,7 +1198,8 @@ public final class XmlBeanFactoryTests {
public @Test void testFileSystemResourceWithImport() throws URISyntaxException { public @Test void testFileSystemResourceWithImport() throws URISyntaxException {
String file = getClass().getResource(RESOURCE_CONTEXT.getPath()).toURI().getPath(); String file = getClass().getResource(RESOURCE_CONTEXT.getPath()).toURI().getPath();
XmlBeanFactory xbf = new XmlBeanFactory(new FileSystemResource(file)); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(new FileSystemResource(file));
// comes from "resourceImport.xml" // comes from "resourceImport.xml"
xbf.getBean("resource1", ResourceTestBean.class); xbf.getBean("resource1", ResourceTestBean.class);
// comes from "resource.xml" // comes from "resource.xml"
@ -1148,8 +1207,9 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testRecursiveImport() { public @Test void testRecursiveImport() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
try { try {
new XmlBeanFactory(RECURSIVE_IMPORT_CONTEXT); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(RECURSIVE_IMPORT_CONTEXT);
fail("Should have thrown BeanDefinitionStoreException"); fail("Should have thrown BeanDefinitionStoreException");
} }
catch (BeanDefinitionStoreException ex) { catch (BeanDefinitionStoreException ex) {
@ -1344,7 +1404,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testConstructorArgWithSingleSimpleTypeMatch() { public @Test void testConstructorArgWithSingleSimpleTypeMatch() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
SingleSimpleTypeConstructorBean bean = (SingleSimpleTypeConstructorBean) xbf.getBean("beanWithBoolean"); SingleSimpleTypeConstructorBean bean = (SingleSimpleTypeConstructorBean) xbf.getBean("beanWithBoolean");
assertTrue(bean.isSingleBoolean()); assertTrue(bean.isSingleBoolean());
@ -1354,7 +1415,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testConstructorArgWithDoubleSimpleTypeMatch() { public @Test void testConstructorArgWithDoubleSimpleTypeMatch() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
SingleSimpleTypeConstructorBean bean = (SingleSimpleTypeConstructorBean) xbf.getBean("beanWithBooleanAndString"); SingleSimpleTypeConstructorBean bean = (SingleSimpleTypeConstructorBean) xbf.getBean("beanWithBooleanAndString");
assertTrue(bean.isSecondBoolean()); assertTrue(bean.isSecondBoolean());
@ -1366,33 +1428,38 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testDoubleBooleanAutowire() { public @Test void testDoubleBooleanAutowire() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
DoubleBooleanConstructorBean bean = (DoubleBooleanConstructorBean) xbf.getBean("beanWithDoubleBoolean"); DoubleBooleanConstructorBean bean = (DoubleBooleanConstructorBean) xbf.getBean("beanWithDoubleBoolean");
assertEquals(Boolean.TRUE, bean.boolean1); assertEquals(Boolean.TRUE, bean.boolean1);
assertEquals(Boolean.FALSE, bean.boolean2); assertEquals(Boolean.FALSE, bean.boolean2);
} }
public @Test void testDoubleBooleanAutowireWithIndex() { public @Test void testDoubleBooleanAutowireWithIndex() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
DoubleBooleanConstructorBean bean = (DoubleBooleanConstructorBean) xbf.getBean("beanWithDoubleBooleanAndIndex"); DoubleBooleanConstructorBean bean = (DoubleBooleanConstructorBean) xbf.getBean("beanWithDoubleBooleanAndIndex");
assertEquals(Boolean.FALSE, bean.boolean1); assertEquals(Boolean.FALSE, bean.boolean1);
assertEquals(Boolean.TRUE, bean.boolean2); assertEquals(Boolean.TRUE, bean.boolean2);
} }
public @Test void testLenientDependencyMatching() { public @Test void testLenientDependencyMatching() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
LenientDependencyTestBean bean = (LenientDependencyTestBean) xbf.getBean("lenientDependencyTestBean"); LenientDependencyTestBean bean = (LenientDependencyTestBean) xbf.getBean("lenientDependencyTestBean");
assertTrue(bean.tb instanceof DerivedTestBean); assertTrue(bean.tb instanceof DerivedTestBean);
} }
public @Test void testLenientDependencyMatchingFactoryMethod() { public @Test void testLenientDependencyMatchingFactoryMethod() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
LenientDependencyTestBean bean = (LenientDependencyTestBean) xbf.getBean("lenientDependencyTestBeanFactoryMethod"); LenientDependencyTestBean bean = (LenientDependencyTestBean) xbf.getBean("lenientDependencyTestBeanFactoryMethod");
assertTrue(bean.tb instanceof DerivedTestBean); assertTrue(bean.tb instanceof DerivedTestBean);
} }
public @Test void testNonLenientDependencyMatching() { public @Test void testNonLenientDependencyMatching() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("lenientDependencyTestBean"); AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("lenientDependencyTestBean");
bd.setLenientConstructorResolution(false); bd.setLenientConstructorResolution(false);
try { try {
@ -1407,7 +1474,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testNonLenientDependencyMatchingFactoryMethod() { public @Test void testNonLenientDependencyMatchingFactoryMethod() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("lenientDependencyTestBeanFactoryMethod"); AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("lenientDependencyTestBeanFactoryMethod");
bd.setLenientConstructorResolution(false); bd.setLenientConstructorResolution(false);
try { try {
@ -1422,7 +1490,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testJavaLangStringConstructor() { public @Test void testJavaLangStringConstructor() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("string"); AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("string");
bd.setLenientConstructorResolution(false); bd.setLenientConstructorResolution(false);
String str = (String) xbf.getBean("string"); String str = (String) xbf.getBean("string");
@ -1430,7 +1499,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testCustomStringConstructor() { public @Test void testCustomStringConstructor() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("stringConstructor"); AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("stringConstructor");
bd.setLenientConstructorResolution(false); bd.setLenientConstructorResolution(false);
StringConstructorTestBean tb = (StringConstructorTestBean) xbf.getBean("stringConstructor"); StringConstructorTestBean tb = (StringConstructorTestBean) xbf.getBean("stringConstructor");
@ -1438,7 +1508,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testPrimitiveConstructorArray() { public @Test void testPrimitiveConstructorArray() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
ConstructorArrayTestBean bean = (ConstructorArrayTestBean) xbf.getBean("constructorArray"); ConstructorArrayTestBean bean = (ConstructorArrayTestBean) xbf.getBean("constructorArray");
assertTrue(bean.array instanceof int[]); assertTrue(bean.array instanceof int[]);
assertEquals(1, ((int[]) bean.array).length); assertEquals(1, ((int[]) bean.array).length);
@ -1446,7 +1517,8 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testIndexedPrimitiveConstructorArray() { public @Test void testIndexedPrimitiveConstructorArray() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
ConstructorArrayTestBean bean = (ConstructorArrayTestBean) xbf.getBean("indexedConstructorArray"); ConstructorArrayTestBean bean = (ConstructorArrayTestBean) xbf.getBean("indexedConstructorArray");
assertTrue(bean.array instanceof int[]); assertTrue(bean.array instanceof int[]);
assertEquals(1, ((int[]) bean.array).length); assertEquals(1, ((int[]) bean.array).length);
@ -1454,14 +1526,16 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testStringConstructorArrayNoType() { public @Test void testStringConstructorArrayNoType() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
ConstructorArrayTestBean bean = (ConstructorArrayTestBean) xbf.getBean("constructorArrayNoType"); ConstructorArrayTestBean bean = (ConstructorArrayTestBean) xbf.getBean("constructorArrayNoType");
assertTrue(bean.array instanceof String[]); assertTrue(bean.array instanceof String[]);
assertEquals(0, ((String[]) bean.array).length); assertEquals(0, ((String[]) bean.array).length);
} }
public @Test void testStringConstructorArrayNoTypeNonLenient() { public @Test void testStringConstructorArrayNoTypeNonLenient() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("constructorArrayNoType"); AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("constructorArrayNoType");
bd.setLenientConstructorResolution(false); bd.setLenientConstructorResolution(false);
ConstructorArrayTestBean bean = (ConstructorArrayTestBean) xbf.getBean("constructorArrayNoType"); ConstructorArrayTestBean bean = (ConstructorArrayTestBean) xbf.getBean("constructorArrayNoType");
@ -1470,8 +1544,9 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testWithDuplicateName() throws Exception { public @Test void testWithDuplicateName() throws Exception {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
try { try {
new XmlBeanFactory(TEST_WITH_DUP_NAMES_CONTEXT); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(TEST_WITH_DUP_NAMES_CONTEXT);
fail("Duplicate name not detected"); fail("Duplicate name not detected");
} }
catch (BeansException ex) { catch (BeansException ex) {
@ -1480,8 +1555,9 @@ public final class XmlBeanFactoryTests {
} }
public @Test void testWithDuplicateNameInAlias() throws Exception { public @Test void testWithDuplicateNameInAlias() throws Exception {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
try { try {
new XmlBeanFactory(TEST_WITH_DUP_NAME_IN_ALIAS_CONTEXT); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(TEST_WITH_DUP_NAME_IN_ALIAS_CONTEXT);
fail("Duplicate name not detected"); fail("Duplicate name not detected");
} }
catch (BeansException e) { catch (BeansException e) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2011 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,7 @@
package org.springframework.cache.config; package org.springframework.cache.config;
import junit.framework.Assert; import static org.junit.Assert.assertSame;
import org.junit.Test; import org.junit.Test;
import org.springframework.cache.interceptor.CacheInterceptor; import org.springframework.cache.interceptor.CacheInterceptor;
@ -39,6 +39,6 @@ public class AnnotationNamespaceDrivenTests extends AbstractAnnotationTests {
public void testKeyStrategy() throws Exception { public void testKeyStrategy() throws Exception {
CacheInterceptor ci = ctx.getBean("org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor ci = ctx.getBean("org.springframework.cache.interceptor.CacheInterceptor#0",
CacheInterceptor.class); CacheInterceptor.class);
Assert.assertSame(ctx.getBean("keyGenerator"), ci.getKeyGenerator()); assertSame(ctx.getBean("keyGenerator"), ci.getKeyGenerator());
} }
} }

View File

@ -16,12 +16,11 @@
package org.springframework.cache.config; package org.springframework.cache.config;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.util.Arrays; import java.util.Arrays;
import junit.framework.Assert;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCreationException;
import org.springframework.cache.CacheManager; import org.springframework.cache.CacheManager;
@ -53,7 +52,7 @@ public class EnableCachingTests extends AbstractAnnotationTests {
@Test @Test
public void testKeyStrategy() throws Exception { public void testKeyStrategy() throws Exception {
CacheInterceptor ci = ctx.getBean(CacheInterceptor.class); CacheInterceptor ci = ctx.getBean(CacheInterceptor.class);
Assert.assertSame(ctx.getBean(KeyGenerator.class), ci.getKeyGenerator()); assertSame(ctx.getBean(KeyGenerator.class), ci.getKeyGenerator());
} }
// --- local tests ------- // --- local tests -------

View File

@ -16,14 +16,16 @@
package org.springframework.context.access; package org.springframework.context.access;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import org.junit.Test; import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.access.BeanFactoryLocator; import org.springframework.beans.factory.access.BeanFactoryLocator;
import org.springframework.beans.factory.access.BeanFactoryReference; import org.springframework.beans.factory.access.BeanFactoryReference;
import org.springframework.beans.factory.access.SingletonBeanFactoryLocatorTests; import org.springframework.beans.factory.access.SingletonBeanFactoryLocatorTests;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
@ -43,8 +45,10 @@ public class ContextSingletonBeanFactoryLocatorTests extends SingletonBeanFactor
public void testBaseBeanFactoryDefs() { public void testBaseBeanFactoryDefs() {
// Just test the base BeanFactory/AppContext defs we are going to work // Just test the base BeanFactory/AppContext defs we are going to work
// with in other tests. // with in other tests.
new XmlBeanFactory(new ClassPathResource("/org/springframework/beans/factory/access/beans1.xml")); new XmlBeanDefinitionReader(new DefaultListableBeanFactory()).loadBeanDefinitions(new ClassPathResource(
new XmlBeanFactory(new ClassPathResource("/org/springframework/beans/factory/access/beans2.xml")); "/org/springframework/beans/factory/access/beans1.xml"));
new XmlBeanDefinitionReader(new DefaultListableBeanFactory()).loadBeanDefinitions(new ClassPathResource(
"/org/springframework/beans/factory/access/beans2.xml"));
} }
@Override @Override

View File

@ -31,8 +31,8 @@ import org.springframework.beans.factory.annotation.Required;
import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.build.junit.Assume; import org.springframework.tests.Assume;
import org.springframework.build.junit.TestGroup; import org.springframework.tests.TestGroup;
import org.springframework.context.support.GenericApplicationContext; import org.springframework.context.support.GenericApplicationContext;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;

View File

@ -34,6 +34,7 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor; import org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor; import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@ -171,9 +172,15 @@ public class CommonAnnotationBeanPostProcessorTests {
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setResourceFactory(bf); bpp.setResourceFactory(bf);
bf.addBeanPostProcessor(bpp); bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ResourceInjectionBean.class, false)); RootBeanDefinition abd = new RootBeanDefinition(ResourceInjectionBean.class);
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, false)); abd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bf.registerBeanDefinition("testBean2", new RootBeanDefinition(TestBean.class, false)); bf.registerBeanDefinition("annotatedBean", abd);
RootBeanDefinition tbd1 = new RootBeanDefinition(TestBean.class);
tbd1.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bf.registerBeanDefinition("testBean", tbd1);
RootBeanDefinition tbd2 = new RootBeanDefinition(TestBean.class);
tbd2.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bf.registerBeanDefinition("testBean2", tbd2);
ResourceInjectionBean bean = (ResourceInjectionBean) bf.getBean("annotatedBean"); ResourceInjectionBean bean = (ResourceInjectionBean) bf.getBean("annotatedBean");
assertTrue(bean.initCalled); assertTrue(bean.initCalled);
@ -202,8 +209,12 @@ public class CommonAnnotationBeanPostProcessorTests {
CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf); bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp); bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ExtendedResourceInjectionBean.class, false)); RootBeanDefinition abd = new RootBeanDefinition(ExtendedResourceInjectionBean.class);
bf.registerBeanDefinition("testBean4", new RootBeanDefinition(TestBean.class, false)); abd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bf.registerBeanDefinition("annotatedBean", abd);
RootBeanDefinition tbd = new RootBeanDefinition(TestBean.class);
tbd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bf.registerBeanDefinition("testBean4", tbd);
bf.registerResolvableDependency(BeanFactory.class, bf); bf.registerResolvableDependency(BeanFactory.class, bf);
bf.registerResolvableDependency(INestedTestBean.class, new ObjectFactory<Object>() { bf.registerResolvableDependency(INestedTestBean.class, new ObjectFactory<Object>() {

View File

@ -25,8 +25,9 @@ import test.beans.TestBean;
import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; 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.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
@ -79,7 +80,9 @@ public class AutowiredConfigurationTests {
*/ */
@Test(expected=BeanCreationException.class) @Test(expected=BeanCreationException.class)
public void testAutowiredConfigurationConstructorsAreNotSupported() { public void testAutowiredConfigurationConstructorsAreNotSupported() {
XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("annotation-config.xml", AutowiredConstructorConfig.class)); DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
new ClassPathResource("annotation-config.xml", AutowiredConstructorConfig.class));
GenericApplicationContext ctx = new GenericApplicationContext(factory); GenericApplicationContext ctx = new GenericApplicationContext(factory);
ctx.registerBeanDefinition("config1", new RootBeanDefinition(AutowiredConstructorConfig.class)); ctx.registerBeanDefinition("config1", new RootBeanDefinition(AutowiredConstructorConfig.class));
ctx.registerBeanDefinition("config2", new RootBeanDefinition(ColorConfig.class)); ctx.registerBeanDefinition("config2", new RootBeanDefinition(ColorConfig.class));

View File

@ -16,14 +16,15 @@
package org.springframework.context.annotation.configuration; package org.springframework.context.annotation.configuration;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*; import static org.junit.Assert.assertThat;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ConfigurationClassPostProcessor; import org.springframework.context.annotation.ConfigurationClassPostProcessor;
@ -47,8 +48,10 @@ import test.beans.TestBean;
*/ */
public class ConfigurationClassAspectIntegrationTests { public class ConfigurationClassAspectIntegrationTests {
private void assertAdviceWasApplied(Class<?> configClass) { private void assertAdviceWasApplied(Class<?> configClass) {
GenericApplicationContext ctx = new GenericApplicationContext( DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanFactory(new ClassPathResource("aspectj-autoproxy-config.xml", ConfigurationClassAspectIntegrationTests.class))); new XmlBeanDefinitionReader(factory).loadBeanDefinitions(
new ClassPathResource("aspectj-autoproxy-config.xml", ConfigurationClassAspectIntegrationTests.class));
GenericApplicationContext ctx = new GenericApplicationContext(factory);
ctx.addBeanFactoryPostProcessor(new ConfigurationClassPostProcessor()); ctx.addBeanFactoryPostProcessor(new ConfigurationClassPostProcessor());
ctx.registerBeanDefinition("config", new RootBeanDefinition(configClass)); ctx.registerBeanDefinition("config", new RootBeanDefinition(configClass));
ctx.refresh(); ctx.refresh();

View File

@ -86,7 +86,7 @@ public class EventPublicationInterceptorTests {
class TestContext extends StaticApplicationContext { class TestContext extends StaticApplicationContext {
@Override @Override
protected void onRefresh() throws BeansException { protected void onRefresh() throws BeansException {
addListener(listener); addApplicationListener(listener);
} }
} }

View File

@ -38,8 +38,8 @@ import org.springframework.beans.factory.support.AutowireCandidateQualifier;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.GenericBeanDefinition; import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.build.junit.Assume; import org.springframework.tests.Assume;
import org.springframework.build.junit.TestGroup; import org.springframework.tests.TestGroup;
import org.springframework.context.annotation.AnnotationConfigUtils; import org.springframework.context.annotation.AnnotationConfigUtils;
import org.springframework.context.support.GenericApplicationContext; import org.springframework.context.support.GenericApplicationContext;
import org.springframework.util.SerializationTestUtils; import org.springframework.util.SerializationTestUtils;

View File

@ -54,7 +54,7 @@ public class StaticApplicationContextMulticasterTests extends AbstractApplicatio
parent.registerSingleton(StaticApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME, parent.registerSingleton(StaticApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME,
TestApplicationEventMulticaster.class, null); TestApplicationEventMulticaster.class, null);
parent.refresh(); parent.refresh();
parent.addListener(parentListener) ; parent.addApplicationListener(parentListener) ;
parent.getStaticMessageSource().addMessage("code1", Locale.getDefault(), "message1"); parent.getStaticMessageSource().addMessage("code1", Locale.getDefault(), "message1");
@ -66,7 +66,7 @@ public class StaticApplicationContextMulticasterTests extends AbstractApplicatio
Resource resource = new ClassPathResource("testBeans.properties", getClass()); Resource resource = new ClassPathResource("testBeans.properties", getClass());
reader.loadBeanDefinitions(new EncodedResource(resource, "ISO-8859-1")); reader.loadBeanDefinitions(new EncodedResource(resource, "ISO-8859-1"));
sac.refresh(); sac.refresh();
sac.addListener(listener); sac.addApplicationListener(listener);
sac.getStaticMessageSource().addMessage("code2", Locale.getDefault(), "message2"); sac.getStaticMessageSource().addMessage("code2", Locale.getDefault(), "message2");

View File

@ -48,7 +48,7 @@ public class StaticApplicationContextTests extends AbstractApplicationContextTes
m.put("name", "Albert"); m.put("name", "Albert");
parent.registerPrototype("father", TestBean.class, new MutablePropertyValues(m)); parent.registerPrototype("father", TestBean.class, new MutablePropertyValues(m));
parent.refresh(); parent.refresh();
parent.addListener(parentListener) ; parent.addApplicationListener(parentListener) ;
parent.getStaticMessageSource().addMessage("code1", Locale.getDefault(), "message1"); parent.getStaticMessageSource().addMessage("code1", Locale.getDefault(), "message1");
@ -59,7 +59,7 @@ public class StaticApplicationContextTests extends AbstractApplicationContextTes
PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(sac.getDefaultListableBeanFactory()); PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(sac.getDefaultListableBeanFactory());
reader.loadBeanDefinitions(new ClassPathResource("testBeans.properties", getClass())); reader.loadBeanDefinitions(new ClassPathResource("testBeans.properties", getClass()));
sac.refresh(); sac.refresh();
sac.addListener(listener); sac.addApplicationListener(listener);
sac.getStaticMessageSource().addMessage("code2", Locale.getDefault(), "message2"); sac.getStaticMessageSource().addMessage("code2", Locale.getDefault(), "message2");

View File

@ -208,7 +208,7 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
parent.registerPrototype("father", org.springframework.beans.TestBean.class, new MutablePropertyValues(m)); parent.registerPrototype("father", org.springframework.beans.TestBean.class, new MutablePropertyValues(m));
parent.refresh(); parent.refresh();
parent.addListener(parentListener); parent.addApplicationListener(parentListener);
this.sac = new StaticApplicationContext(parent); this.sac = new StaticApplicationContext(parent);
@ -221,7 +221,7 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(sac.getDefaultListableBeanFactory()); PropertiesBeanDefinitionReader reader = new PropertiesBeanDefinitionReader(sac.getDefaultListableBeanFactory());
reader.loadBeanDefinitions(new ClassPathResource("testBeans.properties", getClass())); reader.loadBeanDefinitions(new ClassPathResource("testBeans.properties", getClass()));
sac.refresh(); sac.refresh();
sac.addListener(listener); sac.addApplicationListener(listener);
StaticMessageSource messageSource = sac.getStaticMessageSource(); StaticMessageSource messageSource = sac.getStaticMessageSource();
Map<String, String> usMessages = new HashMap<String, String>(3); Map<String, String> usMessages = new HashMap<String, String>(3);

View File

@ -36,6 +36,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.ConfigurablePropertyAccessor; import org.springframework.beans.ConfigurablePropertyAccessor;
import org.springframework.beans.PropertyAccessorFactory; import org.springframework.beans.PropertyAccessorFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@ -112,7 +113,9 @@ public class FormattingConversionServiceTests {
@Test @Test
public void testFormatFieldForValueInjectionUsingMetaAnnotations() { public void testFormatFieldForValueInjectionUsingMetaAnnotations() {
AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
ac.registerBeanDefinition("valueBean", new RootBeanDefinition(MetaValueBean.class, false)); RootBeanDefinition bd = new RootBeanDefinition(MetaValueBean.class);
bd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
ac.registerBeanDefinition("valueBean", bd);
ac.registerBeanDefinition("conversionService", new RootBeanDefinition(FormattingConversionServiceFactoryBean.class)); ac.registerBeanDefinition("conversionService", new RootBeanDefinition(FormattingConversionServiceFactoryBean.class));
ac.registerBeanDefinition("ppc", new RootBeanDefinition(PropertyPlaceholderConfigurer.class)); ac.registerBeanDefinition("ppc", new RootBeanDefinition(PropertyPlaceholderConfigurer.class));
ac.refresh(); ac.refresh();

View File

@ -37,7 +37,7 @@ import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.jmx.AbstractMBeanServerTests; import org.springframework.jmx.AbstractMBeanServerTests;
import org.springframework.jmx.IJmxTestBean; import org.springframework.jmx.IJmxTestBean;
@ -155,7 +155,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
} }
public void testAutodetectMBeans() throws Exception { public void testAutodetectMBeans() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("autodetectMBeans.xml", getClass())); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource("autodetectMBeans.xml", getClass()));
try { try {
bf.getBean("exporter"); bf.getBean("exporter");
MBeanServer server = (MBeanServer) bf.getBean("server"); MBeanServer server = (MBeanServer) bf.getBean("server");
@ -171,7 +172,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
} }
public void testAutodetectWithExclude() throws Exception { public void testAutodetectWithExclude() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("autodetectMBeans.xml", getClass())); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource("autodetectMBeans.xml", getClass()));
try { try {
bf.getBean("exporter"); bf.getBean("exporter");
MBeanServer server = (MBeanServer) bf.getBean("server"); MBeanServer server = (MBeanServer) bf.getBean("server");
@ -189,7 +191,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
} }
public void testAutodetectLazyMBeans() throws Exception { public void testAutodetectLazyMBeans() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("autodetectLazyMBeans.xml", getClass())); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource("autodetectLazyMBeans.xml", getClass()));
try { try {
bf.getBean("exporter"); bf.getBean("exporter");
MBeanServer server = (MBeanServer) bf.getBean("server"); MBeanServer server = (MBeanServer) bf.getBean("server");
@ -209,7 +212,8 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
} }
public void testAutodetectNoMBeans() throws Exception { public void testAutodetectNoMBeans() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("autodetectNoMBeans.xml", getClass())); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource("autodetectNoMBeans.xml", getClass()));
try { try {
bf.getBean("exporter"); bf.getBean("exporter");
} finally { } finally {

View File

@ -22,8 +22,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.build.junit.Assume; import org.springframework.tests.Assume;
import org.springframework.build.junit.TestGroup; import org.springframework.tests.TestGroup;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,6 +24,7 @@ import org.springframework.core.task.NoOpRunnable;
* @author Rick Evans * @author Rick Evans
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
@Deprecated
public class ConcurrentTaskExecutorTests extends TestCase { public class ConcurrentTaskExecutorTests extends TestCase {
public void testZeroArgCtorResultsInDefaultTaskExecutorBeingUsed() throws Exception { public void testZeroArgCtorResultsInDefaultTaskExecutorBeingUsed() throws Exception {

View File

@ -29,6 +29,7 @@ import org.springframework.scheduling.TestMethodInvokingTask;
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 20.02.2004 * @since 20.02.2004
*/ */
@Deprecated
public class TimerSupportTests extends TestCase { public class TimerSupportTests extends TestCase {
public void testTimerFactoryBean() throws Exception { public void testTimerFactoryBean() throws Exception {

View File

@ -28,6 +28,7 @@ import org.junit.Test;
* @author Rick Evans * @author Rick Evans
* @author Chris Beams * @author Chris Beams
*/ */
@Deprecated
public final class TimerTaskExecutorTests { public final class TimerTaskExecutorTests {
@Test(expected=IllegalArgumentException.class) @Test(expected=IllegalArgumentException.class)

View File

@ -19,7 +19,6 @@ package org.springframework.scripting.jruby;
import java.util.Map; import java.util.Map;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.Assert;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
import org.springframework.aop.target.dynamic.Refreshable; import org.springframework.aop.target.dynamic.Refreshable;
@ -55,14 +54,14 @@ public class JRubyScriptFactoryTests extends TestCase {
assertFalse("Scripted object should not be instance of Refreshable", calc instanceof Refreshable); assertFalse("Scripted object should not be instance of Refreshable", calc instanceof Refreshable);
assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable); assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable);
Assert.assertEquals(calc, calc); assertEquals(calc, calc);
Assert.assertEquals(messenger, messenger); assertEquals(messenger, messenger);
assertTrue(!messenger.equals(calc)); assertTrue(!messenger.equals(calc));
assertNotSame(messenger.hashCode(), calc.hashCode()); assertNotSame(messenger.hashCode(), calc.hashCode());
assertTrue(!messenger.toString().equals(calc.toString())); assertTrue(!messenger.toString().equals(calc.toString()));
String desiredMessage = "Hello World!"; String desiredMessage = "Hello World!";
Assert.assertEquals("Message is incorrect", desiredMessage, messenger.getMessage()); assertEquals("Message is incorrect", desiredMessage, messenger.getMessage());
} }
public void testNonStaticScript() throws Exception { public void testNonStaticScript() throws Exception {
@ -73,12 +72,12 @@ public class JRubyScriptFactoryTests extends TestCase {
assertTrue("Should be an instance of Refreshable", messenger instanceof Refreshable); assertTrue("Should be an instance of Refreshable", messenger instanceof Refreshable);
String desiredMessage = "Hello World!"; String desiredMessage = "Hello World!";
Assert.assertEquals("Message is incorrect.", desiredMessage, messenger.getMessage()); assertEquals("Message is incorrect.", desiredMessage, messenger.getMessage());
Refreshable refreshable = (Refreshable) messenger; Refreshable refreshable = (Refreshable) messenger;
refreshable.refresh(); refreshable.refresh();
Assert.assertEquals("Message is incorrect after refresh.", desiredMessage, messenger.getMessage()); assertEquals("Message is incorrect after refresh.", desiredMessage, messenger.getMessage());
assertEquals("Incorrect refresh count", 2, refreshable.getRefreshCount()); assertEquals("Incorrect refresh count", 2, refreshable.getRefreshCount());
} }
@ -142,14 +141,14 @@ public class JRubyScriptFactoryTests extends TestCase {
TestBean testBean = (TestBean) ctx.getBean("testBean"); TestBean testBean = (TestBean) ctx.getBean("testBean");
Messenger messenger = (Messenger) ctx.getBean("messenger"); Messenger messenger = (Messenger) ctx.getBean("messenger");
Assert.assertEquals("Hello World!", messenger.getMessage()); assertEquals("Hello World!", messenger.getMessage());
assertFalse(messenger instanceof Refreshable); assertFalse(messenger instanceof Refreshable);
TestBeanAwareMessenger messengerByType = (TestBeanAwareMessenger) ctx.getBean("messengerByType"); TestBeanAwareMessenger messengerByType = (TestBeanAwareMessenger) ctx.getBean("messengerByType");
Assert.assertEquals(testBean, messengerByType.getTestBean()); assertEquals(testBean, messengerByType.getTestBean());
TestBeanAwareMessenger messengerByName = (TestBeanAwareMessenger) ctx.getBean("messengerByName"); TestBeanAwareMessenger messengerByName = (TestBeanAwareMessenger) ctx.getBean("messengerByName");
Assert.assertEquals(testBean, messengerByName.getTestBean()); assertEquals(testBean, messengerByName.getTestBean());
} }
public void testPrototypeScriptFromTag() throws Exception { public void testPrototypeScriptFromTag() throws Exception {
@ -159,12 +158,12 @@ public class JRubyScriptFactoryTests extends TestCase {
assertNotSame(messenger, messenger2); assertNotSame(messenger, messenger2);
assertSame(messenger.getClass(), messenger2.getClass()); assertSame(messenger.getClass(), messenger2.getClass());
Assert.assertEquals("Hello World!", messenger.getMessage()); assertEquals("Hello World!", messenger.getMessage());
Assert.assertEquals("Hello World!", messenger2.getMessage()); assertEquals("Hello World!", messenger2.getMessage());
messenger.setMessage("Bye World!"); messenger.setMessage("Bye World!");
messenger2.setMessage("Byebye World!"); messenger2.setMessage("Byebye World!");
Assert.assertEquals("Bye World!", messenger.getMessage()); assertEquals("Bye World!", messenger.getMessage());
Assert.assertEquals("Byebye World!", messenger2.getMessage()); assertEquals("Byebye World!", messenger2.getMessage());
} }
public void testInlineScriptFromTag() throws Exception { public void testInlineScriptFromTag() throws Exception {
@ -177,18 +176,18 @@ public class JRubyScriptFactoryTests extends TestCase {
public void testRefreshableFromTag() throws Exception { public void testRefreshableFromTag() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-with-xsd.xml", getClass()); ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-with-xsd.xml", getClass());
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger"); Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
Assert.assertEquals("Hello World!", messenger.getMessage()); assertEquals("Hello World!", messenger.getMessage());
assertTrue("Messenger should be Refreshable", messenger instanceof Refreshable); assertTrue("Messenger should be Refreshable", messenger instanceof Refreshable);
} }
public void testThatMultipleScriptInterfacesAreSupported() throws Exception { public void testThatMultipleScriptInterfacesAreSupported() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-with-xsd.xml", getClass()); ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-with-xsd.xml", getClass());
Messenger messenger = (Messenger) ctx.getBean("calculatingMessenger"); Messenger messenger = (Messenger) ctx.getBean("calculatingMessenger");
Assert.assertEquals("Hello World!", messenger.getMessage()); assertEquals("Hello World!", messenger.getMessage());
// cool, now check that the Calculator interface is also exposed // cool, now check that the Calculator interface is also exposed
Calculator calc = (Calculator) messenger; Calculator calc = (Calculator) messenger;
Assert.assertEquals(0, calc.add(2, -2)); assertEquals(0, calc.add(2, -2));
} }
public void testWithComplexArg() throws Exception { public void testWithComplexArg() throws Exception {
@ -270,7 +269,7 @@ public class JRubyScriptFactoryTests extends TestCase {
public void testAOP() throws Exception { public void testAOP() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-aop.xml", getClass()); ApplicationContext ctx = new ClassPathXmlApplicationContext("jruby-aop.xml", getClass());
Messenger messenger = (Messenger) ctx.getBean("messenger"); Messenger messenger = (Messenger) ctx.getBean("messenger");
Assert.assertEquals(new StringBuffer("Hello World!").reverse().toString(), messenger.getMessage()); assertEquals(new StringBuffer("Hello World!").reverse().toString(), messenger.getMessage());
} }

View File

@ -205,7 +205,7 @@ public class ScriptFactoryPostProcessorTests extends TestCase {
ctx.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition()); ctx.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition());
BeanDefinitionBuilder scriptedBeanBuilder = BeanDefinitionBuilder.rootBeanDefinition(GroovyScriptFactory.class); BeanDefinitionBuilder scriptedBeanBuilder = BeanDefinitionBuilder.rootBeanDefinition(GroovyScriptFactory.class);
scriptedBeanBuilder.setSingleton(false); scriptedBeanBuilder.setScope(BeanDefinition.SCOPE_PROTOTYPE);
scriptedBeanBuilder.addConstructorArgValue(DELEGATING_SCRIPT); scriptedBeanBuilder.addConstructorArgValue(DELEGATING_SCRIPT);
scriptedBeanBuilder.addPropertyReference("messenger", "messenger"); scriptedBeanBuilder.addPropertyReference("messenger", "messenger");

View File

@ -20,7 +20,6 @@ import java.beans.PropertyEditorSupport;
import java.util.Map; import java.util.Map;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.Assert;
import org.springframework.beans.FieldAccessBean; import org.springframework.beans.FieldAccessBean;
import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.MutablePropertyValues;
@ -106,7 +105,7 @@ public class DataBinderFieldAccessTests extends TestCase {
assertTrue("Correct number of age errors", br.getFieldErrorCount("age") == 1); assertTrue("Correct number of age errors", br.getFieldErrorCount("age") == 1);
assertEquals("32x", binder.getBindingResult().getFieldValue("age")); assertEquals("32x", binder.getBindingResult().getFieldValue("age"));
assertEquals("32x", binder.getBindingResult().getFieldError("age").getRejectedValue()); assertEquals("32x", binder.getBindingResult().getFieldError("age").getRejectedValue());
Assert.assertEquals(0, tb.getAge()); assertEquals(0, tb.getAge());
} }
} }
@ -152,7 +151,7 @@ public class DataBinderFieldAccessTests extends TestCase {
assertTrue("Correct number of age errors", br.getFieldErrorCount("age") == 1); assertTrue("Correct number of age errors", br.getFieldErrorCount("age") == 1);
assertEquals("32x", binder.getBindingResult().getFieldValue("age")); assertEquals("32x", binder.getBindingResult().getFieldValue("age"));
assertEquals("32x", binder.getBindingResult().getFieldError("age").getRejectedValue()); assertEquals("32x", binder.getBindingResult().getFieldError("age").getRejectedValue());
Assert.assertEquals(0, tb.getAge()); assertEquals(0, tb.getAge());
assertTrue("Does not have spouse errors", !br.hasFieldErrors("spouse")); assertTrue("Does not have spouse errors", !br.hasFieldErrors("spouse"));
assertEquals("Kerry", binder.getBindingResult().getFieldValue("spouse")); assertEquals("Kerry", binder.getBindingResult().getFieldValue("spouse"));

View File

@ -33,21 +33,25 @@ import org.springframework.util.MultiValueMap;
*/ */
public class CollectionFactoryTests extends TestCase { public class CollectionFactoryTests extends TestCase {
@SuppressWarnings("deprecation")
public void testLinkedSet() { public void testLinkedSet() {
Set set = CollectionFactory.createLinkedSetIfPossible(16); Set set = CollectionFactory.createLinkedSetIfPossible(16);
assertTrue(set instanceof LinkedHashSet); assertTrue(set instanceof LinkedHashSet);
} }
@SuppressWarnings("deprecation")
public void testLinkedMap() { public void testLinkedMap() {
Map map = CollectionFactory.createLinkedMapIfPossible(16); Map map = CollectionFactory.createLinkedMapIfPossible(16);
assertTrue(map instanceof LinkedHashMap); assertTrue(map instanceof LinkedHashMap);
} }
@SuppressWarnings("deprecation")
public void testIdentityMap() { public void testIdentityMap() {
Map map = CollectionFactory.createIdentityMapIfPossible(16); Map map = CollectionFactory.createIdentityMapIfPossible(16);
assertTrue(map instanceof IdentityHashMap); assertTrue(map instanceof IdentityHashMap);
} }
@SuppressWarnings("deprecation")
public void testConcurrentMap() { public void testConcurrentMap() {
Map map = CollectionFactory.createConcurrentMapIfPossible(16); Map map = CollectionFactory.createConcurrentMapIfPossible(16);
assertTrue(map.getClass().getName().endsWith("ConcurrentHashMap")); assertTrue(map.getClass().getName().endsWith("ConcurrentHashMap"));
@ -58,6 +62,7 @@ public class CollectionFactoryTests extends TestCase {
assertTrue(map.getClass().getName().endsWith("MultiValueMap")); assertTrue(map.getClass().getName().endsWith("MultiValueMap"));
} }
@SuppressWarnings("deprecation")
public void testConcurrentMapWithExplicitInterface() { public void testConcurrentMapWithExplicitInterface() {
ConcurrentMap map = CollectionFactory.createConcurrentMap(16); ConcurrentMap map = CollectionFactory.createConcurrentMap(16);
assertTrue(map.getClass().getSuperclass().getName().endsWith("ConcurrentHashMap")); assertTrue(map.getClass().getSuperclass().getName().endsWith("ConcurrentHashMap"));

View File

@ -25,8 +25,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import junit.framework.Assert;
import org.springframework.beans.GenericBean; import org.springframework.beans.GenericBean;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
@ -96,11 +94,11 @@ public class GenericCollectionTypeResolverTests extends AbstractGenericsTests {
public void testProgrammaticListIntrospection() throws Exception { public void testProgrammaticListIntrospection() throws Exception {
Method setter = GenericBean.class.getMethod("setResourceList", List.class); Method setter = GenericBean.class.getMethod("setResourceList", List.class);
Assert.assertEquals(Resource.class, assertEquals(Resource.class,
GenericCollectionTypeResolver.getCollectionParameterType(new MethodParameter(setter, 0))); GenericCollectionTypeResolver.getCollectionParameterType(new MethodParameter(setter, 0)));
Method getter = GenericBean.class.getMethod("getResourceList"); Method getter = GenericBean.class.getMethod("getResourceList");
Assert.assertEquals(Resource.class, assertEquals(Resource.class,
GenericCollectionTypeResolver.getCollectionReturnType(getter)); GenericCollectionTypeResolver.getCollectionReturnType(getter));
} }

View File

@ -20,7 +20,6 @@ import java.io.ByteArrayOutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.Assert;
/** /**
* @author Rod Johnson * @author Rod Johnson
@ -52,7 +51,7 @@ public class NestedExceptionTests extends TestCase {
Exception rootCause = new Exception(rootCauseMesg); Exception rootCause = new Exception(rootCauseMesg);
// Making a class abstract doesn't _really_ prevent instantiation :-) // Making a class abstract doesn't _really_ prevent instantiation :-)
NestedRuntimeException nex = new NestedRuntimeException(myMessage, rootCause) {}; NestedRuntimeException nex = new NestedRuntimeException(myMessage, rootCause) {};
Assert.assertEquals(nex.getCause(), rootCause); assertEquals(nex.getCause(), rootCause);
assertTrue(nex.getMessage().indexOf(myMessage) != -1); assertTrue(nex.getMessage().indexOf(myMessage) != -1);
assertTrue(nex.getMessage().indexOf(rootCauseMesg) != -1); assertTrue(nex.getMessage().indexOf(rootCauseMesg) != -1);
@ -90,7 +89,7 @@ public class NestedExceptionTests extends TestCase {
Exception rootCause = new Exception(rootCauseMesg); Exception rootCause = new Exception(rootCauseMesg);
// Making a class abstract doesn't _really_ prevent instantiation :-) // Making a class abstract doesn't _really_ prevent instantiation :-)
NestedCheckedException nex = new NestedCheckedException(myMessage, rootCause) {}; NestedCheckedException nex = new NestedCheckedException(myMessage, rootCause) {};
Assert.assertEquals(nex.getCause(), rootCause); assertEquals(nex.getCause(), rootCause);
assertTrue(nex.getMessage().indexOf(myMessage) != -1); assertTrue(nex.getMessage().indexOf(myMessage) != -1);
assertTrue(nex.getMessage().indexOf(rootCauseMesg) != -1); assertTrue(nex.getMessage().indexOf(rootCauseMesg) != -1);

View File

@ -401,7 +401,7 @@ public class DefaultConversionTests {
public void convertArrayToObjectAssignableTargetType() { public void convertArrayToObjectAssignableTargetType() {
Long[] array = new Long[] { 3L }; Long[] array = new Long[] { 3L };
Long[] result = (Long[]) conversionService.convert(array, Object.class); Long[] result = (Long[]) conversionService.convert(array, Object.class);
assertEquals(array, result); assertArrayEquals(array, result);
} }
@Test @Test

View File

@ -35,8 +35,6 @@ import java.util.UUID;
import org.junit.Test; import org.junit.Test;
import org.springframework.build.junit.Assume;
import org.springframework.build.junit.TestGroup;
import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConverterNotFoundException; import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.TypeDescriptor;
@ -46,6 +44,8 @@ import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.core.convert.converter.GenericConverter; import org.springframework.core.convert.converter.GenericConverter;
import org.springframework.core.io.DescriptiveResource; import org.springframework.core.io.DescriptiveResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;

View File

@ -29,6 +29,7 @@ import junit.framework.TestCase;
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen * @author Sam Brannen
*/ */
@Deprecated
public class LabeledEnumTests extends TestCase { public class LabeledEnumTests extends TestCase {
private byte[] serializeObject(final Object obj) throws IOException { private byte[] serializeObject(final Object obj) throws IOException {

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