org.springframework.tests.sample.beans.ResourceTestBean Java Examples
The following examples show how to use
org.springframework.tests.sample.beans.ResourceTestBean.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testResourceAndInputStream() throws IOException { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(RESOURCE_CONTEXT); // comes from "resourceImport.xml" ResourceTestBean resource1 = (ResourceTestBean) xbf.getBean("resource1"); // comes from "resource.xml" ResourceTestBean resource2 = (ResourceTestBean) xbf.getBean("resource2"); assertTrue(resource1.getResource() instanceof ClassPathResource); StringWriter writer = new StringWriter(); FileCopyUtils.copy(new InputStreamReader(resource1.getResource().getInputStream()), writer); assertEquals("test", writer.toString()); writer = new StringWriter(); FileCopyUtils.copy(new InputStreamReader(resource1.getInputStream()), writer); assertEquals("test", writer.toString()); writer = new StringWriter(); FileCopyUtils.copy(new InputStreamReader(resource2.getResource().getInputStream()), writer); assertEquals("test", writer.toString()); writer = new StringWriter(); FileCopyUtils.copy(new InputStreamReader(resource2.getInputStream()), writer); assertEquals("test", writer.toString()); }
Example #2
Source File: ConversionServiceFactoryBeanTests.java From spring-analysis-note with MIT License | 5 votes |
private void doTestConversionServiceInApplicationContext(String fileName, Class<?> resourceClass) { ApplicationContext ctx = new ClassPathXmlApplicationContext(fileName, getClass()); ResourceTestBean tb = ctx.getBean("resourceTestBean", ResourceTestBean.class); assertTrue(resourceClass.isInstance(tb.getResource())); assertTrue(tb.getResourceArray().length > 0); assertTrue(resourceClass.isInstance(tb.getResourceArray()[0])); assertTrue(tb.getResourceMap().size() == 1); assertTrue(resourceClass.isInstance(tb.getResourceMap().get("key1"))); assertTrue(tb.getResourceArrayMap().size() == 1); assertTrue(tb.getResourceArrayMap().get("key1").length > 0); assertTrue(resourceClass.isInstance(tb.getResourceArrayMap().get("key1")[0])); }
Example #3
Source File: XmlBeanFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testClassPathResourceWithImport() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(RESOURCE_CONTEXT); // comes from "resourceImport.xml" xbf.getBean("resource1", ResourceTestBean.class); // comes from "resource.xml" xbf.getBean("resource2", ResourceTestBean.class); }
Example #4
Source File: XmlBeanFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testUrlResourceWithImport() { URL url = getClass().getResource(RESOURCE_CONTEXT.getPath()); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(new UrlResource(url)); // comes from "resourceImport.xml" xbf.getBean("resource1", ResourceTestBean.class); // comes from "resource.xml" xbf.getBean("resource2", ResourceTestBean.class); }
Example #5
Source File: XmlBeanFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testFileSystemResourceWithImport() throws URISyntaxException { String file = getClass().getResource(RESOURCE_CONTEXT.getPath()).toURI().getPath(); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(new FileSystemResource(file)); // comes from "resourceImport.xml" xbf.getBean("resource1", ResourceTestBean.class); // comes from "resource.xml" xbf.getBean("resource2", ResourceTestBean.class); }
Example #6
Source File: ConversionServiceFactoryBeanTests.java From java-technology-stack with MIT License | 5 votes |
private void doTestConversionServiceInApplicationContext(String fileName, Class<?> resourceClass) { ApplicationContext ctx = new ClassPathXmlApplicationContext(fileName, getClass()); ResourceTestBean tb = ctx.getBean("resourceTestBean", ResourceTestBean.class); assertTrue(resourceClass.isInstance(tb.getResource())); assertTrue(tb.getResourceArray().length > 0); assertTrue(resourceClass.isInstance(tb.getResourceArray()[0])); assertTrue(tb.getResourceMap().size() == 1); assertTrue(resourceClass.isInstance(tb.getResourceMap().get("key1"))); assertTrue(tb.getResourceArrayMap().size() == 1); assertTrue(tb.getResourceArrayMap().get("key1").length > 0); assertTrue(resourceClass.isInstance(tb.getResourceArrayMap().get("key1")[0])); }
Example #7
Source File: XmlBeanFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testClassPathResourceWithImport() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(RESOURCE_CONTEXT); // comes from "resourceImport.xml" xbf.getBean("resource1", ResourceTestBean.class); // comes from "resource.xml" xbf.getBean("resource2", ResourceTestBean.class); }
Example #8
Source File: XmlBeanFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testUrlResourceWithImport() { URL url = getClass().getResource(RESOURCE_CONTEXT.getPath()); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(new UrlResource(url)); // comes from "resourceImport.xml" xbf.getBean("resource1", ResourceTestBean.class); // comes from "resource.xml" xbf.getBean("resource2", ResourceTestBean.class); }
Example #9
Source File: XmlBeanFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testFileSystemResourceWithImport() throws URISyntaxException { String file = getClass().getResource(RESOURCE_CONTEXT.getPath()).toURI().getPath(); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(new FileSystemResource(file)); // comes from "resourceImport.xml" xbf.getBean("resource1", ResourceTestBean.class); // comes from "resource.xml" xbf.getBean("resource2", ResourceTestBean.class); }
Example #10
Source File: ConversionServiceFactoryBeanTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void doTestConversionServiceInApplicationContext(String fileName, Class<?> resourceClass) { ApplicationContext ctx = new ClassPathXmlApplicationContext(fileName, getClass()); ResourceTestBean tb = ctx.getBean("resourceTestBean", ResourceTestBean.class); assertTrue(resourceClass.isInstance(tb.getResource())); assertTrue(tb.getResourceArray().length > 0); assertTrue(resourceClass.isInstance(tb.getResourceArray()[0])); assertTrue(tb.getResourceMap().size() == 1); assertTrue(resourceClass.isInstance(tb.getResourceMap().get("key1"))); assertTrue(tb.getResourceArrayMap().size() == 1); assertTrue(tb.getResourceArrayMap().get("key1").length > 0); assertTrue(resourceClass.isInstance(tb.getResourceArrayMap().get("key1")[0])); }
Example #11
Source File: ClassPathXmlApplicationContextTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testResourceAndInputStream() throws IOException { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(RESOURCE_CONTEXT) { @Override public Resource getResource(String location) { if (TEST_PROPERTIES.equals(location)) { return new ClassPathResource(TEST_PROPERTIES, ClassPathXmlApplicationContextTests.class); } return super.getResource(location); } }; ResourceTestBean resource1 = (ResourceTestBean) ctx.getBean("resource1"); ResourceTestBean resource2 = (ResourceTestBean) ctx.getBean("resource2"); assertTrue(resource1.getResource() instanceof ClassPathResource); StringWriter writer = new StringWriter(); FileCopyUtils.copy(new InputStreamReader(resource1.getResource().getInputStream()), writer); assertEquals("contexttest", writer.toString()); writer = new StringWriter(); FileCopyUtils.copy(new InputStreamReader(resource1.getInputStream()), writer); assertEquals("test", writer.toString()); writer = new StringWriter(); FileCopyUtils.copy(new InputStreamReader(resource2.getResource().getInputStream()), writer); assertEquals("contexttest", writer.toString()); writer = new StringWriter(); FileCopyUtils.copy(new InputStreamReader(resource2.getInputStream()), writer); assertEquals("test", writer.toString()); ctx.close(); }
Example #12
Source File: XmlBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testClassPathResourceWithImport() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(RESOURCE_CONTEXT); // comes from "resourceImport.xml" xbf.getBean("resource1", ResourceTestBean.class); // comes from "resource.xml" xbf.getBean("resource2", ResourceTestBean.class); }
Example #13
Source File: XmlBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testUrlResourceWithImport() { URL url = getClass().getResource(RESOURCE_CONTEXT.getPath()); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(new UrlResource(url)); // comes from "resourceImport.xml" xbf.getBean("resource1", ResourceTestBean.class); // comes from "resource.xml" xbf.getBean("resource2", ResourceTestBean.class); }
Example #14
Source File: XmlBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testFileSystemResourceWithImport() throws URISyntaxException { String file = getClass().getResource(RESOURCE_CONTEXT.getPath()).toURI().getPath(); DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(new FileSystemResource(file)); // comes from "resourceImport.xml" xbf.getBean("resource1", ResourceTestBean.class); // comes from "resource.xml" xbf.getBean("resource2", ResourceTestBean.class); }