1. 22 3月, 2019 1 次提交
  2. 23 8月, 2017 1 次提交
  3. 12 3月, 2016 2 次提交
    • S
      Polish ContextCustomizer support in the TCF · cbd1342f
      Sam Brannen 提交于
      Issue: SPR-13998
      cbd1342f
    • P
      Introduce ContextCustomizer API in the TestContext Framework · 87a3a5cb
      Phillip Webb 提交于
      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
      87a3a5cb
  4. 09 3月, 2016 1 次提交
    • P
      Allow @ContextConfiguration to be omitted · 22444617
      Phillip Webb 提交于
      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
      22444617
  5. 21 10月, 2014 1 次提交
  6. 17 7月, 2014 3 次提交
  7. 04 7月, 2014 1 次提交
  8. 06 6月, 2014 1 次提交
    • S
      Introduce annotation to execute SQL scripts in the TCF · 5fd6ebb5
      Sam Brannen 提交于
      Prior to this commit, it was possible to execute SQL scripts
      programmatically via ResourceDatabasePopulator, JdbcTestUtils, and
      ScriptUtils. Furthermore, it was also possible to execute SQL scripts
      declaratively via the <jdbc> XML namespace. However, it was not
      possible to execute SQL scripts declaratively on a per test class or
      per test method basis.
      
      This commit makes it possible to declaratively configure SQL scripts
      for execution in integration tests via annotations that can be declared
      at the class or method level. Details follow.
      
       - Introduced a repeatable @DatabaseInitializer annotation that can be
         used to configure SQL scripts at the class or method level with
         method-level overrides. @DatabaseInitializers serves as a container
         for @DatabaseInitializer.
      
       - Introduced a new DatabaseInitializerTestExecutionListener that is
         responsible for parsing @DatabaseInitializer and
         @DatabaseInitializers and executing SQL scripts.
      
       - DatabaseInitializerTestExecutionListener is registered by default in
         abstract base test classes as well as in TestContextBootstrapper
         implementations.
      
       - @DatabaseInitializer and @DatabaseInitializers may be used as
         meta-annotations; however, attribute overrides are not currently
         supported for repeatable annotations used as meta-annotations. This
         is a known limitation of Spring's AnnotationUtils.
      
       - The semantics for locating SQL script resources is consistent with
         @ContextConfiguration's semantics for locating XML configuration
         files. In addition, a default SQL script can be detected based
         either on the name of the annotated class or on the name of the
         annotated test method.
      
       - @DatabaseInitializer allows for specifying which DataSource and
         PlatformTransactionManager to use from the test's
         ApplicationContext, including default conventions consistent with
         TransactionalTestExecutionListener and @TransactionConfiguration.
      
       - @DatabaseInitializer supports all of the script configuration options
         currently supported by ResourceDatabasePopulator.
      
       - @DatabaseInitializer and DatabaseInitializerTestExecutionListener
         support execution phases for scripts that dictate when SQL scripts
         are executed (i.e., before or after a test method).
      
       - SQL scripts can be executed within the current test's transaction if
         present, outside of the current test's transaction if present, or
         always in a new transaction, depending on the value of the boolean
         requireNewTransaction flag in @DatabaseInitializer.
      
       - DatabaseInitializerTestExecutionListener delegates to
         ResourceDatabasePopulator#execute to actually execute the scripts.
      
      Issue: SPR-7655
      5fd6ebb5
  9. 10 4月, 2014 1 次提交
    • S
      Introduce context bootstrap strategy in the TCF · a281bdbf
      Sam Brannen 提交于
      Work done in conjunction with SPR-5243 and SPR-4588 introduced physical
      package cycles in the spring-test module. The work performed in
      conjunction with SPR-9924 uses reflection to resolve these physical
      package cycles; however, prior to this commit the logical package
      cycles still remain.
      
      Furthermore, over time it has become apparent that the Spring
      TestContext Framework (TCF) could better serve application developers
      and especially third-party framework developers by providing a more
      flexible mechanism for "bootstrapping" the TCF. For example, prior to
      this commit, default TestExecutionListeners could only be registered by
      subclassing TestContextManager (and SpringJUnit4ClassRunner if using
      JUnit). Similarly, the default ContextLoader could only be set by
      subclassing SpringJUnit4ClassRunner for JUnit and by copying and
      modifying AbstractTestNGSpringContextTests for TestNG.
      
      This commit addresses the aforementioned issues by introducing a
      bootstrap strategy in the TestContext framework that is responsible for
      determining default TestExecutionListeners and the default
      ContextLoader in an extensible fashion. The new TestContextBootstrapper
      SPI also provides a mechanism for supporting various types of
      MergedContextConfiguration depending on the feature set of the context
      loaders supported by the strategy.
      
      The following provides an overview of the most significant changes in
      this commit.
      
       - Introduced TestContextBootstrapper strategy SPI, BootstrapContext,
         and @BootstrapWith.
      
       - Introduced AbstractTestContextBootstrapper,
         DefaultTestContextBootstrapper, and WebTestContextBootstrapper
         implementations of the TestContextBootstrapper SPI and extracted
         related reflection code from ContextLoaderUtils & TestContextManager.
      
       - Introduced BootstrapUtils for retrieving the TestContextBootstrapper
         from @BootstrapWith, falling back to a default if @BootstrapWith is
         not present.
      
       - @WebAppConfiguration is now annotated with
         @BootstrapWith(WebTestContextBootstrapper.class).
      
       - CacheAwareContextLoaderDelegate is now an interface with a new
         DefaultCacheAwareContextLoaderDelegate implementation class.
      
       - Introduced closeContext(MergedContextConfiguration, HierarchyMode) in
         CacheAwareContextLoaderDelegate.
      
       - DefaultTestContext now uses CacheAwareContextLoaderDelegate instead
         of interacting directly with the ContextCache.
      
       - DefaultTestContext now delegates to a TestContextBootstrapper for
         building the MergedContextConfiguration.
      
       - TestContextManager now delegates to TestContextBootstrapper for
         retrieving TestExecutionListeners.
      
       - Deleted TestContextManager(Class, String) constructor and
         SpringJUnit4ClassRunner.getDefaultContextLoaderClassName(Class)
         method since default ContextLoader support is now implemented by
         TestContextBootstrappers.
      
       - Extracted ActiveProfilesUtils from ContextLoaderUtils.
      
       - Extracted ApplicationContextInitializerUtils from ContextLoaderUtils.
      
       - MetaAnnotationUtils is now a public utility class in the test.util
         package.
      
       - Removed restriction in @ActiveProfiles that a custom resolver cannot
         be used with the 'value' or 'profiles' attributes.
      
       - Introduced DefaultActiveProfilesResolver.
      
      Issue: SPR-9955
      a281bdbf
  10. 28 10月, 2013 1 次提交
    • S
      Provide meta-annotation support in the TCF · 5e7021f3
      Sam Brannen 提交于
      Spring 3.0 already allows component stereotypes to be used in a
      meta-annotation fashion, for example by creating a custom
      @TransactionalService stereotype annotation which combines
      @Transactional and @Service in a single, reusable, application-specific
      annotation. However, the Spring TestContext Framework (TCF) currently
      does not provide any support for test-related annotations to be used as
      meta-annotations.
      
      This commit overhauls the TCF with regard to how annotations are
      retrieved and adds explicit support for the following annotations to be
      used as meta-annotations in conjunction with the TCF.
      
      - @ContextConfiguration
      - @ContextHierarchy
      - @ActiveProfiles
      - @DirtiesContext
      - @IfProfileValue
      - @ProfileValueSourceConfiguration
      - @BeforeTransaction
      - @AfterTransaction
      - @TransactionConfiguration
      - @Rollback
      - @TestExecutionListeners
      - @Repeat
      - @Timed
      - @WebAppConfiguration
      
      Note that meta-annotation support for @Transactional was already
      available prior to this commit.
      
      The following is a summary of the major changes included in this commit.
      
      - Now using AnnotationUtils.getAnnotation() instead of
        Class.getAnnotation() where appropriate in the TestContext Framework.
      - Now using AnnotationUtils.findAnnotation() instead of
        Class.isAnnotationPresent() where appropriate in the TestContext
        Framework.
      - Introduced findAnnotationPrefersInteracesOverLocalMetaAnnotations() in
        AnnotationUtilsTests in order to verify the status quo.
      - AnnotationUtils.findAnnotationDeclaringClass() and
        AnnotationUtils.findAnnotationDeclaringClassForTypes() now support
        meta annotations.
      - Introduced MetaAnnotationUtils and AnnotationDescriptor in the
        spring-test module.
      - Introduced UntypedAnnotationDescriptor in MetaAnnotationUtils.
      - Introduced findAnnotationDescriptorForTypes() in MetaAnnotationUtils.
      - ContextLoaderUtils now uses MetaAnnotationUtils for looking up
        @ActiveProfiles as a potential meta-annotation.
      - TestContextManager now uses MetaAnnotationUtils for looking up
        @TestExecutionListeners as a potential meta-annotation.
      - DirtiesContextTestExecutionListener now uses AnnotationUtils for
        looking up @DirtiesContext as a potential meta-annotation.
      - Introduced DirtiesContextTestExecutionListenerTests.
      - ProfileValueUtils now uses AnnotationUtils for looking up
        @IfProfileValue and @ProfileValueSourceConfiguration as potential
        meta-annotations.
      - @BeforeTransaction and @AfterTransaction now support ANNOTATION_TYPE
        as a target, allowing them to be used as meta-annotations.
      - TransactionalTestExecutionListener now uses AnnotationUtils for
        looking up @BeforeTransaction, @AfterTransaction, @Rollback, and
        @TransactionConfiguration as potential meta-annotations.
      - Introduced TransactionalTestExecutionListenerTests.
      - @Repeat and @Timed now support ANNOTATION_TYPE as a target, allowing
        them to be used as meta-annotations.
      - SpringJUnit4ClassRunner now uses AnnotationUtils for looking up
        @Repeat and @Timed as potential meta-annotations.
      - Moved all remaining logic for building the MergedContextConfiguration
        from the DefaultTestContext constructor to
        ContextLoaderUtils.buildMergedContextConfiguration().
      - Verified meta-annotation support for @WebAppConfiguration and
        @ContextConfiguration.
      
      Issue: SPR-7827
      5e7021f3
  11. 16 6月, 2013 1 次提交
    • S
      Reduce complexity in ContextLoaderUtilsTests · 432f899b
      Sam Brannen 提交于
      This commit refactors ContextLoaderUtilsTests into
      AbstractContextLoaderUtilsTests and several specialized subclasses in
      order to reduce to the growing complexity of ContextLoaderUtilsTests.
      432f899b