Commit Graph

831 Commits

Author SHA1 Message Date
Juergen Hoeller dda0942c78 Polishing 2016-06-30 21:39:51 +02:00
Juergen Hoeller 66ec1c1618 Add missing package-info files for common packages
Issue: SPR-14420
2016-06-30 21:39:06 +02:00
Sam Brannen 3dbf25e018 Implement equals() & hashCode() in MockServerContainerContextCustomizer
Issue: SPR-14367
2016-06-23 13:22:10 +02:00
Sam Brannen f7dd757593 Support WebSocket ServletServerContainerFB in the TCF
Prior to this commit, any attempt to include a bean of type
ServletServerContainerFactoryBean in the WebApplicationContext for an
integration test class annotated with @WebAppConfiguration in
conjunction the Spring TestContext Framework (TCF) would have resulted
in an IllegalStateException stating that "A ServletContext is required
to access the javax.websocket.server.ServerContainer instance."

In such scenarios, the MockServletContext was in fact present in the
WebApplicationContext; however there was no WebSocket ServerContainer
stored in the ServletContext.

This commit addresses this issue by introducing the following.

- MockServerContainer: a private mock implementation of the
  javax.websocket.server.ServerContainer interface.

- MockServerContainerContextCustomizer: a ContextCustomizer that
  instantiates a new MockServerContainer and stores it in the
  ServletContext under the attribute named
  "javax.websocket.server.ServerContainer".

- MockServerContainerContextCustomizerFactory: a
  ContextCustomizerFactory which creates a
  MockServerContainerContextCustomizer if WebSocket support is present
  in the classpath and the test class is annotated with
  @WebAppConfiguration. This factory is registered by default via the
  spring.factories mechanism.

Issue: SPR-14367
2016-06-22 22:10:16 +02:00
nkjackzhang 981a748dcc Fix ambiguous static import in TestPropertySourceUtilsTests 2016-06-17 17:18:36 +02:00
Sam Brannen 045ee52232 Invoke target.toString() safely in ReflectionTestUtils
ReflectionTestUtils invokes toString() on target objects in order to
build exception and logging messages, and prior to this commit problems
could occur if the invocation of toString() threw an exception.

This commit addresses this issue by ensuring that all invocations of
toString() on target objects within ReflectionTestUtils are performed
safely within try-catch blocks.

Issue: SPR-14363
2016-06-14 20:08:26 +02:00
Sam Brannen de78f05707 Polishing 2016-06-07 16:24:50 +02:00
Sam Brannen eaa9511921 Avoid ClassCastException in HandlerResultMatchers.methodCall() 2016-06-07 16:13:42 +02:00
Sam Brannen 5a0100111e Polish HandlerAssertionTests 2016-06-07 16:13:42 +02:00
Juergen Hoeller 8c4bc3656b Polishing 2016-06-07 15:42:16 +02:00
Sam Brannen c19740a020 Clean up warnings in spring-test 2016-06-06 18:54:16 +02:00
Rossen Stoyanchev 998b83ce8c Fix hardcoded value MockRestServiceServerBuilder 2016-06-06 08:46:50 -04:00
Rossen Stoyanchev d10134b5a5 Polish 2016-05-31 12:56:17 -04:00
Rob Winch 54f84cbd97 MockMvcWebConnection stores cookies from response
Previously MockMvcWebConnection did not update the cookie manager with the
cookies from MockHttpServletResponse. This meant that newly added cookies
are not saved to the cookie manager and thus are not presented in the next
request.

This commit ensures that MockMvcWebConnection stores the response cookies
in the cookie manager.

Issue: SPR-14265
2016-05-31 12:43:58 -04:00
Juergen Hoeller 822e40e24f AssertionErrors.assertEquals exposes readable array representation
Issue: SPR-14281
2016-05-30 17:16:03 +02:00
Juergen Hoeller a1e9459a43 @SafeVarargs for header(String, Matcher...) method
Issue: SPR-14278
2016-05-30 15:06:55 +02:00
Sam Brannen 31a93792b2 Delete unused imports 2016-05-27 16:33:43 +02:00
Rossen Stoyanchev 4e8754ea87 Add reset() to MockRestServiceServer
Issue: SPR-14306
2016-05-26 11:44:40 -04:00
Rossen Stoyanchev f4ab6d8d52 MockRestServiceServerBuilder can be re-used
Issue: SPR-14306
2016-05-26 09:48:16 -04:00
Sam Brannen a1a87679da Support test annotations on interfaces
Prior to Java 8 it never really made much sense to author integration
tests using interfaces. Consequently, the Spring TestContext Framework
has never supported finding test-related annotations on interfaces in
its search algorithms.

However, Java 8's support for interface default methods introduces new
testing use cases for which it makes sense to declare test
configuration (e.g., @ContextConfiguration, etc.) on an interface
containing default methods instead of on an abstract base class.

This commit ensures that all non-repeatable, class-level test
annotations in the Spring TestContext Framework can now be declared on
test interfaces. The only test annotations that cannot be declared on
interfaces are therefore @Sql and @SqlGroup.

Issue: SPR-14184
2016-05-05 19:54:44 +02:00
Sam Brannen f09c7868d8 Polishing 2016-05-04 16:04:37 +02:00
Sam Brannen e26478e3de Polish Javadoc regarding @Commit support 2016-05-03 20:26:11 +02:00
Sam Brannen 0f6711fe3b Support @[Before|After]Transaction on default methods
Prior to this commit, @BeforeTransaction and @AfterTransaction could
only be declared on methods within test classes. However, JUnit 5 as
well as some existing third-party Runner implementations for JUnit 4
already support Java 8 based interface default methods in various
scenarios -- for example, @Test, @BeforeEach, etc.

This commit brings the Spring TestContext Framework up to date by
supporting the declaration of @BeforeTransaction and @AfterTransaction
on interface default methods.

Issue: SPR-14183
2016-05-03 18:57:31 +02:00
Sam Brannen 3433fe35df Fix assertion failure messages in TransactionalTestExecutionListenerTests 2016-05-03 18:57:31 +02:00
Juergen Hoeller 8ddb432694 Polishing 2016-04-27 21:35:26 +02:00
Rob Winch 9ec0873604 MockWebResponseBuilder defaults cookie domain
Previously MockWebResponseBuilder would use the cookie domain of the cookie
received from MockMvc response. This caused problems because the cookie
domain can be null, but HtmlUnit forbids a null domain.

