Commit Graph

384 Commits

Author SHA1 Message Date
Sam Brannen e24a7ded62 Simplify Groovy ContextLoaders in the TCF
This commit simplifies the implementations of loadBeanDefinitions() in
GenericGroovyXmlContextLoader and GenericGroovyXmlWebContextLoader.

Due to the recent bug fix for GroovyBeanDefinitionReader regarding full
support for XML config files, these Groovy context loaders can now
simply use a GroovyBeanDefinitionReader instead of a
GroovyBeanDefinitionReader plus an XmlBeanDefinitionReader.

Issue: SPR-12769
2015-02-28 23:28:55 +01:00
Sam Brannen 2ba1151b7f Support XML config fully in web integration tests
Prior to this commit, it was impossible to use all features of XML
configuration (e.g., the <qualifier> tag) in web-based integration
tests (loaded using @WebAppConfiguration, @ContextConfiguration, etc.)
if the Groovy library was on the classpath. The reason is that the
GroovyBeanDefinitionReader used internally by
GenericGroovyXmlWebContextLoader disables XML validation for its
internal XmlBeanDefinitionReader, and this prevents some XML
configuration features from working properly. For example, the default
value for the 'type' attribute (defined in the spring-beans XSD) of the
<qualifier> tag gets ignored, resulting in an exception when the
application context is loaded.

This commit addresses this issue by refactoring the implementation of
loadBeanDefinitions() in GenericGroovyXmlWebContextLoader to use an
XmlBeanDefinitionReader or GroovyBeanDefinitionReader depending on the
file extension of the resource location from which bean definitions
should be loaded. This aligns the functionality of
GenericGroovyXmlWebContextLoader with the existing functionality of
GenericGroovyXmlContextLoader.

Issue: SPR-12768
2015-02-28 19:06:40 +01:00
Sam Brannen fa5ea38210 Delete unused import in AsyncTests 2015-02-28 19:05:37 +01:00
Stephane Nicoll babbf6e871 Harmonize resources location
Issue: SPR-12766
2015-02-28 10:32:40 +01:00
Rossen Stoyanchev c48858c972 Prevent ISE in the MockMvc PrintingResultHandler
Issue: SPR-12735
2015-02-27 11:30:12 -05:00
Rossen Stoyanchev e13c300b53 Fix white space issues 2015-02-27 10:53:34 -05:00
Rossen Stoyanchev 2beca4d75e Update javadoc 2015-02-26 11:45:50 -05:00
Rossen Stoyanchev 2dd5875964 Support @ControllerAdvice in StandaloneMockMvcBuilder
Issue: SPR-12751
2015-02-25 16:57:58 -05:00
Sam Brannen 42af33034d Make TestPropertySourceUtils more robust
- Added assertions for pre-conditions on method arguments for all
   public utility methods.

 - Introduced additional tests in TestPropertySourceUtilsTests to verify
   the new pre-conditions.

 - Introduced INLINED_PROPERTIES_PROPERTY_SOURCE_NAME constant for the
   name of the MapPropertySource created from inlined properties; the
   name therefore no longer contains the inlined properties, but the
   original values of the inlined properties can now be logged at debug
   level.

 - Simplified tests in InlinedPropertiesTestPropertySourceTests.

Issue: SPR-12721
2015-02-17 19:42:52 +01:00
Sam Brannen 0267715c9d Polish Javadoc for @TestPropertySource 2015-02-17 19:32:19 +01:00
Sam Brannen 75e0bc9271 Open up TestPropertySourceUtils for public consumption
Spring Framework 4.1 introduced support for @TestPropertySource;
however, the utilities used to parse inlined properties and add test
property sources to the environment are currently private which
prevents reuse by third-party frameworks like Spring Boot.

This commit addresses this issue by making such utilities public.

 - TestPropertySourceUtils is now a public class.

 - Various utility methods in TestPropertySourceUtils have been made
   public.

 - addResourcePropertySourcesToEnvironment() has been renamed to
   addPropertiesFilesToEnvironment().

 - extractEnvironmentProperties() has been renamed to
   convertInlinedPropertiesToMap().

 - All public methods in TestPropertySourceUtils are now fully
   documented.

Issue: SPR-12721
2015-02-17 03:09:24 +01:00
Sam Brannen d6a799ad4a Preserve ordering of inlined props in @TestPropertySource
The initial implementation for adding inlined properties configured via
@TestPropertySource to the context's environment did not preserve the
order in which the properties were physically declared. This makes
@TestPropertySource a poor testing facility for mimicking the
production environment's configuration if the property source mechanism
used in production preserves ordering of property names -- which is the
case for YAML-based property sources used in Spring Boot, Spring Yarn,
etc.

This commit addresses this issue by ensuring that the ordering of
inlined properties declared via @TestPropertySource is preserved.
Specifically, the original functionality has been refactored. extracted
from AbstractContextLoader, and moved to TestPropertySourceUtils where
it may later be made public for general purpose use in other frameworks.

Issue: SPR-12710
2015-02-16 20:26:49 +01:00
Sam Brannen 67934a22e2 Add further regression tests for @TestPropertySource
This commit introduces further regression tests to ensure proper parsing
of inlined properties configured via @TestPropertySource. Specifically,
these additional tests ensure that we do not introduce a bug like the
one raised in Spring Boot issue #1110 [0].

[0] https://github.com/spring-projects/spring-boot/issues/1110

Issue: SPR-12710
2015-02-12 20:24:06 +01:00
Stephane Nicoll f0fca890bb Annotation-based event listeners
Add support for annotation-based event listeners. Enabled automatically
when using Java configuration or can be enabled explicitly via the
regular <context:annotation-driven/> XML element. Detect methods of
managed beans annotated with @EventListener, either directly or through
a meta-annotation.

Annotated methods must define the event type they listen to as a single
parameter argument. Events are automatically filtered out according to
the method signature. When additional runtime filtering is required, one
can specify the `condition` attribute of the annotation that defines a
SpEL expression that should match to actually invoke the method for a
particular event. The root context exposes the actual `event`
(`#root.event`) and method arguments (`#root.args`). Individual method
arguments are also exposed via either the `a` or `p` alias (`#a0` refers
to the first method argument). Finally, methods arguments are exposed via
their names if that information can be discovered.

Events can be either an ApplicationEvent or any arbitrary payload. Such
payload is wrapped automatically in a PayloadApplicationEvent and managed
explicitly internally. As a result, users can now publish and listen
for arbitrary objects.

If an annotated method has a return value, an non null result is actually
published as a new event, something like:

@EventListener
public FooEvent handle(BarEvent event) { ... }

Events can be handled in an aynchronous manner by adding `@Async` to the
event method declaration and enabling such infrastructure. Events can
also be ordered by adding an `@Order` annotation to the event method.

Issue: SPR-11622
2015-02-10 09:13:02 +01:00
Sam Brannen 2d918380f0 Support @Configuration as meta-annotation in the TCF
Spring Framework 4.0 introduced support for using test-related
annotations as meta-annotations in the Spring TestContext Framework
(TCF) in order to create custom composed annotations within a test
suite; however, the detection of default @Configuration classes in test
classes was not updated to search for @Configuration declared as a
meta-annotation. Specifically, AnnotationConfigContextLoaderUtils
invokes Class.isAnnotated() which only searches for annotations
declared directly on the class in question.

This commit addresses this issue by refactoring the
isDefaultConfigurationClassCandidate() method in
AnnotationConfigContextLoaderUtils so that it uses
AnnotationUtils.findAnnotation() instead of Class.isAnnotated() for
detecting the presence of the @Configuration annotation, either
directly or as a meta-annotation.

Issue: SPR-12659
2015-01-23 22:13:04 +01:00
Sam Brannen c5c32ec206 Refer to static nested classes, not static inner classes
Various parts of the reference manual as well as the Javadoc for
AnnotationConfigContextLoaderUtils improperly refer to "static inner
classes" even though this terminology does not exist in Java. The Java
Language Specification explicitly refers to such classes as "static
nested classes." An "inner class" must be non-static by definition.
2015-01-23 21:41:12 +01:00
Maciej Ziarko 81c750fb1c Fix Javadoc examples 2015-01-17 13:48:50 +01:00
Sam Brannen 276712dcd1 Enable reuse of DefaultActiveProfilesResolver
In order to allow DefaultActiveProfilesResolver to be reused (e.g., via
extension or delegation), the check which asserts that the 'resolver'
attribute of @ActiveProfiles is not set to a customer resolver class
has been removed.

Issue: SPR-12611
2015-01-10 20:36:48 +01:00
Sam Brannen cf7a7932f3 Polish TimedSpringRunnerTests 2015-01-10 17:52:41 +01:00
Sam Brannen b81c522ee1 Handle exceptions properly in SpringJUnit4ClassRunner
JUnit 4.9 introduced a regression in BlockJUnit4ClassRunner.runChild()
such that exceptions thrown from methodBlock() cause the current test
execution to abort immediately. As a result, the failing test method is
unrooted, and subsequent test methods are never invoked. Furthermore,
RunListeners registered with JUnit are not properly notified.

In conjunction with SPR-11908, SpringJUnit4ClassRunner was updated to
use the aforementioned changes to BlockJUnit4ClassRunner.runChild().
Consequently, SpringJUnit4ClassRunner now suffers from the same
regression.

This commit addresses this issue by ensuring that any exceptions thrown
during the invocation of methodBlock() are properly wrapped in a JUnit
Fail Statement.

Issue: SPR-12613
2015-01-10 17:51:51 +01:00
Juergen Hoeller 27b4909f46 Polishing
(cherry picked from commit 8c700b1)
2014-12-30 21:11:56 +01:00
Juergen Hoeller 9ac02b319d Remove pre-3.2 deprecated classes and methods
Issue: SPR-12578
2014-12-30 20:05:15 +01:00
Sebastien Deleuze d8a01cb04a Polish MockMvcBuilders tests 2014-12-22 13:51:56 +01:00
Sebastien Deleuze 32aafb21ff Set ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in DefaultMockMvcBuilder
Issue: SPR-12553
2014-12-22 13:39:21 +01:00
Sam Brannen e901abee06 Fix JavaDoc in TestExecutionListener regarding Ordered 2014-12-08 23:51:40 +01:00
Sam Brannen 1988f8c75f Polish Javadoc for ContextCache 2014-11-09 23:30:16 +01:00
Juergen Hoeller 74500ec8da Avoid unnecessary synchronization in ContextCache, plus forward-ported polishing
Issue: SPR-12409
2014-11-06 17:15:30 +01:00
Rossen Stoyanchev 794566abf5 Fix failing test 2014-11-05 21:17:32 -05:00
Rossen Stoyanchev 7f4bf41c23 Improve exception message
Issue: SPR-12230
2014-11-05 17:32:39 -05:00
Sam Brannen da04362a5e Log context cache statistics in the TCF
Prior to this commit, finding out how many application contexts had
been loaded within a test suite required the use of reflection and a
bit of hacking.

This commit addresses this issue by logging ContextCache statistics
whenever an application context is loaded by the Spring TestContext
Framework (TCF).

The log output can be enabled by setting the
"org.springframework.test.context.cache" logging category to DEBUG.

Issue: SPR-12409
2014-11-03 15:26:44 +01:00
Juergen Hoeller bba38b8862 MockHttpServletRequestBuilder allows for specifying content type as String value
Issue: SPR-12405
2014-11-01 23:01:26 +01:00
Sam Brannen 2f03945410 Delete unused imports in spring-test 2014-10-31 00:26:13 +01:00
Sam Brannen fc7e60678c Fix Javadoc in MockHttpServletRequestBuilder
Class-level Javadoc for MockHttpServletRequestBuilder now correctly
refers to MockMvcRequestBuilders instead of MockMvcBuilders.

