moving unit tests from .testsuite -> .beans
This commit is contained in:
parent
b44d647dad
commit
248a7de73f
|
|
@ -17,7 +17,8 @@
|
||||||
package org.springframework.beans.factory.xml;
|
package org.springframework.beans.factory.xml;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.springframework.test.AssertThrows;
|
|
||||||
|
import org.junit.Test;
|
||||||
import org.xml.sax.EntityResolver;
|
import org.xml.sax.EntityResolver;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
|
|
@ -25,40 +26,30 @@ import org.xml.sax.InputSource;
|
||||||
* Unit tests for the {@link DelegatingEntityResolver} class.
|
* Unit tests for the {@link DelegatingEntityResolver} class.
|
||||||
*
|
*
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public final class DelegatingEntityResolverTests extends TestCase {
|
public final class DelegatingEntityResolverTests {
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void testCtorWhereDtdEntityResolverIsNull() throws Exception {
|
public void testCtorWhereDtdEntityResolverIsNull() throws Exception {
|
||||||
new AssertThrows(IllegalArgumentException.class) {
|
new DelegatingEntityResolver(null, new NoOpEntityResolver());
|
||||||
public void test() throws Exception {
|
|
||||||
new DelegatingEntityResolver(null, new NoOpEntityResolver());
|
|
||||||
}
|
|
||||||
}.runTest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void testCtorWhereSchemaEntityResolverIsNull() throws Exception {
|
public void testCtorWhereSchemaEntityResolverIsNull() throws Exception {
|
||||||
new AssertThrows(IllegalArgumentException.class) {
|
new DelegatingEntityResolver(new NoOpEntityResolver(), null);
|
||||||
public void test() throws Exception {
|
|
||||||
new DelegatingEntityResolver(new NoOpEntityResolver(), null);
|
|
||||||
}
|
|
||||||
}.runTest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void testCtorWhereEntityResolversAreBothNull() throws Exception {
|
public void testCtorWhereEntityResolversAreBothNull() throws Exception {
|
||||||
new AssertThrows(IllegalArgumentException.class) {
|
new DelegatingEntityResolver(null, null);
|
||||||
public void test() throws Exception {
|
|
||||||
new DelegatingEntityResolver(null, null);
|
|
||||||
}
|
|
||||||
}.runTest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final class NoOpEntityResolver implements EntityResolver {
|
private static final class NoOpEntityResolver implements EntityResolver {
|
||||||
|
|
||||||
public InputSource resolveEntity(String publicId, String systemId) {
|
public InputSource resolveEntity(String publicId, String systemId) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -16,14 +16,14 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.xml;
|
package org.springframework.beans.factory.xml;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.mail.Session;
|
import org.junit.Test;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import org.springframework.beans.TestBean;
|
import org.springframework.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;
|
||||||
|
|
@ -32,9 +32,11 @@ import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class FactoryMethodTests extends TestCase {
|
public class FactoryMethodTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFactoryMethodsSingletonOnTargetClass() {
|
public void testFactoryMethodsSingletonOnTargetClass() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -68,6 +70,7 @@ public class FactoryMethodTests extends TestCase {
|
||||||
assertTrue(tb.wasDestroyed());
|
assertTrue(tb.wasDestroyed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFactoryMethodsWithNullInstance() {
|
public void testFactoryMethodsWithNullInstance() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -85,6 +88,7 @@ public class FactoryMethodTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFactoryMethodsWithNullValue() {
|
public void testFactoryMethodsWithNullValue() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -101,6 +105,7 @@ public class FactoryMethodTests extends TestCase {
|
||||||
assertEquals("Juergen", fm.getTestBean().getName());
|
assertEquals("Juergen", fm.getTestBean().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFactoryMethodsWithAutowire() {
|
public void testFactoryMethodsWithAutowire() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -112,6 +117,7 @@ public class FactoryMethodTests extends TestCase {
|
||||||
assertEquals("Juergen", fm.getTestBean().getName());
|
assertEquals("Juergen", fm.getTestBean().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testProtectedFactoryMethod() {
|
public void testProtectedFactoryMethod() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -121,6 +127,7 @@ public class FactoryMethodTests extends TestCase {
|
||||||
assertEquals(1, tb.getAge());
|
assertEquals(1, tb.getAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPrivateFactoryMethod() {
|
public void testPrivateFactoryMethod() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -130,6 +137,7 @@ public class FactoryMethodTests extends TestCase {
|
||||||
assertEquals(1, tb.getAge());
|
assertEquals(1, tb.getAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFactoryMethodsPrototypeOnTargetClass() {
|
public void testFactoryMethodsPrototypeOnTargetClass() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -173,6 +181,7 @@ public class FactoryMethodTests extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Tests where the static factory method is on a different class.
|
* Tests where the static factory method is on a different class.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testFactoryMethodsOnExternalClass() {
|
public void testFactoryMethodsOnExternalClass() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -198,6 +207,7 @@ public class FactoryMethodTests extends TestCase {
|
||||||
assertTrue(Arrays.asList(names).contains("externalFactoryMethodWithArgs"));
|
assertTrue(Arrays.asList(names).contains("externalFactoryMethodWithArgs"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInstanceFactoryMethodWithoutArgs() {
|
public void testInstanceFactoryMethodWithoutArgs() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -215,6 +225,7 @@ public class FactoryMethodTests extends TestCase {
|
||||||
assertEquals(1, InstanceFactory.count);
|
assertEquals(1, InstanceFactory.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFactoryMethodNoMatchingStaticMethod() {
|
public void testFactoryMethodNoMatchingStaticMethod() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -228,6 +239,7 @@ public class FactoryMethodTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCanSpecifyFactoryMethodArgumentsOnFactoryMethodPrototype() {
|
public void testCanSpecifyFactoryMethodArgumentsOnFactoryMethodPrototype() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -263,6 +275,7 @@ public class FactoryMethodTests extends TestCase {
|
||||||
assertEquals("arg1", fm4.getTestBean().getName());
|
assertEquals("arg1", fm4.getTestBean().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCannotSpecifyFactoryMethodArgumentsOnSingleton() {
|
public void testCannotSpecifyFactoryMethodArgumentsOnSingleton() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -276,6 +289,7 @@ public class FactoryMethodTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCannotSpecifyFactoryMethodArgumentsOnSingletonAfterCreation() {
|
public void testCannotSpecifyFactoryMethodArgumentsOnSingletonAfterCreation() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -290,6 +304,7 @@ public class FactoryMethodTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFactoryMethodWithDifferentReturnType() {
|
public void testFactoryMethodWithDifferentReturnType() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -308,18 +323,40 @@ public class FactoryMethodTests extends TestCase {
|
||||||
assertTrue(!Arrays.asList(names).contains("listInstance"));
|
assertTrue(!Arrays.asList(names).contains("listInstance"));
|
||||||
names = xbf.getBeanNamesForType(List.class);
|
names = xbf.getBeanNamesForType(List.class);
|
||||||
assertTrue(Arrays.asList(names).contains("listInstance"));
|
assertTrue(Arrays.asList(names).contains("listInstance"));
|
||||||
List list = (List) xbf.getBean("listInstance");
|
List<?> list = (List<?>) xbf.getBean("listInstance");
|
||||||
assertEquals(Collections.EMPTY_LIST, list);
|
assertEquals(Collections.EMPTY_LIST, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFactoryMethodForJavaMailSession() {
|
public void testFactoryMethodForJavaMailSession() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass()));
|
reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass()));
|
||||||
|
|
||||||
Session session = (Session) xbf.getBean("javaMailSession");
|
MailSession session = (MailSession) xbf.getBean("javaMailSession");
|
||||||
assertEquals("someuser", session.getProperty("mail.smtp.user"));
|
assertEquals("someuser", session.getProperty("mail.smtp.user"));
|
||||||
assertEquals("somepw", session.getProperty("mail.smtp.password"));
|
assertEquals("somepw", session.getProperty("mail.smtp.password"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MailSession {
|
||||||
|
private Properties props;
|
||||||
|
|
||||||
|
private MailSession() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProperties(Properties props) {
|
||||||
|
this.props = props;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MailSession getDefaultInstance(Properties props) {
|
||||||
|
MailSession session = new MailSession();
|
||||||
|
session.setProperties(props);
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getProperty(String key) {
|
||||||
|
return props.get(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
* 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.xml;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.TestBean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Spring's ability to create objects using static
|
||||||
|
* factory methods, rather than constructors.
|
||||||
|
*
|
||||||
|
* @author Rod Johnson
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
*/
|
||||||
|
public class FactoryMethods {
|
||||||
|
|
||||||
|
public static FactoryMethods nullInstance() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FactoryMethods defaultInstance() {
|
||||||
|
TestBean tb = new TestBean();
|
||||||
|
tb.setName("defaultInstance");
|
||||||
|
return new FactoryMethods(tb, "default", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note that overloaded methods are supported.
|
||||||
|
*/
|
||||||
|
public static FactoryMethods newInstance(TestBean tb) {
|
||||||
|
return new FactoryMethods(tb, "default", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static FactoryMethods newInstance(TestBean tb, int num, String name) {
|
||||||
|
if (name == null) {
|
||||||
|
throw new IllegalStateException("Should never be called with null value");
|
||||||
|
}
|
||||||
|
return new FactoryMethods(tb, name, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
static FactoryMethods newInstance(TestBean tb, int num, Integer something) {
|
||||||
|
if (something != null) {
|
||||||
|
throw new IllegalStateException("Should never be called with non-null value");
|
||||||
|
}
|
||||||
|
return new FactoryMethods(tb, null, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List listInstance() {
|
||||||
|
return Collections.EMPTY_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private int num = 0;
|
||||||
|
private String name = "default";
|
||||||
|
private TestBean tb;
|
||||||
|
private String stringValue;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor is private: not for use outside this class,
|
||||||
|
* even by IoC container.
|
||||||
|
*/
|
||||||
|
private FactoryMethods(TestBean tb, String name, int num) {
|
||||||
|
this.tb = tb;
|
||||||
|
this.name = name;
|
||||||
|
this.num = num;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStringValue(String stringValue) {
|
||||||
|
this.stringValue = stringValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStringValue() {
|
||||||
|
return this.stringValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TestBean getTestBean() {
|
||||||
|
return this.tb;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TestBean protectedGetTestBean() {
|
||||||
|
return this.tb;
|
||||||
|
}
|
||||||
|
|
||||||
|
private TestBean privateGetTestBean() {
|
||||||
|
return this.tb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNum() {
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set via Setter Injection once instance is created.
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -130,7 +130,8 @@
|
||||||
<property name="factoryBeanProperty"><value>instanceFactory</value></property>
|
<property name="factoryBeanProperty"><value>instanceFactory</value></property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean name="javaMailSession" class="javax.mail.Session" factory-method="getDefaultInstance">
|
<bean name="javaMailSession" class="org.springframework.beans.factory.xml.MailSession"
|
||||||
|
factory-method="getDefaultInstance">
|
||||||
<constructor-arg>
|
<constructor-arg>
|
||||||
<props>
|
<props>
|
||||||
<prop key="mail.smtp.auth">true</prop>
|
<prop key="mail.smtp.auth">true</prop>
|
||||||
|
|
@ -16,13 +16,14 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.support;
|
package org.springframework.beans.factory.support;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.beans.factory.UnsatisfiedDependencyException;
|
import org.springframework.beans.factory.UnsatisfiedDependencyException;
|
||||||
|
|
@ -35,14 +36,16 @@ import org.springframework.context.support.GenericApplicationContext;
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class QualifierAnnotationAutowireContextTests extends TestCase {
|
public class QualifierAnnotationAutowireContextTests {
|
||||||
|
|
||||||
private static final String JUERGEN = "juergen";
|
private static final String JUERGEN = "juergen";
|
||||||
|
|
||||||
private static final String MARK = "mark";
|
private static final String MARK = "mark";
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredFieldWithSingleNonQualifiedCandidate() {
|
public void testAutowiredFieldWithSingleNonQualifiedCandidate() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
||||||
|
|
@ -62,6 +65,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredMethodParameterWithSingleNonQualifiedCandidate() {
|
public void testAutowiredMethodParameterWithSingleNonQualifiedCandidate() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
||||||
|
|
@ -81,6 +85,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredConstructorArgumentWithSingleNonQualifiedCandidate() {
|
public void testAutowiredConstructorArgumentWithSingleNonQualifiedCandidate() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
||||||
|
|
@ -100,6 +105,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredFieldWithSingleQualifiedCandidate() {
|
public void testAutowiredFieldWithSingleQualifiedCandidate() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
||||||
|
|
@ -114,6 +120,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
assertEquals(JUERGEN, bean.getPerson().getName());
|
assertEquals(JUERGEN, bean.getPerson().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredMethodParameterWithSingleQualifiedCandidate() {
|
public void testAutowiredMethodParameterWithSingleQualifiedCandidate() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
||||||
|
|
@ -130,6 +137,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
assertEquals(JUERGEN, bean.getPerson().getName());
|
assertEquals(JUERGEN, bean.getPerson().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredMethodParameterWithStaticallyQualifiedCandidate() {
|
public void testAutowiredMethodParameterWithStaticallyQualifiedCandidate() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
||||||
|
|
@ -145,6 +153,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
assertEquals(JUERGEN, bean.getPerson().getName());
|
assertEquals(JUERGEN, bean.getPerson().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredConstructorArgumentWithSingleQualifiedCandidate() {
|
public void testAutowiredConstructorArgumentWithSingleQualifiedCandidate() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs = new ConstructorArgumentValues();
|
||||||
|
|
@ -161,6 +170,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
assertEquals(JUERGEN, bean.getPerson().getName());
|
assertEquals(JUERGEN, bean.getPerson().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredFieldWithMultipleNonQualifiedCandidates() {
|
public void testAutowiredFieldWithMultipleNonQualifiedCandidates() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
@ -184,6 +194,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredMethodParameterWithMultipleNonQualifiedCandidates() {
|
public void testAutowiredMethodParameterWithMultipleNonQualifiedCandidates() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
@ -207,6 +218,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredConstructorArgumentWithMultipleNonQualifiedCandidates() {
|
public void testAutowiredConstructorArgumentWithMultipleNonQualifiedCandidates() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
@ -230,6 +242,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredFieldResolvesQualifiedCandidate() {
|
public void testAutowiredFieldResolvesQualifiedCandidate() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
@ -249,6 +262,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
assertEquals(JUERGEN, bean.getPerson().getName());
|
assertEquals(JUERGEN, bean.getPerson().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredMethodParameterResolvesQualifiedCandidate() {
|
public void testAutowiredMethodParameterResolvesQualifiedCandidate() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
@ -269,6 +283,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
assertEquals(JUERGEN, bean.getPerson().getName());
|
assertEquals(JUERGEN, bean.getPerson().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredConstructorArgumentResolvesQualifiedCandidate() {
|
public void testAutowiredConstructorArgumentResolvesQualifiedCandidate() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
@ -289,6 +304,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
assertEquals(JUERGEN, bean.getPerson().getName());
|
assertEquals(JUERGEN, bean.getPerson().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredFieldResolvesQualifiedCandidateWithDefaultValueAndNoValueOnBeanDefinition() {
|
public void testAutowiredFieldResolvesQualifiedCandidateWithDefaultValueAndNoValueOnBeanDefinition() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
@ -310,6 +326,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
assertEquals(JUERGEN, bean.getPerson().getName());
|
assertEquals(JUERGEN, bean.getPerson().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredFieldDoesNotResolveCandidateWithDefaultValueAndConflictingValueOnBeanDefinition() {
|
public void testAutowiredFieldDoesNotResolveCandidateWithDefaultValueAndConflictingValueOnBeanDefinition() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
@ -335,6 +352,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredFieldResolvesWithDefaultValueAndExplicitDefaultValueOnBeanDefinition() {
|
public void testAutowiredFieldResolvesWithDefaultValueAndExplicitDefaultValueOnBeanDefinition() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
@ -356,6 +374,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
assertEquals(JUERGEN, bean.getPerson().getName());
|
assertEquals(JUERGEN, bean.getPerson().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredFieldResolvesWithMultipleQualifierValues() {
|
public void testAutowiredFieldResolvesWithMultipleQualifierValues() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
@ -381,6 +400,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
assertEquals(MARK, bean.getPerson().getName());
|
assertEquals(MARK, bean.getPerson().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredFieldDoesNotResolveWithMultipleQualifierValuesAndConflictingDefaultValue() {
|
public void testAutowiredFieldDoesNotResolveWithMultipleQualifierValuesAndConflictingDefaultValue() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
@ -411,6 +431,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredFieldResolvesWithMultipleQualifierValuesAndExplicitDefaultValue() {
|
public void testAutowiredFieldResolvesWithMultipleQualifierValuesAndExplicitDefaultValue() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
@ -437,6 +458,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
assertEquals(MARK, bean.getPerson().getName());
|
assertEquals(MARK, bean.getPerson().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredFieldDoesNotResolveWithMultipleQualifierValuesAndMultipleMatchingCandidates() {
|
public void testAutowiredFieldDoesNotResolveWithMultipleQualifierValuesAndMultipleMatchingCandidates() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
@ -467,6 +489,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredFieldResolvesWithBaseQualifierAndDefaultValue() {
|
public void testAutowiredFieldResolvesWithBaseQualifierAndDefaultValue() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
@ -487,6 +510,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
assertEquals(MARK, bean.getPerson().getName());
|
assertEquals(MARK, bean.getPerson().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredFieldResolvesWithBaseQualifierAndNonDefaultValue() {
|
public void testAutowiredFieldResolvesWithBaseQualifierAndNonDefaultValue() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
@ -508,6 +532,7 @@ public class QualifierAnnotationAutowireContextTests extends TestCase {
|
||||||
assertEquals("the real juergen", bean.getPerson().getName());
|
assertEquals("the real juergen", bean.getPerson().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowiredFieldDoesNotResolveWithBaseQualifierAndNonDefaultValueAndMultipleMatchingCandidates() {
|
public void testAutowiredFieldDoesNotResolveWithBaseQualifierAndNonDefaultValueAndMultipleMatchingCandidates() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
ConstructorArgumentValues cavs1 = new ConstructorArgumentValues();
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.xml;
|
package org.springframework.beans.factory.xml;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
@ -27,11 +30,8 @@ import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.xml.sax.InputSource;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
|
|
@ -65,6 +65,7 @@ import org.springframework.core.io.support.EncodedResource;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
import org.springframework.util.SerializationTestUtils;
|
import org.springframework.util.SerializationTestUtils;
|
||||||
import org.springframework.util.StopWatch;
|
import org.springframework.util.StopWatch;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Miscellaneous tests for XML bean definitions.
|
* Miscellaneous tests for XML bean definitions.
|
||||||
|
|
@ -72,19 +73,20 @@ import org.springframework.util.StopWatch;
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class XmlBeanFactoryTests extends TestCase {
|
public class XmlBeanFactoryTests {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* http://opensource.atlassian.com/projects/spring/browse/SPR-2368
|
* http://opensource.atlassian.com/projects/spring/browse/SPR-2368
|
||||||
*/
|
*/
|
||||||
public void testCollectionsReferredToAsRefLocals() throws Exception {
|
public @Test void testCollectionsReferredToAsRefLocals() throws Exception {
|
||||||
XmlBeanFactory factory = new XmlBeanFactory(
|
XmlBeanFactory factory = new XmlBeanFactory(
|
||||||
new ClassPathResource("local-collections-using-XSD.xml", getClass()));
|
new ClassPathResource("local-collections-using-XSD.xml", getClass()));
|
||||||
factory.preInstantiateSingletons();
|
factory.preInstantiateSingletons();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRefToSeparatePrototypeInstances() throws Exception {
|
public @Test void testRefToSeparatePrototypeInstances() throws Exception {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||||
|
|
@ -102,7 +104,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue("They object equal direct ref", emmasJenks.equals(xbf.getBean("jenks")));
|
assertTrue("They object equal direct ref", emmasJenks.equals(xbf.getBean("jenks")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRefToSingleton() throws Exception {
|
public @Test void testRefToSingleton() throws Exception {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||||
|
|
@ -118,7 +120,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue("1 jen instance", davesJen == jen);
|
assertTrue("1 jen instance", davesJen == jen);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInnerBeans() throws IOException {
|
public @Test void testInnerBeans() throws IOException {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
||||||
|
|
@ -181,7 +183,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue(inner5.wasDestroyed());
|
assertTrue(inner5.wasDestroyed());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInnerBeansWithoutDestroy() {
|
public @Test void testInnerBeansWithoutDestroy() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||||
|
|
@ -214,7 +216,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertEquals("innerBean", inner5.getBeanName());
|
assertEquals("innerBean", inner5.getBeanName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFailsOnInnerBean() {
|
public @Test void testFailsOnInnerBean() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||||
|
|
@ -241,7 +243,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSingletonInheritanceFromParentFactorySingleton() throws Exception {
|
public @Test void testSingletonInheritanceFromParentFactorySingleton() throws Exception {
|
||||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||||
assertEquals(TestBean.class, child.getType("inheritsFromParentFactory"));
|
assertEquals(TestBean.class, child.getType("inheritsFromParentFactory"));
|
||||||
|
|
@ -254,7 +256,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue(inherits2 == inherits);
|
assertTrue(inherits2 == inherits);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInheritanceWithDifferentClass() throws Exception {
|
public @Test void testInheritanceWithDifferentClass() throws Exception {
|
||||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||||
assertEquals(DerivedTestBean.class, child.getType("inheritsWithClass"));
|
assertEquals(DerivedTestBean.class, child.getType("inheritsWithClass"));
|
||||||
|
|
@ -266,7 +268,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue(inherits.wasInitialized());
|
assertTrue(inherits.wasInitialized());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInheritanceWithClass() throws Exception {
|
public @Test void testInheritanceWithClass() throws Exception {
|
||||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||||
assertEquals(DerivedTestBean.class, child.getType("inheritsWithClass"));
|
assertEquals(DerivedTestBean.class, child.getType("inheritsWithClass"));
|
||||||
|
|
@ -278,7 +280,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue(inherits.wasInitialized());
|
assertTrue(inherits.wasInitialized());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPrototypeInheritanceFromParentFactoryPrototype() throws Exception {
|
public @Test void testPrototypeInheritanceFromParentFactoryPrototype() throws Exception {
|
||||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||||
assertEquals(TestBean.class, child.getType("prototypeInheritsFromParentFactoryPrototype"));
|
assertEquals(TestBean.class, child.getType("prototypeInheritsFromParentFactoryPrototype"));
|
||||||
|
|
@ -295,7 +297,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue(inherits.getAge() == 2);
|
assertTrue(inherits.getAge() == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPrototypeInheritanceFromParentFactorySingleton() throws Exception {
|
public @Test void testPrototypeInheritanceFromParentFactorySingleton() throws Exception {
|
||||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||||
TestBean inherits = (TestBean) child.getBean("protoypeInheritsFromParentFactorySingleton");
|
TestBean inherits = (TestBean) child.getBean("protoypeInheritsFromParentFactorySingleton");
|
||||||
|
|
@ -311,7 +313,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue(inherits.getAge() == 1);
|
assertTrue(inherits.getAge() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAutowireModeNotInherited() {
|
public @Test void testAutowireModeNotInherited() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
reader.loadBeanDefinitions(new ClassPathResource("overrides.xml", getClass()));
|
reader.loadBeanDefinitions(new ClassPathResource("overrides.xml", getClass()));
|
||||||
|
|
@ -325,13 +327,13 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertNull("autowiring not propagated along child relationships", derivedDavid.getSpouse());
|
assertNull("autowiring not propagated along child relationships", derivedDavid.getSpouse());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAbstractParentBeans() {
|
public @Test void testAbstractParentBeans() {
|
||||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||||
parent.preInstantiateSingletons();
|
parent.preInstantiateSingletons();
|
||||||
assertTrue(parent.isSingleton("inheritedTestBeanWithoutClass"));
|
assertTrue(parent.isSingleton("inheritedTestBeanWithoutClass"));
|
||||||
|
|
||||||
// abstract beans should not match
|
// abstract beans should not match
|
||||||
Map tbs = parent.getBeansOfType(TestBean.class);
|
Map<?, ?> tbs = parent.getBeansOfType(TestBean.class);
|
||||||
assertEquals(2, tbs.size());
|
assertEquals(2, tbs.size());
|
||||||
assertTrue(tbs.containsKey("inheritedTestBeanPrototype"));
|
assertTrue(tbs.containsKey("inheritedTestBeanPrototype"));
|
||||||
assertTrue(tbs.containsKey("inheritedTestBeanSingleton"));
|
assertTrue(tbs.containsKey("inheritedTestBeanSingleton"));
|
||||||
|
|
@ -349,7 +351,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue(parent.getBean("inheritedTestBeanPrototype") instanceof TestBean);
|
assertTrue(parent.getBean("inheritedTestBeanPrototype") instanceof TestBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDependenciesMaterializeThis() throws Exception {
|
public @Test void testDependenciesMaterializeThis() throws Exception {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("dependenciesMaterializeThis.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("dependenciesMaterializeThis.xml", getClass()));
|
||||||
|
|
||||||
assertEquals(2, xbf.getBeansOfType(DummyBo.class, true, false).size());
|
assertEquals(2, xbf.getBeansOfType(DummyBo.class, true, false).size());
|
||||||
|
|
@ -366,7 +368,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue(bos.dao == bop.dao);
|
assertTrue(bos.dao == bop.dao);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testChildOverridesParentBean() throws Exception {
|
public @Test void testChildOverridesParentBean() throws Exception {
|
||||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||||
TestBean inherits = (TestBean) child.getBean("inheritedTestBean");
|
TestBean inherits = (TestBean) child.getBean("inheritedTestBean");
|
||||||
|
|
@ -382,7 +384,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
* Check that a prototype can't inherit from a bogus parent.
|
* Check that a prototype can't inherit from a bogus parent.
|
||||||
* If a singleton does this the factory will fail to load.
|
* If a singleton does this the factory will fail to load.
|
||||||
*/
|
*/
|
||||||
public void testBogusParentageFromParentFactory() throws Exception {
|
public @Test void testBogusParentageFromParentFactory() throws Exception {
|
||||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||||
try {
|
try {
|
||||||
|
|
@ -401,7 +403,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
* It's possible for a subclass singleton not to return independent
|
* It's possible for a subclass singleton not to return independent
|
||||||
* instances even if derived from a prototype
|
* instances even if derived from a prototype
|
||||||
*/
|
*/
|
||||||
public void testSingletonInheritsFromParentFactoryPrototype() throws Exception {
|
public @Test void testSingletonInheritsFromParentFactoryPrototype() throws Exception {
|
||||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||||
TestBean inherits = (TestBean) child.getBean("singletonInheritsFromParentFactoryPrototype");
|
TestBean inherits = (TestBean) child.getBean("singletonInheritsFromParentFactoryPrototype");
|
||||||
|
|
@ -413,7 +415,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue(inherits2 == inherits);
|
assertTrue(inherits2 == inherits);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSingletonFromParent() {
|
public @Test void testSingletonFromParent() {
|
||||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||||
TestBean beanFromParent = (TestBean) parent.getBean("inheritedTestBeanSingleton");
|
TestBean beanFromParent = (TestBean) parent.getBean("inheritedTestBeanSingleton");
|
||||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||||
|
|
@ -421,14 +423,14 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue("singleton from parent and child is the same", beanFromParent == beanFromChild);
|
assertTrue("singleton from parent and child is the same", beanFromParent == beanFromChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNestedPropertyValue() {
|
public @Test void testNestedPropertyValue() {
|
||||||
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
|
||||||
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCircularReferences() {
|
public @Test void testCircularReferences() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||||
|
|
@ -445,17 +447,17 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue("Correct circular reference", complexEgo.getSpouse().getSpouse() == complexEgo);
|
assertTrue("Correct circular reference", complexEgo.getSpouse().getSpouse() == complexEgo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCircularReferenceWithFactoryBeanFirst() {
|
public @Test void testCircularReferenceWithFactoryBeanFirst() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||||
reader.loadBeanDefinitions(new ClassPathResource("reftypes.xml", getClass()));
|
reader.loadBeanDefinitions(new ClassPathResource("reftypes.xml", getClass()));
|
||||||
TestBean egoBridge = (TestBean) xbf.getBean("egoBridge");
|
xbf.getBean("egoBridge");
|
||||||
TestBean complexEgo = (TestBean) xbf.getBean("complexEgo");
|
TestBean complexEgo = (TestBean) xbf.getBean("complexEgo");
|
||||||
assertTrue("Correct circular reference", complexEgo.getSpouse().getSpouse() == complexEgo);
|
assertTrue("Correct circular reference", complexEgo.getSpouse().getSpouse() == complexEgo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCircularReferenceWithTwoFactoryBeans() {
|
public @Test void testCircularReferenceWithTwoFactoryBeans() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||||
|
|
@ -466,7 +468,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue("Correct circular reference", ego3.getSpouse().getSpouse() == ego3);
|
assertTrue("Correct circular reference", ego3.getSpouse().getSpouse() == ego3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCircularReferencesWithNotAllowed() {
|
public @Test void testCircularReferencesWithNotAllowed() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
xbf.setAllowCircularReferences(false);
|
xbf.setAllowCircularReferences(false);
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -481,7 +483,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCircularReferencesWithWrapping() {
|
public @Test void testCircularReferencesWithWrapping() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
|
||||||
|
|
@ -496,7 +498,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCircularReferencesWithWrappingAndRawInjectionAllowed() {
|
public @Test void testCircularReferencesWithWrappingAndRawInjectionAllowed() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
xbf.setAllowRawInjectionDespiteWrapping(true);
|
xbf.setAllowRawInjectionDespiteWrapping(true);
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
|
|
@ -516,19 +518,19 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue(!AopUtils.isAopProxy(david.getSpouse()));
|
assertTrue(!AopUtils.isAopProxy(david.getSpouse()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFactoryReferenceCircle() {
|
public @Test void testFactoryReferenceCircle() {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("factoryCircle.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("factoryCircle.xml", getClass()));
|
||||||
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 void testFactoryReferenceWithDoublePrefix() {
|
public @Test void testFactoryReferenceWithDoublePrefix() {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("factoryCircle.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("factoryCircle.xml", getClass()));
|
||||||
DummyFactory db = (DummyFactory) xbf.getBean("&&singletonFactory");
|
assertThat(xbf.getBean("&&singletonFactory"), instanceOf(DummyFactory.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testComplexFactoryReferenceCircle() {
|
public @Test void testComplexFactoryReferenceCircle() {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("complexFactoryCircle.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("complexFactoryCircle.xml", getClass()));
|
||||||
xbf.getBean("proxy1");
|
xbf.getBean("proxy1");
|
||||||
// check that unused instances from autowiring got removed
|
// check that unused instances from autowiring got removed
|
||||||
|
|
@ -538,7 +540,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertEquals(7, xbf.getSingletonCount());
|
assertEquals(7, xbf.getSingletonCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoSuchFactoryBeanMethod() {
|
public @Test void testNoSuchFactoryBeanMethod() {
|
||||||
try {
|
try {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("no-such-factory-method.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("no-such-factory-method.xml", getClass()));
|
||||||
assertNotNull(xbf.getBean("defaultTestBean"));
|
assertNotNull(xbf.getBean("defaultTestBean"));
|
||||||
|
|
@ -549,7 +551,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInitMethodIsInvoked() throws Exception {
|
public @Test void testInitMethodIsInvoked() throws Exception {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("initializers.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("initializers.xml", getClass()));
|
||||||
DoubleInitializer in = (DoubleInitializer) xbf.getBean("init-method1");
|
DoubleInitializer in = (DoubleInitializer) xbf.getBean("init-method1");
|
||||||
// Initializer should have doubled value
|
// Initializer should have doubled value
|
||||||
|
|
@ -559,7 +561,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
/**
|
/**
|
||||||
* 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 void testInitMethodThrowsException() {
|
public @Test void testInitMethodThrowsException() {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("initializers.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("initializers.xml", getClass()));
|
||||||
try {
|
try {
|
||||||
xbf.getBean("init-method2");
|
xbf.getBean("init-method2");
|
||||||
|
|
@ -572,7 +574,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoSuchInitMethod() throws Exception {
|
public @Test void testNoSuchInitMethod() throws Exception {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("initializers.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("initializers.xml", getClass()));
|
||||||
try {
|
try {
|
||||||
xbf.getBean("init-method3");
|
xbf.getBean("init-method3");
|
||||||
|
|
@ -589,7 +591,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Check that InitializingBean method is called first.
|
* Check that InitializingBean method is called first.
|
||||||
*/
|
*/
|
||||||
public void testInitializingBeanAndInitMethod() throws Exception {
|
public @Test void testInitializingBeanAndInitMethod() throws Exception {
|
||||||
InitAndIB.constructed = false;
|
InitAndIB.constructed = false;
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("initializers.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("initializers.xml", getClass()));
|
||||||
assertFalse(InitAndIB.constructed);
|
assertFalse(InitAndIB.constructed);
|
||||||
|
|
@ -608,7 +610,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Check that InitializingBean method is not called twice.
|
* Check that InitializingBean method is not called twice.
|
||||||
*/
|
*/
|
||||||
public void testInitializingBeanAndSameInitMethod() throws Exception {
|
public @Test void testInitializingBeanAndSameInitMethod() throws Exception {
|
||||||
InitAndIB.constructed = false;
|
InitAndIB.constructed = false;
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("initializers.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("initializers.xml", getClass()));
|
||||||
assertFalse(InitAndIB.constructed);
|
assertFalse(InitAndIB.constructed);
|
||||||
|
|
@ -624,7 +626,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue(iib.destroyed && !iib.customDestroyed);
|
assertTrue(iib.destroyed && !iib.customDestroyed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDefaultLazyInit() throws Exception {
|
public @Test void testDefaultLazyInit() throws Exception {
|
||||||
InitAndIB.constructed = false;
|
InitAndIB.constructed = false;
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("default-lazy-init.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("default-lazy-init.xml", getClass()));
|
||||||
assertFalse(InitAndIB.constructed);
|
assertFalse(InitAndIB.constructed);
|
||||||
|
|
@ -638,7 +640,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoSuchXmlFile() throws Exception {
|
public @Test void testNoSuchXmlFile() throws Exception {
|
||||||
try {
|
try {
|
||||||
new XmlBeanFactory(new ClassPathResource("missing.xml", getClass()));
|
new XmlBeanFactory(new ClassPathResource("missing.xml", getClass()));
|
||||||
fail("Must not create factory from missing XML");
|
fail("Must not create factory from missing XML");
|
||||||
|
|
@ -647,7 +649,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInvalidXmlFile() throws Exception {
|
public @Test void testInvalidXmlFile() throws Exception {
|
||||||
try {
|
try {
|
||||||
new XmlBeanFactory(new ClassPathResource("invalid.xml", getClass()));
|
new XmlBeanFactory(new ClassPathResource("invalid.xml", getClass()));
|
||||||
fail("Must not create factory from invalid XML");
|
fail("Must not create factory from invalid XML");
|
||||||
|
|
@ -656,7 +658,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUnsatisfiedObjectDependencyCheck() throws Exception {
|
public @Test void testUnsatisfiedObjectDependencyCheck() throws Exception {
|
||||||
try {
|
try {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("unsatisfiedObjectDependencyCheck.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("unsatisfiedObjectDependencyCheck.xml", getClass()));
|
||||||
xbf.getBean("a", DependenciesBean.class);
|
xbf.getBean("a", DependenciesBean.class);
|
||||||
|
|
@ -666,7 +668,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUnsatisfiedSimpleDependencyCheck() throws Exception {
|
public @Test void testUnsatisfiedSimpleDependencyCheck() throws Exception {
|
||||||
try {
|
try {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("unsatisfiedSimpleDependencyCheck.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("unsatisfiedSimpleDependencyCheck.xml", getClass()));
|
||||||
xbf.getBean("a", DependenciesBean.class);
|
xbf.getBean("a", DependenciesBean.class);
|
||||||
|
|
@ -676,20 +678,20 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSatisfiedObjectDependencyCheck() throws Exception {
|
public @Test void testSatisfiedObjectDependencyCheck() throws Exception {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("satisfiedObjectDependencyCheck.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("satisfiedObjectDependencyCheck.xml", getClass()));
|
||||||
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 void testSatisfiedSimpleDependencyCheck() throws Exception {
|
public @Test void testSatisfiedSimpleDependencyCheck() throws Exception {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("satisfiedSimpleDependencyCheck.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("satisfiedSimpleDependencyCheck.xml", getClass()));
|
||||||
DependenciesBean a = (DependenciesBean) xbf.getBean("a");
|
DependenciesBean a = (DependenciesBean) xbf.getBean("a");
|
||||||
assertEquals(a.getAge(), 33);
|
assertEquals(a.getAge(), 33);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUnsatisfiedAllDependencyCheck() throws Exception {
|
public @Test void testUnsatisfiedAllDependencyCheck() throws Exception {
|
||||||
try {
|
try {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("unsatisfiedAllDependencyCheckMissingObjects.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("unsatisfiedAllDependencyCheckMissingObjects.xml", getClass()));
|
||||||
xbf.getBean("a", DependenciesBean.class);
|
xbf.getBean("a", DependenciesBean.class);
|
||||||
|
|
@ -699,7 +701,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSatisfiedAllDependencyCheck() throws Exception {
|
public @Test void testSatisfiedAllDependencyCheck() throws Exception {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("satisfiedAllDependencyCheck.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("satisfiedAllDependencyCheck.xml", getClass()));
|
||||||
DependenciesBean a = (DependenciesBean) xbf.getBean("a");
|
DependenciesBean a = (DependenciesBean) xbf.getBean("a");
|
||||||
assertEquals(a.getAge(), 33);
|
assertEquals(a.getAge(), 33);
|
||||||
|
|
@ -707,14 +709,14 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertNotNull(a.getSpouse());
|
assertNotNull(a.getSpouse());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAutowire() throws Exception {
|
public @Test void testAutowire() throws Exception {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("autowire.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("autowire.xml", getClass()));
|
||||||
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 void testAutowireWithParent() throws Exception {
|
public @Test void testAutowireWithParent() throws Exception {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("autowire.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("autowire.xml", getClass()));
|
||||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||||
|
|
@ -771,7 +773,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue(appCtx.containsBean("jenny"));
|
assertTrue(appCtx.containsBean("jenny"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAutowireWithDefault() throws Exception {
|
public @Test void testAutowireWithDefault() throws Exception {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("default-autowire.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("default-autowire.xml", getClass()));
|
||||||
|
|
||||||
DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1");
|
DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1");
|
||||||
|
|
@ -792,7 +794,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAutowireByConstructor() throws Exception {
|
public @Test void testAutowireByConstructor() throws Exception {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||||
ConstructorDependenciesBean rod1 = (ConstructorDependenciesBean) xbf.getBean("rod1");
|
ConstructorDependenciesBean rod1 = (ConstructorDependenciesBean) xbf.getBean("rod1");
|
||||||
TestBean kerry = (TestBean) xbf.getBean("kerry2");
|
TestBean kerry = (TestBean) xbf.getBean("kerry2");
|
||||||
|
|
@ -828,7 +830,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertEquals(null, rod.getName());
|
assertEquals(null, rod.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAutowireByConstructorWithSimpleValues() throws Exception {
|
public @Test void testAutowireByConstructorWithSimpleValues() throws Exception {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||||
|
|
||||||
ConstructorDependenciesBean rod5 = (ConstructorDependenciesBean) xbf.getBean("rod5");
|
ConstructorDependenciesBean rod5 = (ConstructorDependenciesBean) xbf.getBean("rod5");
|
||||||
|
|
@ -856,7 +858,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue(rod6.destroyed);
|
assertTrue(rod6.destroyed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRelatedCausesFromConstructorResolution() {
|
public @Test void testRelatedCausesFromConstructorResolution() {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -869,7 +871,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConstructorArgResolution() {
|
public @Test void testConstructorArgResolution() {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||||
TestBean kerry1 = (TestBean) xbf.getBean("kerry1");
|
TestBean kerry1 = (TestBean) xbf.getBean("kerry1");
|
||||||
TestBean kerry2 = (TestBean) xbf.getBean("kerry2");
|
TestBean kerry2 = (TestBean) xbf.getBean("kerry2");
|
||||||
|
|
@ -911,13 +913,13 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertEquals(29, rod16.getAge());
|
assertEquals(29, rod16.getAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConstructorArgWithSingleMatch() {
|
public @Test void testConstructorArgWithSingleMatch() {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||||
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 void testThrowsExceptionOnTooManyArguments() throws Exception {
|
public @Test void testThrowsExceptionOnTooManyArguments() throws Exception {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||||
try {
|
try {
|
||||||
xbf.getBean("rod7", ConstructorDependenciesBean.class);
|
xbf.getBean("rod7", ConstructorDependenciesBean.class);
|
||||||
|
|
@ -927,7 +929,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testThrowsExceptionOnAmbiguousResolution() throws Exception {
|
public @Test void testThrowsExceptionOnAmbiguousResolution() throws Exception {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||||
try {
|
try {
|
||||||
xbf.getBean("rod8", ConstructorDependenciesBean.class);
|
xbf.getBean("rod8", ConstructorDependenciesBean.class);
|
||||||
|
|
@ -937,43 +939,43 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDependsOn() {
|
public @Test void testDependsOn() {
|
||||||
doTestDependencies("dependencies-dependsOn.xml", 1);
|
doTestDependencies("dependencies-dependsOn.xml", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDependsOnInInnerBean() {
|
public @Test void testDependsOnInInnerBean() {
|
||||||
doTestDependencies("dependencies-dependsOn-inner.xml", 4);
|
doTestDependencies("dependencies-dependsOn-inner.xml", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDependenciesThroughConstructorArguments() {
|
public @Test void testDependenciesThroughConstructorArguments() {
|
||||||
doTestDependencies("dependencies-carg.xml", 1);
|
doTestDependencies("dependencies-carg.xml", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDependenciesThroughConstructorArgumentAutowiring() {
|
public @Test void testDependenciesThroughConstructorArgumentAutowiring() {
|
||||||
doTestDependencies("dependencies-carg-autowire.xml", 1);
|
doTestDependencies("dependencies-carg-autowire.xml", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDependenciesThroughConstructorArgumentsInInnerBean() {
|
public @Test void testDependenciesThroughConstructorArgumentsInInnerBean() {
|
||||||
doTestDependencies("dependencies-carg-inner.xml", 1);
|
doTestDependencies("dependencies-carg-inner.xml", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDependenciesThroughProperties() {
|
public @Test void testDependenciesThroughProperties() {
|
||||||
doTestDependencies("dependencies-prop.xml", 1);
|
doTestDependencies("dependencies-prop.xml", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDependenciesThroughPropertiesWithInTheMiddle() {
|
public @Test void testDependenciesThroughPropertiesWithInTheMiddle() {
|
||||||
doTestDependencies("dependencies-prop-inTheMiddle.xml", 1);
|
doTestDependencies("dependencies-prop-inTheMiddle.xml", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDependenciesThroughPropertyAutowiringByName() {
|
public @Test void testDependenciesThroughPropertyAutowiringByName() {
|
||||||
doTestDependencies("dependencies-prop-autowireByName.xml", 1);
|
doTestDependencies("dependencies-prop-autowireByName.xml", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDependenciesThroughPropertyAutowiringByType() {
|
public @Test void testDependenciesThroughPropertyAutowiringByType() {
|
||||||
doTestDependencies("dependencies-prop-autowireByType.xml", 1);
|
doTestDependencies("dependencies-prop-autowireByType.xml", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDependenciesThroughPropertiesInInnerBean() {
|
public @Test void testDependenciesThroughPropertiesInInnerBean() {
|
||||||
doTestDependencies("dependencies-prop-inner.xml", 1);
|
doTestDependencies("dependencies-prop-inner.xml", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1003,7 +1005,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
* bean def is being parsed, 'cos everything on a bean def is now lazy, but
|
* bean def is being parsed, 'cos everything on a bean def is now lazy, but
|
||||||
* must rather only be picked up when the bean is instantiated.
|
* must rather only be picked up when the bean is instantiated.
|
||||||
*/
|
*/
|
||||||
public void testClassNotFoundWithDefaultBeanClassLoader() {
|
public @Test void testClassNotFoundWithDefaultBeanClassLoader() {
|
||||||
BeanFactory factory = new XmlBeanFactory(new ClassPathResource("classNotFound.xml", getClass()));
|
BeanFactory factory = new XmlBeanFactory(new ClassPathResource("classNotFound.xml", getClass()));
|
||||||
// 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 {
|
||||||
|
|
@ -1017,7 +1019,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClassNotFoundWithNoBeanClassLoader() {
|
public @Test void testClassNotFoundWithNoBeanClassLoader() {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
|
||||||
reader.setBeanClassLoader(null);
|
reader.setBeanClassLoader(null);
|
||||||
|
|
@ -1025,7 +1027,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertEquals("WhatALotOfRubbish", bf.getBeanDefinition("classNotFound").getBeanClassName());
|
assertEquals("WhatALotOfRubbish", bf.getBeanDefinition("classNotFound").getBeanClassName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testResourceAndInputStream() throws IOException {
|
public @Test void testResourceAndInputStream() throws IOException {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("resource.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("resource.xml", getClass()));
|
||||||
// comes from "resourceImport.xml"
|
// comes from "resourceImport.xml"
|
||||||
ResourceTestBean resource1 = (ResourceTestBean) xbf.getBean("resource1");
|
ResourceTestBean resource1 = (ResourceTestBean) xbf.getBean("resource1");
|
||||||
|
|
@ -1047,7 +1049,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertEquals("test", writer.toString());
|
assertEquals("test", writer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClassPathResourceWithImport() {
|
public @Test void testClassPathResourceWithImport() {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(
|
XmlBeanFactory xbf = new XmlBeanFactory(
|
||||||
new ClassPathResource("org/springframework/beans/factory/xml/resource.xml"));
|
new ClassPathResource("org/springframework/beans/factory/xml/resource.xml"));
|
||||||
// comes from "resourceImport.xml"
|
// comes from "resourceImport.xml"
|
||||||
|
|
@ -1056,7 +1058,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
xbf.getBean("resource2", ResourceTestBean.class);
|
xbf.getBean("resource2", ResourceTestBean.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUrlResourceWithImport() {
|
public @Test void testUrlResourceWithImport() {
|
||||||
URL url = getClass().getResource("resource.xml");
|
URL url = getClass().getResource("resource.xml");
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new UrlResource(url));
|
XmlBeanFactory xbf = new XmlBeanFactory(new UrlResource(url));
|
||||||
// comes from "resourceImport.xml"
|
// comes from "resourceImport.xml"
|
||||||
|
|
@ -1065,7 +1067,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
xbf.getBean("resource2", ResourceTestBean.class);
|
xbf.getBean("resource2", ResourceTestBean.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFileSystemResourceWithImport() {
|
public @Test void testFileSystemResourceWithImport() {
|
||||||
String file = getClass().getResource("resource.xml").getFile();
|
String file = getClass().getResource("resource.xml").getFile();
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new FileSystemResource(file));
|
XmlBeanFactory xbf = new XmlBeanFactory(new FileSystemResource(file));
|
||||||
// comes from "resourceImport.xml"
|
// comes from "resourceImport.xml"
|
||||||
|
|
@ -1074,10 +1076,9 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
xbf.getBean("resource2", ResourceTestBean.class);
|
xbf.getBean("resource2", ResourceTestBean.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRecursiveImport() {
|
public @Test void testRecursiveImport() {
|
||||||
try {
|
try {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(
|
new XmlBeanFactory(new ClassPathResource("org/springframework/beans/factory/xml/recursiveImport.xml"));
|
||||||
new ClassPathResource("org/springframework/beans/factory/xml/recursiveImport.xml"));
|
|
||||||
fail("Should have thrown BeanDefinitionStoreException");
|
fail("Should have thrown BeanDefinitionStoreException");
|
||||||
}
|
}
|
||||||
catch (BeanDefinitionStoreException ex) {
|
catch (BeanDefinitionStoreException ex) {
|
||||||
|
|
@ -1087,7 +1088,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testLookupOverrideMethodsWithSetterInjection() {
|
public @Test void testLookupOverrideMethodsWithSetterInjection() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
reader.loadBeanDefinitions(new ClassPathResource("overrides.xml", getClass()));
|
reader.loadBeanDefinitions(new ClassPathResource("overrides.xml", getClass()));
|
||||||
|
|
@ -1152,7 +1153,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertSame(dave1, dave2);
|
assertSame(dave1, dave2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testReplaceMethodOverrideWithSetterInjection() {
|
public @Test void testReplaceMethodOverrideWithSetterInjection() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
reader.loadBeanDefinitions(new ClassPathResource("delegationOverrides.xml", getClass()));
|
reader.loadBeanDefinitions(new ClassPathResource("delegationOverrides.xml", getClass()));
|
||||||
|
|
@ -1199,7 +1200,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertEquals(s2, dos.lastArg);
|
assertEquals(s2, dos.lastArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLookupOverrideOneMethodWithConstructorInjection() {
|
public @Test void testLookupOverrideOneMethodWithConstructorInjection() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
reader.loadBeanDefinitions(new ClassPathResource("constructorOverrides.xml", getClass()));
|
reader.loadBeanDefinitions(new ClassPathResource("constructorOverrides.xml", getClass()));
|
||||||
|
|
@ -1222,7 +1223,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
fm1.getTestBean(), fm2.getTestBean());
|
fm1.getTestBean(), fm2.getTestBean());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRejectsOverrideOfBogusMethodName() {
|
public @Test void testRejectsOverrideOfBogusMethodName() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
try {
|
try {
|
||||||
|
|
@ -1239,12 +1240,12 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Assert the presence of this bug until we resolve it.
|
* Assert the presence of this bug until we resolve it.
|
||||||
*/
|
*/
|
||||||
public void testSerializabilityOfMethodReplacer() throws Exception {
|
public @Test void testSerializabilityOfMethodReplacer() throws Exception {
|
||||||
try {
|
try {
|
||||||
BUGtestSerializableMethodReplacerAndSuperclass();
|
BUGtestSerializableMethodReplacerAndSuperclass();
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
catch (AssertionFailedError ex) {
|
catch (AssertionError ex) {
|
||||||
System.err.println("****** SPR-356: Objects with MethodReplace overrides are not serializable");
|
System.err.println("****** SPR-356: Objects with MethodReplace overrides are not serializable");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1262,7 +1263,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertEquals("Method replace still works after serialization and deserialization", backwards, s.replaceMe(forwards));
|
assertEquals("Method replace still works after serialization and deserialization", backwards, s.replaceMe(forwards));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInnerBeanInheritsScopeFromConcreteChildDefinition() {
|
public @Test void testInnerBeanInheritsScopeFromConcreteChildDefinition() {
|
||||||
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
|
||||||
reader.loadBeanDefinitions(new ClassPathResource("overrides.xml", getClass()));
|
reader.loadBeanDefinitions(new ClassPathResource("overrides.xml", getClass()));
|
||||||
|
|
@ -1271,7 +1272,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue(jenny.getFriends().iterator().next() instanceof TestBean);
|
assertTrue(jenny.getFriends().iterator().next() instanceof TestBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConstructorArgWithSingleSimpleTypeMatch() {
|
public @Test void testConstructorArgWithSingleSimpleTypeMatch() {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||||
|
|
||||||
SingleSimpleTypeConstructorBean bean = (SingleSimpleTypeConstructorBean) xbf.getBean("beanWithBoolean");
|
SingleSimpleTypeConstructorBean bean = (SingleSimpleTypeConstructorBean) xbf.getBean("beanWithBoolean");
|
||||||
|
|
@ -1281,7 +1282,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertTrue(bean2.isSingleBoolean());
|
assertTrue(bean2.isSingleBoolean());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConstructorArgWithDoubleSimpleTypeMatch() {
|
public @Test void testConstructorArgWithDoubleSimpleTypeMatch() {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||||
|
|
||||||
SingleSimpleTypeConstructorBean bean = (SingleSimpleTypeConstructorBean) xbf.getBean("beanWithBooleanAndString");
|
SingleSimpleTypeConstructorBean bean = (SingleSimpleTypeConstructorBean) xbf.getBean("beanWithBooleanAndString");
|
||||||
|
|
@ -1293,21 +1294,21 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
assertEquals("A String", bean2.getTestString());
|
assertEquals("A String", bean2.getTestString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDoubleBooleanAutowire() {
|
public @Test void testDoubleBooleanAutowire() {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||||
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 void testDoubleBooleanAutowireWithIndex() {
|
public @Test void testDoubleBooleanAutowireWithIndex() {
|
||||||
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
XmlBeanFactory xbf = new XmlBeanFactory(new ClassPathResource("constructor-arg.xml", getClass()));
|
||||||
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 void testWithDuplicateName() throws Exception {
|
public @Test void testWithDuplicateName() throws Exception {
|
||||||
try {
|
try {
|
||||||
new XmlBeanFactory(new ClassPathResource("testWithDuplicateNames.xml", getClass()));
|
new XmlBeanFactory(new ClassPathResource("testWithDuplicateNames.xml", getClass()));
|
||||||
fail("Duplicate name not detected");
|
fail("Duplicate name not detected");
|
||||||
|
|
@ -1317,7 +1318,7 @@ public class XmlBeanFactoryTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithDuplicateNameInAlias() throws Exception {
|
public @Test void testWithDuplicateNameInAlias() throws Exception {
|
||||||
try {
|
try {
|
||||||
new XmlBeanFactory(new ClassPathResource("testWithDuplicateNameInAlias.xml", getClass()));
|
new XmlBeanFactory(new ClassPathResource("testWithDuplicateNameInAlias.xml", getClass()));
|
||||||
fail("Duplicate name not detected");
|
fail("Duplicate name not detected");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue