Package org.springframework.core.io

Examples of org.springframework.core.io.Resource


* @since 08.07.2004
*/
public class PersistenceBrokerTemplateTests extends TestCase {

  protected void setUp() throws Exception {
    Resource res = new ClassPathResource("OJB.properties");
    System.setProperty("OJB.properties", res.getFile().getAbsolutePath());
  }
View Full Code Here


        engine.afterPropertiesSet();
    }

    public void testCreateTemplate() throws Exception {
        String encoding = "UTF-8";
        Resource resource = new StringResource("Hello $name");
        Template template = engine.createTemplate(resource, encoding);

        Map model = new HashMap();
        model.put("name", "Daan");
        assertEquals("Hello Daan", template.generate(model));
View Full Code Here

        loaderControl.expectAndReturn(loader.getResource("name"), new StringResource("Hello"));

        // second, velocity calls the loader when trying to get the last modified date of the resource.
        loaderControl.expectAndReturn(loader.getResource("name"), null);

        Resource resource = new StringResource("#include( \"name\" )");

        loaderControl.replay();

        Template template = engine.createTemplate(resource, encoding);
View Full Code Here

* @since 08.07.2004
*/
public class PersistenceBrokerTransactionManagerTests extends TestCase {

  protected void setUp() throws Exception {
    Resource res = new ClassPathResource("OJB.properties");
    System.setProperty("OJB.properties", res.getFile().getAbsolutePath());
  }
View Full Code Here

   
    @Test
    public void testBasic() {
        ExternalAttachmentProvider eap = new ExternalAttachmentProvider();
        assertNull(eap.getLocation());
        Resource uri = control.createMock(Resource.class);
        eap.setLocation(uri);
        assertSame(uri, eap.getLocation());
       
    }
View Full Code Here

        context = c;
    }
   

    public InputStream getAsStream(String name) {
        Resource r = context.getResource(name);
        if (r != null && r.exists()) {
            try {
                return r.getInputStream();
            } catch (IOException e) {
                //ignore and return null
            }
        }
        return null;
View Full Code Here

        }
        try {
            if (ClassLoader.class.isAssignableFrom(resourceType)) {
                return resourceType.cast(context.getClassLoader());
            } else if (URL.class.isAssignableFrom(resourceType)) {
                Resource r = context.getResource(resourceName);
                if (r != null && r.exists()) {
                    return resourceType.cast(r.getURL());
                }
            }
        } catch (IOException e) {
            //ignore
        }
View Full Code Here

     * @param contents  String containing the contents of the Resource
     * @return Mocked Resource containing the contents of the String.
     */
    public static Resource createMockedResource(String contents) {
        try {
            Resource entities = mock(Resource.class);
            when(entities.exists()).thenReturn(true);

            if (contents == null) {
                when(entities.getInputStream()).thenReturn((InputStream) null);
            } else {
                InputStream inputStream = new ByteArrayInputStream(contents.getBytes());
                when(entities.getInputStream()).thenReturn(inputStream);
            }

            return entities;
        } catch (IOException e) {
            throw new CedarRuntimeException("Error creating Resource: " + e.getMessage(), e);
View Full Code Here

        ObjectifyServiceProxy objectifyServiceProxy = mock(ObjectifyServiceProxy.class);
        service.setObjectifyServiceProxy(objectifyServiceProxy);
        assertSame(objectifyServiceProxy, service.getObjectifyServiceProxy());

        Resource entities = mock(Resource.class);
        service.setEntities(entities);
        assertSame(entities, service.getEntities());
    }
View Full Code Here

        assertSame(entities, service.getEntities());
    }

    /** Test the afterPropertiesSet() method. */
    @Test public void testAfterPropertiesSet() throws Exception {
        Resource invalid = TestUtils.createMockedResource(""); // invalid because no entities are configured
        Resource valid = TestUtils.createMockedResource("java.lang.String");
        ObjectifyServiceProxy objectifyServiceProxy = mock(ObjectifyServiceProxy.class);

        DaoObjectifyService service = new DaoObjectifyService();
        service.setObjectifyServiceProxy(objectifyServiceProxy);
        service.setEntities(valid);
View Full Code Here

TOP

Related Classes of org.springframework.core.io.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.