This commit defaults the domain of the cookie to the domain of the
WebRequest.

Issues SPR-14169
2016-04-25 16:35:56 -05:00
Sam Brannen c84c1cfd1b Update Javadoc for TestContextBootstrapper
@WebAppConfiguration is no longer meta-annotated with @BootstrapWith.
2016-04-25 15:44:15 +02:00
Sam Brannen 67a9f40c95 Polish Javadoc for TestContextManager 2016-04-23 18:23:25 +02:00
Johnny Lim 44e652f99e Remove duplicate words
Closes gh-1039
2016-04-19 08:24:21 +02:00
Sam Brannen ff38224da6 Introduce tests for @[Before|After]Transaction on default methods
This commit introduces @Ignore'd tests for future support for declaring
@BeforeTransaction and @AfterTransaction on interface default methods.

Issue: SPR-14183
2016-04-17 16:01:07 +02:00
Johnny Lim c402932ba1 Use the defined constant in MergedContextConfiguration
Closes gh-1037
2016-04-16 10:32:41 +02:00
Rob Winch 87ed8e939c HtmlUnitRequestBuilder decodes parameter names
Previously HtmlUnitRequestBuilder did not decode parameter names. This
means if a parameter like row[0] was submittted it would be encoded as
row%5B0%5D When the HttpServletRequest was created the parameter name would
not be decoded so the parameter name row[0] would not be found.

This commit ensures that HTTP parameter names are decoded.

Issue SPR-14177
2016-04-15 10:23:00 -05:00
Juergen Hoeller f1cb793ccb Rename MimeType's getCharSet() to getCharset()
Issue: SPR-14172
2016-04-14 16:38:59 +02:00
Juergen Hoeller b6f1afd471 Polishing 2016-04-11 21:20:31 +02:00
Juergen Hoeller 537193a4e0 Consistent license header 2016-04-11 20:49:38 +02:00
Sam Brannen 463c8f149d Add properties files directly to environment in TestPropertySourceUtils
This commit introduces a new method in TestPropertySourceUtils that
allows properties files to be added directly to the environment without
the need for a ConfigurableApplicationContext upfront; however, a
ResourceLoader is still necessary.

Issue: SPR-14131
2016-04-07 17:02:37 +02:00
Juergen Hoeller 6573e9142c Polishing 2016-04-05 12:17:21 +02:00
Juergen Hoeller d2d528dc05 Polishing 2016-04-05 09:42:41 +02:00
Sam Brannen 6c0cae87b4 Clean up warnings in spring-test 2016-04-04 21:30:01 +02:00
Sam Brannen e18d5b591a Limit size of context cache in the TestContext framework
Prior to this commit, the size of the ApplicationContext cache in the
Spring TestContext Framework could grow without bound, leading to
issues with memory and performance in large test suites.

This commit addresses this issue by introducing support for setting the
maximum cache size via a JVM system property or Spring property called
"spring.test.context.cache.maxSize". If no such property is set, a
default value of 32 will be used.

Furthermore, the DefaultContextCache has been refactored to use a
synchronized LRU cache internally instead of a ConcurrentHashMap. The
LRU cache is a simple bounded cache with a "least recently used" (LRU)
eviction policy.

Issue: SPR-8055
2016-04-04 20:56:04 +02:00
Sam Brannen 2ed3382a60 Document composed support for @Scheduled, @JmsListener, & @Sql
Issue: SPR-13973
2016-03-29 19:53:58 +02:00
Sam Brannen 26bbb6e767 Polishing 2016-03-28 16:17:47 +02:00
Juergen Hoeller 94cb7786c8 Polishing 2016-03-25 23:28:45 +01:00
Sam Brannen b0c6357540 Test @Sql as a merged composed annotation
Issue: SPR-13973
2016-03-25 20:47:16 +01:00
Phillip Webb fc839331a7 Refine TestPropertySourceUtils for direct use
Update methods in TestPropertySourceUtils to accept var-args and allow
addInlinedProperties to be called more than once.

Issue: SPR-14088
2016-03-25 11:12:27 -07:00
Sam Brannen c6f6e192c0 Support @Sql as a merged composed annotation
Issue: SPR-13973
2016-03-25 00:51:42 +01:00
Juergen Hoeller 517ebd1d3e Consistent formatting 2016-03-24 19:22:50 +01:00
Juergen Hoeller 9af12d290e Polishing 2016-03-23 18:39:29 +01:00
Juergen Hoeller 5025c615b1 Consistent use of AnnotatedElementUtils.findMergedAnnotation/hasAnnotation
Issue: SPR-13440
2016-03-23 18:39:20 +01:00
Sam Brannen 532ed0a4cf Clean up warnings in the spring-test module 2016-03-20 19:37:54 +01:00
Sam Brannen c5200978b0 Polishing 2016-03-18 19:44:20 +01:00
Rob Winch 411ff8450f Refine tests for SPR-14066
Explicitly define the response type as text/plain to avoid content type
confusion.

Issue SPR-14066
2016-03-18 13:24:10 -05:00
Sam Brannen 455bf45fa4 Fix test that failed due to upgrade to HtmlUnit 2.20 2016-03-18 18:43:46 +01:00
Brian Clozel 7ae44c2565 Allow skipping JSON prefix in MockMvc result matchers
JSON payloads are sometimes prepended with a static string prefix
to prevent Cross Site Scripting Inclusion attacks (XSSI).
Prior to this commit, doing so would fail the MockMvc
`JsonPathResultMatchers` since they're considering the whole response as
the JSON payload.

This commit adds a new `JsonPathResultMatchers.prefix` method that
configures the matchers to check for the presence of that string (i.e.
fail if it's not there) and only consider the rest of the response body
as the JSON payload for other assertions.

Issue: SPR-13577
2016-03-18 18:13:42 +01:00
Rossen Stoyanchev d3822c8d19 Polish 2016-03-18 12:01:09 -04:00
Rob Winch 7d96ad1f6e MockMvc HtmlUnit support shares CookieManager
Previously MockMvc builders failed to share the WebConnection used for
managing cookies in the MockMvcWebConnection. This meant that the various
CookieManagers would have different states.

This commit ensures that the WebConnection is set on the
MockMvcWebConnection.

Fixes SPR-14066
2016-03-18 12:01:09 -04:00
Sam Brannen 43661ededb Verify inlined props override files in @TestPropertySource
This commit introduces a test to demonstrate that inlined properties
override properties loaded from Properties files in
@TestPropertySource.

Issue: SPR-14068
2016-03-18 15:04:14 +01:00
Sam Brannen 7a3bc2e473 Polishing 2016-03-17 14:08:13 +01:00
Rossen Stoyanchev f5a5a81e95 Support response cookies in HtmlUnit integration
Issue: SPR-14051
2016-03-16 15:26:06 -04:00
Sam Brannen d9025ddaa7 Fully test proxy support in ReflectionTestUtils
This commit adds a test for JDK dynamic proxies and fleshes out the
test for CGLIB proxies.

Issue: SPR-14050
2016-03-16 18:34:07 +01:00
Sam Brannen 7beff7b40a Polishing 2016-03-16 18:34:07 +01:00
Sam Brannen b1ca18e0dc Document proxy support in ReflectionTestUtils
Issue: SPR-14050
2016-03-16 18:34:07 +01:00
Sam Brannen 2d565c7944 Fix bugs in ReflectionTestUtils related to proxies
Issue: SPR-14050
2016-03-16 18:34:07 +01:00
Sam Brannen 7c7e7865bf Polishing 2016-03-16 18:34:07 +01:00
Marten Deinum 8d3ec50e87 Support proxied objects in ReflectionTestUtils
This commit adds support for unwrapping proxies in the setField() and
getField() methods in ReflectionTestUtils.

Instead of always accessing fields directly on the supplied
targetObject (which may be a proxy), AopTestUtils is now used to obtain
the potential ultimateTargetObject which is then used for accessing
fields.

Issue: SPR-14050
2016-03-16 18:34:07 +01:00
Sam Brannen c41c5dd5c9 Polishing 2016-03-12 14:58:06 +01:00
Sam Brannen cbd1342fbb Polish ContextCustomizer support in the TCF
Issue: SPR-13998
2016-03-11 21:22:08 +01:00
Phillip Webb 87a3a5cb3b Introduce ContextCustomizer API in the TestContext Framework
Allow third-parties to contribute ContextCustomizers that can customize
ApplicationContexts created by the Spring TestContext Framework (TCF)
before they are refreshed.

A customizer may be provided via a ContextCustomizerFactory which is
registered with `spring.factories`. Each factory is consulted whenever
a new ApplicationContext needs to be created by the TCF. Factories may
inspect various details about the test and either return a new
ContextCustomizer or null.

ContextCustomizers are similar to ApplicationContextInitializers and
may perform any number of tasks, including bean registration, setting
of active profiles, etc.

Issue: SPR-13998
2016-03-11 20:53:06 +01:00
Juergen Hoeller d124a13eb4 Consistent use of empty enumerations 2016-03-11 15:07:59 +01:00
Sam Brannen 51eccf552f Polish ServletTestExecutionListener[Tests] 2016-03-10 17:20:02 +01:00
Phillip Webb bb590db396 Support servlet listener activate attribute
Add a ServletTestExecutionListener.ACTIVATE_LISTENER attribute which
can be set on the TestContext to trigger activation of the listener
even if a `@WebAppConfiguration` is not present.

Issue: SPR-14035
2016-03-10 16:54:14 +01:00
Phillip Webb 2244461778 Allow @ContextConfiguration to be omitted
Prior to this commit, the @ContextConfiguration annotation was required
to be present even if default XML files, Groovy scripts, or
@Configuration classes were detected; however, in such cases the
@ContextConfiguration was typically declared empty and therefore
seemingly unnecessary boilerplate.

This commit permits @ContextConfiguration to be omitted whenever it can
be reasonably deduced. Consequently, integration tests such as the
following are now supported.

    @RunWith(SpringRunner.class)
    public class MyTest {

        @Autowired String myBean;

        @Test public void example() { /* ... */ }

        @Configuration
        static class Config {

            @Bean String myBean() {
                return "Hello";
            }
        }
    }

Issue: SPR-13955
2016-03-08 19:36:49 +01:00
Sam Brannen 89cf4772d5 Fix malformed HTML in Javadoc 2016-03-08 15:27:35 +01:00
Sam Brannen 93fb7be783 Polishing 2016-03-08 15:18:21 +01:00
Phillip Webb 504779e210 Remove @BootstrapWith from @WebAppConfiguration
Update @WebAppConfiguration so that it no longer directly specifies
a TestContextBootstrapper. This allows third parties to use the
annotation in combination with their own bootstrapper.

BootstrapUtils now provides the detection logic for when
WebTestContextBootstrapper should be used.

Issue: SPR-13991
2016-03-08 14:31:06 +01:00
Sam Brannen 067994712d Make TestContextManager.getTestContext() public
This commit changes the visibility of the getTestContext() method in
TestContextManager from 'protected' to 'public' in order to support
test method injection in JUnit 5 and similar use cases.

Issue: SPR-14011
2016-03-02 20:19:25 +01:00
Sam Brannen 18e9699a2b Demo @ContextConfiguration as composed annotation with ACI
This commit demonstrates how to register one or more @Configuration
classes via an ApplicationContextInitializer in a composed annotation so
that certain @Configuration classes are always registered whenever the
composed annotation is used, even if the composed annotation is used to
declare additional @Configuration classes.
2016-03-02 14:07:15 +01:00
Sebastien Deleuze b3abd3b809 Fix HeaderResultMatchers#string(String, String) assert order
Issue: SPR-14004
2016-03-01 14:18:29 +01:00
Sebastien Deleuze c385427397 Allow to specify AbstractHttpMessageConverter default charset
Before this commit, specifying the charset to use with produces or
consumes @RequestMapping attributes resulted in default charset
loss. That was really annoying for JSON for example, where using
UTF-8 charset is mandatory in a lot of use cases.

This commit adds a defaultCharset property to
AbstractHttpMessageConverter in order to avoid losing the
default charset when specifying the charset with these
@RequestMapping attributes.

It changes slightly the default behavior (that's why we have waited
4.3), but it is much more error prone, and will match with most
user's expectations since the charset loss was accidental in most
use cases (users usually just want to limit the media type supported
by a specific handler method).

Issue: SPR-13631
2016-02-29 23:34:32 +01:00
Sam Brannen 467b5f3f28 Introduce composed annotations for @RequestMapping
This commit introduces the following common composed annotations for
@RequestMapping in Spring MVC and Spring MVC REST.

- @GetMapping
- @PostMapping
- @PutMapping
- @DeleteMapping
- @PatchMapping

Issue: SPR-13992
2016-02-29 18:22:30 +01:00
Sam Brannen df7b24b8e7 Allow non-public @Transactional test methods
Prior to this commit, the TransactionalTestExecutionListener required
@Transactional test methods to be public; however, neither TestNG nor
JUnit 5 require that @Test methods are public. Consequently, non-public
transactional test methods silently run *without* a transaction.

This commit removes the 'public' restriction on transactional test
methods by setting the 'publicMethodsOnly' flag in
AnnotationTransactionAttributeSource to false.

Issue: SPR-14000
2016-02-29 15:30:22 +01:00
Sam Brannen 197434b3ec Polish TestNG integration tests 2016-02-29 15:30:22 +01:00
Sam Brannen 816185233d Polish TransactionalTestExecutionListener 2016-02-29 15:30:22 +01:00
Juergen Hoeller 9c0f99c0b5 Polishing 2016-02-29 12:57:09 +01:00
Sam Brannen a2bfe86630 Support @[Before|After]Transaction on non-public methods
In order to align with the relaxed programming models of TestNG and the
upcoming JUnit 5 (with regard to method visibility), this commit
removes the requirement that @BeforeTransaction and @AfterTransaction
methods must be 'public'.

Issue: SPR-13997
2016-02-29 00:42:47 +01:00
Sam Brannen 31e0386bcb Stop referencing deprecated @TransactionConfiguration in Javadoc 2016-02-27 23:50:00 +01:00
Sam Brannen 9d3dd1bc13 Introduce SpringRunner 'alias' for SpringJUnit4ClassRunner
This commit introduces a SpringRunner extension of
SpringJUnit4ClassRunner that is intended to be used as an 'alias' for
SpringJUnit4ClassRunner, primarily in order to simplify configuration
of JUnit 4 based integration tests.

Developers can use this alias as follows:

    @RunWith(SpringRunner.class)
    public class MySpringIntegrationTests { ... }

Issue: SPR-13954
2016-02-27 23:02:55 +01:00
Sam Brannen 6fcb6630d7 Clean up warnings in SampleAsyncTests 2016-02-26 22:35:51 +01:00
Rossen Stoyanchev 1bc1df2d0f Polish client-side REST updates
Issue: SPR-11365
2016-02-24 15:24:13 -05:00
Juergen Hoeller ca19920d74 Refined ApplicationContextInitializer assignability exception 2016-02-24 17:50:14 +01:00
Rossen Stoyanchev 91872b0d74 Add ExpectedCount
MockRestServicesServer now supports an expect variant that accepts
a range of expected count of executions.

Issue: SPR-11365
2016-02-23 23:31:34 -05:00
Rossen Stoyanchev 08a08725be Allow plugging in custom RequestExpectationManager
The MockRestServiceServer builder now has an option to plug in a
custom RequestExpectationManager.

Issue: SPR-11365
2016-02-23 23:31:33 -05:00
Rossen Stoyanchev a56c69c9ca Introduce MockRestServiceServer builder
MockRestServiceServer now provides static methods for builder-style
creation of MockRestServiceServer. This includes an option ignore
the order of declaration expected requests.

Issue: SPR-11365
2016-02-23 23:31:33 -05:00
Rossen Stoyanchev f58ef24efd Introduce RequestExpectationManager
This commit factors out the logic to declare and manage expectations
including matching them to requests and verifying at the end behind
a commong abstraction.

MockRestServiceServer delegates to the new abstraction and is no longer
aware of how that's done. There are two implementations, one for
ordered and another for unordered expectation.

Issue: SPR-11365
2016-02-23 23:31:33 -05:00
Rossen Stoyanchev 37a3fa96d1 Separate ResponseActions from ClientHttpRequest
Before this commit RequestMatcherClientHttpRequest served both as
API to define request expectations, i.e. ResponseActions, as well as
the implementation of ClientHttpRequest representing actual requests.

DefaultResponseActions replaces this class as a simple holder of
expected requests and mock responses. MockRestServiceServer is then
responsible to match request expectations and create a mock response.

Issue: SPR-11365
2016-02-23 23:31:33 -05:00
Juergen Hoeller 028a690100 Polishing 2016-02-23 14:31:09 +01:00
Juergen Hoeller 1899fb37c1 Polishing 2016-02-22 23:26:41 +01:00
Juergen Hoeller 0adc4921ed TestContextManager consistently handles Errors from listener invocations
Issue: SPR-13961
2016-02-18 21:07:32 +01:00
Juergen Hoeller ac44f9edd9 Consistent equals implementations across class hierarchies
Issue: SPR-13951
2016-02-17 16:57:29 +01:00
Sam Brannen 677a321571 Support primary TxMgrs and DataSources in the TCF
Prior to this commit, the transaction manager and data source look-up
algorithms in the Spring TestContext Framework were not capable of
retrieving 'primary' beans of those types, even though 'primary' beans
are supported in production as well as for injecting dependencies into
test instances. Specifically, if there was more than one transaction
manager or data source bean and one of them was flagged as 'primary',
the retrieveTransactionManager() and retrieveDataSource() methods in
TestContextTransactionUtils would simply return null for such beans.

This commit updates TestContextTransactionUtils by adding support for
looking up primary transaction managers and data sources.

Issue: SPR-13891
2016-02-03 17:58:33 +01:00
Sam Brannen 6d2b9a0136 Throw exception if TxMgr cannot be retrieved for @Transactional test
Prior to this commit, a @Transactional integration test would silently
be executed without a transaction if the transaction manager could not
be retrieved from the application context -- for example, it no such
bean was defined or if multiple beans were present but none satisfied
the qualifier.

This commit addresses this issue by throwing an IllegalStateException
if the PlatformTransactionManager cannot be retrieved for a
@Transactional test.

Issue: SPR-13895
2016-02-03 14:56:27 +01:00
Sam Brannen ea46ad8022 Clean up warnings in spring-test 2016-01-28 19:27:53 +01:00
Rossen Stoyanchev 135738f9bf AbstractController supports HTTP OPTIONS
Issue: SPR-13130
2016-01-25 08:49:04 -05:00
Rossen Stoyanchev 415b2763ce MockHttpServletRequestBuilder parses form data
Spring MVC Test now parses application/x-www-form-urlencoded request
content and populates request parameters from it.

This can be useful when running client-side tests against a MockMvc
via MockMvcClientHttpRequestFactory.

Issue: SPR-13733
2016-01-21 17:26:23 -05:00
Rossen Stoyanchev 6a9455b7d0 Fix failing test 2016-01-21 17:05:05 -05:00
Rossen Stoyanchev 1416c2a00e ContentRequestMatchers asserts request with form data
Issue: SPR-13044
2016-01-21 12:42:33 -05:00
Rossen Stoyanchev 952a3170e6 HeaderResultMatchers supports multi-value headers
Issue: SPR-10087
2016-01-21 11:19:43 -05:00
Rossen Stoyanchev ae224bed3e Polish HeaderResultMatchers 2016-01-21 10:20:04 -05:00
Rossen Stoyanchev df223eb118 Polish custom HTTP verb in Spring MVC Test
Issue: SPR-13719
2016-01-21 09:13:33 -05:00
Kamill Sokol 3554348919 Support custom HTTP verbs in Spring MVC Test
Prior to this commit, Spring MVC Test only supported HTTP methods GET,
POST, HEAD, OPTIONS, PUT, PATCH, DELETE, TRACE and multipart file
upload. This change adds generic methods to MockMvcRequestBuilders in
order to allow testing of arbitrary HTTP methods in a Spring MVC
application.

Issue: SPR-13719
2016-01-21 09:12:43 -05:00
Rossen Stoyanchev 4b1183582a Add methodCall option to HandlerResultMatchers
Issue: SPR-13736
2016-01-15 12:44:00 -05:00
Rossen Stoyanchev 1320da906b Polish HandlerResultMatchers 2016-01-15 12:44:00 -05:00
Stephane Nicoll 2fc2c29e9a Update copyright header 2016-01-15 10:51:11 +01:00
Rossen Stoyanchev 4818378c25 Better document client-side tests against MockMvc
Issue: SPR-13815
2016-01-14 15:15:07 -05:00
Brian Clozel 74d3bceb19 Add missing StatusResultMatcher for HTTP Status 451
Issue: SPR-13632
2015-12-29 21:23:09 +01:00
Juergen Hoeller 41ee25b1e7 Convenience constructors for common view prefix/suffix scenarios
Issue: SPR-13813
2015-12-22 12:00:49 +01:00
Sam Brannen 66562f2589 Require JUnit 4.12 or higher in the TestContext framework
Issue: SPR-13275
2015-12-19 18:43:59 +01:00
Sam Brannen 9eb713ae2c Mention DCBeforeModesTEL in TestExecutionListener Javadoc 2015-12-17 17:45:08 +01:00
Juergen Hoeller db05f43a75 Require JsonPath 1.1+
Issue: SPR-13729
2015-12-17 17:13:27 +01:00
Juergen Hoeller 935c0a463e Revised MockMvcResultHandlers logger initialization
Issue: SPR-13802
2015-12-16 21:49:48 +01:00
Juergen Hoeller 997278e3ed Polishing 2015-12-16 20:19:41 +01:00
Rossen Stoyanchev c8aa48faa9 Add params(MultiValueMap) to MockMvc
Issue: SPR-13801
2015-12-16 11:51:59 -05:00
Juergen Hoeller 11806b9215 Class identity comparisons wherever possible (and further polishing)
Issue: SPR-12926
2015-12-09 12:28:09 +01:00
Juergen Hoeller 4261f34b63 Consistent and lenient HttpMethod resolution across all web modules
Issue: SPR-13776
2015-12-09 12:26:44 +01:00
Juergen Hoeller 40cff5e340 Polishing 2015-12-07 17:30:25 +01:00
Juergen Hoeller a4f5c46fed MockHttpServletResponse.setIntHeader supports 'Content-Length' header as well
Issue: SPR-13752
2015-12-02 13:36:35 +01:00
Juergen Hoeller aef6b20626 Removed tests for invalid -1 index (for compatibility with JsonPath 2.1) 2015-11-27 14:11:40 +01:00
Juergen Hoeller dd647659b3 Rearranged cache test class names across several modules 2015-11-26 16:30:44 +01:00
Juergen Hoeller fd84262e71 Polishing 2015-11-25 23:09:24 +01:00
Stephane Nicoll bf1afdfdc9 Add cache tests for JCache 2015-11-24 10:15:09 +01:00
Stephane Nicoll 610b5a20ea Fix test name 2015-11-23 18:22:53 +01:00
Sam Brannen 59d60c60cf Polishing 2015-11-16 01:44:16 +01:00
Sam Brannen 4b682275c9 Clean up warnings in spring-test 2015-11-14 22:57:33 +01:00
Juergen Hoeller 5b901852e6 Upgrade to HtmlUnit 2.19
This upgrade includes AutoCloseable support for HtmlUnit WebConnections as introduced in 2.19, while remaining compatible with 2.18.

Issue: SPR-13686
2015-11-14 15:32:42 +01:00
Rossen Stoyanchev 8c127ad3c9 Property init HandlerMapping in standalone MockMvc
Issue: SPR-13637
2015-11-11 15:14:18 -05:00
Juergen Hoeller b057e503ef Adapted exception message expectations
Issue: SPR-13621
2015-11-05 18:06:14 +01:00
Hronom 1d60a6a6af Added strict compare mode for Json
Issue: SPR-13607
2015-10-29 17:05:37 +01:00
Rossen Stoyanchev 323fa8510d Call complete() on MockAsyncContext after dispatch
Issue: SPR-13615
2015-10-29 10:12:47 -04:00
Sam Brannen 1bf7249d59 Suppress deprecation warning in HtmlUnitRequestBuilderTests 2015-10-16 19:15:29 +02:00
Juergen Hoeller 66177dfd8c StreamUtils.emptyInput() for consistent empty InputStream exposure
Issue: SPR-13563
2015-10-12 22:25:40 +02:00
Sam Brannen 3db62d5494 Remove MimeTypeResolver since JAF is part of Java SE 6+
The inner MimeTypeResolver class is no longer necessary in the
MockServletContext since the Java Activation Framework (JAF) is a
standard part of Java SE since Java 6.
2015-10-06 15:56:00 +02:00
Sam Brannen 61a46db101 Treat query param w/o "=" as empty string in HtmlUnitRequestBuilder
Prior to this commit, HtmlUnitRequestBuilder stored empty query
parameters declared without an equals sign as null (i.e., query
parameters such as 'error' in 'http://example.com/login?error').

This commit addresses this issue by ensuring that
HtmlUnitRequestBuilder treats all empty query parameter values as empty
strings. Consequently, query strings such as '?error' and '?error=' now
both result in 'error' being stored as an empty string.

Issue: SPR-13524
2015-10-04 19:11:41 +02:00
Sam Brannen 283fc94572 Support null query param values in HtmlUnitRequestBuilder
Prior to this commit, HtmlUnitRequestBuilder would incorrectly attempt
to decode null values for query parameters (i.e., query parameters such
as 'error' in 'http://example.com/login?error') which resulted in a
NullPointerException since URLDecoder.decode() does not support null
values.

This commit fixes this issue by ensuring that HtmlUnitRequestBuilder
only attempts to decode non-null query parameter values.

Issue: SPR-13524
2015-09-30 21:48:14 +02:00
Sam Brannen d5b4685391 Polish HtmlUnitRequestBuilderTests 2015-09-30 21:48:13 +02:00
Juergen Hoeller a9fbbc55e6 Polishing 2015-09-28 22:11:10 +02:00
Sam Brannen d883efcb2a Throw meaningful exception if JUnit 4.9 is not present
SpringJUnit4ClassRunner, SpringClassRule, and SpringMethodRule now
throw an IllegalStateException with a meaningful message if JUnit 4.9
is not present in the classpath (specifically if
org.junit.runners.model.MultipleFailureException cannot be loaded).

Issue: SPR-13521
2015-09-28 20:15:40 +02:00
Sam Brannen d5ee787e1e Migrate JUnit 3 tests to JUnit 4
This commit migrates all remaining tests from JUnit 3 to JUnit 4, with
the exception of Spring's legacy JUnit 3.8 based testing framework that
is still in use in the spring-orm module.

Issue: SPR-13514
2015-09-27 21:17:51 +02:00
Rossen Stoyanchev df171ff5bb MockMvc request builder preserves double slashes
The MockHttpServletRequestBuilder now uses java.net.URI internally
rather than UriComponents.

This means that for the MockMvcRequestBuilders method variants that
accept a java.net.URI we can use it as is. The difference is almost
none but it does mean that you can create a URI with double slashes
(for testing purposes) and have it remain that way.

Issue: SPR-13435
2015-09-23 17:50:29 -04:00
Rossen Stoyanchev fb3e054a31 Update Javadoc
Issue: SPR-13479
2015-09-23 17:29:21 -04:00
Sam Brannen e2bfbdcfd1 Support attribute overrides with @ResponseStatus
This commit introduces support for attribute overrides for
@ResponseStatus when @ResponseStatus is used as a meta-annotation on
a custom composed annotation.

Specifically, this commit migrates all code that looks up
@ResponseStatus from using AnnotationUtils.findAnnotation() to using
AnnotatedElementUtils.findMergedAnnotation().

Issue: SPR-13441
2015-09-11 21:05:30 +02:00
Juergen Hoeller bc13cb2af5 Polishing 2015-09-10 14:05:06 +02:00
Sam Brannen ae8a341a55 Polishing 2015-09-08 18:34:47 +02:00
Juergen Hoeller 52fdfd59ab Polishing 2015-09-08 18:11:30 +02:00
Juergen Hoeller 667fc7e4a9 Polishing 2015-09-04 14:38:47 +02:00
Brian Clozel d3d81c2864 Add MockHttpServletResponse.getDateHeader
This change adds a new `getDateHeader` method that converts date header
Strings to long values - making tests more readable.

This feature is also documented in the "what's new section" for 4.2.
2015-09-03 16:03:46 +02:00
Sam Brannen 527b778bf9 Clean up warnings in spring-test 2015-08-27 22:12:14 +02:00
Juergen Hoeller 7d30017429 StubWebApplicationContext supports AutowireCapableBeanFactory operations (as far as possible)
This is generally worthwhile but in particular fixes a regression with our Jackson SpringHandlerInstantiator in standalone MVC tests.

Issue: SPR-13375
2015-08-25 21:52:49 +02:00
Rossen Stoyanchev 473dd5e9e8 Unwrap if necessary for MultipartHttpServletRequest
Before this commit RequestPartServletServerHttpRequest simply did an
instanceof check for MultipartHttpServletRequest. That hasn't failed
because request wrapping typically happens in filters before the
DispatcherServlet calls the MultipartResolver.

With Spring MVC Test and the Spring Security integraiton however,
this order is reversed since there we prepare the multipart request
upfront, i.e. there is no actual parsing.

The commit unwraps the request if necessary.

Issue: SPR-13317
2015-08-21 10:28:08 -04:00
Sam Brannen 0cd21aa55f Fix typo in Javadoc for TestContextBootstrapper 2015-08-19 20:52:36 +02:00
Sam Brannen 7a17abe448 Introduce empty & non-empty JsonPath matchers
This commit introduces new `isEmpty()` and `isNotEmpty()` methods in
`JsonPathResultMatchers` and `JsonPathRequestMatchers` which delegate
to the new `assertValueIsEmpty()` and `assertValueIsNotEmpty()` methods
in `JsonPathExpectationsHelper`, respectively.

Issue: SPR-13352
2015-08-15 19:28:09 +02:00
Sam Brannen 4799668a98 Introduce additional JsonPath RequestMatchers in Spring MVC Test
Commit fffdd1e9e9 introduced additional
JsonPath result matchers in JsonPathResultMatchers for server-side
testing of MVC controllers.

This commit introduces comparable methods in JsonPathRequestMatchers
for client-side testing with a RestTemplate.

- isString()
- isBoolean()
- isNumber()
- isMap()

Issue: SPR-13320
2015-08-15 14:56:57 +02:00
Sam Brannen e4f386ae1e Add regression test cases to JsonPathRequestMatchersTests 2015-08-15 14:15:13 +02:00
Sam Brannen 687af344de Polishing 2015-08-15 14:13:52 +02:00
Sam Brannen 5ee24c8482 Polish Javadoc for JsonPathRequestMatchers, etc. 2015-08-15 13:55:30 +02:00
Sam Brannen e7c95addeb Rename test classes to avoid confusion 2015-08-15 13:33:26 +02:00
Sam Brannen d4d5e5ce40 Polishing 2015-08-14 22:45:10 +02:00
Sam Brannen 07bb0378b9 Differentiate b/t (in)definite results in JsonPath assertions
Prior to this commit, the exists() method in JsonPathExpectationsHelper
correctly asserted that the evaluated JsonPath expression resulted in a
value (i.e., that a non-null value exists); however, if the value was
an empty array, the exists() method always threw an AssertionError.

The existing behavior makes sense if the JsonPath expression is
'indefinite' -- for example, if the expression uses a filter to select
results based on a predicate for which there is no match in the JSON
document, but the existing behavior is illogical and therefore invalid
if the JsonPath expression is 'definite' (i.e., directly references an
array in the JSON document that exists but happens to be empty). For
example, prior to this commit, the following threw an AssertionError.

    new JsonPathExpectationsHelper("$.arr").exists("{ 'arr': [] }");

Similar arguments can be made for the doesNotExist() method.

After thorough analysis of the status quo, it has become apparent that
the existing specialized treatment of arrays is a result of the fact
that the JsonPath library always returns an empty list if the path is
an 'indefinite' path that does not evaluate to a specific result.
Consult the discussion on "What is Returned When?" in the JsonPath
documentation for details:

    https://github.com/jayway/JsonPath#what-is-returned-when

This commit addresses these issues by ensuring that empty arrays are
considered existent if the JsonPath expression is definite but
nonexistent if the expression is indefinite.

Issue: SPR-13351
2015-08-14 22:07:03 +02:00
Sam Brannen d2503340e7 Polish assertion msgs in JsonPathExpectationsHelper 2015-08-14 20:38:50 +02:00
Sam Brannen af8d9eab59 Polish Javadoc for JsonPathExpectationsHelper 2015-08-14 17:59:12 +02:00
Sam Brannen 5a05cdbedb Consider empty arrays as existent in JsonPath assertions
Prior to this commit, a JsonPath assertion that a path expression
evaluated to an array in JsonPathExpectationsHelper (and therefore
indirectly in JsonPathResultMatchers in Spring MVC Test) would
incorrectly fail if the array was present in the JSON content but empty.

This commit fixes this issue by removing the "not empty" check for
arrays and lists.

Issue: SPR-13320
2015-08-14 17:20:07 +02:00
Sam Brannen 8afea1bc78 Add tests to JsonPathExpectationsHelperTests 2015-08-14 17:10:28 +02:00
Sam Brannen 0dbbbce8d5 Polish JsonPathResultMatchersTests 2015-08-14 17:07:23 +02:00
Sam Brannen ecb15ac58b Polish assertion msgs in JsonPathExpectationsHelper 2015-08-14 17:04:34 +02:00
Juergen Hoeller 3a5cc3df80 JCacheEhCache3Tests enforces EhCache 3.0's CachingProvider
Issue: SPR-13342
2015-08-12 23:09:16 +02:00
Juergen Hoeller d8794a1edc Test against EhCache 3.0 M2 (as a JCache provider)
Includes latest dependency updates (Jackson 2.6.1, Jetty 9.3.2, Undertow 1.2.10)

Issue: SPR-13342
2015-08-12 16:16:25 +02:00
Sam Brannen f3da7b810b Polish HtmlUnitRequestBuilder 2015-08-08 00:27:00 +02:00
Sam Brannen 93c07e76bc Return null instead of empty cookies array in Spring MVC Test
Prior to this commit, MockHttpServletRequestBuilder always supplied an
array of cookies to the MockHttpServletRequest that it built, even if
the array was empty.

However, this violates the contract of HttpServletRequest. According to
the Servlet API, the getCookies() method "returns null if no cookies
were sent."

This commit ensures that MockHttpServletRequestBuilder no longer
configures an empty array of cookies in the mock request that it builds.

Issue: SPR-13314
2015-08-07 01:00:12 +02:00
Craig Andrews fffdd1e9e9 Introduce additional JsonPath matchers in Spring MVC Test
This commit introduces the following methods in JsonPathResultMatchers
in the Spring MVC Test framework.

- isString()
- isBoolean()
- isNumber()
- isMap()

In addition, this commit overhauls the Javadoc in
JsonPathResultMatchers and JsonPathExpectationsHelper.

Issue: SPR-13320
2015-08-06 22:08:24 +02:00
Sam Brannen 725292081e Introduce 'value' alias for 'attribute' in @AliasFor
SPR-11512 introduced support for annotation attribute aliases via
@AliasFor, requiring the explicit declaration of the 'attribute'
attribute. However, for aliases within an annotation, this explicit
declaration is unnecessary.

This commit improves the readability of alias pairs declared within an
annotation by introducing a 'value' attribute in @AliasFor that is an
alias for the existing 'attribute' attribute. This allows annotations
such as @ContextConfiguration from the spring-test module to declare
aliases as follows.

public @interface ContextConfiguration {

     @AliasFor("locations")
     String[] value() default {};

     @AliasFor("value")
     String[] locations() default {};

    // ...
}

Issue: SPR-13289
2015-07-29 15:27:06 +02:00
Sam Brannen 6a59d00576 Fix references and typos in Spring MVC Test Javadoc
This commit fixes numerous references to 'legacy' packages within the
Javadoc for the Spring MVC Test framework.

In addition, this commit improves examples in Javadoc, adds links to
related classes where appropriate, and removes unnecessary imports for
types that are only referenced within documentation.

Issue: SPR-13284
2015-07-28 19:44:47 +02:00
Sam Brannen 29e6272c6b Polish 2015-07-27 22:44:42 +02:00
Sam Brannen 9023cf6ae0 Redesign MockMvcHtmlUnitDriverBuilder API
This commit introduces a dedicated build() method in
MockMvcHtmlUnitDriverBuilder to replace createDriver(). In addition,
the configureDriver() method has been renamed to withDelegate() and now
returns the builder for further customization.

This commit also overhauls the Javadoc for static factory methods and
the class-level Javadoc in MockMvcHtmlUnitDriverBuilder for greater
clarity to end users.

Issues SPR-13158
2015-07-27 22:41:22 +02:00
Sam Brannen 3b84a7e84d Redesign MockMvcWebClientBuilder API
This commit introduces a dedicated build() method in
MockMvcWebClientBuilder to replace createWebClient(). In addition, the
configureWebClient() method has been renamed to withDelegate() and now
returns the builder for further customization.

This commit also overhauls the constructor and class-level Javadoc in
MockMvcWebClientBuilder for greater clarity to end users.

Issues SPR-13158
2015-07-27 19:48:01 +02:00
Sam Brannen 3d6f465625 Polish Javadoc in HtmlUnit support 2015-07-27 19:47:43 +02:00
Sam Brannen 680936f4a2 Rename configureWebClient() to modifyWebClientInternal() in HtmlUnit support
This commit renames the configureWebClient() method in
WebConnectionHtmlUnitDriver to modifyWebClientInternal() in order to
better convey the relationship to HtmlUnitDriver#modifyWebClient().

Issues SPR-13158
2015-07-27 18:04:13 +02:00
Rob Winch 484ac5e242 Polish Javadoc
Issue: SPR-13158
2015-07-27 10:39:15 -05:00
Rob Winch e998c450e6 Add Assume PERFORMANCE to needed HtmlUnit Tests
Some of the HtmlUnit Tests required an internet connection. This
caused failures when running offline.

This commit adds Assume PERFORMANCE to those tests so they are
only ran when the PERFORMANCE group is selected.

Issue: SPR-13158
2015-07-27 10:29:30 -05:00
Sam Brannen 0b0a5a9ed4 Polish tests for HtmlUnit support 2015-07-27 14:30:46 +02:00
Sam Brannen 40ea9ffd63 Remove unnecessary imports 2015-07-27 13:06:54 +02:00
Sam Brannen d21ad29982 Polish MockMvc HtmlUnit Support
- formatting
- code style
- organized imports
- precondition assertions
- suppressed warnings
- Javadoc enhancements

Issue: SPR-13158
2015-07-27 12:03:21 +02:00
Rob Winch b73e39423c Introduce support for HtmlUnit in Spring MVC Test
This commit introduces integration between MockMvc and HtmlUnit, thus
simplifying end-to-end testing when using HTML-based views and enabling
developers to do the following.

 - Easily test HTML pages using tools such as HtmlUnit, WebDriver, & Geb
   without the need to deploy to a Servlet container

 - Test JavaScript within pages

 - Optionally test using mock services to speed up testing

 - Share logic between in-container, end-to-end tests and
   out-of-container integration tests

Issue: SPR-13158
2015-07-27 12:03:21 +02:00
Sam Brannen c5a037a5cf Delete unused Spring Security config file 2015-07-26 20:54:53 +02:00
Sam Brannen 5b8b1dd378 Clean up database tests in spring-test 2015-07-26 20:54:27 +02:00
Sam Brannen 47e1724d0e Deprecate TxConfigAttributes alongside @TxConfig
Since @TransactionConfiguration is now deprecated, this commit also
deprecates TransactionConfigurationAttributes with the intention of
completely removing TransactionConfigurationAttributes once
@TransactionConfiguration has been removed.

Issue: SPR-13277
2015-07-25 21:29:57 +02:00
Sam Brannen d6bdfcaa6e Introduce @Commit alias for @Rollback(false)
Due to common usage of @Rollback(false), this commit introduces a new
@Commit annotation that more clearly conveys the intent of the code
while retaining the run-time semantics.

@Commit is in fact meta-annotated with @Rollback(false).

Issue: SPR-13279
2015-07-25 21:09:32 +02:00
Sam Brannen baa66f7bfa Polishing 2015-07-25 18:43:47 +02:00
Sam Brannen c4bbc9df33 Migrate @TxConfig usage to @Rollback & @Transactional qualifiers
Issue: SPR-13276, SPR-13277
2015-07-25 18:41:50 +02:00
Sam Brannen 3f8b51283e Support @Rollback on classes & deprecate @TxConfig
Since Spring Framework 2.5, @Rollback has been supported on test
methods, with class-level rollback settings configured via
@TransactionConfiguration; however, allowing @Rollback to be declared
on test classes with method-level declarations overriding class-level
declarations would prove more intuitive than having to declare both
@TransactionConfiguration and @Rollback. Furthermore, the
transactionManager flag in @TransactionConfiguration was made
superfluous many years ago with the introduction of support for a
qualifier in @Transactional.

This commit enables @Rollback to be declared at the class level for
default rollback semantics within test class hierarchies and deprecates
@TransactionConfiguration in favor of @Rollback and @Transactional
qualifiers.

Issue: SPR-13276, SPR-13277
2015-07-25 18:22:26 +02:00
Juergen Hoeller efd7f9bf72 Polishing 2015-07-24 18:24:19 +02:00
Sam Brannen 24b1dc14d2 Reduce scope of suppressed deprecation warnings in SpringJUnit4ClassRunner 2015-07-24 16:51:41 +02:00