Search in sources :

Example 51 with ClassPathResource

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

the class XmlBeanDefinitionReaderTests method withFreshInputStream.

@Test
public void withFreshInputStream() {
    SimpleBeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
    Resource resource = new ClassPathResource("test.xml", getClass());
    new XmlBeanDefinitionReader(registry).loadBeanDefinitions(resource);
    testBeanDefinitions(registry);
}
Also used : SimpleBeanDefinitionRegistry(org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry) ClassPathResource(org.springframework.core.io.ClassPathResource) InputStreamResource(org.springframework.core.io.InputStreamResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 52 with ClassPathResource

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

the class EhCacheSupportTests method testCacheManagerFromConfigFile.

public void testCacheManagerFromConfigFile() throws Exception {
    EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean();
    cacheManagerFb.setConfigLocation(new ClassPathResource("testEhcache.xml", getClass()));
    cacheManagerFb.setCacheManagerName("myCacheManager");
    cacheManagerFb.afterPropertiesSet();
    try {
        CacheManager cm = cacheManagerFb.getObject();
        assertTrue("Correct number of caches loaded", cm.getCacheNames().length == 1);
        Cache myCache1 = cm.getCache("myCache1");
        assertFalse("myCache1 is not eternal", myCache1.getCacheConfiguration().isEternal());
        assertTrue("myCache1.maxElements == 300", myCache1.getCacheConfiguration().getMaxEntriesLocalHeap() == 300);
    } finally {
        cacheManagerFb.destroy();
    }
}
Also used : CacheManager(net.sf.ehcache.CacheManager) ClassPathResource(org.springframework.core.io.ClassPathResource) SelfPopulatingCache(net.sf.ehcache.constructs.blocking.SelfPopulatingCache) BlockingCache(net.sf.ehcache.constructs.blocking.BlockingCache) UpdatingSelfPopulatingCache(net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache) Cache(net.sf.ehcache.Cache)

Example 53 with ClassPathResource

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

the class ProxyFactoryBeanTests method testTargetSourceNotAtEndOfInterceptorNamesIsRejected.

@Test
public void testTargetSourceNotAtEndOfInterceptorNamesIsRejected() {
    try {
        DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
        new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(NOTLAST_TARGETSOURCE_CONTEXT, CLASS));
        bf.getBean("targetSourceNotLast");
        fail("TargetSource or non-advised object must be last in interceptorNames");
    } catch (BeanCreationException ex) {
        // Root cause of the problem must be an AOP exception
        AopConfigException aex = (AopConfigException) ex.getCause();
        assertTrue(aex.getMessage().contains("interceptorNames"));
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 54 with ClassPathResource

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

the class ProxyFactoryBeanTests method testPrototypeAdvisor.

@Test
public void testPrototypeAdvisor() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(CONTEXT, CLASS));
    ITestBean bean1 = (ITestBean) bf.getBean("prototypeTestBeanProxy");
    ITestBean bean2 = (ITestBean) bf.getBean("prototypeTestBeanProxy");
    bean1.setAge(3);
    bean2.setAge(4);
    assertEquals(3, bean1.getAge());
    assertEquals(4, bean2.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 55 with ClassPathResource

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

the class ProxyFactoryBeanTests method testSerializableSingletonProxyFactoryBean.

@Test
public void testSerializableSingletonProxyFactoryBean() throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
    Person p = (Person) bf.getBean("serializableSingleton");
    ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&serializableSingleton");
    ProxyFactoryBean pfb2 = (ProxyFactoryBean) SerializationTestUtils.serializeAndDeserialize(pfb);
    Person p2 = (Person) pfb2.getObject();
    assertEquals(p, p2);
    assertNotSame(p, p2);
    assertEquals("serializableSingleton", 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)

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