moving unit tests from .testsuite -> .beans
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.beans.annotation;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.AnnotationBeanWiringInfoResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowire;
|
||||
import org.springframework.beans.factory.annotation.Configurable;
|
||||
import org.springframework.beans.factory.wiring.BeanWiringInfo;
|
||||
|
||||
/**
|
||||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AnnotationBeanWiringInfoResolverTests {
|
||||
|
||||
@Test
|
||||
public void testResolveWiringInfo() throws Exception {
|
||||
try {
|
||||
new AnnotationBeanWiringInfoResolver().resolveWiringInfo(null);
|
||||
fail("Must have thrown an IllegalArgumentException by this point (null argument)");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveWiringInfoWithAnInstanceOfANonAnnotatedClass() {
|
||||
AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
|
||||
BeanWiringInfo info = resolver.resolveWiringInfo("java.lang.String is not @Configurable");
|
||||
assertNull("Must be returning null for a non-@Configurable class instance", info);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClass() {
|
||||
AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
|
||||
BeanWiringInfo info = resolver.resolveWiringInfo(new Soap());
|
||||
assertNotNull("Must *not* be returning null for a non-@Configurable class instance", info);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitly() {
|
||||
AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
|
||||
BeanWiringInfo info = resolver.resolveWiringInfo(new WirelessSoap());
|
||||
assertNotNull("Must *not* be returning null for an @Configurable class instance even when autowiring is NO", info);
|
||||
assertFalse(info.indicatesAutowiring());
|
||||
assertEquals(WirelessSoap.class.getName(), info.getBeanName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitlyAndCustomBeanName() {
|
||||
AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
|
||||
BeanWiringInfo info = resolver.resolveWiringInfo(new NamedWirelessSoap());
|
||||
assertNotNull("Must *not* be returning null for an @Configurable class instance even when autowiring is NO", info);
|
||||
assertFalse(info.indicatesAutowiring());
|
||||
assertEquals("DerBigStick", info.getBeanName());
|
||||
}
|
||||
|
||||
|
||||
@Configurable()
|
||||
private static class Soap {
|
||||
}
|
||||
|
||||
|
||||
@Configurable(autowire = Autowire.NO)
|
||||
private static class WirelessSoap {
|
||||
}
|
||||
|
||||
|
||||
@Configurable(autowire = Autowire.NO, value = "DerBigStick")
|
||||
private static class NamedWirelessSoap {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.beans.factory;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.cglib.proxy.NoOp;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.IndexedTestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.StaticListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 04.07.2003
|
||||
*/
|
||||
public class BeanFactoryUtilsTests {
|
||||
|
||||
private ConfigurableListableBeanFactory listableBeanFactory;
|
||||
|
||||
private ConfigurableListableBeanFactory dependentBeansBF;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// Interesting hierarchical factory to test counts.
|
||||
// Slow to read so we cache it.
|
||||
XmlBeanFactory grandParent = new XmlBeanFactory(new ClassPathResource("root.xml", getClass()));
|
||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("middle.xml", getClass()), grandParent);
|
||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("leaf.xml", getClass()), parent);
|
||||
this.dependentBeansBF = new XmlBeanFactory(new ClassPathResource("dependentBeans.xml", getClass()));
|
||||
dependentBeansBF.preInstantiateSingletons();
|
||||
this.listableBeanFactory = child;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHierarchicalCountBeansWithNonHierarchicalFactory() {
|
||||
StaticListableBeanFactory lbf = new StaticListableBeanFactory();
|
||||
lbf.addBean("t1", new TestBean());
|
||||
lbf.addBean("t2", new TestBean());
|
||||
assertTrue(BeanFactoryUtils.countBeansIncludingAncestors(lbf) == 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that override doesn't count as two separate beans.
|
||||
*/
|
||||
@Test
|
||||
public void testHierarchicalCountBeansWithOverride() throws Exception {
|
||||
// Leaf count
|
||||
assertTrue(this.listableBeanFactory.getBeanDefinitionCount() == 1);
|
||||
// Count minus duplicate
|
||||
assertTrue("Should count 7 beans, not "
|
||||
+ BeanFactoryUtils.countBeansIncludingAncestors(this.listableBeanFactory),
|
||||
BeanFactoryUtils.countBeansIncludingAncestors(this.listableBeanFactory) == 7);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHierarchicalNamesWithNoMatch() throws Exception {
|
||||
List<String> names = Arrays.asList(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory,
|
||||
NoOp.class));
|
||||
assertEquals(0, names.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHierarchicalNamesWithMatchOnlyInRoot() throws Exception {
|
||||
List<String> names = Arrays.asList(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory,
|
||||
IndexedTestBean.class));
|
||||
assertEquals(1, names.size());
|
||||
assertTrue(names.contains("indexedBean"));
|
||||
// Distinguish from default ListableBeanFactory behavior
|
||||
assertTrue(listableBeanFactory.getBeanNamesForType(IndexedTestBean.class).length == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBeanNamesForTypeWithOverride() throws Exception {
|
||||
List<String> names = Arrays.asList(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory,
|
||||
ITestBean.class));
|
||||
// includes 2 TestBeans from FactoryBeans (DummyFactory definitions)
|
||||
assertEquals(4, names.size());
|
||||
assertTrue(names.contains("test"));
|
||||
assertTrue(names.contains("test3"));
|
||||
assertTrue(names.contains("testFactory1"));
|
||||
assertTrue(names.contains("testFactory2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoBeansOfType() {
|
||||
StaticListableBeanFactory lbf = new StaticListableBeanFactory();
|
||||
lbf.addBean("foo", new Object());
|
||||
Map<?, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
|
||||
assertTrue(beans.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindsBeansOfTypeWithStaticFactory() {
|
||||
StaticListableBeanFactory lbf = new StaticListableBeanFactory();
|
||||
TestBean t1 = new TestBean();
|
||||
TestBean t2 = new TestBean();
|
||||
DummyFactory t3 = new DummyFactory();
|
||||
DummyFactory t4 = new DummyFactory();
|
||||
t4.setSingleton(false);
|
||||
lbf.addBean("t1", t1);
|
||||
lbf.addBean("t2", t2);
|
||||
lbf.addBean("t3", t3);
|
||||
lbf.addBean("t4", t4);
|
||||
|
||||
Map<?, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
|
||||
assertEquals(2, beans.size());
|
||||
assertEquals(t1, beans.get("t1"));
|
||||
assertEquals(t2, beans.get("t2"));
|
||||
|
||||
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, false, true);
|
||||
assertEquals(3, beans.size());
|
||||
assertEquals(t1, beans.get("t1"));
|
||||
assertEquals(t2, beans.get("t2"));
|
||||
assertEquals(t3.getObject(), beans.get("t3"));
|
||||
|
||||
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, true);
|
||||
assertEquals(4, beans.size());
|
||||
assertEquals(t1, beans.get("t1"));
|
||||
assertEquals(t2, beans.get("t2"));
|
||||
assertEquals(t3.getObject(), beans.get("t3"));
|
||||
assertTrue(beans.get("t4") instanceof TestBean);
|
||||
|
||||
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true);
|
||||
assertEquals(2, beans.size());
|
||||
assertEquals(t3, beans.get("&t3"));
|
||||
assertEquals(t4, beans.get("&t4"));
|
||||
|
||||
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, FactoryBean.class, true, true);
|
||||
assertEquals(2, beans.size());
|
||||
assertEquals(t3, beans.get("&t3"));
|
||||
assertEquals(t4, beans.get("&t4"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindsBeansOfTypeWithDefaultFactory() {
|
||||
Object test3 = this.listableBeanFactory.getBean("test3");
|
||||
Object test = this.listableBeanFactory.getBean("test");
|
||||
|
||||
TestBean t1 = new TestBean();
|
||||
TestBean t2 = new TestBean();
|
||||
DummyFactory t3 = new DummyFactory();
|
||||
DummyFactory t4 = new DummyFactory();
|
||||
t4.setSingleton(false);
|
||||
this.listableBeanFactory.registerSingleton("t1", t1);
|
||||
this.listableBeanFactory.registerSingleton("t2", t2);
|
||||
this.listableBeanFactory.registerSingleton("t3", t3);
|
||||
this.listableBeanFactory.registerSingleton("t4", t4);
|
||||
|
||||
Map<?, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, true,
|
||||
false);
|
||||
assertEquals(6, beans.size());
|
||||
assertEquals(test3, beans.get("test3"));
|
||||
assertEquals(test, beans.get("test"));
|
||||
assertEquals(t1, beans.get("t1"));
|
||||
assertEquals(t2, beans.get("t2"));
|
||||
assertEquals(t3.getObject(), beans.get("t3"));
|
||||
assertTrue(beans.get("t4") instanceof TestBean);
|
||||
// t3 and t4 are found here as of Spring 2.0, since they are
|
||||
// pre-registered
|
||||
// singleton instances, while testFactory1 and testFactory are *not*
|
||||
// found
|
||||
// because they are FactoryBean definitions that haven't been
|
||||
// initialized yet.
|
||||
|
||||
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, false, true);
|
||||
Object testFactory1 = this.listableBeanFactory.getBean("testFactory1");
|
||||
assertEquals(5, beans.size());
|
||||
assertEquals(test, beans.get("test"));
|
||||
assertEquals(testFactory1, beans.get("testFactory1"));
|
||||
assertEquals(t1, beans.get("t1"));
|
||||
assertEquals(t2, beans.get("t2"));
|
||||
assertEquals(t3.getObject(), beans.get("t3"));
|
||||
|
||||
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, true, true);
|
||||
assertEquals(8, beans.size());
|
||||
assertEquals(test3, beans.get("test3"));
|
||||
assertEquals(test, beans.get("test"));
|
||||
assertEquals(testFactory1, beans.get("testFactory1"));
|
||||
assertTrue(beans.get("testFactory2") instanceof TestBean);
|
||||
assertEquals(t1, beans.get("t1"));
|
||||
assertEquals(t2, beans.get("t2"));
|
||||
assertEquals(t3.getObject(), beans.get("t3"));
|
||||
assertTrue(beans.get("t4") instanceof TestBean);
|
||||
|
||||
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, DummyFactory.class, true, true);
|
||||
assertEquals(4, beans.size());
|
||||
assertEquals(this.listableBeanFactory.getBean("&testFactory1"), beans.get("&testFactory1"));
|
||||
assertEquals(this.listableBeanFactory.getBean("&testFactory2"), beans.get("&testFactory2"));
|
||||
assertEquals(t3, beans.get("&t3"));
|
||||
assertEquals(t4, beans.get("&t4"));
|
||||
|
||||
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, FactoryBean.class, true, true);
|
||||
assertEquals(4, beans.size());
|
||||
assertEquals(this.listableBeanFactory.getBean("&testFactory1"), beans.get("&testFactory1"));
|
||||
assertEquals(this.listableBeanFactory.getBean("&testFactory2"), beans.get("&testFactory2"));
|
||||
assertEquals(t3, beans.get("&t3"));
|
||||
assertEquals(t4, beans.get("&t4"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHierarchicalResolutionWithOverride() throws Exception {
|
||||
Object test3 = this.listableBeanFactory.getBean("test3");
|
||||
Object test = this.listableBeanFactory.getBean("test");
|
||||
|
||||
Map<?, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, true,
|
||||
false);
|
||||
assertEquals(2, beans.size());
|
||||
assertEquals(test3, beans.get("test3"));
|
||||
assertEquals(test, beans.get("test"));
|
||||
|
||||
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, false, false);
|
||||
assertEquals(1, beans.size());
|
||||
assertEquals(test, beans.get("test"));
|
||||
|
||||
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, false, true);
|
||||
Object testFactory1 = this.listableBeanFactory.getBean("testFactory1");
|
||||
assertEquals(2, beans.size());
|
||||
assertEquals(test, beans.get("test"));
|
||||
assertEquals(testFactory1, beans.get("testFactory1"));
|
||||
|
||||
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, true, true);
|
||||
assertEquals(4, beans.size());
|
||||
assertEquals(test3, beans.get("test3"));
|
||||
assertEquals(test, beans.get("test"));
|
||||
assertEquals(testFactory1, beans.get("testFactory1"));
|
||||
assertTrue(beans.get("testFactory2") instanceof TestBean);
|
||||
|
||||
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, DummyFactory.class, true, true);
|
||||
assertEquals(2, beans.size());
|
||||
assertEquals(this.listableBeanFactory.getBean("&testFactory1"), beans.get("&testFactory1"));
|
||||
assertEquals(this.listableBeanFactory.getBean("&testFactory2"), beans.get("&testFactory2"));
|
||||
|
||||
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, FactoryBean.class, true, true);
|
||||
assertEquals(2, beans.size());
|
||||
assertEquals(this.listableBeanFactory.getBean("&testFactory1"), beans.get("&testFactory1"));
|
||||
assertEquals(this.listableBeanFactory.getBean("&testFactory2"), beans.get("&testFactory2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testADependencies() {
|
||||
String[] deps = this.dependentBeansBF.getDependentBeans("a");
|
||||
assertTrue(ObjectUtils.isEmpty(deps));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBDependencies() {
|
||||
String[] deps = this.dependentBeansBF.getDependentBeans("b");
|
||||
assertTrue(Arrays.equals(new String[] { "c" }, deps));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCDependencies() {
|
||||
String[] deps = this.dependentBeansBF.getDependentBeans("c");
|
||||
assertTrue(Arrays.equals(new String[] { "int", "long" }, deps));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntDependencies() {
|
||||
String[] deps = this.dependentBeansBF.getDependentBeans("int");
|
||||
assertTrue(Arrays.equals(new String[] { "buffer" }, deps));
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.beans.factory;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class FactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testFactoryBeanReturnsNull() throws Exception {
|
||||
XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("factoryBeanReturnsNull.xml", getClass()));
|
||||
Object result = factory.getBean("factoryBean");
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactoryBeansWithAutowiring() throws Exception {
|
||||
XmlBeanFactory factory =
|
||||
new XmlBeanFactory(new ClassPathResource("factoryBeansWithAutowiring.xml", getClass()));
|
||||
|
||||
BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
|
||||
ppc.postProcessBeanFactory(factory);
|
||||
|
||||
Alpha alpha = (Alpha) factory.getBean("alpha");
|
||||
Beta beta = (Beta) factory.getBean("beta");
|
||||
Gamma gamma = (Gamma) factory.getBean("gamma");
|
||||
Gamma gamma2 = (Gamma) factory.getBean("gammaFactory");
|
||||
assertSame(beta, alpha.getBeta());
|
||||
assertSame(gamma, beta.getGamma());
|
||||
assertSame(gamma2, beta.getGamma());
|
||||
assertEquals("yourName", beta.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactoryBeansWithIntermediateFactoryBeanAutowiringFailure() throws Exception {
|
||||
XmlBeanFactory factory =
|
||||
new XmlBeanFactory(new ClassPathResource("factoryBeansWithAutowiring.xml", getClass()));
|
||||
|
||||
BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
|
||||
ppc.postProcessBeanFactory(factory);
|
||||
|
||||
Beta beta = (Beta) factory.getBean("beta");
|
||||
Alpha alpha = (Alpha) factory.getBean("alpha");
|
||||
Gamma gamma = (Gamma) factory.getBean("gamma");
|
||||
assertSame(beta, alpha.getBeta());
|
||||
assertSame(gamma, beta.getGamma());
|
||||
}
|
||||
|
||||
|
||||
public static class NullReturningFactoryBean implements FactoryBean<Object> {
|
||||
|
||||
public Object getObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Class<?> getObjectType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Alpha implements InitializingBean {
|
||||
|
||||
private Beta beta;
|
||||
|
||||
public void setBeta(Beta beta) {
|
||||
this.beta = beta;
|
||||
}
|
||||
|
||||
public Beta getBeta() {
|
||||
return beta;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
Assert.notNull(beta, "'beta' property is required");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Beta implements InitializingBean {
|
||||
|
||||
private Gamma gamma;
|
||||
|
||||
private String name;
|
||||
|
||||
public void setGamma(Gamma gamma) {
|
||||
this.gamma = gamma;
|
||||
}
|
||||
|
||||
public Gamma getGamma() {
|
||||
return gamma;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
Assert.notNull(gamma, "'gamma' property is required");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Gamma {
|
||||
}
|
||||
|
||||
|
||||
public static class BetaFactoryBean implements FactoryBean<Object> {
|
||||
|
||||
private Beta beta;
|
||||
|
||||
public void setBeta(Beta beta) {
|
||||
this.beta = beta;
|
||||
}
|
||||
|
||||
public Object getObject() {
|
||||
return this.beta;
|
||||
}
|
||||
|
||||
public Class<?> getObjectType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2002-2005 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.beans.factory;
|
||||
|
||||
public class KnowsIfInstantiated {
|
||||
|
||||
private static boolean instantiated;
|
||||
|
||||
public static void clearInstantiationRecord() {
|
||||
instantiated = false;
|
||||
}
|
||||
|
||||
public static boolean wasInstantiated() {
|
||||
return instantiated;
|
||||
}
|
||||
|
||||
public KnowsIfInstantiated() {
|
||||
instantiated = true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<bean id="a" class="java.lang.Object" />
|
||||
|
||||
<bean id="b" class="java.lang.Integer">
|
||||
<constructor-arg value="50" />
|
||||
</bean>
|
||||
|
||||
<bean id="c" class="java.lang.String">
|
||||
<constructor-arg ref="b" />
|
||||
</bean>
|
||||
|
||||
<bean id="int" class="java.lang.Integer">
|
||||
<constructor-arg ref="c" />
|
||||
</bean>
|
||||
|
||||
<bean id="long" class="java.lang.Long">
|
||||
<constructor-arg ref="c" />
|
||||
</bean>
|
||||
|
||||
<bean id="buffer" class="java.lang.StringBuffer">
|
||||
<constructor-arg ref="int" />
|
||||
</bean>
|
||||
|
||||
<bean id="thread" class="java.lang.Thread"/>
|
||||
|
||||
<bean id="field" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
|
||||
<property name="targetObject" ref="thread"/>
|
||||
<property name="targetField" value="MAX_PRIORITY"/>
|
||||
</bean>
|
||||
|
||||
<bean id="secondBuffer" class="java.lang.StringBuffer">
|
||||
<constructor-arg ref="field"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="factoryBean" class="org.springframework.beans.factory.FactoryBeanTests$NullReturningFactoryBean"/>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans default-lazy-init="true">
|
||||
|
||||
<bean name="beta" class="org.springframework.beans.factory.FactoryBeanTests$Beta" autowire="byType">
|
||||
<property name="name" value="${myName}"/>
|
||||
</bean>
|
||||
|
||||
<bean id="alpha" class="org.springframework.beans.factory.FactoryBeanTests$Alpha" autowire="byType"/>
|
||||
|
||||
<bean id="gamma" class="org.springframework.beans.factory.FactoryBeanTests$Gamma"/>
|
||||
|
||||
<bean id="betaFactory" class="org.springframework.beans.factory.FactoryBeanTests$BetaFactoryBean">
|
||||
<property name="beta" ref="beta"/>
|
||||
</bean>
|
||||
|
||||
<bean id="gammaFactory" factory-bean="betaFactory" factory-method="getGamma"/>
|
||||
|
||||
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="properties">
|
||||
<props>
|
||||
<prop key="myName">yourName</prop>
|
||||
</props>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="test3" class="org.springframework.beans.TestBean" scope="prototype">
|
||||
<property name="name"><value>custom</value></property>
|
||||
<property name="age"><value>25</value></property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<!-- Simple target -->
|
||||
<bean id="test" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><value>custom</value></property>
|
||||
<property name="age"><value>666</value></property>
|
||||
</bean>
|
||||
|
||||
<!--
|
||||
Check that invoker is automatically added to wrap target.
|
||||
Non pointcut bean name should be wrapped in invoker.
|
||||
-->
|
||||
<bean id="numberTestBean" class="org.springframework.beans.NumberTestBean"/>
|
||||
|
||||
</beans>
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<!--
|
||||
Just included for the count: not to mean anything in particular
|
||||
-->
|
||||
<bean id="something" class="org.springframework.beans.GenericIntegerBean"/>
|
||||
|
||||
<bean id="indexedBean" class="org.springframework.beans.IndexedTestBean"/>
|
||||
|
||||
<!-- Overridden by next factory -->
|
||||
<bean id="test" class="org.springframework.beans.TestBean">
|
||||
<property name="name"><value>custom</value></property>
|
||||
<property name="age"><value>25</value></property>
|
||||
</bean>
|
||||
|
||||
<bean id="testFactory1" class="org.springframework.beans.factory.DummyFactory"/>
|
||||
|
||||
<bean id="testFactory2" class="org.springframework.beans.factory.DummyFactory">
|
||||
<property name="singleton"><value>false</value></property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 2002-2005 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.beans.factory.xml;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.beans.IndexedTestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
|
||||
/**
|
||||
* Simple bean used to check constructor dependency checking.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 09.11.2003
|
||||
*/
|
||||
public class ConstructorDependenciesBean implements Serializable {
|
||||
|
||||
private int age;
|
||||
|
||||
private String name;
|
||||
|
||||
private TestBean spouse1;
|
||||
|
||||
private TestBean spouse2;
|
||||
|
||||
private IndexedTestBean other;
|
||||
|
||||
public ConstructorDependenciesBean(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1) {
|
||||
this.spouse1 = spouse1;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1, TestBean spouse2) {
|
||||
this.spouse1 = spouse1;
|
||||
this.spouse2 = spouse2;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1, TestBean spouse2, int age) {
|
||||
this.spouse1 = spouse1;
|
||||
this.spouse2 = spouse2;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public ConstructorDependenciesBean(TestBean spouse1, TestBean spouse2, IndexedTestBean other) {
|
||||
this.spouse1 = spouse1;
|
||||
this.spouse2 = spouse2;
|
||||
this.other = other;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public TestBean getSpouse1() {
|
||||
return spouse1;
|
||||
}
|
||||
|
||||
public TestBean getSpouse2() {
|
||||
return spouse2;
|
||||
}
|
||||
|
||||
public IndexedTestBean getOther() {
|
||||
return other;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2002-2005 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.beans.factory.xml;
|
||||
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
|
||||
/**
|
||||
* Simple bean used to test dependency checking.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @since 04.09.2003
|
||||
*/
|
||||
public class DependenciesBean implements BeanFactoryAware {
|
||||
|
||||
private int age;
|
||||
|
||||
private String name;
|
||||
|
||||
private TestBean spouse;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setSpouse(TestBean spouse) {
|
||||
this.spouse = spouse;
|
||||
}
|
||||
|
||||
public TestBean getSpouse() {
|
||||
return spouse;
|
||||
}
|
||||
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
public BeanFactory getBeanFactory() {
|
||||
return beanFactory;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.springframework.beans.factory.xml;
|
||||
/**
|
||||
* Bean that changes state on a business invocation, so that
|
||||
* we can check whether it's been invoked
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public class SideEffectBean {
|
||||
|
||||
private int count;
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
public void doWork() {
|
||||
++count;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user