Commit Graph

5300 Commits

Author SHA1 Message Date
Sam Brannen e71cd06a46 Doc. usage of JSR-250 lifecycle annotations in TCF
The reference manual previously did not mention the applicability of
JSR-250 lifecycle annotations within the TestContext framework. The
lacking documentation here has lead to misunderstandings of the support
provided for @PostConstruct and @PreDestroy in test classes.

The testing chapter of the reference manual has therefore been updated
to explicitly define the limited support for these annotations.

Also introduced Jsr250LifecycleTests for empirical verification of the 
expected behavior.

Issue: SPR-4868
2012-05-19 04:03:40 +02:00
Rossen Stoyanchev 03d6350e4b Fix issue with resolution of WebDataBinder argument
There is usually not need to put annotations on a WebDataBinder
argument in an `@InitBinder` method. However, the presence of any
annotation prevented the successful resolution of the argument.
This fix addresses the issue.

Issue: SPR-8946
2012-05-18 18:35:49 -04:00
Sam Brannen 5cd6543d83 Update @Bean Javadoc re: 'lite' mode, scope, etc.
Updated the "@Bean Lite Mode" section in order to properly document 
scoping and lifecycle semantics.

Also fleshed out the discussion of the non-applicability of 'inter-bean 
references' in lite mode.

Issue: SPR-9425
2012-05-19 00:05:29 +02:00
Sam Brannen dc6b2abe46 Verify scope support for 'lite' @Beans in the TCF
Introduced AtBeanLiteModeScopeTests integration tests to verify proper 
scoping of beans created in 'lite' mode.

Updated comments in TACCWithoutACTests to better reflect the runtime 
behavior for 'lite' @Bean methods.

Issue: SPR-9401
2012-05-18 21:54:17 +02:00
Sam Brannen 49966258f1 Polish doc for 'annotated class' support in TCF
Revised the content in the @ContextConfiguration annotation section.

Issue: SPR-9401
2012-05-18 17:15:38 +02:00
Chris Beams 6a01ca6d35 Merge branch garyrussell/SPR-9249
* SPR-9249:
  Add value-type attrib to beans->map->entry element
2012-05-18 14:48:39 +03:00
Gary Russell 183ac0c1ff Add value-type attrib to beans->map->entry element
Previously, the <value> subelement of a map <entry> allowed one to
specify the type of a specific map entry value. This patch allows a
value-type attribute as well, such that instead of the following
syntax

    <entry key="x-message-ttl">
        <value type="java.lang.Long">100</value>
    </entry>
    <entry key="x-ha-policy" value="all" />

one can now use the more concise form

    <entry key="x-message-ttl" value="100" value-type="java.lang.Long"/>
    <entry key="x-ha-policy" value="all"/>

The new value-type attribute may be used at the <map> level as well,
indicating that all elements are of the same type.

Appropriate tests have been added exercising value-type at the <map> and
<entry> levels.

Issue: SPR-9249
2012-05-18 14:43:28 +03:00
Chris Beams f3bcb6e2e4 Update spring.schemas to reflect 3.2 schemas
Commit 180c5b2ef6 introduced 3.2 versions
of all spring-* schemas; this commit updates spring.schemas mapping
files to include these new versions.
2012-05-18 14:31:33 +03:00
Sam Brannen 504cdf498e Update documentation of 'annotated class' support in the TCF
Updated the testing chapter of the reference manual to refer to 
'annotated classes' instead of 'configuration classes' where 
appropriate.

Also revised the content and examples in the @ContextConfiguration 
annotation section, mentioned Gradle, and reformatted the entire text.

Issue: SPR-9401
2012-05-18 04:33:40 +02:00
Sam Brannen 09d98fd3ae Delete superfluous fail() invocations in RequestResponseBodyMethodProcessorTests
Several test methods in RequestResponseBodyMethodProcessorTests
are currently annotated with @Test(expected=…) and additionally contain:

    fail("Expected exception");

This combination is superfluous, and the unnecessary fail() invocations
have therefore been removed.
2012-05-18 03:10:13 +02:00
Rossen Stoyanchev 77ae101402 Add required flag to @RequestBody
If true and there is no body => HttpMessageNotReadableException
If false and there is no body, the argument resolves to null.

