Browse Source

Introduce dedicated 'cache' subpackage in the TCF

Since the ContextCache is now a published SPI, it and its collaborators
have been moved to a dedicated 'org.sfw.test.context.cache' subpackage.

Issue: SPR-12683
pull/783/head
Sam Brannen 10 years ago
parent
commit
5cbe4b948d
  1. 4
      spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java
  2. 7
      spring-test/src/main/java/org/springframework/test/context/CacheAwareContextLoaderDelegate.java
  3. 3
      spring-test/src/main/java/org/springframework/test/context/cache/ContextCache.java
  4. 3
      spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java
  5. 3
      spring-test/src/main/java/org/springframework/test/context/cache/DefaultContextCache.java
  6. 11
      spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java
  7. 5
      spring-test/src/test/java/org/springframework/test/context/MergedContextConfigurationTests.java
  8. 3
      spring-test/src/test/java/org/springframework/test/context/TestContextTestUtils.java
  9. 6
      spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTestNGTests.java
  10. 6
      spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTests.java
  11. 4
      spring-test/src/test/java/org/springframework/test/context/cache/ContextCacheTestUtils.java
  12. 12
      spring-test/src/test/java/org/springframework/test/context/cache/ContextCacheTests.java
  13. 8
      spring-test/src/test/java/org/springframework/test/context/cache/SpringRunnerContextCacheTests.java
  14. 7
      spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4TestSuite.java

4
spring-test/src/main/java/org/springframework/test/context/BootstrapUtils.java