Issue: SPR-12393
2014-10-30 00:07:01 +01:00
Juergen Hoeller 1146d5ba1d Polishing 2014-10-29 22:44:59 +01:00
Juergen Hoeller 065104a485 Restored compatibility with JsonPath 0.9.x
Issue: SPR-12299
2014-10-21 12:37:56 +02:00
Juergen Hoeller 8325b10080 Consistent formatting of license headers, package javadocs, and import declarations 2014-10-21 01:44:07 +02:00
Juergen Hoeller 77a62ec8b8 Polishing 2014-10-20 17:42:18 +02:00
Juergen Hoeller d501137f4e Consistently accept empty Content-Type header and empty character encoding
Issue: SPR-12173
2014-10-14 14:26:07 +02:00
Sam Brannen 25d13ac41e Sensible defaults for Servlet & Filter registrations in mock
Prior to this commit, the getter methods in MockServletContext threw an
UnsupportedOperationException when trying to retrieve Servlet and
Filter registrations.

This commit improves the behavior of these methods by returning null
when a single registration is requested and an empty map when all
registrations are requested. This is now in line with the Javadoc for
ServletContext. Note, however, that the corresponding setter methods
still throw UnsupportedOperationExceptions which is suitable behavior
for a mock.

Issue: SPR-12290
2014-10-02 14:03:39 +02:00
Sam Brannen 0026d8faf8 Update package-info for org.springframework.test 2014-09-22 15:06:43 +02:00
Sam Brannen 0083cc0a01 Add missing package-info files in spring-test 2014-09-22 15:06:43 +02:00
Juergen Hoeller 16325c2eaa Polishing 2014-09-20 00:29:16 +02:00
Sam Brannen 703cc0d6ae Polish Javadoc for MergedContextConfiguration 2014-08-31 21:03:38 +02:00
Sam Brannen f9855b7901 Polish Javadoc for @Sql and SqlScriptsTestExecutionListener 2014-08-31 17:17:04 +02:00
Sam Brannen 8008e466aa Refactor AssertThrows to support Throwable
Prior to this commit, AssertThrows in the spring-test module only
supported Exception; however, there are legitimate test cases where the
subject under test (SUT) may potentially throw a subclass of Throwable.

This commit refactors AssertThrows so that it supports exceptions of
type Throwable instead of the limiting support for Exception.
Furthermore, AssertThrows has been refactored to use generics (e.g.,
Class<? extends Throwable> instead of merely Class).

Issue: SPR-6362
2014-08-29 16:00:01 +02:00
Sam Brannen 1bce6ac60c Discontinue use of deprecated AssertThrows
This commit refactors ReflectionTestUtilsTests so that it no longer uses
the deprecated AssertThrows class.
2014-08-29 15:28:19 +02:00
Sam Brannen 27be396b06 Update Javadoc for AssertThrows 2014-08-29 15:28:19 +02:00
Sam Brannen 0b0ddc6ed1 Honor scheme in MockHttpServletRequest.isSecure()
Prior to this commit the implementation of isSecure() in
MockHttpServletRequest simply returned the value of the 'secure'
boolean flag. Thus setting the scheme to 'https' had no effect on the
value returned by isSecure() even though most non-mock implementations
(e.g., Tomcat, Jetty, etc.) base the return value on the actual scheme
in the request.

This commit makes the behavior of MockHttpServletRequest.isSecure()
more intuitive by honoring both the 'secure' boolean flag and the
current value of the scheme.

Issue: SPR-12098
2014-08-28 15:05:36 +02:00
Sam Brannen d5c6bcb901 How to register MIME types in MockServletContext
Prior to this commit, it was unclear that it was possible to register
custom MIME types when using MockServletContext.

This commit updates the Javadoc for MockServletContext.getMimeType()
with an example of how to achieve this using the MimetypesFileTypeMap
from the Java Activation Framework.

Issue: SPR-12126
2014-08-27 00:23:01 +02:00
Sam Brannen 2f2fe9bd05 Verify custom MIME type support in MockServletContext 2014-08-26 23:54:02 +02:00