Issue: SPR-9239
2012-05-17 17:48:48 -04:00
Rossen Stoyanchev 0105c5ebb9 Decode path vars in pre-3.1 `@MVC` support clases too
See the commit comments for:
57307a0b2e

This commit also applies the change to pre-3.1 `@MVC` suppor classes.

Issue: SPR-6951
2012-05-17 16:35:55 -04:00
Rossen Stoyanchev 57307a0b2e Decode path vars when url decoding is turned off
When URL decoding is turned off in AbstractHandlerMapping, the
extracted path variables are also not encoded. Turning off URL decoding
may be necessary for request mapping to work correctly when the path
may contain the (encoded) special character '/'. At the same time there
is no good reason not to leave path variables encoded. This change
ensures path variables are encoded when URL decoding is turned off.

Issue: SPR-9098
2012-05-17 16:01:20 -04:00
Sam Brannen 36e7cb2d31 Improve documentation of annotated class support in the TCF
Updated all Javadoc in the Spring TestContext Framework (TCF) to explain
and refer to 'annotated classes' instead of 'configuration classes'.

Specifically, @ContextConfiguration now explicitly defines what is meant
by 'annotated classes', and various other classes now refer to this
definition. Otherwise, the term 'configuration class' has simply been
replaced with 'annotated class'.

Also deleted cross references to deprecated JUnit 3.8 classes and
formatted Javadoc in general for greater readability.

Issue: SPR-9401
2012-05-17 20:17:48 +02:00
Sam Brannen 59e3223c84 Polish recent changes to Log4jWebConfigurer
Reordered inline comments so that they now apply to current
state of the code.

Added logger entry in testlog4j.properties to avoid console
warning.

Issue: SPR-9417
2012-05-17 18:05:38 +02:00
Chris Beams 98bf01adfb Merge pull request #42 from sslavic/SPR-5369
* SPR-5369:
  Fix circular placeholder prevention
2012-05-17 14:50:41 +03:00
Stevo Slavic 18006c72b0 Fix circular placeholder prevention
A set of resolved placeholder references is used for circular
placeholder prevention. For complex property definitions this mechanism
would put property values with unresolved inner placeholder references
in the set, but would try to remove property values with placeholders
resolved, leaving the set in an invalid state and the mechanism broken.

This fix makes sure that the value that is put in the set is same one
that is removed from it, and by doing so avoids false positives in
reporting circular placeholders.

Issue: SPR-5369
2012-05-17 14:48:18 +03:00
Chris Beams f667db56b1 Merge pull request #34 from marschall/warnings
* warnings:
  Fix compiler warnings
2012-05-17 14:38:49 +03:00
Philippe Marschall 13239a0c3d Fix compiler warnings
This patch fixes several compiler warnings that do not point to code
problems. Two kinds of warnings are fixed. First in a lot of cases
@SuppressWarnings("unchecked") is used although there are no unchecked
casts happening. This seems to be a leftover from when the code base
was on Java 1.4, now that the code base was moved to Java 1.5 these are
no longer necessary. Secondly there some places where the raw types of
List and Class are used where there wildcard types (List<?> and
Class<?>) would work just as well without causing any raw type warnings.

These changes are beneficial particularly when working in Eclipse or
other IDEs because it reduces 'noise', helping to isolate actual
potential problems in the code.

The following changes have been made:

 - remove @SuppressWarnings where no longer needed

 - use wildcard types instead of raw types where possible
2012-05-17 14:32:34 +03:00
Chris Beams e68b563626 Merge pull request #53 from aclement/SPR-9203
* SPR-9203:
  Eliminate trailing whitespace in SpEL classes
  Support [] array ref syntax in SpEL T() construct
2012-05-17 13:46:16 +03:00
Chris Beams de2d808212 Eliminate trailing whitespace in SpEL classes 2012-05-17 13:46:00 +03:00
Andy Clement 916e9d6efa Support [] array ref syntax in SpEL T() construct
Prior to this change, SpEL would not allow the use of '[]' in
expressions like the following:

    T(foo.Bar[])

This commit updates TypeReference and InternalSpelExpressionParser to
support this syntax, avoiding the need for workarounds like:

    new foo.bar[0].class