@ -40,7 +40,7 @@ abstract class BootstrapUtils { @@ -40,7 +40,7 @@ abstract class BootstrapUtils {
private static final String DEFAULT_BOOTSTRAP_CONTEXT_CLASS_NAME = "org.springframework.test.context.support.DefaultBootstrapContext";
private static final String DEFAULT_CACHE_AWARE_CONTEXT_LOADER_DELEGATE_CLASS_NAME = "org.springframework.test.context.support.DefaultCacheAwareContextLoaderDelegate";
private static final String DEFAULT_CACHE_AWARE_CONTEXT_LOADER_DELEGATE_CLASS_NAME = "org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate";
private static final String DEFAULT_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME = "org.springframework.test.context.support.DefaultTestContextBootstrapper";
@ -55,7 +55,7 @@ abstract class BootstrapUtils { @@ -55,7 +55,7 @@ abstract class BootstrapUtils {
* Create the {@code BootstrapContext} for the specified {@linkplain Class test class}.
*
* <p>Uses reflection to create a {@link org.springframework.test.context.support.DefaultBootstrapContext}
* that uses a {@link org.springframework.test.context.support.DefaultCacheAwareContextLoaderDelegate}.
* that uses a {@link org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate}.
*
* @param testClass the test class for which the bootstrap context should be created
* @return a new {@code BootstrapContext}; never {@code null}

7
spring-test/src/main/java/org/springframework/test/context/CacheAwareContextLoaderDelegate.java

@ -23,8 +23,9 @@ import org.springframework.test.annotation.DirtiesContext.HierarchyMode; @@ -23,8 +23,9 @@ import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
/**
* A {@code CacheAwareContextLoaderDelegate} is responsible for {@linkplain
* #loadContext loading} and {@linkplain #closeContext closing} application
* contexts, interacting transparently with a {@link ContextCache} behind
* the scenes.
* contexts, interacting transparently with a
* {@link org.springframework.test.context.cache.ContextCache ContextCache}
* behind the scenes.
*
* <p>Note: {@code CacheAwareContextLoaderDelegate} does not extend the
* {@link ContextLoader} or {@link SmartContextLoader} interface.
@ -41,7 +42,7 @@ public interface CacheAwareContextLoaderDelegate { @@ -41,7 +42,7 @@ public interface CacheAwareContextLoaderDelegate {
* <p>If the context is present in the {@code ContextCache} it will simply
* be returned; otherwise, it will be loaded, stored in the cache, and returned.
* <p>The cache statistics should be logged by invoking
* {@link ContextCache#logStatistics()}.
* {@link org.springframework.test.context.cache.ContextCache#logStatistics()}.
* @param mergedContextConfiguration the merged context configuration to use
* to load the application context; never {@code null}
* @return the application context

3
spring-test/src/main/java/org/springframework/test/context/ContextCache.java → spring-test/src/main/java/org/springframework/test/context/cache/ContextCache.java vendored

@ -14,10 +14,11 @@ @@ -14,10 +14,11 @@
* limitations under the License.
*/
package org.springframework.test.context;
package org.springframework.test.context.cache;
import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
import org.springframework.test.context.MergedContextConfiguration;
/**
* {@code ContextCache} defines the SPI for caching Spring

3
spring-test/src/main/java/org/springframework/test/context/support/DefaultCacheAwareContextLoaderDelegate.java → spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java vendored

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.test.context.support;
package org.springframework.test.context.cache;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -22,7 +22,6 @@ import org.apache.commons.logging.LogFactory; @@ -22,7 +22,6 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
import org.springframework.test.context.CacheAwareContextLoaderDelegate;
import org.springframework.test.context.ContextCache;
import org.springframework.test.context.ContextLoader;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.SmartContextLoader;

3
spring-test/src/main/java/org/springframework/test/context/support/DefaultContextCache.java → spring-test/src/main/java/org/springframework/test/context/cache/DefaultContextCache.java vendored

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.test.context.support;
package org.springframework.test.context.cache;
import java.util.ArrayList;
import java.util.HashSet;
@ -31,7 +31,6 @@ import org.springframework.context.ApplicationContext; @@ -31,7 +31,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.style.ToStringCreator;
import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
import org.springframework.test.context.ContextCache;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.util.Assert;

11
spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java

@ -38,7 +38,6 @@ import org.springframework.core.annotation.AnnotationUtils; @@ -38,7 +38,6 @@ import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.test.context.BootstrapContext;
import org.springframework.test.context.CacheAwareContextLoaderDelegate;
import org.springframework.test.context.ContextCache;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextConfigurationAttributes;
import org.springframework.test.context.ContextHierarchy;
@ -68,8 +67,9 @@ import org.springframework.util.StringUtils; @@ -68,8 +67,9 @@ import org.springframework.util.StringUtils;
* <li>{@link #processMergedContextConfiguration}
* </ul>
*
* <p>To plug in custom {@link ContextCache} support, override
* {@link #getCacheAwareContextLoaderDelegate()}.
* <p>To plug in custom
* {@link org.springframework.test.context.cache.ContextCache ContextCache}
* support, override {@link #getCacheAwareContextLoaderDelegate()}.
*
* @author Sam Brannen
* @author Juergen Hoeller
@ -481,8 +481,9 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot @@ -481,8 +481,9 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
* <p>The default implementation simply delegates to
* {@code getBootstrapContext().getCacheAwareContextLoaderDelegate()}.
* <p>Concrete subclasses may choose to override this method to return a
* custom {@code CacheAwareContextLoaderDelegate} implementation with
* custom {@link ContextCache} support.
* custom {@code CacheAwareContextLoaderDelegate} implementation with custom
* {@link org.springframework.test.context.cache.ContextCache ContextCache}
* support.
* @return the context loader delegate (never {@code null})
*/
protected CacheAwareContextLoaderDelegate getCacheAwareContextLoaderDelegate() {

5
spring-test/src/test/java/org/springframework/test/context/MergedContextConfigurationTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,7 +33,8 @@ import static org.junit.Assert.*; @@ -33,7 +33,8 @@ import static org.junit.Assert.*;
* Unit tests for {@link MergedContextConfiguration}.
*
* <p>These tests primarily exist to ensure that {@code MergedContextConfiguration}
* can safely be used as the cache key for {@link ContextCache}.
* can safely be used as the cache key for
* {@link org.springframework.test.context.cache.ContextCache ContextCache}.
*
* @author Sam Brannen
* @since 3.1

3
spring-test/src/test/java/org/springframework/test/context/TestContextTestUtils.java

@ -16,8 +16,9 @@ @@ -16,8 +16,9 @@
package org.springframework.test.context;
import org.springframework.test.context.cache.ContextCache;
import org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate;
import org.springframework.test.context.support.DefaultBootstrapContext;
import org.springframework.test.context.support.DefaultCacheAwareContextLoaderDelegate;
/**
* Collection of test-related utility methods for working with {@link TestContext TestContexts}.

6
spring-test/src/test/java/org/springframework/test/context/ClassLevelDirtiesContextTestNGTests.java → spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTestNGTests.java vendored

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.test.context;
package org.springframework.test.context.cache;
import java.util.concurrent.atomic.AtomicInteger;
@ -29,6 +29,8 @@ import org.springframework.context.ApplicationContext; @@ -29,6 +29,8 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
@ -37,7 +39,7 @@ import org.springframework.test.context.testng.TrackingTestNGTestListener; @@ -37,7 +39,7 @@ import org.springframework.test.context.testng.TrackingTestNGTestListener;
import org.testng.TestNG;
import static org.junit.Assert.*;
import static org.springframework.test.context.support.ContextCacheTestUtils.*;
import static org.springframework.test.context.cache.ContextCacheTestUtils.*;
/**
* JUnit 4 based integration test which verifies correct {@linkplain ContextCache

6
spring-test/src/test/java/org/springframework/test/context/ClassLevelDirtiesContextTests.java → spring-test/src/test/java/org/springframework/test/context/cache/ClassLevelDirtiesContextTests.java vendored

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.test.context;
package org.springframework.test.context.cache;
import java.util.concurrent.atomic.AtomicInteger;
@ -30,13 +30,15 @@ import org.springframework.context.ApplicationContext; @@ -30,13 +30,15 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.TrackingRunListener;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
import static org.junit.Assert.*;
import static org.springframework.test.context.support.ContextCacheTestUtils.*;
import static org.springframework.test.context.cache.ContextCacheTestUtils.*;
/**
* JUnit 4 based integration test which verifies correct {@linkplain ContextCache

4
spring-test/src/test/java/org/springframework/test/context/support/ContextCacheTestUtils.java → spring-test/src/test/java/org/springframework/test/context/cache/ContextCacheTestUtils.java vendored

@ -14,9 +14,7 @@ @@ -14,9 +14,7 @@
* limitations under the License.
*/
package org.springframework.test.context.support;
import org.springframework.test.context.ContextCache;
package org.springframework.test.context.cache;
import static org.junit.Assert.*;

12
spring-test/src/test/java/org/springframework/test/context/ContextCacheTests.java → spring-test/src/test/java/org/springframework/test/context/cache/ContextCacheTests.java vendored

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.test.context;
package org.springframework.test.context.cache;
import org.junit.Before;
import org.junit.Test;
@ -22,12 +22,18 @@ import org.junit.Test; @@ -22,12 +22,18 @@ import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ActiveProfilesResolver;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.TestContextTestUtils;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import org.springframework.test.context.support.DefaultContextCache;
import org.springframework.test.util.ReflectionTestUtils;
import static org.junit.Assert.*;
import static org.springframework.test.context.support.ContextCacheTestUtils.*;
import static org.springframework.test.context.cache.ContextCacheTestUtils.*;
/**
* Integration tests for verifying proper behavior of the {@link ContextCache} in

8
spring-test/src/test/java/org/springframework/test/context/SpringRunnerContextCacheTests.java → spring-test/src/test/java/org/springframework/test/context/cache/SpringRunnerContextCacheTests.java vendored

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.test.context;
package org.springframework.test.context.cache;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@ -26,12 +26,14 @@ import org.junit.runners.MethodSorters; @@ -26,12 +26,14 @@ import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
import static org.junit.Assert.*;
import static org.springframework.test.context.support.ContextCacheTestUtils.*;
import static org.springframework.test.context.cache.ContextCacheTestUtils.*;
/**
* JUnit 4 based unit test which verifies correct {@link ContextCache
@ -47,7 +49,7 @@ import static org.springframework.test.context.support.ContextCacheTestUtils.*; @@ -47,7 +49,7 @@ import static org.springframework.test.context.support.ContextCacheTestUtils.*;
@RunWith(SpringJUnit4ClassRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class })
@ContextConfiguration("junit4/SpringJUnit4ClassRunnerAppCtxTests-context.xml")
@ContextConfiguration("../junit4/SpringJUnit4ClassRunnerAppCtxTests-context.xml")
public class SpringRunnerContextCacheTests {
private static ApplicationContext dirtiedApplicationContext;

7
spring-test/src/test/java/org/springframework/test/context/junit4/SpringJUnit4TestSuite.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,9 +19,8 @@ package org.springframework.test.context.junit4; @@ -19,9 +19,8 @@ package org.springframework.test.context.junit4;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.springframework.test.context.ClassLevelDirtiesContextTests;
import org.springframework.test.context.SpringRunnerContextCacheTests;
import org.springframework.test.context.cache.ClassLevelDirtiesContextTests;
import org.springframework.test.context.cache.SpringRunnerContextCacheTests;
import org.springframework.test.context.junit4.annotation.AnnotationConfigSpringJUnit4ClassRunnerAppCtxTests;
import org.springframework.test.context.junit4.annotation.BeanOverridingDefaultConfigClassesInheritedTests;
import org.springframework.test.context.junit4.annotation.BeanOverridingExplicitConfigClassesInheritedTests;

Loading…
Cancel
Save