public class SpringApplicationContextLoader
extends AbstractContextLoader
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.
IntegrationTest| Constructor and Description |
|---|
SpringApplicationContextLoader() |
| Modifier and Type | Method and Description |
|---|---|
protected Class<?>[] |
detectDefaultConfigurationClasses(Class<?> declaringClass)
Detect the default configuration classes for the supplied test class.
|
protected Map<String,Object> |
getEnvironmentProperties(MergedContextConfiguration config) |
protected String |
getResourceSuffix() |
protected SpringApplication |
getSpringApplication()
Builds new
SpringApplication instance. |
ApplicationContext |
loadContext(MergedContextConfiguration config) |
ApplicationContext |
loadContext(String... locations) |
void |
processContextConfiguration(ContextConfigurationAttributes configAttributes) |
public ApplicationContext loadContext(MergedContextConfiguration config) throws Exception
Exceptionpublic void processContextConfiguration(ContextConfigurationAttributes configAttributes)
protected SpringApplication getSpringApplication()
SpringApplication instance. You can
override this method to add custom behaviourSpringApplication instanceprotected Class<?>[] detectDefaultConfigurationClasses(Class<?> declaringClass)
AnnotationConfigContextLoaderUtils#detectDefaultConfigurationClasses .declaringClass - the test class that declared @ContextConfigurationnullAnnotationConfigContextLoaderUtilsprotected Map<String,Object> getEnvironmentProperties(MergedContextConfiguration config)
public ApplicationContext loadContext(String... locations) throws Exception
Exceptionprotected String getResourceSuffix()
Copyright © 2014 Pivotal Software, Inc.. All rights reserved.