Moved tests from testsuite to beans
This commit is contained in:
parent
a1b810fbdf
commit
7f90f08705
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright 2002-2006 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 org.springframework.beans.TestBean;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class CountingFactory implements FactoryBean {
|
||||
|
||||
private static int factoryBeanInstanceCount = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Clear static state.
|
||||
*/
|
||||
public static void reset() {
|
||||
factoryBeanInstanceCount = 0;
|
||||
}
|
||||
|
||||
public static int getFactoryBeanInstanceCount() {
|
||||
return factoryBeanInstanceCount;
|
||||
}
|
||||
|
||||
|
||||
public CountingFactory() {
|
||||
factoryBeanInstanceCount++;
|
||||
}
|
||||
|
||||
public void setTestBean(TestBean tb) {
|
||||
if (tb.getSpouse() == null) {
|
||||
throw new IllegalStateException("TestBean needs to have spouse");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Object getObject() {
|
||||
return "myString";
|
||||
}
|
||||
|
||||
public Class getObjectType() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?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="rob" class="org.springframework.beans.TestBean" scope="prototype" autowire="constructor"/>
|
||||
|
||||
<bean id="sally" class="org.springframework.beans.TestBean" scope="prototype"/>
|
||||
|
||||
<bean id="props1" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<property name="properties">
|
||||
<value>name=props1</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="props2" class="org.springframework.beans.factory.config.PropertiesFactoryBean" autowire-candidate="false">
|
||||
<property name="properties">
|
||||
<value>name=props2</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,26 @@
|
|||
<?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="rob" class="org.springframework.beans.TestBean" autowire="byType"/>
|
||||
|
||||
<bean id="sally" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
<bean id="props1" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<property name="properties">
|
||||
<value>name=props1</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="props2" class="org.springframework.beans.factory.config.PropertiesFactoryBean" autowire-candidate="false">
|
||||
<property name="properties">
|
||||
<value>name=props2</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.factory.CountingFactory">
|
||||
<property name="testBean" ref="rob"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,27 @@
|
|||
<?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.5.xsd"
|
||||
default-autowire-candidates="">
|
||||
|
||||
<bean id="rob" class="org.springframework.beans.TestBean" autowire="byType"/>
|
||||
|
||||
<bean id="sally" class="org.springframework.beans.TestBean" autowire-candidate="true"/>
|
||||
|
||||
<bean id="props1" class="org.springframework.beans.factory.config.PropertiesFactoryBean" autowire-candidate="true">
|
||||
<property name="properties">
|
||||
<value>name=props1</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="props2" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<property name="properties">
|
||||
<value>name=props2</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.factory.CountingFactory">
|
||||
<property name="testBean" ref="rob"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,33 @@
|
|||
<?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.5.xsd"
|
||||
default-autowire-candidates="props*,*ly">
|
||||
|
||||
<bean id="rob" class="org.springframework.beans.TestBean" autowire="byType"/>
|
||||
|
||||
<bean id="sally" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
<bean id="props1" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<property name="properties">
|
||||
<value>name=props1</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="props2" class="org.springframework.beans.factory.config.PropertiesFactoryBean" autowire-candidate="false">
|
||||
<property name="properties">
|
||||
<value>name=props2</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="someProps" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<property name="properties">
|
||||
<value>name=someProps</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.beans.factory.CountingFactory">
|
||||
<property name="testBean" ref="rob"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
Loading…
Reference in New Issue