public final class WebApplicationContextTester extends Object
ApplicationContext tester
for a Servlet
based ConfigurableWebApplicationContext
.
See AbstractApplicationContextTester
for details.
Constructor and Description |
---|
WebApplicationContextTester()
Create a new
WebApplicationContextTester instance using an
AnnotationConfigWebApplicationContext with a MockServletContext as
the underlying source. |
WebApplicationContextTester(Supplier<ConfigurableWebApplicationContext> contextFactory)
Create a new
WebApplicationContextTester instance using the specified
contextFactory as the underlying source. |
Modifier and Type | Method and Description |
---|---|
void |
run(ContextConsumer<? super A> consumer)
Create and refresh a new
ApplicationContext based on the current state of
this loader. |
protected SELF |
self() |
SELF |
withClassLoader(ClassLoader classLoader)
Customize the
ClassLoader that the ApplicationContext should use. |
SELF |
withConfiguration(Configurations configurations)
Register the specified configuration classes with the
ApplicationContext . |
static Supplier<ConfigurableWebApplicationContext> |
withMockServletContext(Supplier<ConfigurableWebApplicationContext> contextFactory)
Decorate the specified
contextFactory to set a MockServletContext
on each newly created WebApplicationContext . |
SELF |
withParent(ApplicationContext parent)
Configure the
parent of the ApplicationContext . |
SELF |
withPropertyValue(String name,
String value)
Add the specified
Environment property. |
SELF |
withPropertyValues(String... pairs)
Add the specified
Environment property pairs. |
SELF |
withSystemProperties(String... pairs)
Add the specified
System property pairs. |
SELF |
withSystemProperty(String name,
String value)
Add the specified
System property. |
SELF |
withUserConfiguration(Class<?>... configurationClasses)
Register the specified user configuration classes with the
ApplicationContext . |
public WebApplicationContextTester()
WebApplicationContextTester
instance using an
AnnotationConfigWebApplicationContext
with a MockServletContext
as
the underlying source.withMockServletContext(Supplier)
public WebApplicationContextTester(Supplier<ConfigurableWebApplicationContext> contextFactory)
WebApplicationContextTester
instance using the specified
contextFactory
as the underlying source.contextFactory
- a supplier that returns a new instance on each callpublic static Supplier<ConfigurableWebApplicationContext> withMockServletContext(Supplier<ConfigurableWebApplicationContext> contextFactory)
contextFactory
to set a MockServletContext
on each newly created WebApplicationContext
.contextFactory
- the context factory to decorateMockServletContext
public SELF withPropertyValues(String... pairs)
Environment
property pairs. Key-value pairs can be
specified with colon (":") or equals ("=") separators. Override matching keys that
might have been specified previously.pairs
- the key-value pairs for properties that need to be added to the
environmentTestPropertyValues
,
withSystemProperties(String...)
public SELF withPropertyValue(String name, String value)
Environment
property.name
- the name of the propertyvalue
- the value of the propertyTestPropertyValues
,
withSystemProperties(String...)
public SELF withSystemProperties(String... pairs)
System
property pairs. Key-value pairs can be specified
with colon (":") or equals ("=") separators. System properties are added before the
context is run
and restored when the context is
closed.pairs
- the key-value pairs for properties that need to be added to the systemTestPropertyValues
,
withSystemProperties(String...)
public SELF withSystemProperty(String name, String value)
System
property. System properties are added before the
context is run
and restored when the context is
closed.name
- the property namevalue
- the property valueTestPropertyValues
,
withSystemProperties(String...)
public SELF withClassLoader(ClassLoader classLoader)
ClassLoader
that the ApplicationContext
should use.
Customizing the ClassLoader
is an effective manner to hide resources from
the classpath.classLoader
- the classloader to use (can be null to use the default)HidePackagesClassLoader
public SELF withParent(ApplicationContext parent)
parent
of the ApplicationContext
.parent
- the parentpublic SELF withUserConfiguration(Class<?>... configurationClasses)
ApplicationContext
.configurationClasses
- the user configuration classes to addpublic SELF withConfiguration(Configurations configurations)
ApplicationContext
.configurations
- the configurations to addprotected final SELF self()
public void run(ContextConsumer<? super A> consumer)
ApplicationContext
based on the current state of
this loader. The context is consumed by the specified consumer
and closed
upon completion.consumer
- the consumer of the created ApplicationContext
Copyright © 2017 Pivotal Software, Inc.. All rights reserved.