Package org.impalaframework.module.resource

Source Code of org.impalaframework.module.resource.ApplicationModuleLocationsResourceLoaderTest

package org.impalaframework.module.resource;

import junit.framework.TestCase;

import org.impalaframework.exception.ConfigurationException;
import org.impalaframework.module.ModuleDefinition;
import org.impalaframework.module.definition.SimpleRootModuleDefinition;
import org.impalaframework.spring.resource.ClassPathResourceLoader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.util.ClassUtils;

public class ApplicationModuleLocationsResourceLoaderTest extends TestCase {
   
    private String rootModuleName = "project1";
    private ClassPathResourceLoader resourceLoader;
    private ModuleLocationsResourceLoader loader;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        resourceLoader = new ClassPathResourceLoader();
        loader = new ModuleLocationsResourceLoader();
        loader.setResourceLoader(resourceLoader);
    }

    public final void testApplicationModuleSpringLocationsResourceLoader() {

        ModuleDefinition definition = new SimpleRootModuleDefinition(rootModuleName, new String[] { "parentTestContext.xml" });

        Resource[] springLocations = loader.getSpringLocations(definition, ClassUtils.getDefaultClassLoader());
        assertEquals(1, springLocations.length);
       
        for (Resource resource : springLocations) {
            assertTrue(resource.exists());
            assertTrue(resource instanceof ClassPathResource);
        }
    }
   
    public final void testNotFound() {

        ModuleDefinition definition = new SimpleRootModuleDefinition(rootModuleName, new String[] { "unknown.xml" });

        try {
            loader.getSpringLocations(definition, ClassUtils.getDefaultClassLoader());
            fail();
        }
        catch (ConfigurationException e) {
            assertEquals("Unable to load resource from location 'unknown.xml' for module definition 'project1'", e.getMessage());
        }
    }

}
TOP

Related Classes of org.impalaframework.module.resource.ApplicationModuleLocationsResourceLoaderTest

TOP
Copyright © 2018 www.massapi.com. 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.