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). Normally never starts an embedded web server, but detects the @WebAppConfiguration annotation on the test class and only creates a web application context if it is present. Non-web features, like a repository layer, can be tested cleanly by simply not marking the test class @WebAppConfiguration.

    If you want to start a web server, mark the test class as @WebAppConfiguration @IntegrationTest. This is useful for testing HTTP endpoints using TestRestTemplate (for instance), especially since you can @Autowired application context components into your test case to see the internal effects of HTTP requests directly.

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

    Author:
    Dave Syer
    See Also:
    IntegrationTest
    • Constructor Detail

      • SpringApplicationContextLoader

        public SpringApplicationContextLoader()
    • Method Detail

      • loadContext

        public org.springframework.context.ApplicationContext loadContext(org.springframework.test.context.MergedContextConfiguration config)
                                                                   throws Exception
        Throws:
        Exception
      • 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
      • getEnvironmentProperties

        protected Map<String,Object> getEnvironmentProperties(org.springframework.test.context.MergedContextConfiguration config)
      • 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 © 2014 Pivotal Software, Inc.. All rights reserved.