Search in sources :

Example 56 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.

the class CommonsPool2TargetSourceTests method setUp.

@Before
public void setUp() throws Exception {
    this.beanFactory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass()));
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Before(org.junit.Before)

Example 57 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.

the class ProxyFactoryBeanTests method testPrototypeInstancesAreIndependent.

/**
	 * Uses its own bean factory XML for clarity
	 * @param beanName name of the ProxyFactoryBean definition that should
	 * be a prototype
	 */
private Object testPrototypeInstancesAreIndependent(String beanName) {
    // Initial count value set in bean factory XML
    int INITIAL_COUNT = 10;
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(PROTOTYPE_CONTEXT, CLASS));
    // Check it works without AOP
    SideEffectBean raw = (SideEffectBean) bf.getBean("prototypeTarget");
    assertEquals(INITIAL_COUNT, raw.getCount());
    raw.doWork();
    assertEquals(INITIAL_COUNT + 1, raw.getCount());
    raw = (SideEffectBean) bf.getBean("prototypeTarget");
    assertEquals(INITIAL_COUNT, raw.getCount());
    // Now try with advised instances
    SideEffectBean prototype2FirstInstance = (SideEffectBean) bf.getBean(beanName);
    assertEquals(INITIAL_COUNT, prototype2FirstInstance.getCount());
    prototype2FirstInstance.doWork();
    assertEquals(INITIAL_COUNT + 1, prototype2FirstInstance.getCount());
    SideEffectBean prototype2SecondInstance = (SideEffectBean) bf.getBean(beanName);
    assertFalse("Prototypes are not ==", prototype2FirstInstance == prototype2SecondInstance);
    assertEquals(INITIAL_COUNT, prototype2SecondInstance.getCount());
    assertEquals(INITIAL_COUNT + 1, prototype2FirstInstance.getCount());
    return prototype2FirstInstance;
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) SideEffectBean(org.springframework.tests.sample.beans.SideEffectBean) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 58 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.

the class ProxyFactoryBeanTests method testSerializablePrototypeProxy.

@Test
public void testSerializablePrototypeProxy() throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
    Person p = (Person) bf.getBean("serializablePrototype");
    assertNotSame("Should not be a Singleton", p, bf.getBean("serializablePrototype"));
    Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
    assertEquals(p, p2);
    assertNotSame(p, p2);
    assertEquals("serializablePrototype", p2.getName());
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Person(org.springframework.tests.sample.beans.Person) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 59 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.

the class ProxyFactoryBeanTests method testPrototypeInterceptorSingletonTarget.

@Test
public void testPrototypeInterceptorSingletonTarget() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(CONTEXT, CLASS));
    ITestBean bean1 = (ITestBean) bf.getBean("prototypeTestBeanProxySingletonTarget");
    ITestBean bean2 = (ITestBean) bf.getBean("prototypeTestBeanProxySingletonTarget");
    bean1.setAge(1);
    bean2.setAge(2);
    assertEquals(2, bean1.getAge());
    ((Lockable) bean1).lock();
    try {
        bean1.setAge(5);
        fail("expected LockedException");
    } catch (LockedException ex) {
    // expected
    }
    try {
        bean2.setAge(6);
    } catch (LockedException ex) {
        fail("did not expect LockedException");
    }
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) LockedException(test.mixin.LockedException) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Lockable(test.mixin.Lockable) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 60 with ClassPathResource

use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.

the class ProxyFactoryBeanTests method setUp.

@Before
public void setUp() throws Exception {
    DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
    parent.registerBeanDefinition("target2", new RootBeanDefinition(TestListener.class));
    this.factory = new DefaultListableBeanFactory(parent);
    new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.factory).loadBeanDefinitions(new ClassPathResource(CONTEXT, getClass()));
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) TestListener(org.springframework.context.TestListener) ClassPathResource(org.springframework.core.io.ClassPathResource) Before(org.junit.Before)

Aggregations

ClassPathResource (org.springframework.core.io.ClassPathResource)628 Test (org.junit.Test)404 Resource (org.springframework.core.io.Resource)182 DhisSpringTest (org.hisp.dhis.DhisSpringTest)85 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)80 List (java.util.List)63 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)62 Before (org.junit.Before)55 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)54 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)39 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)36 ArrayList (java.util.ArrayList)35 DataElement (org.hisp.dhis.dataelement.DataElement)32 File (java.io.File)29 UrlResource (org.springframework.core.io.UrlResource)29 TestBean (org.springframework.tests.sample.beans.TestBean)27 IOException (java.io.IOException)26 InputStream (java.io.InputStream)23 FileSystemResource (org.springframework.core.io.FileSystemResource)23 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)19