org.springframework.boot.test

Class SpringApplicationContextLoader

  • java.lang.Object
    • org.springframework.test.context.support.AbstractContextLoader
      • org.springframework.boot.test.SpringApplicationContextLoader
  • All Implemented Interfaces:
    org.springframework.test.context.ContextLoader, org.springframework.test.context.SmartContextLoader


    public class SpringApplicationContextLoader
    extends org.springframework.test.context.support.AbstractContextLoader
    A ContextLoader that can be used to test Spring Boot applications (those that normally startup using SpringApplication). Can be used to test non-web features (like a repository layer) or start an fully-configured embedded servlet container.

    Use @WebIntegrationTest (or @IntegrationTest with @WebAppConfiguration) to indicate that you want to use a real servlet container or @WebAppConfiguration alone to use a MockServletContext.

    If @ActiveProfiles are provided in the test class they will be used to create the application context.

    Author:
    Dave Syer, Phillip Webb, Andy Wilkinson
    See Also:
    IntegrationTest, WebIntegrationTest, TestRestTemplate
    • Constructor Detail

      • SpringApplicationContextLoader

        public SpringApplicationContextLoader()
    • Method Detail

      • loadContext

        public org.springframework.context.ApplicationContext loadContext(org.springframework.test.context.MergedContextConfiguration config)
                                                                   throws Exception
        Throws:
        Exception
      • getEnvironmentProperties

        protected Map<String,Object> getEnvironmentProperties(org.springframework.test.context.MergedContextConfiguration config)
      • processContextConfiguration

        public void processContextConfiguration(org.springframework.test.context.ContextConfigurationAttributes configAttributes)
        Specified by:
        processContextConfiguration in interface org.springframework.test.context.SmartContextLoader
        Overrides:
        processContextConfiguration in class org.springframework.test.context.support.AbstractContextLoader
      • detectDefaultConfigurationClasses

        protected Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringClass)
        Detect the default configuration classes for the supplied test class. By default simply delegates to AnnotationConfigContextLoaderUtils.detectDefaultConfigurationClasses(java.lang.Class<?>) .
        Parameters:
        declaringClass - the test class that declared @ContextConfiguration
        Returns:
        an array of default configuration classes, potentially empty but never null
        See Also:
        AnnotationConfigContextLoaderUtils
      • loadContext

        public org.springframework.context.ApplicationContext loadContext(String... locations)
                                                                   throws Exception
        Throws:
        Exception
      • getResourceSuffix

        protected String getResourceSuffix()
        Specified by:
        getResourceSuffix in class org.springframework.test.context.support.AbstractContextLoader

Copyright © 2015 Pivotal Software, Inc.. All rights reserved.