Issue: SPR-9203
2012-05-17 13:45:30 +03:00
Chris Beams 0e8f5d877a Merge pull request #57 from sslavic/SPR-8278
* SPR-8278:
  Fix compiler warnings in Constants/ConstantsTests
  Allow null params as advertised in Constants#toCode*
2012-05-17 13:00:26 +03:00
Chris Beams 1f4b33c4ad Fix compiler warnings in Constants/ConstantsTests 2012-05-17 12:59:21 +03:00
Stevo Slavic 6ffb0436fa Allow null params as advertised in Constants#toCode*
Even though the Javadoc for Constants#toCode and #toCodeForSuffix
specifies that a null value for the 'namePrefix' and 'nameSuffix'
parameters are respectively allowed, before this change passing a null
to either would result in a NullPointerException.

This change fixes constant name lookup for null values of these params
as if an empty string had been passed instead. This way of handling a
null value is consistent with the rest of Constants class API.

Issue: SPR-8278
2012-05-17 12:53:32 +03:00
Chris Beams 95e99fe2a3 Merge pull request #59 from sslavic/SPR-8360
* SPR-8360:
  Fix JibxMarshallerTests failing on Windows
2012-05-17 10:54:56 +03:00
Stevo Slavic 51ae6845ad Fix JibxMarshallerTests failing on Windows
Before this change JibxMarshallerTests would fail on Windows with an
error message explaining that JiBX compiler generated classes are not
found on the classpath for binding with name 'binding'. Tests would
execute well on Linux and OS X.

Actual root cause of this bug is found to be in JiBX 1.1.5 release that
is used to build Spring. The binding name can be explicitly specified in
JiBX binding file. If omitted, when generating classes the JiBX compiler
as fall-back mechanism tries to derive the binding name from the binding
file name. That logic had a bug which gets manifested when configured
binding file path has mixed Windows and *nix style file separators, as
in case of JibxMarshallerTests being executed on a Windows platform.

This commit resolves this issue by upgrading Spring's build from JiBX
1.1.5 to 1.2.3, as the bug mentioned was fixed in JiBX 1.2. See JIBX-441
for more details.

Issue: SPR-8360
2012-05-17 10:53:42 +03:00
Chris Beams 0ca11d2296 Merge pull request #49 from sslavic/SPR-9123
* SPR-9123:
  Fix SpEL JavaBean compliance
2012-05-17 10:28:39 +03:00
Stevo Slavic 1f28bdfbfa Fix SpEL JavaBean compliance
Before this fix ReflectivePropertyAccessor was not able to find write
method for valid property name that has first character in lower case
and second character in upper case. Write method lookup would always
convert first character of property name to upper case which is not
compliant with JavaBean specification. As consequence this caused an
unwanted behavior in SpEL when obtaining values of expressions that
reference such JavaBean properties.

As of this change, write method lookup skips conversion of property
name first character to upper case when property name is longer than
one character and second character is in upper case. This also fixes
mentioned bug in SpEL value resolution.

Issue: SPR-9123
2012-05-17 10:27:52 +03:00
Chris Beams 2503b7eb89 Fix property replacement bug in Log4jWebConfigurer
Previously, if the resolution of a ${...} placeholder resulted in a
valid URL for the location of a log4j properties/XML file, the URL
would ultimately be malformed by an unnecessary call to to
WebUtils#getRealPath.

The implementation of Log4jWebConfigurer#initLogging now eagerly
attempts SystemPropertyUtils#resolvePlaceholders before checking to see
if the location is a valid URL, and bypassing the call to
WebUtils#getRealPath if so.

Issue: SPR-9417
2012-05-17 10:11:46 +03:00
Chris Beams f1246a4317 Fix locale parsing error with en_en, tr_tr, etc
Previously, StringUtils#parseLocaleString would parse locale strings
having the same lowercase token for both language and country
incorrectly, e.g. 'tr_tr' would parse to 'tr_TR_tr' as opposed to the
expected 'tr_TR'.

This commit fixes this behavior by using using String#lastIndexOf
instead of String#indexOf when determining the location of the country
code token.

Issue: SPR-9420
2012-05-17 09:42:42 +03:00
Sam Brannen e8f8559a2e Improve documentation of @Bean 'lite' mode
Removed misleading mention of "configuration classes" in the
"@Bean Lite Mode" section.

Issue: SPR-9401
2012-05-17 00:47:07 +02:00
Sam Brannen 94c9f96449 Improve documentation of @Bean 'lite' mode
Updated the class-level JavaDoc for @Bean to better explain the
semantics of 'lite' mode.

Renamed "Configuration Class Lite Mode" to "@Bean Lite Mode".

Added discussion of @DependsOn to the class-level JavaDoc.

Issue: SPR-9401
2012-05-17 00:32:36 +02:00
Chris Beams dfd2b77b8a Merge pull request #81 from JanecekPetr/SPR-9342
* SPR-9342:
  Fix annotation search ending too early
2012-05-17 00:46:55 +03:00
Petr Janecek ef7e728bb8 Fix annotation search ending too early
In AnnotationUtils#findAnnotation(Method, Class), the search for a
method annotation fails if:

 - the original method does not have the annotation

 - an abstract superclass does not have an equivalent method declared

 - an interface implemented by the superclass has the method and
   the annotation -> this should be found, but is not!

This happens because the try-catch block in #findAnnotation is too wide:
cl.getDeclaredMethod() can throw NoSuchMethodException and skip the
'#searchOnInterfaces' call prematurely.

The try-catch block was made narrower to allow #searchOnInterfaces to
be called even if the abstract class does not have the method declared
at all.

Issue: SPR-9342
2012-05-17 00:45:21 +03:00
Sam Brannen 6023b2060b Fix minor grammatical errors in AbstractBeanDefinition 2012-05-16 23:09:49 +02:00
Sam Brannen 98050268c5 Improve documentation for configuration class 'lite' mode
Overhauled the class-level JavaDoc in @Bean:

 - added h3 headers for greater clarity and readability
 - mentioned 'prototype' semantics for lite mode

Issue: SPR-9401
2012-05-16 23:08:06 +02:00
Rossen Stoyanchev cf5d55173b Pattern suffix issue in AnnotationMethodHandlerAdapter
SPR-9333
2012-05-16 13:22:50 -04:00
Chris Beams ae216fbbb5 Merge pull request #63 from dukehoops/SPR-9298
* SPR-9298:
  Cache MethodParameter annotation lookup results
2012-05-16 16:39:10 +03:00
Nikita Tovstoles c10d63dc01 Cache MethodParameter annotation lookup results
Prior to this change, Spring's MethodParameter#getParameterAnnotations
called java.lang.Method#getParameterAnnotations on every invocation.
The latter ends up contending for a monitor inside (Sun) JDK code. This
is problematic when dealing with the high number of @RequestMapping
invocations that can occur in a Spring MVC @Controller.

This commit eliminates this contention by caching values returned by
java.lang.Method#getParameterAnnotations in a static ConcurrentMap.

Note that only Method parameter annotations are cached, while
Constructor parameter annotations are not. This is because the
issue of primary concern is, as mentioned above, @RequestMapping
methods. By nature, constructors are called much more infrequently, and
in most cases in a single-threaded fashion.

Issue: SPR-9298
2012-05-16 16:22:38 +03:00
Chris Beams 39f74b2374 Merge pull request #37 from marschall/small-memory-fixes
* small-memory-fixes:
  Optimize memory usage in factory *Metadata classes
2012-05-16 13:06:03 +03:00
Philippe Marschall cdb6d7447e Optimize memory usage in factory *Metadata classes
InjectionMetadata and LifecycleMetadata can end up having mostly empty
instance variables. In such cases memory usage can be improved a little
bit.

This patch addresses this in two ways:

 - Creating a LinkedHashSet of the "right" size, the default capacity
   is 16 but the exact capacity needed is known in advance.

 - If the argument is empty then use Collections#emptySet which is a
   constant so no additional memory is used. Since it's immutable there
   is no need for the Collections#synchronizedSet wrapper.

Issue: SPR-9264
2012-05-16 13:01:08 +03:00
Chris Beams 46bdb2de07 Merge pull request #64 from marschall/SPR-9316
* SPR-9316:
  Avoid NPE in AutowiredAnnotationBeanPostProcessor
2012-05-16 11:48:07 +03:00
Philippe Marschall 2624b90906 Avoid NPE in AutowiredAnnotationBeanPostProcessor
Prior to this change, AABPP#determineRequiredStatus never checked the
return value of ReflectionUtils#findMethod when searching for a
'#required' attribute. This call returns null for annotations such as
@Inject, @Value and @Resource, and subsequently causes a
NullPointerException to be thrown when ReflectionUtils#invokeMethod is
called. The NPE is caught immediately and #determineRequiredStatus
returns defaulting to true, but this this approach is inefficient. It
is also problematic for users who have set breakpoints on NPE -- they
end up debugging into Spring internals, which is a false positive.

This commit checks the return value of of ReflectionUtils#findMethod,
and in the case of null, eagerly returns true.  There is no change to
external behavior, simply a more efficient and debugging-friendly
implementation.

Existing test cases already cover this change, given that it is purely
a refactoring.

Issue: SPR-9316
2012-05-16 11:39:43 +03:00
Sam Brannen b50f6e19a6 Fix regression in ClassPathResource descriptions
ClassPathResource.getDescription() now returns consistent, meaningful
results for all variants of ClassPathResource's constructors.

Issue: SPR-9413
2012-05-16 04:24:53 +02:00
Sam Brannen 500a4dd995 Fix tx annotated tests so that they pass in the build
AbstractTransactionalAnnotatedConfigClassTests is now annotated with
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) so 
that side-effects between tests are avoided.

Re-enabled TransactionalAnnotatedConfigClassWithAtConfigurationTests
and TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests.

Also introduced a log4j FileAppender for tests that writes to
"build/spring-test.log".

Issue: SPR-9051
2012-05-16 03:08:15 +02:00
Rossen Stoyanchev 01a9dd9772 Add option to set Content-Length in JSON Views
MappingJackson2JsonView and MappingJacksonJsonView now provide an
option that will set the Content-Length header of JSON responses.
Use of the option implies buffering of the response and it must be
enabled explicitly.

Issue: SPR-7866
2012-05-15 18:10:24 -04:00
Sam Brannen 2017b24867 Disable tx annotated tests until working within the build
Issue: SPR-9051
2012-05-15 23:45:49 +02:00
Rossen Stoyanchev 2af294ab26 Add MessageCodesResolver hook to WebMvcConfigurer
This change makes it possible to provide a custom MessageCodesResolver
through the MVC Java config whether using @EnableWebMvc and extending
WebMVcConfigurerAdapter or sub-classing directly from
WebMvcConfigurationSupport.

Issue: SPR-9223
2012-05-15 17:11:28 -04:00
Sam Brannen 1cec0f9c65 Investigate claims made in SPR-9051 regarding transactional tests
The claim: given an integration test class that is annotated with 
@ContextConfiguration and declares a configuration class that is missing

an @Configuration annotation, if a transactional test method (i.e., one 
annotated with @Transactional) changes the state of the database then
the 
changes will not be rolled back as would be expected with the default 
rollback semantics of the Spring TestContext Framework (TCF).

TransactionalAnnotatedConfigClassWithAtConfigurationTests is a concrete 
implementation of AbstractTransactionalAnnotatedConfigClassTests that
uses 
a true @Configuration class and thereby demonstrates the expected
behavior 
of such transactional tests with automatic rollback.

TransactionalAnnotatedConfigClassesWithoutAtConfigurationTests is a 
concrete implementation of
AbstractTransactionalAnnotatedConfigClassTests 
that does NOT use a true @Configuration class but rather a 'lite mode'
configuration class (see the Javadoc for @Bean for details).

Using such a 'lite mode' configuration class results in the following:

 - Its @Bean methods act as factory methods instead of singleton beans.
 - The dataSource() method is invoked multiple times instead of once.
 - The test instance and the TCF operate on different data sources.
 - The transaction managed (and rolled back) by the TCF is not the 
   transaction that the application code or test instance uses.

Ultimately, the use of a 'lite mode' configuration class gives the false
appearance that there is a bug in the TCF (in that the transaction is
not 
rolled back); however, the transaction managed by the TCF is in fact 
rolled back.

In conclusion, these tests demonstrate both the intended behavior of the

TCF and the fact that using 'lite mode' configuration classes can lead
to 
confusing results (both in tests and production code).

Issue: SPR-9051
2012-05-15 23:04:31 +02:00