Search in sources :

Example 36 with UrlResource

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

the class BeanWrapperGenericsTests method testGenericListElement.

@Test
public void testGenericListElement() throws MalformedURLException {
    GenericBean<?> gb = new GenericBean<>();
    gb.setResourceList(new ArrayList<>());
    BeanWrapper bw = new BeanWrapperImpl(gb);
    bw.setPropertyValue("resourceList[0]", "http://localhost:8080");
    assertEquals(new UrlResource("http://localhost:8080"), gb.getResourceList().get(0));
}
Also used : UrlResource(org.springframework.core.io.UrlResource) GenericBean(org.springframework.tests.sample.beans.GenericBean) Test(org.junit.Test)

Example 37 with UrlResource

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

the class BeanFactoryGenericsTests method testGenericSetListConstructorWithOptionalAutowiring.

@Test
public void testGenericSetListConstructorWithOptionalAutowiring() throws MalformedURLException {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
    bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
    RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
    rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
    bf.registerBeanDefinition("genericBean", rbd);
    GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
    assertNull(gb.getIntegerSet());
    assertNull(gb.getResourceList());
}
Also used : UrlResource(org.springframework.core.io.UrlResource) GenericBean(org.springframework.tests.sample.beans.GenericBean) Test(org.junit.Test)

Example 38 with UrlResource

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

the class BeanFactoryGenericsTests method testGenericSetListConstructorWithAutowiring.

@Test
public void testGenericSetListConstructorWithAutowiring() throws MalformedURLException {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.registerSingleton("integer1", new Integer(4));
    bf.registerSingleton("integer2", new Integer(5));
    bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
    bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
    RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
    rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
    bf.registerBeanDefinition("genericBean", rbd);
    GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
    assertTrue(gb.getIntegerSet().contains(new Integer(4)));
    assertTrue(gb.getIntegerSet().contains(new Integer(5)));
    assertEquals(new UrlResource("http://localhost:8080"), gb.getResourceList().get(0));
    assertEquals(new UrlResource("http://localhost:9090"), gb.getResourceList().get(1));
}
Also used : UrlResource(org.springframework.core.io.UrlResource) GenericBean(org.springframework.tests.sample.beans.GenericBean) Test(org.junit.Test)

Example 39 with UrlResource

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

the class BeanFactoryGenericsTests method testGenericSetListConstructor.

@Test
public void testGenericSetListConstructor() throws MalformedURLException {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
    Set<String> input = new HashSet<>();
    input.add("4");
    input.add("5");
    List<String> input2 = new ArrayList<>();
    input2.add("http://localhost:8080");
    input2.add("http://localhost:9090");
    rbd.getConstructorArgumentValues().addGenericArgumentValue(input);
    rbd.getConstructorArgumentValues().addGenericArgumentValue(input2);
    bf.registerBeanDefinition("genericBean", rbd);
    GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
    assertTrue(gb.getIntegerSet().contains(new Integer(4)));
    assertTrue(gb.getIntegerSet().contains(new Integer(5)));
    assertEquals(new UrlResource("http://localhost:8080"), gb.getResourceList().get(0));
    assertEquals(new UrlResource("http://localhost:9090"), gb.getResourceList().get(1));
}
Also used : UrlResource(org.springframework.core.io.UrlResource) ArrayList(java.util.ArrayList) GenericBean(org.springframework.tests.sample.beans.GenericBean) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 40 with UrlResource

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

the class BeanFactoryGenericsTests method testGenericMapResourceConstructor.

@Test
public void testGenericMapResourceConstructor() throws MalformedURLException {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
    Map<String, String> input = new HashMap<>();
    input.put("4", "5");
    input.put("6", "7");
    rbd.getConstructorArgumentValues().addGenericArgumentValue(input);
    rbd.getConstructorArgumentValues().addGenericArgumentValue("http://localhost:8080");
    bf.registerBeanDefinition("genericBean", rbd);
    GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
    assertEquals(new Integer(5), gb.getShortMap().get(new Short("4")));
    assertEquals(new Integer(7), gb.getShortMap().get(new Short("6")));
    assertEquals(new UrlResource("http://localhost:8080"), gb.getResourceList().get(0));
}
Also used : HashMap(java.util.HashMap) UrlResource(org.springframework.core.io.UrlResource) GenericBean(org.springframework.tests.sample.beans.GenericBean) Test(org.junit.Test)

Aggregations

UrlResource (org.springframework.core.io.UrlResource)68 Test (org.junit.Test)36 Resource (org.springframework.core.io.Resource)31 URL (java.net.URL)25 ArrayList (java.util.ArrayList)10 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)10 ClassPathResource (org.springframework.core.io.ClassPathResource)10 GenericBean (org.springframework.tests.sample.beans.GenericBean)9 IOException (java.io.IOException)8 MalformedURLException (java.net.MalformedURLException)8 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)8 InputStream (java.io.InputStream)6 FileSystemResource (org.springframework.core.io.FileSystemResource)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 JUnitDNSServer (org.opennms.core.test.dns.annotations.JUnitDNSServer)5 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)5 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)5 JAXBContext (javax.xml.bind.JAXBContext)4 Unmarshaller (javax.xml.bind.Unmarshaller)4 BeansException (org.springframework.beans.BeansException)4