Class TestContextResourceUtils

java.lang.Object
org.springframework.test.context.util.TestContextResourceUtils

public abstract class TestContextResourceUtils extends Object
Utility methods for working with resources within the Spring TestContext Framework. Mainly for internal use within the framework.
Since:
4.1
Author:
Sam Brannen, Tadaya Tsuyukubo
See Also:
  • ResourceUtils
  • Resource
  • ClassPathResource
  • FileSystemResource
  • UrlResource
  • ResourceLoader
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String[]
    convertToClasspathResourcePaths(Class<?> clazz, boolean preservePlaceholders, String... paths)
    Convert the supplied paths to classpath resource paths.
    static String[]
    Convert the supplied paths to classpath resource paths.
    static List<org.springframework.core.io.Resource>
    convertToResourceList(org.springframework.core.io.ResourceLoader resourceLoader, String... paths)
    Convert the supplied paths to a list of Resource handles using the given ResourceLoader.
    static List<org.springframework.core.io.Resource>
    convertToResourceList(org.springframework.core.io.ResourceLoader resourceLoader, org.springframework.core.env.Environment environment, String... paths)
    Convert the supplied paths to a list of Resource handles using the given ResourceLoader and Environment.
    static org.springframework.core.io.Resource[]
    convertToResources(org.springframework.core.io.ResourceLoader resourceLoader, String... paths)
    Convert the supplied paths to an array of Resource handles using the given ResourceLoader.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TestContextResourceUtils

      public TestContextResourceUtils()
  • Method Details

    • convertToClasspathResourcePaths

      public static String[] convertToClasspathResourcePaths(Class<?> clazz, String... paths)
      Convert the supplied paths to classpath resource paths.

      Delegates to convertToClasspathResourcePaths(Class, boolean, String...) with false supplied for the preservePlaceholders flag.

      Parameters:
      clazz - the class with which the paths are associated
      paths - the paths to be converted
      Returns:
      a new array of converted resource paths
      See Also:
    • convertToClasspathResourcePaths

      public static String[] convertToClasspathResourcePaths(Class<?> clazz, boolean preservePlaceholders, String... paths)
      Convert the supplied paths to classpath resource paths.

      For each of the supplied paths:

      • A plain path — for example, "context.xml" — will be treated as a classpath resource that is relative to the package in which the specified class is defined. Such a path will be prepended with the classpath: prefix and the path to the package for the class.
      • A path starting with a slash will be treated as an absolute path within the classpath, for example: "/org/example/schema.sql". Such a path will be prepended with the classpath: prefix.
      • A path which is already prefixed with a URL protocol (for example, classpath:, file:, http:, etc.) will not have its protocol modified.

      Each path will then be cleaned, unless the preservePlaceholders flag is true and the path contains one or more placeholders in the form ${placeholder.name}.

      Parameters:
      clazz - the class with which the paths are associated
      preservePlaceholders - true if placeholders should be preserved
      paths - the paths to be converted
      Returns:
      a new array of converted resource paths
      Since:
      5.2
      See Also:
    • convertToResources

      public static org.springframework.core.io.Resource[] convertToResources(org.springframework.core.io.ResourceLoader resourceLoader, String... paths)
      Convert the supplied paths to an array of Resource handles using the given ResourceLoader.
      Parameters:
      resourceLoader - the ResourceLoader to use to convert the paths
      paths - the paths to be converted
      Returns:
      a new array of resources
      See Also:
    • convertToResourceList

      public static List<org.springframework.core.io.Resource> convertToResourceList(org.springframework.core.io.ResourceLoader resourceLoader, String... paths)
      Convert the supplied paths to a list of Resource handles using the given ResourceLoader.
      Parameters:
      resourceLoader - the ResourceLoader to use to convert the paths
      paths - the paths to be converted
      Returns:
      a new, mutable list of resources
      Since:
      4.2
      See Also:
    • convertToResourceList

      public static List<org.springframework.core.io.Resource> convertToResourceList(org.springframework.core.io.ResourceLoader resourceLoader, org.springframework.core.env.Environment environment, String... paths)
      Convert the supplied paths to a list of Resource handles using the given ResourceLoader and Environment.
      Parameters:
      resourceLoader - the ResourceLoader to use to convert the paths
      environment - the Environment to use to resolve property placeholders in the paths
      paths - the paths to be converted
      Returns:
      a new, mutable list of resources
      Since:
      6.2
      See Also: