1. 27 7月, 2015 2 次提交
    • R
      Introduce support for HtmlUnit in Spring MVC Test · b73e3942
      Rob Winch 提交于
      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
      b73e3942
    • S
      Clean up database tests in spring-test · 5b8b1dd3
      Sam Brannen 提交于
      5b8b1dd3
  2. 26 7月, 2015 4 次提交
    • S
      Introduce @Commit alias for @Rollback(false) · d6bdfcaa
      Sam Brannen 提交于
      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
      d6bdfcaa
    • S
      Polishing · baa66f7b
      Sam Brannen 提交于
      baa66f7b
    • S
      Migrate @TxConfig usage to @Rollback & @Transactional qualifiers · c4bbc9df
      Sam Brannen 提交于
      Issue: SPR-13276, SPR-13277
      c4bbc9df
    • S
      Support @Rollback on classes & deprecate @TxConfig · 3f8b5128
      Sam Brannen 提交于
      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
      3f8b5128
  3. 23 7月, 2015 1 次提交
    • B
      Improve DateHeaders in MockServletRequest/Response · 43e36e2d
      Brian Clozel 提交于
      Prior to this change, calling the `setDateHeader` method on a
      Spring Test MockHttpServletResponse instance would just store the given
      long value in a Map, not writing it as a formatted date String.
      Also, calling `getDateHeader` on a MockHttpServletRequest would not
      support date strings and could not parse those values.
      
      This can be problematic when testing features related to date headers
      such as "Expires", "If-Modified-Since", "Last-Modified", etc.
      
      This commit adds formatting and parsing capabilities to Servlet Mocks
      for date strings in HTTP headers.
      
      When formatting dates to Strings, the date format used is the one
      preferred by the HTTP RFC. When parsing date Strings, multiple date
      formats are supported for better compatibility.
      
      Issue: SPR-11912
      43e36e2d
  4. 22 7月, 2015 2 次提交
    • S
      Do not reuse mock requests in Spring MVC Test · 3c799e6e
      Sam Brannen 提交于
      SPR-13211 introduced support for reusing mock requests in Spring MVC
      Test if the request was created by the the Spring TestContext
      Framework. Unfortunately, that change makes it impossible for
      MockMvc.perform() to be invoked multiple times within the same test
      method without side effects. For example, session attributes and
      request parameters are transparently and unexpectedly retained for
      subsequent invocations of perform(), causing certain categories of
      tests to fail.
      
      This commit reverts the changes introduced in SPR-13211 and introduces
      a new MockMvcReuseTests class to serve as regression tests within
      Spring's test suite.
      
      Issue: SPR-13260, SPR-13211
      3c799e6e
    • B
      Add a dateValue HeaderResultMatcher · cf2aed9d
      Brian Clozel 提交于
      HTTP headers such as "Expires", "Last-Modified" all use date
      strings like "Tue, 21 Jul 2015 10:00:00 GMT". Prior to this commit,
      there was no way to match those header values, besides formatting dates
      manually.
      
      This commit introduces a new HeaderResultMatcher to test those date
      headers using a long timestamp:
      
      ```
      this.mockMvc.perform(get("/persons/1").header("If-Modified-Since", now))
        .andExpect(status().isNotModified())
        .andExpect(header().dateValue("Last-Modified", timestamp));
      ```
      
      Issue: SPR-13263
      cf2aed9d
  5. 21 7月, 2015 3 次提交
    • S
      Delete unused imports in HeaderAssertionTests · d8fb6c55
      Sam Brannen 提交于
      d8fb6c55
    • B
      Partial revert of SPR-13090 · dba46c13
      Brian Clozel 提交于
      Use ServletHttpResponse.setDateHeader whenever possible and avoid using
      SimpleDateFormat.
      dba46c13
    • S
      Reuse mock request from the TCF in Spring MVC Test · bf06bf33
      Sam Brannen 提交于
      Prior to this commit, the Spring MVC Test Framework always created a
      new MockHttpServletRequest, disregarding any mock request already
      present in Spring Web's RequestContextHolder -- for example, one
      created by the ServletTestExecutionListener in the Spring TestContext
      Framework (TCF).
      
      This commit modifies MockHttpServletRequestBuilder so that it reuses a
      mock request created by the TCF. However,
      MockMultipartHttpServletRequestBuilder continues to always create a new
      MockMultipartHttpServletRequest since a MockHttpServletRequest created
      by the TCF is not directly compatible with a
      MockMultipartHttpServletRequest. Furthermore, in order to avoid
      unforeseen side effects, MockHttpServletRequestBuilder will always
      create a new MockHttpServletRequest if a mock request is present in the
      RequestContextHolder but not created by the TCF.
      
      Issue: SPR-13211
      bf06bf33
  6. 17 7月, 2015 2 次提交
  7. 15 7月, 2015 1 次提交
  8. 10 7月, 2015 1 次提交
    • S
      Populate RequestAttributes before invoking Filters in MockMvc · 9c46228a
      Sam Brannen 提交于
      When using the Spring TestContext Framework (TCF) to load a
      WebApplicationContext and the Spring MVC Test Framework (MockMvc) to
      test a controller, two instances of MockHttpServletRequest will be
      created. Due to an ordering issue with regard to population of the
      RequestAttributes, it is therefore possible that a filter accesses the
      mocked request managed by the TCF, while the controller accesses the
      mocked request managed by MockMvc, and this leads to test failures if
      the controller expects data from the filter to be present in the
      request.
      
      This commit fixes this bug by ensuring that the RequestAttributes
      backed by the mocked request managed by MockMvc are stored in the
      RequestContextHolder before any filters are invoked by MockMvc.
      
      Issue: SPR-13217
      9c46228a
  9. 08 7月, 2015 2 次提交
    • S
      Investigate claims raised in SPR-13211 · 3c2efeec
      Sam Brannen 提交于
      This commit adds additional tests to RequestContextHolderTests that
      verify proper support for the MockHttpServletRequest managed by Spring
      MVC Test in the following scenarios:
      
      - request-scoped service invoked by controller
      - session-scoped service invoked by controller
      - custom filter that sets request attributes
      
      Issue: SPR-13211
      3c2efeec
    • S
      Update RequestContextHolderTests · 5e24ee9b
      Sam Brannen 提交于
      This commit refactors RequestContextHolderTests in preparation for the
      work to be done in SPR-13211.
      
      Issue: SPR-13211
      5e24ee9b
  10. 04 7月, 2015 1 次提交
  11. 03 7月, 2015 2 次提交
  12. 02 7月, 2015 1 次提交
    • S
      Introduce DirtiesContextBeforeModesTestExecutionListener · 0aac02d6
      Sam Brannen 提交于
      SPR-12429 introduced various `BEFORE_*` modes in `@DirtiesContext`. To
      support these new modes, `DirtiesContextTestExecutionListener` (DCTEL)
      was updated to support both `BEFORE_*` and `AFTER_*` modes. However,
      there is a problem with having DCTEL support `BEFORE_*` modes since it
      is typically configured to execute after the
      `DependencyInjectionTestExecutionListener` (DITEL), and this leads to
      several undesired side effects:
      
       - The test's `ApplicationContext` is closed by DCTEL *after*
         dependencies have been injected into the test instance.
      
       - Injected dependencies may therefore attempt to interact with an
         `ApplicationContext` that is no longer _active_.
      
       - If a test has its `ApplicationContext` injected as a dependency,
         interaction with the context will likely fail since the context has
         been closed.
      
       - Any `TestExecutionListeners` registered after DCTEL will get a _new_
         `ApplicationContext` if they invoke `getApplicationContext()` on the
         `TestContext`.
      
      This commit fixes these issues by introducing a new
      `DirtiesContextBeforeModesTestExecutionListener` (DCBMTEL) that is
      registered by default before DITEL. The previous support for `BEFORE_*`
      modes has been moved from DCTEL to DCBMTEL. In addition, an
      `AbstractDirtiesContextTestExecutionListener` has been extracted from
      DCTEL in order to avoid code duplication.
      
      Issue: SPR-13180
      0aac02d6
  13. 28 6月, 2015 1 次提交
    • S
      Introduce LoggingResultHandler in Spring MVC Test · 693dcba8
      Sam Brannen 提交于
      Prior to this commit, the Spring MVC Test framework only provided
      support for printing debug information about the MvcResult to STDOUT.
      
      This commit introduces support for logging `MvcResult` details at
      `DEBUG` level via the Apache Commons Logging API. In addition, this
      commit introduces additional `print(..)` variants for printing debug
      information to custom output streams and writers.
      
      Specifically, `MockMvcResultHandlers` has been augmented with the
      following new static methods:
      
       - `log()`
       - `print(OutputStream)`
       - `print(Writer)`
      
      Issue: SPR-13171
      693dcba8
  14. 27 6月, 2015 2 次提交
    • S
      Print cookies in human-readable form in Spring MVC Test · 895d43a2
      Sam Brannen 提交于
      Prior to this commit, when rendering cookies via `andDo(print())` in
      Spring MVC Test, the output for the `MockHttpServletResponse` would
      look something like the following:
      
        Cookies = [javax.servlet.http.Cookie@25084a1e]
      
      The reason is that the Cookie class in javax.servlet-api-3.0.1.jar does
      not implement toString(). Consequently, nothing about the cookie's
      name, value, etc., is displayed, thereby making the debug output for
      cookies next to useless.
      
      This commit improves on this by implementing custom toString() logic
      for cookies in debug output in Spring MVC Test. For example, the output
      now looks like this (without the newlines):
      
        Cookies = [[Cookie@47faa49c name = 'enigma', value = '42', \\
                  comment = [null], domain = [null], maxAge = -1, \\
                  path = [null], secure = false, version = 0, \\
                  httpOnly = false]]
      
      In addition, this commit fixes a minor bug for FlashMap debug output if
      the FlashMap is empty.
      
      Issue: SPR-13168
      895d43a2
    • J
      Allow MVC handler methods to return any CharSequence type as view name · a2d3c27e
      Juergen Hoeller 提交于
      Issue: SPR-13165
      a2d3c27e
  15. 24 6月, 2015 1 次提交
    • S
      Support inlined SQL statements in @Sql · 10a691bd
      Sam Brannen 提交于
      Prior to this commit, it was only possible to declare SQL statements
      via @Sql within external script resources (i.e., classpath or file
      system resources); however, many developers have inquired about the
      ability to inline SQL statements with @Sql analogous to the support for
      inlined properties in @TestPropertySource.
      
      This commit introduces support for declaring _inlined SQL statements_
      in `@Sql` via a new `statements` attribute. Inlined statements are
      executed after statements in scripts.
      
      Issue: SPR-13159
      10a691bd
  16. 19 6月, 2015 1 次提交
  17. 17 6月, 2015 1 次提交
    • B
      Improve charset management in XpathResultMatchers · f9881511
      Brian Clozel 提交于
      Prior to this change, `XpathResultMatchers` and more generally the
      `MockHttpServletResponse` would default to ISO-8859-1 encoding even when
      it's not supposed to. The Servlet/HTTP specs mention this encoding
      for all `text/*` mime types when decoding bodies to Strings, but this
      issue is about XML Parsers.
      
      XML Parsers should use the encoding:
      
      * defined in the `Content-Type` response header (if available)
      * written in the XML declaration of the document
      * "guessed" by a built-in auto-detection mechanism
      
      This commit changes the following:
      
      * XPathMatchers now feed the XML parser with byte arrays instead of
      decoded Strings
      * the response should be written to `MockHttpServletResponse` using
      its OutputStream, and not a PrintWriter which defaults to ISO-8859-1
      
      Issue: SPR-12676
      f9881511
  18. 15 6月, 2015 1 次提交
    • S
      Retain order of active profiles in the TCF · 68a70437
      Sam Brannen 提交于
      Ever since @ActiveProfiles was introduced, the declared active profiles
      for integration tests have been sorted in order to support unique cache
      key generation; however, there are use cases for which the original
      ordering should be retained.
      
      For example, Spring Boot's ConfigFileApplicationListener loads
      configuration files for active profiles in the order returned by
      Environment.getActiveProfiles(), with the assumption that the ordering
      matches the order in which the developer declared the active profiles.
      
      This commit maintains the uniqueness of active profiles declared via
      @ActiveProfiles but no longer sorts them.
      
      Issue: SPR-12492
      68a70437
  19. 13 6月, 2015 1 次提交
  20. 12 6月, 2015 1 次提交
    • S
      Proper support for Root WAC in Spring MVC Test · f6d2fe47
      Sam Brannen 提交于
      The modifications to DefaultMockMvcBuilder performed in conjunction
      with SPR-12553 introduced a breaking change: the WebApplicationContext
      supplied to DefaultMockMvcBuilder's constructor was *always* stored in
      the ServletContext as the root WebApplicationContext, overwriting a
      root WebApplicationContext that had been set by the user or by the
      Spring TestContext Framework (TCF) -- for example, in
      AbstractGenericWebContextLoader. Consequently, the changes in SPR-12553
      cause tests that use @ContextHierarchy to fail if web components rely
      on the correct WebApplicationContext being stored under the
      WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE key.
      
      This commit reverts the breaking changes introduced in SPR-12553: if
      the root WebApplicationContext has already been set in the
      ServletContext of the WebApplicationContext supplied to
      DefaultMockMvcBuilder, no action is taken.
      
      Furthermore, this commit introduces new code to address the initial
      intent of SPR-12553. Specifically, if the root WebApplicationContext
      has NOT been set in the ServletContext of the WebApplicationContext
      supplied to DefaultMockMvcBuilder, the application context hierarchy
      will be traversed in search of the root WebApplicationContext, and the
      root WebApplicationContext will then be stored under the
      ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE key.
      
      Issue: SPR-13075, SPR-12553
      f6d2fe47
  21. 11 6月, 2015 1 次提交
  22. 31 5月, 2015 1 次提交
  23. 29 5月, 2015 1 次提交
    • S
      Synthesize annotation from a map of attributes · e30c9b2e
      Sam Brannen 提交于
      Spring Framework 4.2 RC1 introduced support for synthesizing an
      annotation from an existing annotation in order to provide additional
      functionality above and beyond that provided by Java. Specifically,
      such synthesized annotations provide support for @AliasFor semantics.
      As luck would have it, the same principle can be used to synthesize an
      annotation from any map of attributes, and in particular, from an
      instance of AnnotationAttributes.
      
      The following highlight the major changes in this commit toward
      achieving this goal.
      
      - Introduced AnnotationAttributeExtractor abstraction and refactored
        SynthesizedAnnotationInvocationHandler to delegate to an
        AnnotationAttributeExtractor.
      
      - Extracted code from SynthesizedAnnotationInvocationHandler into new
        AbstractAliasAwareAnnotationAttributeExtractor and
        DefaultAnnotationAttributeExtractor implementation classes.
      
      - Introduced MapAnnotationAttributeExtractor for synthesizing an
        annotation that is backed by a map or AnnotationAttributes instance.
      
      - Introduced a variant of synthesizeAnnotation() in AnnotationUtils
        that accepts a map.
      
      - Introduced findAnnotation(*) methods in AnnotatedElementUtils that
        synthesize merged AnnotationAttributes back into an annotation of the
        target type.
      
      The following classes have been refactored to use the new support for
      synthesizing AnnotationAttributes back into an annotation.
      
      - ApplicationListenerMethodAdapter
      - TestAnnotationUtils
      - AbstractTestContextBootstrapper
      - ActiveProfilesUtils
      - ContextLoaderUtils
      - DefaultActiveProfilesResolver
      - DirtiesContextTestExecutionListener
      - TestPropertySourceAttributes
      - TestPropertySourceUtils
      - TransactionalTestExecutionListener
      - MetaAnnotationUtils
      - MvcUriComponentsBuilder
      - RequestMappingHandlerMapping
      
      In addition, this commit also includes changes to ensure that arrays
      returned by synthesized annotations are properly cloned first.
      
      Issue: SPR-13067
      e30c9b2e
  24. 22 5月, 2015 1 次提交
    • S
      Support annotation attribute aliases and overrides via @AliasFor · ca66e076
      Sam Brannen 提交于
      This commit introduces first-class support for aliases for annotation
      attributes. Specifically, this commit introduces a new @AliasFor
      annotation that can be used to declare a pair of aliased attributes
      within a single annotation or an alias from an attribute in a custom
      composed annotation to an attribute in a meta-annotation.
      
      To support @AliasFor within annotation instances, AnnotationUtils has
      been overhauled to "synthesize" any annotations returned by "get" and
      "find" searches. A SynthesizedAnnotation is an annotation that is
      wrapped in a JDK dynamic proxy which provides run-time support for
      @AliasFor semantics. SynthesizedAnnotationInvocationHandler is the
      actual handler behind the proxy.
      
      In addition, the contract for @AliasFor is fully validated, and an
      AnnotationConfigurationException is thrown in case invalid
      configuration is detected.
      
      For example, @ContextConfiguration from the spring-test module is now
      declared as follows:
      
          public @interface ContextConfiguration {
      
              @AliasFor(attribute = "locations")
              String[] value() default {};
      
              @AliasFor(attribute = "value")
              String[] locations() default {};
      
              // ...
          }
      
      The following annotations and their related support classes have been
      modified to use @AliasFor.
      
      - @ManagedResource
      - @ContextConfiguration
      - @ActiveProfiles
      - @TestExecutionListeners
      - @TestPropertySource
      - @Sql
      - @ControllerAdvice
      - @RequestMapping
      
      Similarly, support for AnnotationAttributes has been reworked to
      support @AliasFor as well. This allows for fine-grained control over
      exactly which attributes are overridden within an annotation hierarchy.
      In fact, it is now possible to declare an alias for the 'value'
      attribute of a meta-annotation.
      
      For example, given the revised declaration of @ContextConfiguration
      above, one can now develop a composed annotation with a custom
      attribute override as follows.
      
          @ContextConfiguration
          public @interface MyTestConfig {
      
              @AliasFor(
                 annotation = ContextConfiguration.class,
                 attribute = "locations"
              )
              String[] xmlFiles();
      
              // ...
          }
      
      Consequently, the following are functionally equivalent.
      
      - @MyTestConfig(xmlFiles = "test.xml")
      - @ContextConfiguration("test.xml")
      - @ContextConfiguration(locations = "test.xml").
      
      Issue: SPR-11512, SPR-11513
      ca66e076
  25. 19 5月, 2015 1 次提交
  26. 17 5月, 2015 3 次提交
    • S
      Introduce TestContextManager cache in SpringClassRule · 973582e7
      Sam Brannen 提交于
      In order to simplify configuration of the SpringMethodRule and to ensure
      that the correct TestContextManager is always retrieved for the
      currently executing test class, this commit introduces a static
      TestContextManager cache in SpringClassRule.
      
      In addition, since it is not foreseen that SpringClassRule and
      SpringMethodRule should be able to be subclassed, their internal methods
      are now private instead of protected.
      
      Issue: SPR-7731
      973582e7
    • S
      68322fc4
    • S
      Introduce JUnit Rule alternative to SpringJUnit4ClassRunner · d1b1c4f8
      Sam Brannen 提交于
      Since Spring Framework 2.5, support for integrating the Spring
      TestContext Framework (TCF) into JUnit 4 based tests has been provided
      via the SpringJUnit4ClassRunner, but this approach precludes the
      ability for tests to be run with alternative runners like JUnit's
      Parameterized or third-party runners such as the MockitoJUnitRunner.
      
      This commit remedies this situation by introducing @ClassRule and @Rule
      based alternatives to the SpringJUnit4ClassRunner. These rules are
      independent of any Runner and can therefore be combined with
      alternative runners.
      
      Due to the limitations of JUnit's implementation of rules, as of JUnit
      4.12 it is currently impossible to create a single rule that can be
      applied both at the class level and at the method level (with access to
      the test instance). Consequently, this commit introduces the following
      two rules that must be used together.
      
       - SpringClassRule: a JUnit TestRule that provides the class-level
         functionality of the TCF to JUnit-based tests
      
       - SpringMethodRule: a JUnit MethodRule that provides the
         instance-level and method-level functionality of the TCF to
         JUnit-based tests
      
      In addition, this commit also introduces the following new JUnit
      Statements for use with rules:
      
       - RunPrepareTestInstanceCallbacks
      
       - ProfileValueChecker
      
      Issue: SPR-7731
      d1b1c4f8
  27. 11 5月, 2015 1 次提交